KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > PluginActionSetReader


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 package org.eclipse.ui.internal;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.ui.internal.decorators.LightweightActionDescriptor;
18 import org.eclipse.ui.internal.registry.ActionSetDescriptor;
19 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
20 import org.eclipse.ui.internal.registry.RegistryReader;
21
22 /**
23  * Read the actions for an plugin action set.
24  *
25  * [Issue: There is some overlap with the class
26  * PluginActionSetBuilder which should be reviewed
27  * at a later time and maybe merged together]
28  */

29 public class PluginActionSetReader extends RegistryReader {
30     private List JavaDoc cache = new ArrayList JavaDoc();
31
32     /**
33      * PluginActionSetReader constructor comment.
34      */

35     public PluginActionSetReader() {
36         super();
37     }
38
39     /**
40      * This factory method returns a new ActionDescriptor for the
41      * configuration element.
42      */

43     protected LightweightActionDescriptor createActionDescriptor(
44             IConfigurationElement element) {
45         return new LightweightActionDescriptor(element);
46     }
47
48     /**
49      * Return all the action descriptor within the set.
50      *
51      * @param actionSet the set
52      * @return the descriptors
53      */

54     public LightweightActionDescriptor[] readActionDescriptors(
55             ActionSetDescriptor actionSet) {
56         readElements(new IConfigurationElement[] { actionSet.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 JavaDoc tag = element.getName();
68         if (tag.equals(IWorkbenchRegistryConstants.TAG_ACTION_SET)) {
69             readElementChildren(element);
70             return true;
71         }
72         if (tag.equals(IWorkbenchRegistryConstants.TAG_OBJECT_CONTRIBUTION)) {
73             // This builder is sometimes used to read the popup menu
74
// extension point. Ignore all object contributions.
75
return true;
76         }
77         if (tag.equals(IWorkbenchRegistryConstants.TAG_MENU)) {
78             return true; // just cache the element - don't go into it
79
}
80         if (tag.equals(IWorkbenchRegistryConstants.TAG_ACTION)) {
81             cache.add(createActionDescriptor(element));
82             return true; // just cache the action - don't go into
83
}
84
85         return false;
86     }
87 }
88
Popular Tags