01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 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;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: import org.eclipse.core.runtime.IConfigurationElement;
16: import org.eclipse.ui.internal.decorators.LightweightActionDescriptor;
17: import org.eclipse.ui.internal.registry.ActionSetDescriptor;
18: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
19: import org.eclipse.ui.internal.registry.RegistryReader;
20:
21: /**
22: * Read the actions for an plugin action set.
23: *
24: * [Issue: There is some overlap with the class
25: * PluginActionSetBuilder which should be reviewed
26: * at a later time and maybe merged together]
27: */
28: public class PluginActionSetReader extends RegistryReader {
29: private List cache = new ArrayList();
30:
31: /**
32: * PluginActionSetReader constructor comment.
33: */
34: public PluginActionSetReader() {
35: super ();
36: }
37:
38: /**
39: * This factory method returns a new ActionDescriptor for the
40: * configuration element.
41: */
42: protected LightweightActionDescriptor createActionDescriptor(
43: IConfigurationElement element) {
44: return new LightweightActionDescriptor(element);
45: }
46:
47: /**
48: * Return all the action descriptor within the set.
49: *
50: * @param actionSet the set
51: * @return the descriptors
52: */
53: public LightweightActionDescriptor[] readActionDescriptors(
54: ActionSetDescriptor actionSet) {
55: readElements(new IConfigurationElement[] { actionSet
56: .getConfigurationElement() });
57: LightweightActionDescriptor[] actions = new LightweightActionDescriptor[cache
58: .size()];
59: cache.toArray(actions);
60: return actions;
61: }
62:
63: /**
64: * @see RegistryReader
65: */
66: protected boolean readElement(IConfigurationElement element) {
67: String tag = element.getName();
68: if (tag.equals(IWorkbenchRegistryConstants.TAG_ACTION_SET)) {
69: readElementChildren(element);
70: return true;
71: }
72: if (tag
73: .equals(IWorkbenchRegistryConstants.TAG_OBJECT_CONTRIBUTION)) {
74: // This builder is sometimes used to read the popup menu
75: // extension point. Ignore all object contributions.
76: return true;
77: }
78: if (tag.equals(IWorkbenchRegistryConstants.TAG_MENU)) {
79: return true; // just cache the element - don't go into it
80: }
81: if (tag.equals(IWorkbenchRegistryConstants.TAG_ACTION)) {
82: cache.add(createActionDescriptor(element));
83: return true; // just cache the action - don't go into
84: }
85:
86: return false;
87: }
88: }
|