繁体   English   中英

Eclipse RCP中ContainerSelectionDialog内的JFace选项卡

[英]JFace Tabs inside ContainerSelectionDialog in Eclipse RCP

我在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();
// ...

如何在此对话框中添加标签?

最好的办法是在选择树下添加控件。 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;
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM