1 11 package org.eclipse.ui.internal.navigator.extensions; 12 13 import java.util.HashSet ; 14 import java.util.Properties ; 15 import java.util.Set ; 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 33 public final class NavigatorViewerDescriptor implements 34 INavigatorViewerDescriptor { 35 36 37 41 public static final String PROP_ENFORCE_HAS_CHILDREN = "org.eclipse.ui.navigator.enforceHasChildren"; 43 static final String TAG_INCLUDES = "includes"; 45 static final String TAG_EXCLUDES = "excludes"; 47 static final String ATT_IS_ROOT = "isRoot"; 49 static final String ATT_PATTERN = "pattern"; 51 private static final String TAG_CONTENT_EXTENSION = "contentExtension"; 53 private static final String TAG_ACTION_EXTENSION = "actionExtension"; 55 private final String viewerId; 56 57 private String 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 properties = new Properties (); 68 69 private Set dragAssistants; 70 71 77 NavigatorViewerDescriptor(String aViewerId) { 78 super(); 79 this.viewerId = aViewerId; 80 } 81 82 87 public String getViewerId() { 88 return viewerId; 89 } 90 91 96 public String getPopupMenuId() { 97 return popupMenuId != null ? popupMenuId : viewerId; 98 } 99 100 107 public void consumeActionBinding(IConfigurationElement element) { 108 consumeBinding(element, false); 109 } 110 111 118 public void consumeContentBinding(IConfigurationElement element) { 119 consumeBinding(element, true); 120 } 121 122 public boolean isRootExtension(String aContentExtensionId) { 123 return contentBinding.isRootExtension(aContentExtensionId); 124 } 125 126 public boolean allowsPlatformContributionsToContextMenu() { 127 return allowsPlatformContributions; 128 } 129 130 public boolean isVisibleContentExtension(String aContentExtensionId) { 131 return contentBinding.isVisibleExtension(aContentExtensionId); 132 } 133 134 public boolean isVisibleActionExtension(String 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 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); return; } 163 customInsertionPoints = newCustomInsertionPoints; 164 } 165 166 173 public void setAllowsPlatformContributions( 174 boolean toAllowPlatformContributions) { 175 allowsPlatformContributions = toAllowPlatformContributions; 176 } 177 178 183 public String getStringConfigProperty(String aPropertyName) { 184 return properties.getProperty(aPropertyName); 185 } 186 187 192 public boolean getBooleanConfigProperty(String aPropertyName) { 193 String propValue = properties.getProperty(aPropertyName); 194 if (propValue == null) { 195 return false; 196 } 197 return Boolean.valueOf(propValue).booleanValue(); 198 } 199 200 201 void setProperty(String aPropertyName, String aPropertyValue) { 202 properties.setProperty(aPropertyName, aPropertyValue); 203 } 204 205 210 public String toString() { 211 return "ViewerDescriptor[" + viewerId + "]"; } 213 214 221 void setPopupMenuId(String 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 [] { getViewerId(), 233 popupMenuId, 234 newPopupMenuId }), null); 235 } 236 popupMenuId = newPopupMenuId; 237 } 238 } 239 240 244 void addDragAssistant(CommonDragAssistantDescriptor descriptor) { 245 getDragAssistants().add(descriptor); 246 247 } 248 249 254 public Set getDragAssistants() { 255 if (dragAssistants == null) { 256 dragAssistants = new HashSet (); 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 [] { 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 [] { 296 TAG_EXCLUDES, 297 element.getDeclaringExtension() 298 .getUniqueIdentifier(), 299 element.getDeclaringExtension().getNamespaceIdentifier() }), 300 null); 301 } 302 } 303 304 } 305 | Popular Tags |