1 11 package org.eclipse.ui.internal.contexts; 12 13 import java.util.Collection ; 14 import java.util.Iterator ; 15 16 import org.eclipse.core.commands.contexts.Context; 17 import org.eclipse.core.commands.contexts.ContextManager; 18 import org.eclipse.core.commands.contexts.IContextManagerListener; 19 import org.eclipse.core.expressions.Expression; 20 import org.eclipse.swt.widgets.Shell; 21 import org.eclipse.ui.ISourceProvider; 22 import org.eclipse.ui.ISources; 23 import org.eclipse.ui.contexts.IContextActivation; 24 import org.eclipse.ui.contexts.IContextService; 25 26 34 public final class ContextService implements IContextService { 35 36 39 private final ContextAuthority contextAuthority; 40 41 45 private final ContextManager contextManager; 46 47 50 private final ContextPersistence contextPersistence; 51 52 59 public ContextService(final ContextManager contextManager) { 60 if (contextManager == null) { 61 throw new NullPointerException ( 62 "Cannot create a context service with a null manager"); } 64 this.contextManager = contextManager; 65 this.contextAuthority = new ContextAuthority(contextManager, this); 66 this.contextPersistence = new ContextPersistence(contextManager); 67 } 68 69 74 public final IContextActivation activateContext(final String contextId) { 75 return activateContext(contextId, null); 76 } 77 78 84 public final IContextActivation activateContext(final String contextId, 85 final Expression expression) { 86 final IContextActivation activation = new ContextActivation(contextId, 87 expression, this); 88 contextAuthority.activateContext(activation); 89 return activation; 90 } 91 92 98 public IContextActivation activateContext(String contextId, 99 Expression expression, boolean global) { 100 return activateContext(contextId, expression); 101 } 102 103 109 public final IContextActivation activateContext(final String contextId, 110 final Expression expression, final int sourcePriority) { 111 return activateContext(contextId, expression); 112 } 113 114 119 public final void addContextManagerListener( 120 final IContextManagerListener listener) { 121 contextManager.addContextManagerListener(listener); 122 } 123 124 129 public final void addSourceProvider(final ISourceProvider provider) { 130 contextAuthority.addSourceProvider(provider); 131 } 132 133 138 public final void deactivateContext(final IContextActivation activation) { 139 if (activation.getContextService() == this) { 140 contextAuthority.deactivateContext(activation); 141 } 142 } 143 144 149 public final void deactivateContexts(final Collection activations) { 150 final Iterator activationItr = activations.iterator(); 151 while (activationItr.hasNext()) { 152 final IContextActivation activation = (IContextActivation) activationItr 153 .next(); 154 deactivateContext(activation); 155 } 156 } 157 158 163 public final void dispose() { 164 contextPersistence.dispose(); 165 contextAuthority.dispose(); 166 } 167 168 173 public final Collection getActiveContextIds() { 174 return contextManager.getActiveContextIds(); 175 } 176 177 182 public final Context getContext(final String contextId) { 183 return contextManager.getContext(contextId); 184 } 185 186 191 public final Collection getDefinedContextIds() { 192 return contextManager.getDefinedContextIds(); 193 } 194 195 200 public final Context[] getDefinedContexts() { 201 return contextManager.getDefinedContexts(); 202 } 203 204 209 public final int getShellType(final Shell shell) { 210 return contextAuthority.getShellType(shell); 211 } 212 213 218 public final void readRegistry() { 219 contextPersistence.read(); 220 } 221 222 228 public final boolean registerShell(final Shell shell, final int type) { 229 return contextAuthority.registerShell(shell, type); 230 } 231 232 237 public final void removeContextManagerListener( 238 final IContextManagerListener listener) { 239 contextManager.addContextManagerListener(listener); 240 } 241 242 247 public final void removeSourceProvider(final ISourceProvider provider) { 248 contextAuthority.removeSourceProvider(provider); 249 } 250 251 256 public final boolean unregisterShell(final Shell shell) { 257 return contextAuthority.unregisterShell(shell); 258 } 259 260 270 public final void updateShellKludge() { 271 contextAuthority.updateShellKludge(); 272 } 273 274 288 public final void updateShellKludge(final Shell shell) { 289 final Shell currentActiveShell = contextAuthority.getActiveShell(); 290 if (currentActiveShell != shell) { 291 contextAuthority.sourceChanged(ISources.ACTIVE_SHELL, 292 ISources.ACTIVE_SHELL_NAME, shell); 293 } 294 } 295 } 296 | Popular Tags |