2016-05-30 36 views
1

我正在尝试编写一个供个人使用的eclipse插件。它应该像这样简单:下拉列表应该在工具栏中有3个项目(item1,item2,item3),它们是切换按钮。切换每个按钮时,环境变量或构建变量应该取对应的值。为什么不调用eclipse插件处理程序?

我的问题是没有调用切换按钮的处理程序。

为了实现这一点,我写了下面的到现在为止:

的plugin.xml

<extension point="org.eclipse.ui.commands"> 
     <category 
      name="Sample Category" 
      id="example.commands.category"> 
     </category> 
     <command 
      name="Sample Command" 
      categoryId="example.commands.category" 
      id="example.commands.sampleCommand"> 
     </command> 
     <command 
      name="Dropdown Command" 
      categoryId="example.commands.category" 
      id="example.commands.dropdownCommand"> 
     </command> 
    </extension> 

    <extension point="org.eclipse.ui.handlers"> 
     <handler 
      commandId="example.commands.sampleCommand" 
      class="example.handlers.SampleHandler"> 
     </handler> 
     <handler 
      commandId="example.commands.dropdownCommand" 
      class="example.handlers.DropdownHandler"> 
     </handler> 
    </extension> 

    <extension point="org.eclipse.ui.menus"> 
     <menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions"> 
     <toolbar 
       id="example.toolbars.sampleToolbar" 
       label="Sample Menu"> 
      <command 
        commandId="example.commands.sampleCommand" 
        tooltip="Say hello world" 
        id="example.toolbars.sampleCommand" 
        style="pulldown"> 
      </command> 
     </toolbar> 
     </menuContribution> 
     <menuContribution locationURI="menu:example.toolbars.sampleCommand"> 
     <command commandId="example.commands.dropdownCommand" label="Processor1" style="toggle"> 
      <parameter name="example.toolbars.msg1" value="Processor1"></parameter> 
     </command> 

     <separator name="separator1" visible="true"/> 

     <command commandId="example.commands.dropdownCommand" label="Processor2" style="toggle"> 
      <parameter name="example.toolbars.msg2" value="Processor2"></parameter> 
     </command> 

     <separator name="separator2" visible="true"/> 

     <command commandId="example.commands.dropdownCommand" label="Processor3" style="toggle"> 
      <parameter name="example.toolbars.msg3" value="Processor3"></parameter> 
     </command> 
     </menuContribution> 
    </extension> 

</plugin> 

DropdownHandler.java

public class DropdownHandler extends AbstractHandler { 
    /** 
    * The constructor. 
    */ 
    public DropdownHandler() { 
    } 

    /** 
    * the command has been executed, so extract extract the needed information 
    * from the application context. 
    */ 
    public Object execute(ExecutionEvent event) throws ExecutionException { 
     IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); 
     MessageDialog.openInformation(
       window.getShell(), 
       "GreeHills Project", 
       "Hello, Eclipse World"); 
     return null; 
    } 
} 

SampleHandler.java

public class SampleHandler extends AbstractHandler { 
    /** 
    * The constructor. 
    */ 
    public SampleHandler() { 
    } 

    /** 
    * the command has been executed, so extract extract the needed information 
    * from the application context. 
    */ 
    public Object execute(ExecutionEvent event) throws ExecutionException { 
     IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); 
     MessageDialog.openInformation(
       window.getShell(), 
       "GreeHills Project", 
       "Please pick a processor from the dropdown list!"); 
     return null; 
    } 
} 

用户界面效果很好,一切都在它的位置。 enter image description here

当我点击Sample Command时,会调用正确的处理程序,并且弹出窗口显示相应的消息。 当我点击处理器1,处理器2或处理器3没有任何反应,没有消息。

我发现这个谷歌搜索:https://wiki.eclipse.org/Menu_Contributions/Dropdown_Command 试过分开(改SysOutPrintln的处理程序,以显示MessageDialog),并得到了相同的结果,没有显示的消息。

关于如何最终让我的插件工作的任何想法,高度赞赏!

回答

1

所以你的问题是,当按下'Processor 2'按钮时,没有任何反应。

对于处理器2按钮,您已经设置了一个参数,但在命令部分您不接受任何参数。

能不能请你和编辑此:

<command 
    name="Dropdown Command" 
    categoryId="example.commands.category" 
    id="example.commands.dropdownCommand"> 
</command> 

,使它像这样

<command name="Dropdown Command" categoryId="example.commands.category" id="example.commands.dropdownCommand"> 
     <commandParameter id="example.toolbars.msg2" name="DropOpts" optional="true"></commandParameter> 
</command> 

请注意,命令参数我已经设置“example.toolbars.msg2”,这应该仅在按下Process 2按钮时才能工作

相关问题