01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.services;
11:
12: import java.util.HashMap;
13: import java.util.Map;
14:
15: import org.eclipse.ui.AbstractSourceProvider;
16: import org.eclipse.ui.ISources;
17: import org.eclipse.ui.internal.ActionSetsEvent;
18: import org.eclipse.ui.internal.menus.IActionSetsListener;
19: import org.eclipse.ui.internal.registry.IActionSetDescriptor;
20: import org.eclipse.ui.internal.util.Util;
21:
22: /**
23: * <p>
24: * A listener to changes in the action sets.
25: * </p>
26: * <p>
27: * This class is only intended for internal use within
28: * <code>org.eclipse.ui.workbench</code>.
29: * </p>
30: *
31: * @since 3.2
32: */
33: public final class ActionSetSourceProvider extends
34: AbstractSourceProvider implements IActionSetsListener {
35:
36: /**
37: * The names of the sources supported by this source provider.
38: */
39: private static final String[] PROVIDED_SOURCE_NAMES = new String[] { ISources.ACTIVE_ACTION_SETS_NAME };
40:
41: /**
42: * The action sets last seen as active by this source provider. This value
43: * may be <code>null</code>.
44: */
45: private IActionSetDescriptor[] activeActionSets;
46:
47: public ActionSetSourceProvider() {
48: super ();
49: }
50:
51: public final void actionSetsChanged(final ActionSetsEvent event) {
52: final IActionSetDescriptor[] newActionSets = event
53: .getNewActionSets();
54: if (!Util.equals(newActionSets, activeActionSets)) {
55: if (DEBUG) {
56: final StringBuffer message = new StringBuffer();
57: message.append("Action sets changed to ["); //$NON-NLS-1$
58: if (newActionSets != null) {
59: for (int i = 0; i < newActionSets.length; i++) {
60: message.append(newActionSets[i].getLabel());
61: if (i < newActionSets.length - 1) {
62: message.append(", "); //$NON-NLS-1$
63: }
64: }
65: }
66: message.append(']');
67: logDebuggingInfo(message.toString());
68: }
69:
70: activeActionSets = newActionSets;
71: fireSourceChanged(ISources.ACTIVE_ACTION_SETS,
72: ISources.ACTIVE_ACTION_SETS_NAME, activeActionSets);
73:
74: }
75: }
76:
77: public final void dispose() {
78: activeActionSets = null;
79: }
80:
81: public final Map getCurrentState() {
82: final Map currentState = new HashMap();
83: currentState.put(ISources.ACTIVE_ACTION_SETS_NAME,
84: activeActionSets);
85: return currentState;
86: }
87:
88: public final String[] getProvidedSourceNames() {
89: return PROVIDED_SOURCE_NAMES;
90: }
91: }
|