1 11 package org.eclipse.ui.internal.navigator.extensions; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.ui.internal.navigator.NavigatorPlugin; 18 import org.eclipse.ui.navigator.MenuInsertionPoint; 19 20 30 public class NavigatorViewerDescriptorManager { 31 32 private static final NavigatorViewerDescriptorManager INSTANCE = new NavigatorViewerDescriptorManager(); 33 34 private final Map viewerDescriptors = new HashMap (); 35 36 40 public static NavigatorViewerDescriptorManager getInstance() { 41 return INSTANCE; 42 } 43 44 protected NavigatorViewerDescriptorManager() { 45 new NavigatorViewerDescriptorRegistry().readRegistry(); 46 } 47 48 54 public NavigatorViewerDescriptor getNavigatorViewerDescriptor( 55 String aViewerId) { 56 57 NavigatorViewerDescriptor viewerDescriptor = (NavigatorViewerDescriptor) viewerDescriptors 58 .get(aViewerId); 59 if (viewerDescriptor != null) { 60 return viewerDescriptor; 61 } 62 63 synchronized (viewerDescriptors) { 64 viewerDescriptor = (NavigatorViewerDescriptor) viewerDescriptors 65 .get(aViewerId); 66 if (viewerDescriptor == null) { 67 viewerDescriptor = new NavigatorViewerDescriptor(aViewerId); 68 viewerDescriptors.put(viewerDescriptor.getViewerId(), 69 viewerDescriptor); 70 } 71 } 72 return viewerDescriptor; 73 74 } 75 76 private class NavigatorViewerDescriptorRegistry extends RegistryReader 77 implements IViewerExtPtConstants { 78 79 protected NavigatorViewerDescriptorRegistry() { 80 super(NavigatorPlugin.PLUGIN_ID, TAG_VIEWER); 81 } 82 83 protected boolean readElement(IConfigurationElement element) { 84 if (TAG_VIEWER.equals(element.getName())) { 85 String viewerId = element.getAttribute(ATT_VIEWER_ID); 86 NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId); 87 88 String attPopupMenuId = element.getAttribute(ATT_POPUP_MENU_ID); 89 IConfigurationElement[] tagPopupMenu = element 90 .getChildren(TAG_POPUP_MENU); 91 if (tagPopupMenu.length == 0 && attPopupMenuId != null) { 92 descriptor.setPopupMenuId(attPopupMenuId); 93 } else { 94 if (attPopupMenuId != null) { 95 NavigatorPlugin 96 .logError( 97 0, 98 "A popupMenuId attribute and popupMenu element may NOT be concurrently specified. (see " + element.getNamespaceIdentifier() + ")", null); } else if (tagPopupMenu.length > 1) { 100 NavigatorPlugin 101 .logError( 102 0, 103 "Only one \"popupMenu\" child of \"viewer\" may be specified. (see " + element.getNamespaceIdentifier() + ")", null); } else if(tagPopupMenu.length == 1) { 106 String popupMenuId = tagPopupMenu[0] 107 .getAttribute(ATT_ID); 108 String allowsPlatformContributions = tagPopupMenu[0] 109 .getAttribute(ATT_ALLOWS_PLATFORM_CONTRIBUTIONS); 110 111 if (popupMenuId != null) { 112 descriptor.setPopupMenuId(popupMenuId); 113 } 114 115 if (allowsPlatformContributions != null) { 116 descriptor.setAllowsPlatformContributions(Boolean 117 .valueOf(allowsPlatformContributions) 118 .booleanValue()); 119 } 120 121 IConfigurationElement[] insertionPointElements = tagPopupMenu[0] 122 .getChildren(TAG_INSERTION_POINT); 123 MenuInsertionPoint[] insertionPoints = new MenuInsertionPoint[insertionPointElements.length]; 124 String name; 125 String stringAttSeparator; 126 127 boolean isSeparator; 128 for (int indx = 0; indx < insertionPointElements.length; indx++) { 129 name = insertionPointElements[indx] 130 .getAttribute(ATT_NAME); 131 stringAttSeparator = insertionPointElements[indx] 132 .getAttribute(ATT_SEPARATOR); 133 isSeparator = stringAttSeparator != null ? Boolean 134 .valueOf(stringAttSeparator).booleanValue() 135 : false; 136 insertionPoints[indx] = new MenuInsertionPoint(name, 137 isSeparator); 138 } 139 descriptor.setCustomInsertionPoints(insertionPoints); 140 } 141 } 142 143 IConfigurationElement[] options = element 144 .getChildren(TAG_OPTIONS); 145 if (options.length == 1) { 146 IConfigurationElement[] properties = options[0] 147 .getChildren(TAG_PROPERTY); 148 String name; 149 String value; 150 for (int i = 0; i < properties.length; i++) { 151 name = properties[i].getAttribute(ATT_NAME); 152 if (name != null) { 153 value = properties[i].getAttribute(ATT_VALUE); 154 descriptor.setProperty(name, value); 155 } 156 } 157 } else if (options.length > 1) { 158 NavigatorPlugin 159 .logError( 160 0, 161 "Only one \"options\" child of \"viewer\" may be specified. (see " + element.getNamespaceIdentifier() + ")", null); 163 } 164 return true; 165 } 166 if (TAG_VIEWER_CONTENT_BINDING.equals(element.getName())) { 167 String viewerId = element.getAttribute(ATT_VIEWER_ID); 168 NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId); 169 descriptor.consumeContentBinding(element); 170 return true; 171 } 172 if (TAG_VIEWER_ACTION_BINDING.equals(element.getName())) { 173 String viewerId = element.getAttribute(ATT_VIEWER_ID); 174 NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId); 175 descriptor.consumeActionBinding(element); 176 return true; 177 } if (TAG_DRAG_ASSISTANT.equals(element.getName())) { 178 String viewerId = element.getAttribute(ATT_VIEWER_ID); 179 NavigatorViewerDescriptor descriptor = getNavigatorViewerDescriptor(viewerId); 180 descriptor.addDragAssistant(new CommonDragAssistantDescriptor(element)); 181 return true; 182 } 183 return false; 184 } 185 } 186 187 } 188 | Popular Tags |