I added a main menu button for an eclipse plugin, and this code was generated to handle the action when the button is pressed:
package de.vogella.plugin.experiment;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
public class SomethingHandler implements IHandler {
@Override
public void addHandlerListener(IHandlerListener handlerListener) {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("Hello");
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isEnabled() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isHandled() {
// TODO Auto-generated method stub
return false;
}
@Override
public void removeHandlerListener(IHandlerListener handlerListener) {
// TODO Auto-generated method stub
}
}
I added the print statement in the execute class to test to see if anything would happen when I pressed the button. However, when I run this plugin as an eclipse application, and press the button, the button stays pressed until I click it again, and nothing else happens. How can I execute some event when I press the button? And then have the process complete so I don't have to press the button again to turn it off?
EDIT:
Here is my plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="de.vogella.plugin.experiment.SomethingHandler"
id="de.vogella.plugin.experiment.SomethingHandler"
name="name">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="SomethingHandler"
commandId="de.vogella.plugin.experiment.SomethingHandler">
</handler>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<command
commandId="de.vogella.plugin.experiment.SomethingHandler"
label="DoSomething"
style="push">
</command>
</menuContribution>
</extension>
</plugin>
org.eclipse.core.commands.AbstractHandlerrather than implementingIHandlerfrom scratch, it will deal with everything exceptexecute. How is the menu, command and handler defined in theplugin.xml? - greg-449