NOTE: These two methods:
Tip: Subclass AbstractHandler rather than implementing IHandler. but you can use it to the below section you need to set:
IHandler the chosen operation is not enabled
NOT USE popupMenus instead of Menus
isEnabled: should be set to true
isHandled:should be set to true
import org.eclipse.core.commands.AbstractHandler; 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.MessageBox; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; public class MyHandler implements IHandler { private FontChanger font=FontChanger.getInstance(); @Override public Object execute(ExecutionEvent event) throws ExecutionException { // TODO Auto-generated method stub IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); MessageDialog.openInformation( window.getShell(), "Demo", "Hello, Eclipse world"); font.decreaseSize(); return null; } @Override public void addHandlerListener(IHandlerListener handlerListener) { // TODO Auto-generated method stub } @Override public void dispose() { // TODO Auto-generated method stub } @Override public boolean isEnabled() { // TODO Auto-generated method stub return true; } @Override public boolean isHandled() { // TODO Auto-generated method stub return true; } @Override public void removeHandlerListener(IHandlerListener handlerListener) { // TODO Auto-generated method stub } }
时间: 2024-12-13 06:22:43