KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > registry > ActionSetDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.registry;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Preferences;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.ui.IPluginContribution;
21 import org.eclipse.ui.internal.PluginActionSet;
22 import org.eclipse.ui.internal.PluginActionSetReader;
23 import org.eclipse.ui.internal.WorkbenchPlugin;
24 import org.eclipse.ui.model.IWorkbenchAdapter;
25
26 /**
27  * ActionSetDescriptor
28  */

29 public class ActionSetDescriptor implements IActionSetDescriptor, IAdaptable,
30         IWorkbenchAdapter, IPluginContribution {
31     private static final Object JavaDoc[] NO_CHILDREN = new Object JavaDoc[0];
32
33     private static final String JavaDoc INITIALLY_HIDDEN_PREF_ID_PREFIX = "actionSet.initiallyHidden."; //$NON-NLS-1$
34

35     private String JavaDoc id;
36
37     private String JavaDoc pluginId;
38
39     private String JavaDoc label;
40
41     private boolean visible;
42
43     private String JavaDoc description;
44
45     private IConfigurationElement configElement;
46
47     /**
48      * Create a descriptor from a configuration element.
49      *
50      * @param configElement the configuration element
51      * @throws CoreException thrown if there is an issue creating the descriptor
52      */

53     public ActionSetDescriptor(IConfigurationElement configElement)
54             throws CoreException {
55         super();
56         this.configElement = configElement;
57         id = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
58         pluginId = configElement.getNamespace();
59         label = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_LABEL);
60         description = configElement.getAttribute(IWorkbenchRegistryConstants.TAG_DESCRIPTION);
61         String JavaDoc str = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_VISIBLE);
62         if (str != null && str.equals("true")) { //$NON-NLS-1$
63
visible = true;
64         }
65
66         // Sanity check.
67
if (label == null) {
68             throw new CoreException(new Status(IStatus.ERROR,
69                     WorkbenchPlugin.PI_WORKBENCH, 0,
70                     "Invalid extension (missing label): " + id,//$NON-NLS-1$
71
null));
72         }
73     }
74
75     /**
76      * Returns the action set for this descriptor.
77      *
78      * @return the action set
79      */

80     public IActionSet createActionSet() throws CoreException {
81         return new PluginActionSet(this);
82     }
83
84     /**
85      * Returns an object which is an instance of the given class
86      * associated with this object. Returns <code>null</code> if
87      * no such object can be found.
88      */

89     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
90         if (adapter == IWorkbenchAdapter.class) {
91             return this;
92         }
93         return null;
94     }
95
96     /**
97      * @see IWorkbenchAdapter#getChildren
98      */

99     public Object JavaDoc[] getChildren(Object JavaDoc o) {
100         if (o == this) {
101             return (new PluginActionSetReader()).readActionDescriptors(this);
102         }
103
104         return NO_CHILDREN;
105     }
106
107
108     /* (non-Javadoc)
109      * @see org.eclipse.ui.internal.registry.IActionSetDescriptor#getConfigurationElement()
110      */

111     public IConfigurationElement getConfigurationElement() {
112         return configElement;
113     }
114
115     /**
116      * Returns this action set's description.
117      * This is the value of its <code>"description"</code> attribute.
118      *
119      * @return the description
120      */

121     public String JavaDoc getDescription() {
122         return description;
123     }
124
125     /**
126      * Returns this action set's id.
127      * This is the value of its <code>"id"</code> attribute.
128      * <p>
129      *
130      * @return the action set id
131      */

132     public String JavaDoc getId() {
133         return id;
134     }
135
136     /**
137      * Returns this action set's label.
138      * This is the value of its <code>"label"</code> attribute.
139      *
140      * @return the label
141      */

142     public String JavaDoc getLabel() {
143         return label;
144     }
145
146     /**
147      * @see IWorkbenchAdapter#getLabel
148      */

149     public String JavaDoc getLabel(Object JavaDoc o) {
150         if (o == this) {
151             return getLabel();
152         }
153         return "Unknown Label";//$NON-NLS-1$
154
}
155
156     /**
157      * Returns whether this action set is initially visible.
158      */

159     public boolean isInitiallyVisible() {
160         if (id == null) {
161             return visible;
162         }
163         Preferences prefs = WorkbenchPlugin.getDefault().getPluginPreferences();
164         String JavaDoc prefId = INITIALLY_HIDDEN_PREF_ID_PREFIX + getId();
165         if (prefs.getBoolean(prefId)) {
166             return false;
167         }
168         return visible;
169     }
170
171     /**
172      * Sets whether this action set is initially visible.
173      * If the action set identifier is undefined, then this is ignored.
174      *
175      * @since 3.0
176      */

177     public void setInitiallyVisible(boolean newValue) {
178         if (id == null) {
179             return;
180         }
181         Preferences prefs = WorkbenchPlugin.getDefault().getPluginPreferences();
182         String JavaDoc prefId = INITIALLY_HIDDEN_PREF_ID_PREFIX + getId();
183         prefs.setValue(prefId, !newValue);
184     }
185
186     /* (non-Javadoc)
187      * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
188      */

189     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
190         return null;
191     }
192
193     /* (non-Javadoc)
194      * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
195      */

196     public Object JavaDoc getParent(Object JavaDoc o) {
197         return null;
198     }
199
200     /* (non-Javadoc)
201      * @see org.eclipse.ui.IPluginContribution#getLocalId()
202      */

203     public String JavaDoc getLocalId() {
204         return id;
205     }
206
207     /* (non-Javadoc)
208      * @see org.eclipse.ui.IPluginContribution#getPluginId()
209      */

210     public String JavaDoc getPluginId() {
211         return pluginId;
212     }
213     
214     public boolean equals(Object JavaDoc arg0) {
215         if (!(arg0 instanceof ActionSetDescriptor)) {
216             return false;
217         }
218         
219         ActionSetDescriptor descr = (ActionSetDescriptor) arg0;
220         
221         return id.equals(descr.id) && descr.pluginId.equals(pluginId);
222     }
223     
224     public int hashCode() {
225         return id.hashCode() + pluginId.hashCode();
226     }
227 }
228
Popular Tags