【问题标题】:JFace Tabs inside ContainerSelectionDialog in Eclipse RCPEclipse RCP 中 ContainerSelectionDialog 内的 JFace 选项卡
【发布时间】:2015-05-28 08:12:37
【问题描述】:

我在我的 Eclipse RCP 应用程序中使用ContainerSelectionDialog。我现在想在对话框中添加标签,里面有一些额外的东西。

这就是我的ContainerSelectionDialog 的样子:

// ...
ContainerSelectionDialog dialog = new ContainerSelectionDialog(
        Display.getDefault().getActiveShell(), c, true,
        "Please select target folder");
int open = dialog.open();
if (!(open == org.eclipse.jface.window.Window.OK))
    return null;
Object[] result = dialog.getResult();

IPath path = (IPath) result[0];
targetFolder = ResourcesPlugin.getWorkspace().getRoot()
        .findMember(path);
containerPath = targetFolder.getLocation().toPortableString();
// ...

如何向此对话框添加选项卡?

【问题讨论】:

  • 我认为你可以用这个对话框做的最好的事情是在树下面添加额外的控件。
  • 你能举个例子吗?

标签: java dialog swt eclipse-rcp jface


【解决方案1】:

您可以做的最好的事情是在选择树下方添加控件。 ContainerSelectionDialog 中的一个错误甚至使这变得困难。此代码显示了如何执行此操作并解决该错误:

public class MyContainerSelectionDialog extends ContainerSelectionDialog
{
  public MyContainerSelectionDialog(final Shell parentShell, final IContainer initialRoot, final boolean allowNewContainerName, final String message)
  {
    super(parentShell, initialRoot, allowNewContainerName, message);
  }

  @Override
  protected Control createDialogArea(final Composite parent)
  {
    Composite body = (Composite)super.createDialogArea(parent);

    // Bug in ContainerSelectionDialog is returning null for the body!

    if (body == null)
     {
       // body is the last control added to the parent

       final Control [] children = parent.getChildren();

       if (children[children.length - 1] instanceof Composite)
         body = (Composite)children[children.length - 1];
     }

    // TODO add your controls here, this example just adds a Label

    final Label label = new Label(body, SWT.NONE);
    label.setText("My label");

    return body;
  }
}

【讨论】:

  • 是否可以将ContainerSelectionDialog 作为子元素添加到一种选项卡式对话框中,以便ContainerSelectionDialog 是许多选项卡之一的内容?我找不到允许我定义选项卡式对话框的元素...
  • 不是真的,它被设计成一个独立的对话框。
  • 哦,我明白了。有什么可能实现这样一个带有ContainerSelectionDialog 的选项卡式对话框作为其中一个选项卡的内容?
  • 这个对话框中的大部分工作都是在ContainerSelectionGroup 类中完成的,可以在选项卡中使用,但是这是一个内部类并在您的代码中使用它会破坏Eclipse API Rules of Engagement。这个类相当小,所以你可以编写自己的版本。
猜你喜欢
  • 2013-10-31
  • 2010-12-03
  • 2011-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-12
  • 1970-01-01
相关资源
最近更新 更多