1 11 12 package org.eclipse.ui.internal.handlers; 13 14 import java.util.Iterator ; 15 16 import org.eclipse.core.commands.IHandler; 17 import org.eclipse.core.expressions.Expression; 18 import org.eclipse.ui.handlers.IHandlerActivation; 19 import org.eclipse.ui.handlers.IHandlerService; 20 import org.eclipse.ui.internal.services.INestable; 21 22 36 public final class NestableHandlerService extends SlaveHandlerService implements 37 INestable { 38 39 42 private boolean active = false; 43 44 55 public NestableHandlerService(final IHandlerService parentHandlerService, 56 final Expression defaultExpression) { 57 super(parentHandlerService, defaultExpression); 58 } 59 60 public final void activate() { 61 if (active) { 62 return; 63 } 64 65 final Iterator localActivationItr = localActivationsToParentActivations 66 .keySet().iterator(); 67 while (localActivationItr.hasNext()) { 68 final Object object = localActivationItr.next(); 69 if (object instanceof IHandlerActivation) { 70 final IHandlerActivation localActivation = (IHandlerActivation) object; 71 final String commandId = localActivation.getCommandId(); 72 final IHandler handler = localActivation.getHandler(); 73 final IHandlerActivation parentActivation = parent 74 .activateHandler(commandId, handler, defaultExpression); 75 parentActivations.add(parentActivation); 76 localActivationsToParentActivations.put(localActivation, 77 parentActivation); 78 } 79 } 80 81 active = true; 82 } 83 84 protected final IHandlerActivation doActivation( 85 final IHandlerActivation localActivation) { 86 final IHandlerActivation parentActivation; 87 if (active) { 88 parentActivation = parent.activateHandler(localActivation); 89 parentActivations.add(parentActivation); 90 } else { 91 parentActivation = null; 92 } 93 localActivationsToParentActivations.put(localActivation, 94 parentActivation); 95 return localActivation; 96 } 97 98 public final void deactivate() { 99 if (!active) { 100 return; 101 } 102 103 deactivateHandlers(parentActivations); 104 parentActivations.clear(); 105 106 final Iterator localActivationItr = localActivationsToParentActivations 107 .keySet().iterator(); 108 while (localActivationItr.hasNext()) { 109 final Object object = localActivationItr.next(); 110 localActivationsToParentActivations.put(object, null); 111 } 112 113 active = false; 114 } 115 } 116 117 | Popular Tags |