1 11 12 package org.eclipse.ui.internal.contexts; 13 14 import java.util.Collection ; 15 import java.util.Map ; 16 import java.util.TreeMap ; 17 18 import org.eclipse.core.commands.contexts.ContextManagerEvent; 19 import org.eclipse.core.commands.contexts.IContextManagerListener; 20 import org.eclipse.ui.AbstractSourceProvider; 21 import org.eclipse.ui.ISources; 22 import org.eclipse.ui.contexts.IContextService; 23 24 33 public final class ActiveContextSourceProvider extends AbstractSourceProvider 34 implements IContextManagerListener { 35 36 39 private static final String [] PROVIDED_SOURCE_NAMES = new String [] { ISources.ACTIVE_CONTEXT_NAME }; 40 41 45 private final IContextService contextService; 46 47 53 public ActiveContextSourceProvider(final IContextService contextService) { 54 this.contextService = contextService; 55 contextService.addContextManagerListener(this); 56 } 57 58 public final void contextManagerChanged(final ContextManagerEvent event) { 59 if (event.isActiveContextsChanged()) { 60 final Map currentState = getCurrentState(); 61 62 if (DEBUG) { 63 logDebuggingInfo("Contexts changed to " + currentState.get(ISources.ACTIVE_CONTEXT_NAME)); 65 } 66 67 fireSourceChanged(ISources.ACTIVE_CONTEXT, currentState); 68 } 69 } 70 71 public final void dispose() { 72 contextService.removeContextManagerListener(this); 73 } 74 75 public final Map getCurrentState() { 76 final Map currentState = new TreeMap (); 77 final Collection activeContextIds = contextService 78 .getActiveContextIds(); 79 currentState.put(ISources.ACTIVE_CONTEXT_NAME, activeContextIds); 80 return currentState; 81 } 82 83 public final String [] getProvidedSourceNames() { 84 return PROVIDED_SOURCE_NAMES; 85 } 86 87 } 88 | Popular Tags |