KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > extensions > NavigatorViewerDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2003, 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 package org.eclipse.ui.internal.navigator.extensions;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Properties JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.osgi.util.NLS;
20 import org.eclipse.ui.internal.navigator.CommonNavigatorMessages;
21 import org.eclipse.ui.internal.navigator.NavigatorPlugin;
22 import org.eclipse.ui.navigator.CommonActionProvider;
23 import org.eclipse.ui.navigator.INavigatorViewerDescriptor;
24 import org.eclipse.ui.navigator.MenuInsertionPoint;
25 import org.eclipse.ui.navigator.NavigatorActionService;
26
27 /**
28  * Encapsulates the <code>org.eclipse.ui.navigator.viewer</code> extension.
29  * <p>
30  *
31  * @since 3.2
32  */

33 public final class NavigatorViewerDescriptor implements
34         INavigatorViewerDescriptor {
35     
36
37     /**
38      * {@value} (boolean): True indicates the ITreeContentProvider.hasChildren()
39      * should force plugins to load if necessary <b>false</b>).
40      */

41     public static final String JavaDoc PROP_ENFORCE_HAS_CHILDREN = "org.eclipse.ui.navigator.enforceHasChildren"; //$NON-NLS-1$
42

43     static final String JavaDoc TAG_INCLUDES = "includes"; //$NON-NLS-1$
44

45     static final String JavaDoc TAG_EXCLUDES = "excludes"; //$NON-NLS-1$
46

47     static final String JavaDoc ATT_IS_ROOT = "isRoot"; //$NON-NLS-1$
48

49     static final String JavaDoc ATT_PATTERN = "pattern"; //$NON-NLS-1$
50

51     private static final String JavaDoc TAG_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
52

53     private static final String JavaDoc TAG_ACTION_EXTENSION = "actionExtension"; //$NON-NLS-1$
54

55     private final String JavaDoc viewerId;
56
57     private String JavaDoc popupMenuId = null;
58
59     private Binding actionBinding = new Binding(TAG_ACTION_EXTENSION);
60
61     private Binding contentBinding = new Binding(TAG_CONTENT_EXTENSION);
62
63     private MenuInsertionPoint[] customInsertionPoints = null;
64
65     private boolean allowsPlatformContributions = true;
66
67     private final Properties JavaDoc properties = new Properties JavaDoc();
68
69     private Set JavaDoc dragAssistants;
70
71     /**
72      * Creates a new content descriptor from a configuration element.
73      *
74      * @param aViewerId
75      * The identifier for this descriptor.
76      */

77     /* package */NavigatorViewerDescriptor(String JavaDoc aViewerId) {
78         super();
79         this.viewerId = aViewerId;
80     }
81
82     /*
83      * (non-Javadoc)
84      *
85      * @see org.eclipse.ui.internal.navigator.extensions.INavigatorViewerDescriptor#getViewerId()
86      */

87     public String JavaDoc getViewerId() {
88         return viewerId;
89     }
90
91     /*
92      * (non-Javadoc)
93      *
94      * @see org.eclipse.ui.internal.navigator.extensions.INavigatorViewerDescriptor#getPopupMenuId()
95      */

96     public String JavaDoc getPopupMenuId() {
97         return popupMenuId != null ? popupMenuId : viewerId;
98     }
99
100     /**
101      * Consume an action binding for this viewer.
102      *
103      * @param element
104      * The IConfigurationElement containing a viewerActionBinding
105      * element.
106      */

107     public void consumeActionBinding(IConfigurationElement element) {
108         consumeBinding(element, false);
109     }
110
111     /**
112      * Consume a content binding for this viewer.
113      *
114      * @param element
115      * The IConfigurationElement containing a viewerContentBinding
116      * element.
117      */

118     public void consumeContentBinding(IConfigurationElement element) {
119         consumeBinding(element, true);
120     }
121
122     public boolean isRootExtension(String JavaDoc aContentExtensionId) {
123         return contentBinding.isRootExtension(aContentExtensionId);
124     }
125
126     public boolean allowsPlatformContributionsToContextMenu() {
127         return allowsPlatformContributions;
128     }
129
130     public boolean isVisibleContentExtension(String JavaDoc aContentExtensionId) {
131         return contentBinding.isVisibleExtension(aContentExtensionId);
132     }
133
134     public boolean isVisibleActionExtension(String JavaDoc anActionExtensionId) {
135         return actionBinding.isVisibleExtension(anActionExtensionId);
136     }
137
138     public boolean hasOverriddenRootExtensions() {
139         return contentBinding.hasOverriddenRootExtensions();
140     }
141
142     public MenuInsertionPoint[] getCustomInsertionPoints() {
143         return customInsertionPoints;
144     }
145
146     /**
147      *
148      * @param newCustomInsertionPoints
149      * The set of custom insertion points, if any. A null list
150      * indicates the default set (as defined by
151      * {@link NavigatorActionService}) should be used. An empty list
152      * indicates there are no declarative insertion points.
153      */

154     public void setCustomInsertionPoints(
155             MenuInsertionPoint[] newCustomInsertionPoints) {
156         if (customInsertionPoints != null) {
157             NavigatorPlugin
158                     .logError(
159                             0,
160                             "Attempt to override custom insertion points denied. Verify there are no colliding org.eclipse.ui.navigator.viewer extension points.", null); //$NON-NLS-1$
161
return; // do not let them override the insertion points.
162
}
163         customInsertionPoints = newCustomInsertionPoints;
164     }
165
166     /**
167      *
168      * @param toAllowPlatformContributions
169      * A value of 'true' enables object/viewer contributions. 'false'
170      * will only allow programmatic contributions from
171      * {@link CommonActionProvider}s.
172      */

173     public void setAllowsPlatformContributions(
174             boolean toAllowPlatformContributions) {
175         allowsPlatformContributions = toAllowPlatformContributions;
176     }
177
178     /*
179      * (non-Javadoc)
180      *
181      * @see org.eclipse.ui.navigator.INavigatorViewerDescriptor#getStringConfigProperty(java.lang.String)
182      */

183     public String JavaDoc getStringConfigProperty(String JavaDoc aPropertyName) {
184         return properties.getProperty(aPropertyName);
185     }
186
187     /*
188      * (non-Javadoc)
189      *
190      * @see org.eclipse.ui.navigator.INavigatorViewerDescriptor#getBooleanConfigProperty(java.lang.String)
191      */

192     public boolean getBooleanConfigProperty(String JavaDoc aPropertyName) {
193         String JavaDoc propValue = properties.getProperty(aPropertyName);
194         if (propValue == null) {
195             return false;
196         }
197         return Boolean.valueOf(propValue).booleanValue();
198     }
199      
200
201     /* package */ void setProperty(String JavaDoc aPropertyName, String JavaDoc aPropertyValue) {
202         properties.setProperty(aPropertyName, aPropertyValue);
203     }
204
205     /*
206      * (non-Javadoc)
207      *
208      * @see java.lang.Object#toString()
209      */

210     public String JavaDoc toString() {
211         return "ViewerDescriptor[" + viewerId + "]"; //$NON-NLS-1$ //$NON-NLS-2$
212
}
213
214     /**
215      * Update the popupMenuId. If a value is already set, then a warning message
216      * will be logged.
217      *
218      * @param newPopupMenuId
219      * The new popup menu id.
220      */

221     /* package */ void setPopupMenuId(String JavaDoc newPopupMenuId) {
222
223         if (newPopupMenuId != null) {
224             if (popupMenuId != null) {
225                 NavigatorPlugin
226                         .log(
227                                 IStatus.WARNING,
228                                 0,
229                                 NLS
230                                         .bind(
231                                                 CommonNavigatorMessages.NavigatorViewerDescriptor_Popup_Menu_Overridden,
232                                                 new Object JavaDoc[] { getViewerId(),
233                                                         popupMenuId,
234                                                         newPopupMenuId }), null);
235             }
236             popupMenuId = newPopupMenuId;
237         }
238     }
239
240     /**
241      * @param descriptor
242      * A non-null descriptor to add
243      */

244     /* package */ void addDragAssistant(CommonDragAssistantDescriptor descriptor) {
245         getDragAssistants().add(descriptor);
246
247     }
248
249     /**
250      *
251      * @return The set of {@link CommonDragAssistantDescriptor}s for this
252      * viewer.
253      */

254     public Set JavaDoc getDragAssistants() {
255         if (dragAssistants == null) {
256             dragAssistants = new HashSet JavaDoc();
257         }
258         return dragAssistants;
259     }
260
261     private void consumeBinding(IConfigurationElement element, boolean isContent) {
262         IConfigurationElement[] includesElement = element
263                 .getChildren(TAG_INCLUDES);
264
265         if (includesElement.length == 1) {
266             if (isContent) {
267                 contentBinding.consumeIncludes(includesElement[0], true);
268             } else {
269                 actionBinding.consumeIncludes(includesElement[0], false);
270             }
271         } else if (includesElement.length >= 1) {
272             NavigatorPlugin.logError(0, NLS.bind(
273                     CommonNavigatorMessages.Too_many_elements_Warning,
274                     new Object JavaDoc[] {
275                             TAG_INCLUDES,
276                             element.getDeclaringExtension()
277                                     .getUniqueIdentifier(),
278                             element.getDeclaringExtension().getNamespaceIdentifier() }),
279                     null);
280         }
281
282         IConfigurationElement[] excludesElement = element
283                 .getChildren(TAG_EXCLUDES);
284
285         if (excludesElement.length == 1) {
286
287             if (isContent) {
288                 contentBinding.consumeExcludes(excludesElement[0]);
289             } else {
290                 actionBinding.consumeExcludes(excludesElement[0]);
291             }
292         } else if (excludesElement.length >= 1) {
293             NavigatorPlugin.logError(0, NLS.bind(
294                     CommonNavigatorMessages.Too_many_elements_Warning,
295                     new Object JavaDoc[] {
296                             TAG_EXCLUDES,
297                             element.getDeclaringExtension()
298                                     .getUniqueIdentifier(),
299                             element.getDeclaringExtension().getNamespaceIdentifier() }),
300                     null);
301         }
302     }
303
304 }
305
Popular Tags