1 11 package org.eclipse.ui.internal.ide; 12 13 import java.util.ArrayList ; 14 import java.util.StringTokenizer ; 15 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.jface.resource.ImageDescriptor; 18 import org.eclipse.ui.ISharedImages; 19 import org.eclipse.ui.PlatformUI; 20 import org.eclipse.ui.WorkbenchException; 21 import org.eclipse.ui.model.IWorkbenchAdapter; 22 import org.eclipse.ui.model.WorkbenchAdapter; 23 24 33 public class Category extends WorkbenchAdapter { 34 37 public final static String MISC_NAME = IDEWorkbenchMessages.ICategory_other; 38 39 42 public final static String MISC_ID = "org.eclipse.ui.internal.otherCategory"; 44 private static final String ATT_ID = "id"; 46 private static final String ATT_PARENT = "parentCategory"; 48 private static final String ATT_NAME = "name"; 50 private String id; 51 52 private String name; 53 54 private String [] parentPath; 55 56 private String unparsedPath; 57 58 private ArrayList elements; 59 60 64 public Category() { 65 this.id = MISC_ID; 66 this.name = MISC_NAME; 67 } 68 69 76 public Category(String id, String label) { 77 this.id = id; 78 this.name = label; 79 } 80 81 89 public Category(IConfigurationElement configElement) 90 throws WorkbenchException { 91 id = configElement.getAttribute(ATT_ID); 92 name = configElement.getAttribute(ATT_NAME); 93 unparsedPath = configElement.getAttribute(ATT_PARENT); 94 95 if (id == null || name == null) { 96 throw new WorkbenchException("Invalid category: " + id); } 98 } 99 100 103 public void addElement(Object element) { 104 if (elements == null) { 105 elements = new ArrayList (5); 106 } 107 elements.add(element); 108 } 109 110 113 public Object getAdapter(Class adapter) { 114 if (adapter == IWorkbenchAdapter.class) { 115 return this; 116 } else { 117 return null; 118 } 119 } 120 121 124 public Object [] getChildren(Object o) { 125 return getElements().toArray(); 126 } 127 128 131 public ImageDescriptor getImageDescriptor(Object object) { 132 return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( 133 ISharedImages.IMG_OBJ_FOLDER); 134 } 135 136 139 public String getLabel(Object o) { 140 return getLabel(); 141 } 142 143 146 public String getId() { 147 return id; 148 } 149 150 153 public String getLabel() { 154 return name; 155 } 156 157 160 public String [] getParentPath() { 161 if (unparsedPath != null) { 162 StringTokenizer stok = new StringTokenizer (unparsedPath, "/"); parentPath = new String [stok.countTokens()]; 164 for (int i = 0; stok.hasMoreTokens(); i++) { 165 parentPath[i] = stok.nextToken(); 166 } 167 unparsedPath = null; 168 } 169 170 return parentPath; 171 } 172 173 176 public String getRootPath() { 177 String [] path = getParentPath(); 178 if (path != null && path.length > 0) { 179 return path[0]; 180 } else { 181 return id; 182 } 183 } 184 185 188 public ArrayList getElements() { 189 return elements; 190 } 191 192 195 public boolean hasElements() { 196 if (elements != null) { 197 return !elements.isEmpty(); 198 } else { 199 return false; 200 } 201 } 202 } 203 | Popular Tags |