1 11 package org.eclipse.ui.internal.ide.registry; 12 13 import org.eclipse.core.runtime.IConfigurationElement; 14 import org.eclipse.core.runtime.IExtensionRegistry; 15 import org.eclipse.ui.WorkbenchException; 16 import org.eclipse.ui.internal.ide.Category; 17 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 18 19 24 public class CapabilityRegistryReader extends IDERegistryReader { 25 private static final String TAG_CAPABILITY = "capability"; 27 private static final String TAG_CATEGORY = "category"; 29 private static final String TAG_HANDLE_UI = "handleUI"; 31 private static final String TAG_PERSPECTIVE_CHOICE = "perspectiveChoice"; 33 private static final String ATT_ID = "id"; 35 private CapabilityRegistry capabilityRegistry; 36 37 private Capability currentCapability; 38 39 45 protected boolean readElement(IConfigurationElement element) { 46 String name = element.getName(); 47 if (name.equals(TAG_CAPABILITY)) 48 return readCapability(element); 49 if (name.equals(TAG_CATEGORY)) 50 return readCategory(element); 51 if (name.equals(TAG_HANDLE_UI)) 52 return readHandleUI(element); 53 if (name.equals(TAG_PERSPECTIVE_CHOICE)) 54 return readPerspectiveChoice(element); 55 return false; 56 } 57 58 63 private boolean readCapability(IConfigurationElement element) { 64 try { 65 Capability capability = new Capability(element, this); 66 capabilityRegistry.addCapability(capability); 67 currentCapability = capability; 68 readElementChildren(element); 69 currentCapability = null; 70 return true; 71 } catch (WorkbenchException e) { 72 currentCapability = null; 73 return false; 74 } 75 } 76 77 80 private boolean readCategory(IConfigurationElement element) { 81 try { 82 Category category = new Category(element); 83 capabilityRegistry.addCategory(category); 84 } catch (WorkbenchException e) { 85 IDEWorkbenchPlugin.log( 87 "Unable to create capability category. ", e.getStatus()); } 89 return true; 90 } 91 92 98 private boolean readHandleUI(IConfigurationElement element) { 99 String capabilityId = element.getAttribute(ATT_ID); 100 101 if (capabilityId == null) { 102 logMissingAttribute(element, ATT_ID); 103 } 104 105 if (currentCapability != null) 106 currentCapability.addHandleUI(capabilityId); 107 return true; 108 } 109 110 114 private boolean readPerspectiveChoice(IConfigurationElement element) { 115 String perspId = element.getAttribute(ATT_ID); 116 117 if (perspId == null) { 118 logMissingAttribute(element, ATT_ID); 119 } 120 121 if (currentCapability != null) 122 currentCapability.addPerspectiveChoice(perspId); 123 return true; 124 } 125 126 130 public void read(IExtensionRegistry registry, CapabilityRegistry out) { 131 capabilityRegistry = out; 132 readRegistry(registry, IDEWorkbenchPlugin.IDE_WORKBENCH, 133 IDEWorkbenchPlugin.PL_CAPABILITIES); 134 } 135 } 136 | Popular Tags |