1 11 package org.eclipse.ui.internal.registry; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.IExtension; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.ui.IPluginContribution; 24 import org.eclipse.ui.IWorkingSetElementAdapter; 25 import org.eclipse.ui.IWorkingSetUpdater; 26 import org.eclipse.ui.dialogs.IWorkingSetPage; 27 import org.eclipse.ui.internal.WorkbenchPlugin; 28 import org.eclipse.ui.plugin.AbstractUIPlugin; 29 30 36 public class WorkingSetDescriptor implements IPluginContribution { 37 private String id; 38 39 private String name; 40 41 private String icon; 42 43 private String pageClassName; 44 45 private String updaterClassName; 46 47 private IConfigurationElement configElement; 48 49 private String [] classTypes; 50 51 private String [] adapterTypes; 52 53 private static final String ATT_ID = "id"; 55 private static final String ATT_NAME = "name"; 57 private static final String ATT_ICON = "icon"; 59 private static final String ATT_PAGE_CLASS = "pageClass"; 61 private static final String ATT_UPDATER_CLASS = "updaterClass"; 63 private static final String ATT_ELEMENT_ADAPTER_CLASS = "elementAdapterClass"; 65 private static final String TAG_APPLICABLE_TYPE = "applicableType"; 67 72 public WorkingSetDescriptor(IConfigurationElement configElement) 73 throws CoreException { 74 super(); 75 this.configElement = configElement; 76 id = configElement.getAttribute(ATT_ID); 77 name = configElement.getAttribute(ATT_NAME); 78 icon = configElement.getAttribute(ATT_ICON); 79 pageClassName = configElement.getAttribute(ATT_PAGE_CLASS); 80 updaterClassName = configElement.getAttribute(ATT_UPDATER_CLASS); 81 82 if (name == null) { 83 throw new CoreException(new Status(IStatus.ERROR, 84 WorkbenchPlugin.PI_WORKBENCH, 0, 85 "Invalid extension (missing class name): " + id, null)); 87 } 88 89 IConfigurationElement[] containsChildren = configElement 90 .getChildren(TAG_APPLICABLE_TYPE); 91 if (containsChildren.length > 0) { 92 List byClassList = new ArrayList (containsChildren.length); 93 List byAdapterList = new ArrayList (containsChildren.length); 94 for (int i = 0; i < containsChildren.length; i++) { 95 IConfigurationElement child = containsChildren[i]; 96 String className = child 97 .getAttribute(IWorkbenchRegistryConstants.ATT_CLASS); 98 if (className != null) 99 byClassList.add(className); 100 if ("true".equals(child.getAttribute(IWorkbenchRegistryConstants.ATT_ADAPTABLE))) byAdapterList.add(className); 102 } 103 if (!byClassList.isEmpty()) { 104 classTypes = (String []) byClassList.toArray(new String [byClassList 105 .size()]); 106 Arrays.sort(classTypes); 107 } 108 109 if (!byAdapterList.isEmpty()) { 110 adapterTypes = (String []) byAdapterList.toArray(new String [byAdapterList 111 .size()]); 112 Arrays.sort(adapterTypes); 113 } 114 } 115 } 116 117 122 public String getDeclaringNamespace() { 123 return configElement.getNamespace(); 124 } 125 126 134 public String getUpdaterNamespace() { 135 return WorkbenchPlugin.getBundleForExecutableExtension(configElement, 136 ATT_UPDATER_CLASS).getSymbolicName(); 137 } 138 139 147 public String getElementAdapterNamespace() { 148 return WorkbenchPlugin.getBundleForExecutableExtension(configElement, 149 ATT_UPDATER_CLASS).getSymbolicName(); 150 } 151 152 157 public IWorkingSetPage createWorkingSetPage() { 158 Object page = null; 159 160 if (pageClassName != null) { 161 try { 162 page = WorkbenchPlugin.createExtension(configElement, 163 ATT_PAGE_CLASS); 164 } catch (CoreException exception) { 165 WorkbenchPlugin.log("Unable to create working set page: " + pageClassName, exception.getStatus()); 167 } 168 } 169 return (IWorkingSetPage) page; 170 } 171 172 177 public ImageDescriptor getIcon() { 178 if (icon == null) { 179 return null; 180 } 181 182 IExtension extension = configElement.getDeclaringExtension(); 183 String extendingPluginId = extension.getNamespace(); 184 return AbstractUIPlugin.imageDescriptorFromPlugin(extendingPluginId, 185 icon); 186 } 187 188 193 public String getId() { 194 return id; 195 } 196 197 203 public String getPageClassName() { 204 return pageClassName; 205 } 206 207 213 public String getName() { 214 return name; 215 } 216 217 223 public String getUpdaterClassName() { 224 return updaterClassName; 225 } 226 227 233 public IWorkingSetElementAdapter createWorkingSetElementAdapter() { 234 if (!WorkbenchPlugin.hasExecutableExtension(configElement, ATT_ELEMENT_ADAPTER_CLASS)) 235 return null; 236 IWorkingSetElementAdapter result = null; 237 try { 238 result = (IWorkingSetElementAdapter) WorkbenchPlugin 239 .createExtension(configElement, ATT_ELEMENT_ADAPTER_CLASS); 240 } catch (CoreException exception) { 241 WorkbenchPlugin.log("Unable to create working set element adapter: " + result, exception.getStatus()); 243 } 244 return result; 245 } 246 247 253 public IWorkingSetUpdater createWorkingSetUpdater() { 254 if (updaterClassName == null) { 255 return null; 256 } 257 IWorkingSetUpdater result = null; 258 try { 259 result = (IWorkingSetUpdater)WorkbenchPlugin.createExtension(configElement, ATT_UPDATER_CLASS); 260 } catch (CoreException exception) { 261 WorkbenchPlugin.log("Unable to create working set updater: " + updaterClassName, exception.getStatus()); 263 } 264 return result; 265 } 266 267 public boolean isUpdaterClassLoaded() { 268 return WorkbenchPlugin.isBundleLoadedForExecutableExtension(configElement, ATT_UPDATER_CLASS); 269 } 270 271 public boolean isElementAdapterClassLoaded() { 272 return WorkbenchPlugin.isBundleLoadedForExecutableExtension(configElement, ATT_ELEMENT_ADAPTER_CLASS); 273 } 274 275 283 public boolean isEditable() { 284 return getPageClassName() != null; 285 } 286 287 public String getLocalId() { 288 return getId(); 289 } 290 291 public String getPluginId() { 292 return getDeclaringNamespace(); 293 } 294 295 301 public IConfigurationElement getConfigurationElement() { 302 return configElement; 303 } 304 } 305 | Popular Tags |