Author: scabanovich
Date: 2008-02-27 11:39:00 -0500 (Wed, 27 Feb 2008)
New Revision: 6603
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorManager.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorPart.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultXModelObjectLabelProvider.java
Log:
JBIDE-1433 Extention point for decorating label in Web Projects view and tree selectors
added
with example extension for TLD file.
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/META-INF/MANIFEST.MF 2008-02-27
12:57:41 UTC (rev 6602)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/META-INF/MANIFEST.MF 2008-02-27
16:39:00 UTC (rev 6603)
@@ -41,6 +41,7 @@
org.jboss.tools.common.model.ui.image,
org.jboss.tools.common.model.ui.messages,
org.jboss.tools.common.model.ui.navigator,
+ org.jboss.tools.common.model.ui.navigator.decorator,
org.jboss.tools.common.model.ui.objecteditor,
org.jboss.tools.common.model.ui.outline,
org.jboss.tools.common.model.ui.preferences,
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml 2008-02-27 12:57:41
UTC (rev 6602)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml 2008-02-27 16:39:00
UTC (rev 6603)
@@ -8,6 +8,7 @@
<extension-point id="paletteConstraints" name="Palette
Constraints" schema="schema/paletteConstraints.exsd"/>
<extension-point id="metaTemplates" name="Meta Templates"
schema="schema/metaTemplates.exsd"/>
<extension-point id="InsertTagWizard" name="InsertTagWizard"
schema="schema/InsertTagWizard.exsd"/>
+ <extension-point id="labelDecorator" name="Model Object Label
Decorator" schema="schema/labelDecorator.exsd"/>
<extension point="org.eclipse.ui.elementFactories">
<factory
class="org.jboss.tools.common.core.resources.XModelObjectEditorInputFactory"
id="org.jboss.tools.common.core.resources.XModelObjectEditorInputFactory">
Added: trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd 2008-02-27
16:39:00 UTC (rev 6603)
@@ -0,0 +1,130 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.tools.common.model.ui">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.jboss.tools.common.model.ui"
id="labelDecorator" name="Model Object Label Decorator"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="labelDecorator" minOccurs="0"
maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="labelDecorator">
+ <complexType>
+ <attribute name="partition" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="entities" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="variables" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="defaultValue" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultXModelObjectLabelProvider.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultXModelObjectLabelProvider.java 2008-02-27
12:57:41 UTC (rev 6602)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultXModelObjectLabelProvider.java 2008-02-27
16:39:00 UTC (rev 6603)
@@ -15,6 +15,8 @@
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.filesystems.XFileObject;
+import org.jboss.tools.common.model.ui.navigator.decorator.DecoratorManager;
+import org.jboss.tools.common.model.ui.navigator.decorator.XModelObjectDecorator;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
public class DefaultXModelObjectLabelProvider extends LabelProvider {
@@ -28,7 +30,12 @@
if (element != null) {
if (element instanceof XModelObject) {
XModelObject modelObject = (XModelObject)element;
- result = modelObject.getPresentationString();
+ XModelObjectDecorator d =
DecoratorManager.getInstance().getDecoratorByEntity(modelObject.getModelEntity().getName());
+ if(d != null) {
+ result = d.getLabel(modelObject);
+ } else {
+ result = modelObject.getPresentationString();
+ }
if(modelObject.getFileType() == XFileObject.FILE && modelObject.isModified())
result += "*";
} else {
result = element.toString();
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java 2008-02-27
16:39:00 UTC (rev 6603)
@@ -0,0 +1,16 @@
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import org.jboss.tools.common.model.XModelObject;
+
+public class AttributeDecoratorPart extends DecoratorPart {
+
+ public AttributeDecoratorPart(String value) {
+ super(value);
+ }
+
+ public String getLabelPart(XModelObject object) {
+ String v = object.getAttributeValue(value);
+ return v == null ? "{" + value + "}" : v;
+ }
+
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorManager.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorManager.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorManager.java 2008-02-27
16:39:00 UTC (rev 6603)
@@ -0,0 +1,122 @@
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.preference.IPersistentPreferenceStore;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+
+public class DecoratorManager {
+ private static String EXTENSION_POINT_ID = ModelUIPlugin.PLUGIN_ID +
".labelDecorator";
+
+ private static Object LOCK = new Object();
+ private static DecoratorManager INSTANCE;
+
+ private Map<String, XModelObjectDecorator> mapByName = new HashMap<String,
XModelObjectDecorator>();
+ private Map<String, XModelObjectDecorator> mapByEntity = new HashMap<String,
XModelObjectDecorator>();
+ private Map<String, Set<XModelObjectDecorator>> mapByPartition = new
HashMap<String, Set<XModelObjectDecorator>>();
+
+ private DecoratorManager() {
+ load();
+ }
+
+ public static DecoratorManager getInstance() {
+ if(INSTANCE == null) {
+ synchronized(LOCK) {
+ if(INSTANCE == null) {
+ DecoratorManager d = new DecoratorManager();
+ INSTANCE = d;
+ }
+ }
+ }
+ return INSTANCE;
+ }
+
+ public XModelObjectDecorator getDecoratorByEntity(String entity) {
+ return mapByEntity.get(entity);
+ }
+
+ public Set<XModelObjectDecorator> getDecoratorsByPartition(String partition) {
+ return mapByPartition.get(partition);
+ }
+
+ private void load() {
+ IExtensionPoint point =
Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID);
+ if(point == null) return;
+ IExtension[] es = point.getExtensions();
+ if(es != null) for (int i = 0; i < es.length; i++) {
+ IConfigurationElement[] elements = es[i].getConfigurationElements();
+ for (int j = 0; j < elements.length; j++) {
+ XModelObjectDecorator d = new XModelObjectDecorator();
+ d.load(elements[j]);
+ String name = d.getName();
+ String partition = d.getPartition();
+ Set<String> entities = d.getEntities();
+ mapByName.put(name, d);
+ Set<XModelObjectDecorator> set = mapByPartition.get(partition);
+ if(set == null) {
+ set = new HashSet<XModelObjectDecorator>();
+ mapByPartition.put(partition, set);
+ }
+ set.add(d);
+ for (String entity: entities) {
+ mapByEntity.put(entity, d);
+ }
+ }
+ }
+ loadFromPreferences();
+ }
+
+ public void loadFromPreferences() {
+ IPreferenceStore p = getPreferences();
+ for (String name: mapByName.keySet()) {
+ XModelObjectDecorator d = mapByName.get(name);
+ String key = ModelUIPlugin.PLUGIN_ID + ".labelDecorator." + name;
+ String value = p.getString(key);
+ if(value != null && value.length() > 0) {
+ d.setValue(value);
+ }
+ }
+ }
+
+ public void applyToPreferences() {
+ IPreferenceStore p = getPreferences();
+ for (String name: mapByName.keySet()) {
+ XModelObjectDecorator d = mapByName.get(name);
+ String key = ModelUIPlugin.PLUGIN_ID + ".labelDecorator." + name;
+ String value = d.getValue();
+ if(value != null && !value.equals(d.getDefaultValue()) &&
!value.equals("{name}")) {
+ p.setValue(key, value);
+ } else {
+ p.setValue(key, "");
+ }
+ }
+ if(p instanceof IPersistentPreferenceStore) {
+ try {
+ ((IPersistentPreferenceStore) p).save();
+ } catch (IOException e) {
+ ModelUIPlugin.getPluginLog().logError(e);
+ }
+ }
+ }
+
+ public void setDefaults() {
+ for (String name: mapByName.keySet()) {
+ XModelObjectDecorator d = mapByName.get(name);
+ d.setValue(d.getDefaultValue());
+ }
+ }
+
+ public static IPreferenceStore getPreferences() {
+ return ModelUIPlugin.getDefault().getPreferenceStore();
+ }
+
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorPart.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorPart.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorPart.java 2008-02-27
16:39:00 UTC (rev 6603)
@@ -0,0 +1,16 @@
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import org.jboss.tools.common.model.XModelObject;
+
+public class DecoratorPart {
+ String value;
+
+ public DecoratorPart(String value) {
+ this.value = value;
+ }
+
+ public String getLabelPart(XModelObject object) {
+ return value == null ? "" : value;
+ }
+
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java 2008-02-27
16:39:00 UTC (rev 6603)
@@ -0,0 +1,15 @@
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import org.jboss.tools.common.model.XModelObject;
+
+public class NameDecoratorPart extends DecoratorPart {
+
+ public NameDecoratorPart() {
+ super("name");
+ }
+
+ public String getLabelPart(XModelObject object) {
+ return "" + object.getPresentationString();
+ }
+
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java 2008-02-27
16:39:00 UTC (rev 6603)
@@ -0,0 +1,127 @@
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.jboss.tools.common.model.XModelObject;
+
+public class XModelObjectDecorator {
+ static String ATTR_NAME = "name";
+ static String ATTR_PARTITION= "partition";
+ static String ATTR_ENTITIES = "entities";
+ static String ATTR_VARIABLES = "variables";
+ static String ATTR_DEFAULT = "defaultValue";
+
+
+ String name;
+ String partition;
+ Set<String> entities = new HashSet<String>();
+ String[] variables = new String[0];
+ String defaultValue;
+ String value;
+
+ List<DecoratorPart> parts = null;
+
+ public XModelObjectDecorator() {}
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPartition() {
+ return partition;
+ }
+
+ public Set<String> getEntities() {
+ return entities;
+ }
+
+ public String[] getVariables() {
+ return variables;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ if(value != null && value.equals(this.value)) {
+ return;
+ }
+ this.value = value;
+ if(value == null || value.length() == 0) {
+ value = "{name}";
+ }
+ parts = null;
+ }
+
+ void load(IConfigurationElement element) {
+ name = element.getAttribute(ATTR_NAME);
+ partition = element.getAttribute(ATTR_PARTITION);
+ defaultValue = element.getAttribute(ATTR_DEFAULT);
+ setValue(defaultValue);
+ value = defaultValue;
+ String s = element.getAttribute(ATTR_ENTITIES);
+ if(s != null) {
+ String[] es = s.split(",");
+ for (int i = 0; i < es.length; i++) entities.add(es[i]);
+ }
+ s = element.getAttribute(ATTR_VARIABLES);
+ List<String> vs = new ArrayList<String>();
+ vs.add("name");
+ if(s != null) {
+ String[] es = s.split(",");
+ for (int i = 0; i < es.length; i++) vs.add(es[i]);
+ }
+ variables = vs.toArray(new String[0]);
+ }
+
+ List<DecoratorPart> compile() {
+ if(this.parts != null) return this.parts;
+ List<DecoratorPart> parts = new ArrayList<DecoratorPart>();
+ String v = value;
+ if(value == null || value.length() == 0) v = defaultValue;
+ if(v == null) v = "";
+ if(v.indexOf("{name}") < 0) {
+ if(v.length() > 0) v += " ";
+ v += "{name}";
+ }
+ StringTokenizer s = new StringTokenizer(v, "{}", true);
+ boolean inVariable = false;
+ while(s.hasMoreTokens()) {
+ String t = s.nextToken();
+ if(t.equals("{")) {
+ inVariable = true;
+ } else if(t.equals("}")) {
+ inVariable = false;
+ } else if(inVariable) {
+ if(t.equals("name")) {
+ parts.add(new NameDecoratorPart());
+ } else {
+ parts.add(new AttributeDecoratorPart(t));
+ }
+ } else {
+ parts.add(new DecoratorPart(t));
+ }
+ }
+ return this.parts = parts;
+ }
+
+ public String getLabel(XModelObject object) {
+ List<DecoratorPart> parts = compile();
+ StringBuffer sb = new StringBuffer();
+ for (DecoratorPart d: parts) {
+ sb.append(d.getLabelPart(object));
+ }
+ return sb.toString();
+ }
+
+}