1 11 12 package org.eclipse.ui.internal.handlers; 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 37 public final class LegacyHandlerProxy extends AbstractHandler { 38 39 43 private static final String HANDLER_ATTRIBUTE_NAME = "handler"; 45 50 private IConfigurationElement configurationElement; 51 52 57 private IHandler handler; 58 59 67 public LegacyHandlerProxy( 68 final IConfigurationElement newConfigurationElement) { 69 configurationElement = newConfigurationElement; 70 handler = null; 71 } 72 73 76 public void dispose() { 77 if (handler != null) { 78 handler.dispose(); 79 } 80 } 81 82 85 public Object execute(Map parameters) throws ExecutionException { 86 if (loadHandler()) { 87 return handler.execute(parameters); 88 } 89 90 return null; 91 } 92 93 96 public Map getAttributeValuesByName() { 97 if (loadHandler()) { 98 return handler.getAttributeValuesByName(); 99 } else { 100 return Collections.EMPTY_MAP; 101 } 102 } 103 104 111 private final boolean loadHandler() { 112 if (handler == null) { 113 try { 115 handler = (IHandler) configurationElement 116 .createExecutableExtension(HANDLER_ATTRIBUTE_NAME); 117 configurationElement = null; 118 return true; 119 } catch (final CoreException e) { 120 124 final String message = "The proxied handler for '" + configurationElement.getAttribute(HANDLER_ATTRIBUTE_NAME) + "' could not be loaded"; IStatus status = new Status(IStatus.ERROR, 127 WorkbenchPlugin.PI_WORKBENCH, 0, message, e); 128 WorkbenchPlugin.log(message, status); 129 return false; 130 } 131 } 132 133 return true; 134 } 135 136 public final String toString() { 137 final StringBuffer buffer = new StringBuffer (); 138 139 buffer.append("LegacyProxy("); if (handler == null) { 141 final String className = configurationElement 142 .getAttribute(HANDLER_ATTRIBUTE_NAME); 143 buffer.append(className); 144 } else { 145 buffer.append(handler); 146 } 147 buffer.append(')'); 148 149 return buffer.toString(); 150 } 151 } 152 | Popular Tags |