Viewpart中带有JFace的自定义Eclipse RAP对话框



我有一个扩展ViewPart的类"View"。在课堂上,我想展示一个对话框,其中包含两个标签。

首先,我使用了这样的"InputDialog":

        Composite composite = new Composite(top, SWT.NONE);
    Label label= new Label(tmpComposite, SWT.NONE);
    label.setText("");
    InputDialog dlg;
        dlg = new InputDialog(Display.getCurrent().getActiveShell(),
                "Title", "Some Text", label.getText(), insertValidator());
    if (dlg.open() == Window.OK) {
        //Do sth.                   
    }

这是有效的。但现在我有两个标签。我怎么能意识到呢?我找到了一些解决方案,但它们都不能在ViewPart或EclipseRCP中使用。

谢谢你的帮助!

顺便说一句,如果你的解决方案是从我的"View"调用一个java类,我如何才能回到"View",如何才能看到我的新对话框?试过了,没用。

您需要通过扩展org.eclipse.jface.dialogs.Dialog:来创建一个自定义对话框

public class MyDialog extends Dialog 
{
  public MyDialog(Shell parentShell)
  {
    super(parentShell);
  }
  @Override
  protected Control createDialogArea(Composite parent) 
  {
    Composite container = (Composite)super.createDialogArea(parent);
    // Add your controls here
    return container;
  }
}

使用此方法的方式与InputDialog 类似

MyDialog dialog = new MyDialog(shell);
dialog.open();

看看http://www.vogella.com/articles/EclipseDialogs/article.html了解更多详细信息。

最新更新