1 11 12 package org.eclipse.ui.internal.commands.ws; 13 14 import java.util.Collections ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.ui.commands.AbstractHandler; 22 import org.eclipse.ui.commands.ExecutionException; 23 import org.eclipse.ui.commands.IHandler; 24 import org.eclipse.ui.internal.WorkbenchPlugin; 25 26 35 public final class HandlerProxy extends AbstractHandler { 36 37 41 private static final String HANDLER_ATTRIBUTE_NAME = "handler"; 43 47 private final String commandId; 48 49 54 private IConfigurationElement configurationElement; 55 56 61 private IHandler handler; 62 63 74 public HandlerProxy(final String newCommandId, 75 final IConfigurationElement newConfigurationElement) { 76 commandId = newCommandId; 77 configurationElement = newConfigurationElement; 78 handler = null; 79 } 80 81 84 public void dispose() { 85 if (handler != null) { 86 handler.dispose(); 87 } 88 } 89 90 93 public Object execute(Map parameterValuesByName) throws ExecutionException { 94 if (loadHandler()) { return handler.execute(parameterValuesByName); } 95 96 return null; 97 } 98 99 105 final String getCommandId() { 106 return commandId; 107 } 108 109 112 public Map getAttributeValuesByName() { 113 if (loadHandler()) 114 return handler.getAttributeValuesByName(); 115 else 116 return Collections.EMPTY_MAP; 117 } 118 119 126 private final boolean loadHandler() { 127 if (handler == null) { 128 try { 130 handler = (IHandler) configurationElement 131 .createExecutableExtension(HANDLER_ATTRIBUTE_NAME); 132 configurationElement = null; 133 return true; 134 } catch (final CoreException e) { 135 139 final String message = "The proxied handler for '" + commandId + "' could not be loaded"; IStatus status = new Status(IStatus.ERROR, 142 WorkbenchPlugin.PI_WORKBENCH, 0, message, e); 143 WorkbenchPlugin.log(message, status); 144 return false; 145 } 146 } 147 148 return true; 149 } 150 } 151 | Popular Tags |