1 11 12 package org.eclipse.ui.internal.menus; 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 import org.eclipse.core.expressions.Expression; 21 import org.eclipse.core.runtime.IConfigurationElement; 22 import org.eclipse.core.runtime.IExtensionRegistry; 23 import org.eclipse.core.runtime.Platform; 24 import org.eclipse.jface.action.IContributionItem; 25 import org.eclipse.jface.menus.IWidget; 26 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 27 import org.eclipse.ui.internal.util.Util; 28 import org.eclipse.ui.menus.IMenuService; 29 import org.eclipse.ui.menus.IWorkbenchWidget; 30 31 38 public class TrimAdditionCacheEntry { 39 private IConfigurationElement additionElement; 40 private MenuLocationURI uri = null; 41 42 48 private Map failedWidgets = new HashMap (); 49 52 private Map widgetToConfigElementMap = new HashMap (); 53 54 55 57 60 Map iciToConfigElementMap = new HashMap (); 61 62 public TrimAdditionCacheEntry(IConfigurationElement element, 63 MenuLocationURI uri, IMenuService service) { 64 this.additionElement = element; 65 this.uri = uri; 66 } 67 68 73 public void getContributionItems(List additions) { 74 additions.clear(); 75 76 } 77 78 81 public void generateSubCaches() { 82 84 } 85 86 89 public Expression getVisibleWhenForItem(IContributionItem item) { 90 return null; 92 } 93 94 97 public String getId() { 98 return additionElement.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 99 } 100 101 106 public boolean isAtStart() { 107 IConfigurationElement location = additionElement.getChildren(IWorkbenchRegistryConstants.TAG_LOCATION)[0]; 108 if (location.getChildren(IWorkbenchRegistryConstants.TAG_ORDER).length > 0) { 109 IConfigurationElement order = location.getChildren(IWorkbenchRegistryConstants.TAG_ORDER)[0]; 110 111 String pos = order.getAttribute(IWorkbenchRegistryConstants.ATT_POSITION); 112 if (pos != null) 113 return (pos.equals("start") | pos.equals("before")); } 115 return true; 116 } 117 118 131 public boolean fillMajor(IConfigurationElement widgetElement) { 132 if (widgetElement.getChildren(IWorkbenchRegistryConstants.TAG_LAYOUT).length==0) { 133 return false; 134 } 135 IConfigurationElement layout = widgetElement.getChildren(IWorkbenchRegistryConstants.TAG_LAYOUT)[0]; 136 String fillMajorVal = layout.getAttribute(IWorkbenchRegistryConstants.ATT_FILL_MAJOR); 137 138 return (fillMajorVal != null && fillMajorVal.equals("true")); } 140 141 152 public boolean fillMinor(IConfigurationElement widgetElement) { 153 if (widgetElement.getChildren(IWorkbenchRegistryConstants.TAG_LAYOUT).length==0) { 154 return false; 155 } 156 IConfigurationElement layout = widgetElement.getChildren(IWorkbenchRegistryConstants.TAG_LAYOUT)[0]; 157 String fillMinorVal = layout.getAttribute(IWorkbenchRegistryConstants.ATT_FILL_MINOR); 158 159 return (fillMinorVal != null && fillMinorVal.equals("true")); } 161 162 166 private List getWidgetConfigs() { 167 List widgetConfigs = new ArrayList (); 168 169 final IExtensionRegistry registry = Platform.getExtensionRegistry(); 174 final IConfigurationElement[] widgetElements = registry 175 .getConfigurationElementsFor(IWorkbenchRegistryConstants.EXTENSION_MENUS); 176 177 for (int i = 0; i < widgetElements.length; i++) { 179 if (!IWorkbenchRegistryConstants.TAG_WIDGET.equals(widgetElements[i].getName())) 181 continue; 182 183 if (widgetElements[i].getChildren(IWorkbenchRegistryConstants.TAG_LOCATION).length > 0) { 185 IConfigurationElement location = widgetElements[i].getChildren(IWorkbenchRegistryConstants.TAG_LOCATION)[0]; 186 if (location.getChildren(IWorkbenchRegistryConstants.TAG_BAR).length > 0) { 187 IConfigurationElement bar = location.getChildren(IWorkbenchRegistryConstants.TAG_BAR)[0]; 188 189 String path = bar.getAttribute(IWorkbenchRegistryConstants.ATT_PATH); 191 if (path != null && path.equals(getId())) 192 widgetConfigs.add(widgetElements[i]); 193 } 194 } 195 } 196 197 return widgetConfigs; 198 } 199 200 209 public List getWidgets() { 210 List loadedWidgets = new ArrayList (); 211 212 List widgetConfigs = getWidgetConfigs(); 214 for (Iterator iterator = widgetConfigs.iterator(); iterator 215 .hasNext();) { 216 IConfigurationElement widgetCE = (IConfigurationElement) iterator.next(); 217 218 if (failedWidgets.containsKey(widgetCE)) 220 continue; 221 222 IWorkbenchWidget loadedWidget = loadWidget(widgetCE); 223 224 if (loadedWidget != null) { 227 loadedWidgets.add(loadedWidget); 228 widgetToConfigElementMap.put(loadedWidget, widgetCE); 229 } 230 else 231 failedWidgets.put(widgetCE, widgetCE); 232 } 233 234 return loadedWidgets; 235 } 236 237 248 private IWorkbenchWidget loadWidget(IConfigurationElement widgetCE) { 249 return (IWorkbenchWidget) Util.safeLoadExecutableExtension(widgetCE, 250 IWorkbenchRegistryConstants.ATT_CLASS, 251 IWorkbenchWidget.class); 252 } 253 254 260 public IConfigurationElement getElement(IWorkbenchWidget widget) { 261 return (IConfigurationElement) widgetToConfigElementMap.get(widget); 262 } 263 264 267 public void removeWidget(IWidget widget) { 268 widgetToConfigElementMap.remove(widget); 269 } 270 271 public MenuLocationURI getUri() { 272 return uri; 273 } 274 } 275 | Popular Tags |