1 11 package org.eclipse.ui.internal.ide.registry; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.resources.IProjectNatureDescriptor; 16 import org.eclipse.core.resources.ResourcesPlugin; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IAdaptable; 19 import org.eclipse.core.runtime.IConfigurationElement; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.eclipse.osgi.util.NLS; 22 import org.eclipse.ui.ICapabilityInstallWizard; 23 import org.eclipse.ui.ICapabilityUninstallWizard; 24 import org.eclipse.ui.WorkbenchException; 25 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 26 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 27 import org.eclipse.ui.model.IWorkbenchAdapter; 28 import org.eclipse.ui.model.WorkbenchAdapter; 29 import org.eclipse.ui.plugin.AbstractUIPlugin; 30 31 42 public class Capability extends WorkbenchAdapter implements IAdaptable { 43 private static final String ATT_ID = "id"; 45 private static final String ATT_ICON = "icon"; 47 private static final String ATT_NATURE_ID = "natureId"; 49 private static final String ATT_CATEGORY = "category"; 51 private static final String ATT_DESCRIPTION = "description"; 53 private static final String ATT_INSTALL_WIZARD = "installWizard"; 55 private static final String ATT_INSTALL_DETAILS = "installDetails"; 57 private static final String ATT_UNINSTALL_WIZARD = "uninstallWizard"; 59 private static final String ATT_UNINSTALL_DETAILS = "uninstallDetails"; 61 private String id; 62 63 private String natureId; 64 65 private IProjectNatureDescriptor natureDescriptor; 66 67 private ImageDescriptor icon; 68 69 private IConfigurationElement element; 70 71 private ArrayList handleUIs; 72 73 private ArrayList perspectiveChoices; 74 75 84 public Capability(IConfigurationElement configElement, 85 CapabilityRegistryReader reader) throws WorkbenchException { 86 super(); 87 88 boolean missingAttribute = false; 89 String attr_id = configElement.getAttribute(ATT_ID); 90 String attr_nature = configElement.getAttribute(ATT_NATURE_ID); 91 92 if (attr_id == null) { 93 reader.logMissingAttribute(configElement, ATT_ID); 94 missingAttribute = true; 95 } 96 if (attr_nature == null) { 97 reader.logMissingAttribute(configElement, ATT_NATURE_ID); 98 missingAttribute = true; 99 } 100 if (configElement.getAttribute(ATT_INSTALL_WIZARD) == null) { 101 reader.logMissingAttribute(configElement, ATT_INSTALL_WIZARD); 102 missingAttribute = true; 103 } 104 105 if (missingAttribute) 106 throw new WorkbenchException( 107 "Capability missing required attributes."); 109 id = attr_id; 110 natureId = attr_nature; 111 element = configElement; 112 natureDescriptor = ResourcesPlugin.getWorkspace().getNatureDescriptor( 113 natureId); 114 } 115 116 122 public Capability(String natureId) { 123 super(); 124 this.id = natureId; 125 this.natureId = natureId; 126 } 127 128 132 public void addHandleUI(String capabilityId) { 133 if (handleUIs == null) 134 handleUIs = new ArrayList (4); 135 handleUIs.add(capabilityId); 136 } 137 138 142 public void addPerspectiveChoice(String perspId) { 143 if (perspectiveChoices == null) 144 perspectiveChoices = new ArrayList (4); 145 perspectiveChoices.add(perspId); 146 } 147 148 public String getId() { 149 return id; 150 } 151 152 155 public ImageDescriptor getImageDescriptor(Object object) { 156 return getIconDescriptor(); 157 } 158 159 162 public String getLabel(Object o) { 163 return getName(); 164 } 165 166 public String getName() { 167 if (isValid()) 168 return natureDescriptor.getLabel(); 169 else 170 return NLS.bind(IDEWorkbenchMessages.Capability_nameMissing, id); 171 } 172 173 public ImageDescriptor getIconDescriptor() { 174 if (icon == null && isValid()) { 175 String extendingPluginId = element.getNamespace(); 176 String location = element.getAttribute(ATT_ICON); 177 if (location != null && location.length() > 0) 178 icon = AbstractUIPlugin.imageDescriptorFromPlugin( 179 extendingPluginId, location); 180 } 181 return icon; 182 } 183 184 188 public IProjectNatureDescriptor getNatureDescriptor() { 189 return natureDescriptor; 190 } 191 192 public String getNatureId() { 193 return natureId; 194 } 195 196 199 public Object getAdapter(Class adapter) { 200 if (adapter == IWorkbenchAdapter.class) 201 return this; 202 else 203 return null; 204 } 205 206 public String getCategoryPath() { 207 if (element == null) 208 return ""; else 210 return element.getAttribute(ATT_CATEGORY); 211 } 212 213 222 public ICapabilityInstallWizard getInstallWizard() { 223 if (!isValid()) 224 return null; 225 226 try { 227 return (ICapabilityInstallWizard) element 228 .createExecutableExtension(ATT_INSTALL_WIZARD); 229 } catch (CoreException e) { 230 IDEWorkbenchPlugin 231 .log( 232 "Could not create capability install wizard.", e.getStatus()); return null; 234 } 235 } 236 237 241 public String getInstallDetails() { 242 if (!isValid()) 243 return null; 244 return element.getAttribute(ATT_INSTALL_DETAILS); 245 } 246 247 256 public ICapabilityUninstallWizard getUninstallWizard() { 257 if (!isValid()) 258 return null; 259 260 try { 261 return (ICapabilityUninstallWizard) element 262 .createExecutableExtension(ATT_UNINSTALL_WIZARD); 263 } catch (CoreException e) { 264 IDEWorkbenchPlugin 265 .log( 266 "Could not create capability uninstall wizard.", e.getStatus()); return null; 268 } 269 } 270 271 275 public String getUninstallDetails() { 276 if (!isValid()) 277 return null; 278 return element.getAttribute(ATT_UNINSTALL_DETAILS); 279 } 280 281 public String getDescription() { 282 if (!isValid()) 283 return ""; String description = element.getAttribute(ATT_DESCRIPTION); 285 if (description == null) 286 description = ""; return description; 288 } 289 290 295 public ArrayList getHandleUIs() { 296 return handleUIs; 297 } 298 299 304 public ArrayList getPerspectiveChoices() { 305 return perspectiveChoices; 306 } 307 308 311 public boolean isValid() { 312 return natureDescriptor != null; 313 } 314 } 315 | Popular Tags |