1 11 package org.eclipse.ui.internal.views.properties.tabbed.view; 12 13 import com.ibm.icu.text.MessageFormat; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.jface.viewers.IFilter; 22 import org.eclipse.jface.viewers.ISelection; 23 import org.eclipse.ui.IWorkbenchPart; 24 import org.eclipse.ui.internal.views.properties.tabbed.TabbedPropertyViewPlugin; 25 import org.eclipse.ui.internal.views.properties.tabbed.TabbedPropertyViewStatusCodes; 26 import org.eclipse.ui.internal.views.properties.tabbed.l10n.TabbedPropertyMessages; 27 import org.eclipse.ui.views.properties.tabbed.ISection; 28 import org.eclipse.ui.views.properties.tabbed.ISectionDescriptor; 29 import org.eclipse.ui.views.properties.tabbed.ITypeMapper; 30 31 38 public class SectionDescriptor 39 implements ISectionDescriptor { 40 41 private final static String SECTION_ERROR = TabbedPropertyMessages.SectionDescriptor_Section_error; 42 43 private static final String ATT_ID = "id"; 45 private static final String ATT_TARGET_TAB = "tab"; 47 private static final String ATT_AFTER_SECTION = "afterSection"; 49 private static final String ATT_CLASS = "class"; 51 private static final String ATT_SECTION_FILTER = "filter"; 53 private static final String ATT_SECTION_ENABLES_FOR = "enablesFor"; 55 private static final String ATT_INPUT_TYPE = "type"; 57 private static final String ELEMENT_INPUT = "input"; 59 private static final String TOP = "top"; 61 private String id; 62 63 private String targetTab; 64 65 private String afterSection; 66 67 private ArrayList inputTypes; 68 69 private TabbedPropertyRegistryClassSectionFilter classFilter; 70 71 private IFilter filter; 72 73 private int enablesFor = ENABLES_FOR_ANY; 74 75 private IConfigurationElement configurationElement; 76 77 85 protected SectionDescriptor(IConfigurationElement configurationElement, 86 ITypeMapper typeMapper) { 87 this.configurationElement = configurationElement; 88 89 classFilter = new TabbedPropertyRegistryClassSectionFilter(typeMapper); 90 id = getConfigurationElement().getAttribute(ATT_ID); 91 targetTab = getConfigurationElement().getAttribute(ATT_TARGET_TAB); 92 afterSection = getConfigurationElement() 93 .getAttribute(ATT_AFTER_SECTION); 94 if (getConfigurationElement().getAttribute(ATT_SECTION_ENABLES_FOR) != null) { 95 String enablesForStr = getConfigurationElement().getAttribute( 96 ATT_SECTION_ENABLES_FOR); 97 int enablesForTest = Integer.parseInt(enablesForStr); 98 if (enablesForTest > 0) { 99 enablesFor = enablesForTest; 100 } 101 } 102 103 if (id == null || targetTab == null) { 104 handleSectionError(null); 106 } 107 if (getAfterSection() == null) { 108 afterSection = TOP; 109 } 110 } 111 112 121 private void handleSectionError(CoreException exception) { 122 String pluginId = getConfigurationElement().getDeclaringExtension() 123 .getNamespace(); 124 String message = MessageFormat.format(SECTION_ERROR, 125 new Object [] {pluginId}); 126 IStatus status = new Status(IStatus.ERROR, pluginId, 127 TabbedPropertyViewStatusCodes.SECTION_ERROR, message, exception); 128 TabbedPropertyViewPlugin.getPlugin().getLog().log(status); 129 } 130 131 134 public String getId() { 135 return id; 136 } 137 138 141 public IFilter getFilter() { 142 if (filter == null) { 143 try { 144 if (getConfigurationElement().getAttribute(ATT_SECTION_FILTER) != null) { 145 filter = (IFilter) configurationElement 146 .createExecutableExtension(ATT_SECTION_FILTER); 147 } 148 } catch (CoreException exception) { 149 handleSectionError(exception); 150 } 151 } 152 return filter; 153 } 154 155 162 public int getEnablesFor() { 163 return enablesFor; 164 } 165 166 169 public String getTargetTab() { 170 return targetTab; 171 } 172 173 177 public boolean appliesTo(IWorkbenchPart part, ISelection selection) { 178 return classFilter.appliesToSelection(this, selection); 179 } 180 181 184 public String getAfterSection() { 185 return afterSection; 186 } 187 188 193 public ISection getSectionClass() { 194 ISection section = null; 195 try { 196 section = (ISection) getConfigurationElement() 197 .createExecutableExtension(ATT_CLASS); 198 } catch (CoreException exception) { 199 handleSectionError(exception); 200 } 201 202 return section; 203 } 204 205 210 public List getInputTypes() { 211 if (inputTypes == null) { 212 inputTypes = new ArrayList (); 213 IConfigurationElement[] elements = getConfigurationElement() 214 .getChildren(ELEMENT_INPUT); 215 for (int i = 0; i < elements.length; i++) { 216 IConfigurationElement element = elements[i]; 217 inputTypes.add(element.getAttribute(ATT_INPUT_TYPE)); 218 } 219 } 220 221 return inputTypes; 222 } 223 224 227 public String toString() { 228 return getId(); 229 } 230 231 234 private IConfigurationElement getConfigurationElement() { 235 return configurationElement; 236 } 237 } 238 | Popular Tags |