Reputation: 69
I'm trying to write an eclipse plugin for personal use. It should be as simple as this: a dropdown list should be in the toolbar with 3 items(item1, item2, item3) which are toggle buttons. When toggling each of these buttons an environment variable or build variable should take the corresponding value.
My problem is that the handler for the toggle buttons isn't called.
In order to achieve this I wrote the following until now:
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;
}
}
UI works good, everything is in it's place.
When I click Sample Command the proper handler is called and I get the pop-up window with the corresponding message. When I click on Processor1, Processor2 or Processor3 nothing happens, no message.
I've found this googling: https://wiki.eclipse.org/Menu_Contributions/Dropdown_Command tried it separately (changed the SysOutPrintln in handler to display MessageDialog) and got the same results, no message displayed.
Any ideas on how to eventually make my plugin work are highly appreciated!
Upvotes: 1
Views: 204
Reputation: 1289
So your problem is, when pressing the 'Processor 2' button for example, nothing happens.
For Processor 2 button you have set a parameter, but in the command section you are not accepting any parameters.
Can you please try and edit this:
<command
name="Dropdown Command"
categoryId="example.commands.category"
id="example.commands.dropdownCommand">
</command>
And make it like this
<command name="Dropdown Command" categoryId="example.commands.category" id="example.commands.dropdownCommand">
<commandParameter id="example.toolbars.msg2" name="DropOpts" optional="true"></commandParameter>
</command>
Please note that for command parameter I have set "example.toolbars.msg2" and this should work only when pressing the Process 2 button
Upvotes: 1