【问题标题】:how to open a wizardpage using a toolbar button in eclipse?如何使用 Eclipse 中的工具栏按钮打开向导页面?
【发布时间】:2012-02-07 08:41:32
【问题描述】:

我正在做一个 GUI 项目,它由一个向导和一个 向导页面。向导页面是使用 eclipse 插件创建的 "org.eclipse.jface.wizard.WizardPage" 我可以使用带有 Eclipse 插件的工具栏按钮打开向导 “org.eclipse.jface.wizard.WizardDialog” 但我无法使用相同的插件打开向导页面。

还有其他插件吗 向导页面。谁能帮我做这件事?

【问题讨论】:

  • 你的意思是向导对话框打开了,但是里面什么都没有?您应该发布一些向导的相关代码,以便我们为您提供帮助。
  • @Baldrick 我有两个向导,后跟一个向导页面,我可以打开向导。我应该可以直接打开向导页面。你想给我发什么代码?要么用于创建向导页面的代码还是从工具栏按钮打开向导页面的代码?
  • 对不起,我不明白你想做什么。向导页面在向导内部,而不是在向导之后。也许看看这些教程,你会找到一些帮助:vogella.de/articles/EclipseWizards/article.htmleclipse.org/articles/article.php?file=Article-JFaceWizards/…
  • @Baldrick 我必须在按下工具栏中的按钮时打开向导页面?
  • @Baldrick 我浏览了这些教程,但我没有得到问题的解决方案。有两个向导,后面跟着一个向导页面。我需要直接访问向导页面而不通过向导吗?我应该为向导页面创建一个对话框页面以直接访问吗?

标签: java eclipse eclipse-plugin


【解决方案1】:

您不能转到特定的向导页面,除非它是向导的第一页。

要打开特定的向导 - 而不是“向导选择器” - 然后将 newWizardId 参数添加到菜单定义...

<extension point="org.eclipse.ui.menus">
   <menuContribution
         allPopups="false"
         locationURI="menu:org.eclipse.ui.main.toolbar">
      <toolbar id="id.of..toolbar">
         <command commandId="org.eclipse.ui.newWizard">
            <parameter name="newWizardId" value="id.of.wizard" />
         </command>
      </toolbar>
   </menuContribution>
</extension>

【讨论】:

  • 所以我应该再创建一个向导页面,它是第一页。然后如果我将它创建为第一页,如何使用工具栏按钮打开它。
【解决方案2】:

在处理程序类(扩展 org.eclipse.core.commands.AbstractHandler)中的覆盖 execute 方法中,尝试以下代码:

    IWizard wizard = new YourWizard();
    WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
    dialog.open();

;-)

【讨论】:

    【解决方案3】:

    你可以这样做:

     public  void openWizard(String id) {
     // First see if this is a "new wizard".
     IWizardDescriptor descriptor = PlatformUI.getWorkbench()
       .getNewWizardRegistry().findWizard(id);
     // If not check if it is an "import wizard".
     if  (descriptor == null) {
       descriptor = PlatformUI.getWorkbench().getImportWizardRegistry()
       .findWizard(id);
     }
     // Or maybe an export wizard
     if  (descriptor == null) {
       descriptor = PlatformUI.getWorkbench().getExportWizardRegistry()
       .findWizard(id);
     }
     try  {
       // Then if we have a wizard, open it.
       if  (descriptor != null) {
         **IWizard wizard = descriptor.createWizard();**   
                                     **//here you can set the first show page**
    
         WizardDialog wd = new  WizardDialog(getStandardDisplay()
           .getActiveShell(), wizard);
         wd.setTitle(wizard.getWindowTitle());
         wd.open();
       }
     } catch  (CoreException e) {
       e.printStackTrace();
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多