【问题标题】:Eclipse Plugin: Opening A New Window From The WorkBenchEclipse 插件:从 WorkBench 打开一个新窗口
【发布时间】:2018-04-29 23:04:57
【问题描述】:

我是开发 Eclipse 插件的新手,我已经做了很多工作。这就是我卡住的地方。我有一个带有按钮的视图。当用户点击按钮时,我希望打开一个新窗口(该窗口是一个带有文本区域、按钮和其他 SWT 小部件的表单)。我已经完成了窗口的创建。

编译应用程序后,我得到了一个新的 eclipse 工作台实例(如预期的那样),但是当我打开视图并单击按钮时,窗口不显示。这是窗口代码sn -p:

public class NewWindow {
    private Display display;
    private Shell shell;

    public NewWindow(){

        this.display = new Display();
    shell = new Shell(displaySWT.TITLE | SWT.MIN | SWT.CLOSE);
    shell.setText("fffffffffffff");

              // additional code here
               ...
               ...

    shell.open();
    this.shellSleep();  // this methode is implemented in my code
}

这是调用这个类的代码sn-p:

... ...

this.btnCreateNewQuery.addSelectionListener(new SelectionListener(){
            public void widgetDefaultSelected(SelectionEvent e){

            }
            public void widgetSelected(SelectionEvent e){                                   NewWindow b = new NewWindow();

        }
    });

... ...

我不明白为什么窗口不显示。我试图修复它,但还没有找到任何东西。我在这个网站上读过一些东西,但我不明白它们的意思。这是链接: How do I get the workbench window to open a modal dialog in an Eclipse based project?

【问题讨论】:

    标签: eclipse-plugin swt eclipse-rcp


    【解决方案1】:

    Eddy,这很容易解决。只是不要创建一个新的显示。重用工作台中的那个:

    public NewWindow() {
            this.display = PlatformUI.getWorkbench().getDisplay();
            shell = new Shell(display, SWT.TITLE | SWT.MIN | SWT.CLOSE);
            shell.setText("fffffffffffff");
    
                  // additional code here
                   ...
                   ...
    
            shell.open();
            this.shellSleep();  // this methode is implemented in my code
    }
    

    您也可以关闭显示变量并将 null 传递给 Shell 构造函数。

    【讨论】:

      【解决方案2】:

      我认为您不想创建新的 Shell。而是将父 Shell 传递给您的新类。我发现为新窗口扩展 Dialog 类(或 Dialog 本身)更容易。然后在您的构造函数中,您可以调用 super(Shell parent) 为您初始化所有环境/GUI 内容,然后您可以按照您想要的方式布局对话框区域。然后打开新窗口,您执行 dialog.open()。

      【讨论】:

      • 我看不懂上面的说法。能否请您详细说明一下,可能有代码sn-p
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      相关资源
      最近更新 更多