【问题标题】:SWT JFace: SelectionProvider not working in TabFolderSWT JFace:SelectionProvider 在 TabFolder 中不起作用
【发布时间】:2011-11-25 07:47:36
【问题描述】:

在 GraphicalEditor 中,我创建了一个选项卡文件夹:

private final String[] tabNames = { "Text", "Image" };

private ResourcesTextComposite comText;

private ResourcesImageComposite comImage;

...

public void createPartControl(Composite parent) {
    ...
    tabFolder = new TabFolder(parent, SWT.BORDER);
    for (int loopIndex = 0; loopIndex < tabNames.length; loopIndex++) {
        TabItem tabItem = new TabItem(tabFolder, SWT.NULL);
        tabItem.setText(tabNames[loopIndex]);

        if (loopIndex == 0) {
            comText = new ResourcesTextComposite(tabFolder, SWT.NONE,
                    resources);
            tabItem.setControl(comText);
        } else if (loopIndex == 1) {
            comImage = new ResourcesImageComposite(tabFolder, SWT.NONE,
                    resources);
            tabItem.setControl(comImage);
        }
    }
    ...
}

它有2个tab item,每个item里面都有一个composite,每个composite都有一个TableViewer。

当用户选择相应的选项卡项时,我尝试让每个 TableViewer 成为选择提供者(编辑器的相同函数 createPartControl):

public void createPartControl(Composite parent) {
    ...
    tabFolder.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            int tabIdx = tabFolder.getSelectionIndex();
            getSite().setSelectionProvider(null);
            if (tabIdx == 0) {
                getSite().setSelectionProvider(comText.getViewer());
            } else if (tabIdx == 1) {
                getSite().setSelectionProvider(comImage.getViewer());
            }
            System.out.println("widgetSelected" + getSite() + ": "
                    + getSite().getSelectionProvider());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    ...
}

我希望当我在 TableViewer 中选择一行时,Properties 视图将显示所选模型的属性,我已经完成了那些 IPropertySource 的事情并且它们在没有选项卡文件夹的其他编辑器中运行良好,所以我认为问题应该位于选择提供程序区域中。

有什么想法或有人遇到过同样的问题吗?

【问题讨论】:

    标签: tabs swt selection jface


    【解决方案1】:

    如果您在视图或编辑器中有多个选择提供程序,那么您需要使用像 org.eclipse.jdt.internal.ui.viewsupport.SelectionProviderMediator 这样的中介。请注意,不幸的是它是内部的,因此您需要将其复制到您自己的项目中

    【讨论】:

    • 我认为在给定的时间,我希望只有一个 TableViewer 可以工作,所以如果可能的话,使用 setSelectionProvider 只设置一个查看器就足够了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多