1 11 package org.eclipse.ui.internal.handlers; 12 13 import org.eclipse.core.commands.ExecutionEvent; 14 import org.eclipse.core.commands.ExecutionException; 15 import org.eclipse.core.commands.IHandler; 16 import org.eclipse.core.commands.IHandlerListener; 17 import org.eclipse.core.commands.util.Tracing; 18 import org.eclipse.ui.internal.commands.ILegacyAttributeNames; 19 import org.eclipse.ui.internal.misc.Policy; 20 21 27 public final class LegacyHandlerWrapper implements IHandler { 28 29 33 private static final boolean DEBUG_HANDLERS = Policy.DEBUG_HANDLERS 34 && Policy.DEBUG_HANDLERS_VERBOSE; 35 36 39 private final org.eclipse.ui.commands.IHandler handler; 40 41 48 public LegacyHandlerWrapper(final org.eclipse.ui.commands.IHandler handler) { 49 if (handler == null) { 50 throw new NullPointerException ( 51 "A handler wrapper cannot be constructed on a null handler"); } 53 54 this.handler = handler; 55 } 56 57 62 public final void addHandlerListener(final IHandlerListener handlerListener) { 63 handler.addHandlerListener(new LegacyHandlerListenerWrapper(this, 64 handlerListener)); 65 } 66 67 72 public final void dispose() { 73 handler.dispose(); 74 } 75 76 public final boolean equals(final Object object) { 77 if (object instanceof org.eclipse.ui.commands.IHandler) { 78 return this.handler == object; 79 } 80 81 if (object instanceof LegacyHandlerWrapper) { 82 return this.handler == ((LegacyHandlerWrapper) object).handler; 83 } 84 85 return false; 86 } 87 88 93 public final Object execute(final ExecutionEvent event) 94 throws ExecutionException { 95 if (DEBUG_HANDLERS) { 97 final StringBuffer buffer = new StringBuffer ("Executing LegacyHandlerWrapper for "); if (handler == null) { 99 buffer.append("no handler"); } else { 101 buffer.append('\''); 102 buffer.append(handler.getClass().getName()); 103 buffer.append('\''); 104 } 105 Tracing.printTrace("HANDLERS", buffer.toString()); } 107 108 try { 109 return handler.execute(event.getParameters()); 110 } catch (final org.eclipse.ui.commands.ExecutionException e) { 111 throw new ExecutionException(e.getMessage(), e.getCause()); 112 } 113 } 114 115 public final int hashCode() { 116 return this.handler.hashCode(); 117 } 118 119 public final boolean isEnabled() { 120 final Object enabled = handler.getAttributeValuesByName().get( 121 ILegacyAttributeNames.ENABLED); 122 if (enabled instanceof Boolean ) { 123 return ((Boolean ) enabled).booleanValue(); 124 } 125 126 return true; 127 } 128 129 public final boolean isHandled() { 130 final Object handled = handler.getAttributeValuesByName().get( 131 ILegacyAttributeNames.HANDLED); 132 if (handled instanceof Boolean ) { 133 return ((Boolean ) handled).booleanValue(); 134 } 135 136 return true; 137 } 138 139 public final void removeHandlerListener( 140 final IHandlerListener handlerListener) { 141 handler.removeHandlerListener(new LegacyHandlerListenerWrapper(this, 142 handlerListener)); 143 } 144 145 public final String toString() { 146 final StringBuffer buffer = new StringBuffer (); 147 148 buffer.append("LegacyHandlerWrapper("); buffer.append(handler); 150 buffer.append(')'); 151 152 return buffer.toString(); 153 } 154 } 155 | Popular Tags |