1 11 package org.eclipse.ui.internal.registry; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.core.runtime.IConfigurationElement; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Preferences; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.ui.IPluginContribution; 21 import org.eclipse.ui.internal.PluginActionSet; 22 import org.eclipse.ui.internal.PluginActionSetReader; 23 import org.eclipse.ui.internal.WorkbenchPlugin; 24 import org.eclipse.ui.model.IWorkbenchAdapter; 25 26 29 public class ActionSetDescriptor implements IActionSetDescriptor, IAdaptable, 30 IWorkbenchAdapter, IPluginContribution { 31 private static final Object [] NO_CHILDREN = new Object [0]; 32 33 private static final String INITIALLY_HIDDEN_PREF_ID_PREFIX = "actionSet.initiallyHidden."; 35 private String id; 36 37 private String pluginId; 38 39 private String label; 40 41 private boolean visible; 42 43 private String description; 44 45 private IConfigurationElement configElement; 46 47 53 public ActionSetDescriptor(IConfigurationElement configElement) 54 throws CoreException { 55 super(); 56 this.configElement = configElement; 57 id = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 58 pluginId = configElement.getNamespace(); 59 label = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_LABEL); 60 description = configElement.getAttribute(IWorkbenchRegistryConstants.TAG_DESCRIPTION); 61 String str = configElement.getAttribute(IWorkbenchRegistryConstants.ATT_VISIBLE); 62 if (str != null && str.equals("true")) { visible = true; 64 } 65 66 if (label == null) { 68 throw new CoreException(new Status(IStatus.ERROR, 69 WorkbenchPlugin.PI_WORKBENCH, 0, 70 "Invalid extension (missing label): " + id, null)); 72 } 73 } 74 75 80 public IActionSet createActionSet() throws CoreException { 81 return new PluginActionSet(this); 82 } 83 84 89 public Object getAdapter(Class adapter) { 90 if (adapter == IWorkbenchAdapter.class) { 91 return this; 92 } 93 return null; 94 } 95 96 99 public Object [] getChildren(Object o) { 100 if (o == this) { 101 return (new PluginActionSetReader()).readActionDescriptors(this); 102 } 103 104 return NO_CHILDREN; 105 } 106 107 108 111 public IConfigurationElement getConfigurationElement() { 112 return configElement; 113 } 114 115 121 public String getDescription() { 122 return description; 123 } 124 125 132 public String getId() { 133 return id; 134 } 135 136 142 public String getLabel() { 143 return label; 144 } 145 146 149 public String getLabel(Object o) { 150 if (o == this) { 151 return getLabel(); 152 } 153 return "Unknown Label"; } 155 156 159 public boolean isInitiallyVisible() { 160 if (id == null) { 161 return visible; 162 } 163 Preferences prefs = WorkbenchPlugin.getDefault().getPluginPreferences(); 164 String prefId = INITIALLY_HIDDEN_PREF_ID_PREFIX + getId(); 165 if (prefs.getBoolean(prefId)) { 166 return false; 167 } 168 return visible; 169 } 170 171 177 public void setInitiallyVisible(boolean newValue) { 178 if (id == null) { 179 return; 180 } 181 Preferences prefs = WorkbenchPlugin.getDefault().getPluginPreferences(); 182 String prefId = INITIALLY_HIDDEN_PREF_ID_PREFIX + getId(); 183 prefs.setValue(prefId, !newValue); 184 } 185 186 189 public ImageDescriptor getImageDescriptor(Object object) { 190 return null; 191 } 192 193 196 public Object getParent(Object o) { 197 return null; 198 } 199 200 203 public String getLocalId() { 204 return id; 205 } 206 207 210 public String getPluginId() { 211 return pluginId; 212 } 213 214 public boolean equals(Object arg0) { 215 if (!(arg0 instanceof ActionSetDescriptor)) { 216 return false; 217 } 218 219 ActionSetDescriptor descr = (ActionSetDescriptor) arg0; 220 221 return id.equals(descr.id) && descr.pluginId.equals(pluginId); 222 } 223 224 public int hashCode() { 225 return id.hashCode() + pluginId.hashCode(); 226 } 227 } 228 | Popular Tags |