2013-05-08 35 views
0

我学会了如何编写一个基于SWT的应用程序,遵循tutorial。但是,我不知道如何前进到一个GUI eclipse插件。如何在Eclipse插件中编写基于SWT的GUI?

我正在编写的插件是右键单击Package Explorer中的任何IJavaElement节点,它将显示一个更多的动作,该动作将弹出一个GUI对话框,让我填写一些值并将结果保存到我的数据库。

现在我的问题是:

  • 我可以写一个独立的基于SWT GUI应用程序,但我不知道如何把下面的代码片段在public void run(IAction action)

    Display display = new Display(); 
    Shell shell = new Shell(display); 
    
    shell.setLayout(new GridLayout()); 
    shell.open(); 
    
    while (!shell.isDisposed()) { 
        if (!display.readAndDispatch()) 
         display.sleep(); 
    } 
    display.dispose(); 
    

    我发现的所有SWT教程都是在主界面中创建Shell,Display,但看起来应该在Eclipse插件中做不同的处理。在开发Eclipse插件时,我必须使用JFace创建Dialog吗?

  • 没有在plugin.xml依赖关系中添加org.eclipse.swt(.cocoa.macosx.x86_64.source),只有在右键单击IJavaElement时,我才能显示该操作。但是,当我尝试运行行动,日食会显示

    Problem Occurred 
    Unhandled event loop exception 
    Not implemented [multiple displays] 
    

    我想这是因为我新的更Display。但是,如果我将org.eclipse.swt(.cocoa.macosx.x86_64.source)添加到plugin.xml依赖项中,我的操作甚至不会显示在弹出菜单中。

回答

3

您的代码正在创建一个新的显示 - 创建Eclipse插件时不应该这样做。 Eclipse已经有显示和事件循环运行。

尝试把眼前这个代码在动作:

Shell shell = new Shell(Display.getCurrent()); 

shell.setLayout(new GridLayout()); 
shell.open(); 
相关问题