1 11 package org.eclipse.ui.internal.decorators; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.core.runtime.IConfigurationElement; 15 import org.eclipse.core.runtime.IExtension; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.ui.internal.dialogs.DialogUtil; 18 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 19 import org.eclipse.ui.model.IWorkbenchAdapter; 20 import org.eclipse.ui.plugin.AbstractUIPlugin; 21 22 30 public class LightweightActionDescriptor implements IAdaptable, 31 IWorkbenchAdapter { 32 private static final Object [] NO_CHILDREN = new Object [0]; 33 34 private String id; 35 36 private String label; 37 38 private String description; 39 40 private ImageDescriptor image; 41 42 47 public LightweightActionDescriptor(IConfigurationElement actionElement) { 48 super(); 49 50 this.id = actionElement.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 51 this.label = actionElement.getAttribute(IWorkbenchRegistryConstants.ATT_LABEL); 52 this.description = actionElement 53 .getAttribute(IWorkbenchRegistryConstants.TAG_DESCRIPTION); 54 55 String iconName = actionElement.getAttribute(IWorkbenchRegistryConstants.ATT_ICON); 56 if (iconName != null) { 57 IExtension extension = actionElement.getDeclaringExtension(); 58 this.image = AbstractUIPlugin.imageDescriptorFromPlugin(extension 59 .getNamespace(), iconName); 60 } 61 } 62 63 68 public Object getAdapter(Class adapter) { 69 if (adapter == IWorkbenchAdapter.class) { 70 return this; 71 } 72 return null; 73 } 74 75 80 public String getDescription() { 81 return description; 82 } 83 84 89 public String getId() { 90 return id; 91 } 92 93 98 public ImageDescriptor getImageDescriptor() { 99 return image; 100 } 101 102 105 public ImageDescriptor getImageDescriptor(Object o) { 106 if (o == this) { 107 return getImageDescriptor(); 108 } 109 return null; 110 } 111 112 117 public String getLabel() { 118 return label; 119 } 120 121 124 public String getLabel(Object o) { 125 if (o == this) { 126 String text = getLabel(); 127 int end = text.lastIndexOf('@'); 128 if (end >= 0) { 129 text = text.substring(0, end); 130 } 131 return DialogUtil.removeAccel(text); 132 } 133 return o == null ? "" : o.toString(); } 135 136 139 public Object [] getChildren(Object o) { 140 return NO_CHILDREN; 141 } 142 143 146 public Object getParent(Object o) { 147 return null; 148 } 149 } 150 | Popular Tags |