1 15 16 package org.eclipse.ui.internal.registry; 17 18 import java.util.HashSet ; 19 import java.util.Set ; 20 21 import org.eclipse.core.runtime.IConfigurationElement; 22 import org.eclipse.core.runtime.Platform; 23 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; 24 import org.eclipse.ui.IPageLayout; 25 import org.eclipse.ui.IViewLayout; 26 import org.eclipse.ui.PlatformUI; 27 import org.eclipse.ui.internal.DirtyPerspectiveMarker; 28 import org.eclipse.ui.internal.PageLayout; 29 import org.eclipse.ui.internal.WorkbenchPlugin; 30 31 36 public class PerspectiveExtensionReader extends RegistryReader { 37 private String targetID; 38 39 private PageLayout pageLayout; 40 41 private Set includeOnlyTags = null; 42 43 private static final String VAL_LEFT = "left"; 45 private static final String VAL_RIGHT = "right"; 47 private static final String VAL_TOP = "top"; 49 private static final String VAL_BOTTOM = "bottom"; 51 private static final String VAL_STACK = "stack"; 53 private static final String VAL_FAST = "fast"; 55 private static final String VAL_TRUE = "true"; 57 private static final String VAL_FALSE = "false"; 62 private IExtensionTracker tracker; 63 64 67 public PerspectiveExtensionReader() { 68 } 70 71 78 public void extendLayout(IExtensionTracker extensionTracker, String id, PageLayout out) { 79 tracker = extensionTracker; 80 targetID = id; 81 pageLayout = out; 82 readRegistry(Platform.getExtensionRegistry(), PlatformUI.PLUGIN_ID, 83 IWorkbenchRegistryConstants.PL_PERSPECTIVE_EXTENSIONS); 84 } 85 86 89 private boolean includeTag(String tag) { 90 return includeOnlyTags == null || includeOnlyTags.contains(tag); 91 } 92 93 96 private boolean processActionSet(IConfigurationElement element) { 97 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 98 if (id != null) { 99 pageLayout.addActionSet(id); 100 } 101 return true; 102 } 103 104 108 private boolean processExtension(IConfigurationElement element) { 109 IConfigurationElement[] children = element.getChildren(); 110 for (int nX = 0; nX < children.length; nX++) { 111 IConfigurationElement child = children[nX]; 112 String type = child.getName(); 113 if (includeTag(type)) { 114 boolean result = false; 115 if (type.equals(IWorkbenchRegistryConstants.TAG_ACTION_SET)) { 116 result = processActionSet(child); 117 } else if (type.equals(IWorkbenchRegistryConstants.TAG_VIEW)) { 118 result = processView(child); 119 } else if (type.equals(IWorkbenchRegistryConstants.TAG_VIEW_SHORTCUT)) { 120 result = processViewShortcut(child); 121 } else if (type.equals(IWorkbenchRegistryConstants.TAG_NEW_WIZARD_SHORTCUT)) { 122 result = processWizardShortcut(child); 123 } else if (type.equals(IWorkbenchRegistryConstants.TAG_PERSP_SHORTCUT)) { 124 result = processPerspectiveShortcut(child); 125 } else if (type.equals(IWorkbenchRegistryConstants.TAG_SHOW_IN_PART)) { 126 result = processShowInPart(child); 127 } 128 if (!result) { 129 WorkbenchPlugin.log("Unable to process element: " + type 131 + " in perspective extension: " + element.getDeclaringExtension() 133 .getUniqueIdentifier()); 134 } 135 } 136 } 137 return true; 138 } 139 140 143 private boolean processPerspectiveShortcut(IConfigurationElement element) { 144 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 145 if (id != null) { 146 pageLayout.addPerspectiveShortcut(id); 147 } 148 return true; 149 } 150 151 154 private boolean processShowInPart(IConfigurationElement element) { 155 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 156 if (id != null) { 157 pageLayout.addShowInPart(id); 158 } 159 return true; 160 } 161 162 166 private boolean processView(IConfigurationElement element) { 167 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 169 String relative = element.getAttribute(IWorkbenchRegistryConstants.ATT_RELATIVE); 170 String relationship = element.getAttribute(IWorkbenchRegistryConstants.ATT_RELATIONSHIP); 171 String ratioString = element.getAttribute(IWorkbenchRegistryConstants.ATT_RATIO); 172 boolean visible = !VAL_FALSE.equals(element.getAttribute(IWorkbenchRegistryConstants.ATT_VISIBLE)); 173 String closeable = element.getAttribute(IWorkbenchRegistryConstants.ATT_CLOSEABLE); 174 String moveable = element.getAttribute(IWorkbenchRegistryConstants.ATT_MOVEABLE); 175 String standalone = element.getAttribute(IWorkbenchRegistryConstants.ATT_STANDALONE); 176 String showTitle = element.getAttribute(IWorkbenchRegistryConstants.ATT_SHOW_TITLE); 177 178 String minVal = element.getAttribute(IWorkbenchRegistryConstants.ATT_MINIMIZED); 180 boolean minimized = minVal != null && VAL_TRUE.equals(minVal); 181 182 float ratio; 183 184 if (id == null) { 185 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ID); 186 return false; 187 } 188 if (relationship == null) { 189 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_RELATIONSHIP); 190 return false; 191 } 192 if (!VAL_FAST.equals(relationship) && relative == null) { 193 logError( 194 element, 195 "Attribute '" + IWorkbenchRegistryConstants.ATT_RELATIVE + "' not defined. This attribute is required when " + IWorkbenchRegistryConstants.ATT_RELATIONSHIP + "=\"" + relationship + "\"."); return false; 197 } 198 199 if (ratioString == null) { 201 ratio = IPageLayout.NULL_RATIO; 203 } else { 204 try { 205 ratio = new Float (ratioString).floatValue(); 206 } catch (NumberFormatException e) { 207 return false; 208 } 209 if (ratio < IPageLayout.RATIO_MIN || ratio > IPageLayout.RATIO_MAX) { 211 ratio = IPageLayout.INVALID_RATIO; 212 } 213 } 214 215 boolean stack = false; 217 boolean fast = false; 218 int intRelation = 0; 219 if (relationship.equals(VAL_LEFT)) { 220 intRelation = IPageLayout.LEFT; 221 } else if (relationship.equals(VAL_RIGHT)) { 222 intRelation = IPageLayout.RIGHT; 223 } else if (relationship.equals(VAL_TOP)) { 224 intRelation = IPageLayout.TOP; 225 } else if (relationship.equals(VAL_BOTTOM)) { 226 intRelation = IPageLayout.BOTTOM; 227 } else if (relationship.equals(VAL_STACK)) { 228 stack = true; 229 } else if (relationship.equals(VAL_FAST)) { 230 fast = true; 231 } else { 232 return false; 233 } 234 235 if (visible) { 236 pageLayout.removePlaceholder(id); 239 } 240 241 if (stack) { 243 if (visible) { 244 pageLayout.stackView(id, relative); 245 } else { 246 pageLayout.stackPlaceholder(id, relative); 247 } 248 } 249 250 else if (fast) { 252 if (ratio == IPageLayout.NULL_RATIO) { 253 pageLayout.addFastView(id); 255 } else { 256 pageLayout.addFastView(id, ratio); 257 } 258 } else { 259 260 if (ratio == IPageLayout.NULL_RATIO 263 || ratio == IPageLayout.INVALID_RATIO) { 264 ratio = IPageLayout.DEFAULT_VIEW_RATIO; 265 } 266 267 if (visible) { 268 if (VAL_TRUE.equals(standalone)) { 269 pageLayout.addStandaloneView(id, !VAL_FALSE 270 .equals(showTitle), intRelation, ratio, relative); 271 } else { 272 pageLayout.addView(id, intRelation, ratio, relative, minimized); 273 } 274 } else { 275 if (VAL_TRUE.equals(standalone)) { 278 pageLayout.addStandaloneViewPlaceholder(id, intRelation, 279 ratio, relative, !VAL_FALSE.equals(showTitle)); 280 } else { 281 pageLayout.addPlaceholder(id, intRelation, ratio, relative); 282 } 283 } 284 } 285 IViewLayout viewLayout = pageLayout.getViewLayout(id); 286 if (viewLayout != null) { 288 if (closeable != null) { 289 viewLayout.setCloseable(!VAL_FALSE.equals(closeable)); 290 } 291 if (moveable != null) { 292 viewLayout.setMoveable(!VAL_FALSE.equals(moveable)); 293 } 294 } 295 296 return true; 297 } 298 299 302 private boolean processViewShortcut(IConfigurationElement element) { 303 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 304 if (id != null) { 305 pageLayout.addShowViewShortcut(id); 306 } 307 return true; 308 } 309 310 313 private boolean processWizardShortcut(IConfigurationElement element) { 314 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 315 if (id != null) { 316 pageLayout.addNewWizardShortcut(id); 317 } 318 return true; 319 } 320 321 protected boolean readElement(IConfigurationElement element) { 322 String type = element.getName(); 323 if (type.equals(IWorkbenchRegistryConstants.TAG_PERSPECTIVE_EXTENSION)) { 324 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_TARGET_ID); 325 if (targetID.equals(id) || "*".equals(id)) { if (tracker != null) { 327 tracker.registerObject(element.getDeclaringExtension(), new DirtyPerspectiveMarker(id), IExtensionTracker.REF_STRONG); 328 } 329 return processExtension(element); 330 } 331 return true; 332 } 333 return false; 334 } 335 336 341 public void setIncludeOnlyTags(String [] tags) { 342 includeOnlyTags = new HashSet (); 343 for (int i = 0; i < tags.length; i++) { 344 includeOnlyTags.add(tags[i]); 345 } 346 } 347 } 348 | Popular Tags |