KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > services > ActionSetSourceProvider


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.services;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.ui.AbstractSourceProvider;
18 import org.eclipse.ui.ISources;
19 import org.eclipse.ui.internal.ActionSetsEvent;
20 import org.eclipse.ui.internal.menus.IActionSetsListener;
21 import org.eclipse.ui.internal.registry.IActionSetDescriptor;
22 import org.eclipse.ui.internal.util.Util;
23
24 /**
25  * <p>
26  * A listener to changes in the action sets.
27  * </p>
28  * <p>
29  * This class is only intended for internal use within
30  * <code>org.eclipse.ui.workbench</code>.
31  * </p>
32  *
33  * @since 3.2
34  */

35 public final class ActionSetSourceProvider extends AbstractSourceProvider
36         implements IActionSetsListener {
37
38     /**
39      * The names of the sources supported by this source provider.
40      */

41     private static final String JavaDoc[] PROVIDED_SOURCE_NAMES = new String JavaDoc[] { ISources.ACTIVE_ACTION_SETS_NAME };
42
43     /**
44      * The action sets last seen as active by this source provider. This value
45      * may be <code>null</code>.
46      */

47     private IActionSetDescriptor[] activeActionSets;
48
49     public ActionSetSourceProvider() {
50         super();
51     }
52
53     public final void actionSetsChanged(final ActionSetsEvent event) {
54         final IActionSetDescriptor[] newActionSets = event.getNewActionSets();
55         if (!Util.equals(newActionSets, activeActionSets)) {
56             if (DEBUG) {
57                 final StringBuffer JavaDoc message = new StringBuffer JavaDoc();
58                 message.append("Action sets changed to ["); //$NON-NLS-1$
59
if (newActionSets != null) {
60                     for (int i = 0; i < newActionSets.length; i++) {
61                         message.append(newActionSets[i].getLabel());
62                         if (i < newActionSets.length - 1) {
63                             message.append(", "); //$NON-NLS-1$
64
}
65                     }
66                 }
67                 message.append(']');
68                 logDebuggingInfo(message.toString());
69             }
70
71             activeActionSets = newActionSets;
72             fireSourceChanged(ISources.ACTIVE_ACTION_SETS,
73                     ISources.ACTIVE_ACTION_SETS_NAME, activeActionSets);
74
75         }
76     }
77
78     public final void dispose() {
79         activeActionSets = null;
80     }
81
82     public final Map JavaDoc getCurrentState() {
83         final Map JavaDoc currentState = new HashMap JavaDoc();
84         currentState.put(ISources.ACTIVE_ACTION_SETS_NAME, activeActionSets);
85         return currentState;
86     }
87
88     public final String JavaDoc[] getProvidedSourceNames() {
89         return PROVIDED_SOURCE_NAMES;
90     }
91 }
Popular Tags