我正在嘗試編寫一個供個人使用的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;
}
}
當我點擊Sample Command時,會調用正確的處理程序,並且彈出窗口顯示相應的消息。 當我點擊處理器1,處理器2或處理器3沒有任何反應,沒有消息。
我發現這個谷歌搜索:https://wiki.eclipse.org/Menu_Contributions/Dropdown_Command 試過分開(改SysOutPrintln的處理程序,以顯示MessageDialog),並得到了相同的結果,沒有顯示的消息。
關於如何最終讓我的插件工作的任何想法,高度讚賞!