Author: scabanovich
Date: 2008-02-28 12:10:42 -0500 (Thu, 28 Feb 2008)
New Revision: 6644
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorConstants.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Example.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/IDecoratorPart.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Variable.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorGeneralPreferencesPage.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesListener.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesPage.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorTextPreferencesPage.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml
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/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
Log:
JBIDE-1433
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-28 16:05:23
UTC (rev 6643)
+++ trunk/common/plugins/org.jboss.tools.common.model.ui/plugin.xml 2008-02-28 17:10:42
UTC (rev 6644)
@@ -221,6 +221,12 @@
id="org.jboss.tools.common.model.ui"
name="Web">
</page>
+ <page
+ category="org.jboss.tools.common.model.ui"
+
class="org.jboss.tools.common.model.ui.preferences.DecoratorPreferencesPage"
+ id="org.jboss.tools.common.model.ui.decorator"
+ name="Label Decorations">
+ </page>
</extension>
<extension point="org.eclipse.ui.preferencePages">
<page
Modified: trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd 2008-02-28
16:05:23 UTC (rev 6643)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/schema/labelDecorator.exsd 2008-02-28
17:10:42 UTC (rev 6644)
@@ -44,6 +44,10 @@
<element name="labelDecorator">
<complexType>
+ <sequence>
+ <element ref="variable" minOccurs="0"
maxOccurs="unbounded"/>
+ <element ref="example" minOccurs="0"
maxOccurs="unbounded"/>
+ </sequence>
<attribute name="partition" type="string"
use="required">
<annotation>
<documentation>
@@ -65,23 +69,69 @@
</documentation>
</annotation>
</attribute>
- <attribute name="variables" type="string">
+ <attribute name="defaultValue" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
- <attribute name="defaultValue" type="string">
+ </complexType>
+ </element>
+
+ <element name="variable">
+ <complexType>
+ <attribute name="name" type="string"
use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
+ <attribute name="description" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
+ <element name="example">
+ <complexType>
+ <sequence>
+ <element ref="put" minOccurs="0"
maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="entity" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="put">
+ <complexType>
+ <attribute name="name" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="value" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>
Modified:
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 2008-02-28
16:05:23 UTC (rev 6643)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/AttributeDecoratorPart.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.common.model.ui.navigator.decorator;
import org.jboss.tools.common.model.XModelObject;
@@ -2,11 +12,15 @@
-public class AttributeDecoratorPart extends DecoratorPart {
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class AttributeDecoratorPart implements IDecoratorPart {
+ Variable variable;
- public AttributeDecoratorPart(String value) {
- super(value);
+ public AttributeDecoratorPart(Variable variable) {
+ this.variable = variable;
}
public String getLabelPart(XModelObject object) {
- String v = object.getAttributeValue(value);
- return v == null ? "{" + value + "}" : v;
+ String v = object.getAttributeValue(variable.getName());
+ return v == null ? "{" + variable.getName() + "}" : v;
}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorConstants.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorConstants.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorConstants.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public interface DecoratorConstants {
+
+ public String ATTR_NAME = "name";
+
+ public String ATTR_PARTITION = "partition";
+
+ public String ATTR_ENTITIES = "entities";
+
+ public String ATTR_ENTITY = "entity";
+
+ public String ATTR_DEFAULT = "defaultValue";
+
+ public String ATTR_DESCRIPTION = "description";
+
+ public String ATTR_VALUE = "value";
+
+ public String NODE_VARIABLE = "variable";
+
+ public String NODE_EXAMPLE = "example";
+
+ public String NODE_PUT = "put";
+
+ public String RULE_OPENING = "{";
+
+ public String RULE_CLOSING = "}";
+
+}
Modified:
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 2008-02-28
16:05:23 UTC (rev 6643)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorManager.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.common.model.ui.navigator.decorator;
import java.io.IOException;
@@ -5,6 +15,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.TreeSet;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@@ -14,8 +25,11 @@
import org.eclipse.jface.preference.IPreferenceStore;
import org.jboss.tools.common.model.ui.ModelUIPlugin;
+/**
+ * @author Viacheslav Kabanovich
+ */
public class DecoratorManager {
- private static String EXTENSION_POINT_ID = ModelUIPlugin.PLUGIN_ID +
".labelDecorator";
+ public static final String EXTENSION_POINT_ID = ModelUIPlugin.PLUGIN_ID +
".labelDecorator";
private static Object LOCK = new Object();
private static DecoratorManager INSTANCE;
@@ -23,6 +37,7 @@
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 Map<String, String> entityByPartition = new HashMap<String,
String>();
private DecoratorManager() {
load();
@@ -48,6 +63,16 @@
return mapByPartition.get(partition);
}
+ public String getBaseEntityForPartition(String partition) {
+ return entityByPartition.get(partition);
+ }
+
+ public String[] getPartitions() {
+ Set<String> set = new TreeSet<String>();
+ set.addAll(mapByPartition.keySet());
+ return set.toArray(new String[0]);
+ }
+
private void load() {
IExtensionPoint point =
Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID);
if(point == null) return;
@@ -69,6 +94,9 @@
set.add(d);
for (String entity: entities) {
mapByEntity.put(entity, d);
+ if(entity.startsWith("File") && entityByPartition.get(partition)
== null) {
+ entityByPartition.put(partition, entity);
+ }
}
}
}
@@ -114,7 +142,7 @@
d.setValue(d.getDefaultValue());
}
}
-
+
public static IPreferenceStore getPreferences() {
return ModelUIPlugin.getDefault().getPreferenceStore();
}
Modified:
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 2008-02-28
16:05:23 UTC (rev 6643)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/DecoratorPart.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.common.model.ui.navigator.decorator;
import org.jboss.tools.common.model.XModelObject;
@@ -2,3 +12,6 @@
-public class DecoratorPart {
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class DecoratorPart implements IDecoratorPart {
String value;
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Example.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Example.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Example.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.options.PreferenceModelUtilities;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class Example implements DecoratorConstants {
+
+ public static XModelObject load(IConfigurationElement element) {
+ String entity = element.getAttribute(ATTR_ENTITY);
+ if(entity == null || entity.length() == 0) {
+ return null;
+ }
+ Properties p = new Properties();
+ IConfigurationElement[] cs = element.getChildren(NODE_PUT);
+ for (int i = 0; i < cs.length; i++) {
+ String name = cs[i].getAttribute(ATTR_NAME);
+ String value = cs[i].getAttribute(ATTR_VALUE);
+ if(name == null || value == null) continue;
+ p.setProperty(name, value);
+ }
+
+ return PreferenceModelUtilities.getPreferenceModel().createModelObject(entity, p);
+ }
+
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/IDecoratorPart.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/IDecoratorPart.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/IDecoratorPart.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import org.jboss.tools.common.model.XModelObject;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public interface IDecoratorPart {
+ public String getLabelPart(XModelObject object);
+}
Modified:
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 2008-02-28
16:05:23 UTC (rev 6643)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/NameDecoratorPart.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.common.model.ui.navigator.decorator;
import org.jboss.tools.common.model.XModelObject;
@@ -2,6 +12,8 @@
-public class NameDecoratorPart extends DecoratorPart {
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class NameDecoratorPart implements IDecoratorPart {
public NameDecoratorPart() {
- super("name");
}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Variable.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Variable.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/Variable.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.navigator.decorator;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class Variable implements DecoratorConstants {
+ public static Variable NAME = new Variable("name", "default
label");
+
+ String name;
+ String description;
+
+ public Variable() {}
+
+ Variable(String name, String description) {
+ this.name = name;
+ this.description = description;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getRuleText() {
+ return RULE_OPENING + name + RULE_CLOSING;
+ }
+
+ public String toString() {
+ if(description == null || description.length() == 0) {
+ return name;
+ }
+ return name + " - " + description;
+ }
+
+ public void load(IConfigurationElement element) {
+ name = element.getAttribute(ATTR_NAME);
+ description = element.getAttribute(ATTR_DESCRIPTION);
+ }
+
+}
Modified:
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 2008-02-28
16:05:23 UTC (rev 6643)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/navigator/decorator/XModelObjectDecorator.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -1,31 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.common.model.ui.navigator.decorator;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
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";
-
-
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class XModelObjectDecorator implements DecoratorConstants {
String name;
String partition;
Set<String> entities = new HashSet<String>();
- String[] variables = new String[0];
+ Variable[] variables = new Variable[0];
+ Map<String, Variable> variableByName = new HashMap<String, Variable>();
String defaultValue;
String value;
- List<DecoratorPart> parts = null;
+ List<IDecoratorPart> parts = null;
+ XModelObject[] examples = new XModelObject[0];
+
public XModelObjectDecorator() {}
public String getName() {
@@ -40,10 +51,18 @@
return entities;
}
- public String[] getVariables() {
+ public Variable[] getVariables() {
return variables;
}
+ public Variable getVariableByName(String name) {
+ return variableByName.get(name);
+ }
+
+ public XModelObject[] getExamples() {
+ return examples;
+ }
+
public String getDefaultValue() {
return defaultValue;
}
@@ -58,7 +77,7 @@
}
this.value = value;
if(value == null || value.length() == 0) {
- value = "{name}";
+ value = Variable.NAME.getRuleText();
}
parts = null;
}
@@ -74,39 +93,53 @@
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]);
+ IConfigurationElement[] cs = element.getChildren(NODE_VARIABLE);
+ List<Variable> vs = new ArrayList<Variable>();
+ vs.add(Variable.NAME);
+ variableByName.put(Variable.NAME.getName(), Variable.NAME);
+ for (int i = 0; i < cs.length; i++) {
+ Variable v = new Variable();
+ v.load(cs[i]);
+ vs.add(v);
+ variableByName.put(v.getName(), v);
}
- variables = vs.toArray(new String[0]);
+ variables = vs.toArray(new Variable[0]);
+
+ List<XModelObject> es = new ArrayList<XModelObject>();
+ cs = element.getChildren(NODE_EXAMPLE);
+ for (int i = 0; i < cs.length; i++) {
+ XModelObject o = Example.load(cs[i]);
+ if(o != null) es.add(o);
+ }
+ examples = es.toArray(new XModelObject[0]);
}
- List<DecoratorPart> compile() {
+ List<IDecoratorPart> compile() {
if(this.parts != null) return this.parts;
- List<DecoratorPart> parts = new ArrayList<DecoratorPart>();
+ List<IDecoratorPart> parts = new ArrayList<IDecoratorPart>();
String v = value;
if(value == null || value.length() == 0) v = defaultValue;
if(v == null) v = "";
- if(v.indexOf("{name}") < 0) {
+ if(v.indexOf(Variable.NAME.getRuleText()) < 0) {
if(v.length() > 0) v += " ";
- v += "{name}";
+ v += Variable.NAME.getRuleText();
}
- StringTokenizer s = new StringTokenizer(v, "{}", true);
+ StringTokenizer s = new StringTokenizer(v, RULE_OPENING + RULE_CLOSING, true);
boolean inVariable = false;
while(s.hasMoreTokens()) {
String t = s.nextToken();
- if(t.equals("{")) {
+ if(t.equals(RULE_OPENING)) {
inVariable = true;
- } else if(t.equals("}")) {
+ } else if(t.equals(RULE_CLOSING)) {
inVariable = false;
} else if(inVariable) {
- if(t.equals("name")) {
+ Variable variable = getVariableByName(t);
+ if(variable == Variable.NAME) {
parts.add(new NameDecoratorPart());
+ } else if(variable != null){
+ parts.add(new AttributeDecoratorPart(variable));
} else {
- parts.add(new AttributeDecoratorPart(t));
+ parts.add(new DecoratorPart(RULE_OPENING + t + RULE_CLOSING));
}
} else {
parts.add(new DecoratorPart(t));
@@ -116,12 +149,29 @@
}
public String getLabel(XModelObject object) {
- List<DecoratorPart> parts = compile();
+ List<IDecoratorPart> parts = compile();
StringBuffer sb = new StringBuffer();
- for (DecoratorPart d: parts) {
+ for (IDecoratorPart d: parts) {
sb.append(d.getLabelPart(object));
}
return sb.toString();
}
+
+ /**
+ * Needed only to work with value
+ * @return
+ */
+ public XModelObjectDecorator getWorkingCopy() {
+ XModelObjectDecorator copy = new XModelObjectDecorator();
+ copy.name = name;
+ copy.partition = partition;
+ copy.defaultValue = defaultValue;
+ copy.value = value;
+ copy.entities = entities;
+ copy.variables = variables;
+ copy.variableByName = variableByName;
+
+ return copy;
+ }
}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorGeneralPreferencesPage.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorGeneralPreferencesPage.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorGeneralPreferencesPage.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.preferences;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class DecoratorGeneralPreferencesPage extends PreferencePage implements
IWorkbenchPreferencePage, IPreferencePageExt {
+
+ public DecoratorGeneralPreferencesPage() {
+ setTitle("General");
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite g = new Composite(parent, SWT.NONE);
+ g.setLayout(new GridLayout(1, false));
+ Label label = new Label(g, SWT.NONE);
+ label.setText("Bla-bla-bla");
+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ return g;
+ }
+
+ public void init(IWorkbench workbench) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean performCancel() {
+
+ return true;
+ }
+
+ public boolean performOk() {
+
+ return super.performOk();
+ }
+
+ public void performDefaults() {
+
+ }
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesListener.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesListener.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesListener.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.preferences;
+
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.navigator.decorator.DecoratorManager;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class DecoratorPreferencesListener implements IPropertyChangeListener {
+ StructuredViewer viewer;
+
+ public DecoratorPreferencesListener() {}
+
+ public void setViewer(StructuredViewer viewer) {
+ this.viewer = viewer;
+ }
+
+ public void init() {
+ ModelUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
+ }
+
+ public void dispose() {
+ ModelUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ String s = event.getProperty();
+ if(s.startsWith(DecoratorManager.EXTENSION_POINT_ID + ".")) {
+ if(viewer != null && viewer.getControl() != null &&
!viewer.getControl().isDisposed()) {
+ viewer.refresh(true);
+ }
+ }
+ }
+
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesPage.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesPage.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorPreferencesPage.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.preferences;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class DecoratorPreferencesPage extends PreferencePage implements
IWorkbenchPreferencePage {
+ DecoratorGeneralPreferencesPage general = new DecoratorGeneralPreferencesPage();
+ DecoratorTextPreferencesPage text = new DecoratorTextPreferencesPage();
+
+ public DecoratorPreferencesPage() {}
+
+ @Override
+ protected Control createContents(Composite parent) {
+ this.noDefaultAndApplyButton();
+ TabFolder tabbedComposite = new TabFolder(parent,SWT.NULL);
+ tabbedComposite.setBackground(parent.getBackground());
+ TabItem newTab = new TabItem(tabbedComposite,SWT.NULL);
+
+ general.createControl(tabbedComposite);
+ newTab.setControl(general.getControl());
+ newTab.setText(general.getTitle());
+
+ newTab = new TabItem(tabbedComposite,SWT.NULL);
+
+ text.createControl(tabbedComposite);
+ newTab.setControl(text.getControl());
+ newTab.setText(text.getTitle());
+
+ return tabbedComposite;
+ }
+
+ public void init(IWorkbench workbench) {
+
+ }
+
+ public boolean performCancel() {
+ general.performCancel();
+ text.performCancel();
+
+ return true;
+ }
+
+ public boolean performOk() {
+ general.performOk();
+ text.performOk();
+
+ return super.performOk();
+ }
+
+ public void performDefaults() {
+ general.performDefaults();
+ text.performDefaults();
+ }
+
+ public void dispose() {
+ general.dispose();
+ text.dispose();
+
+ super.dispose();
+ }
+
+}
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorTextPreferencesPage.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorTextPreferencesPage.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/preferences/DecoratorTextPreferencesPage.java 2008-02-28
17:10:42 UTC (rev 6644)
@@ -0,0 +1,388 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.preferences;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.options.PreferenceModelUtilities;
+import
org.jboss.tools.common.model.ui.attribute.adapter.DefaultXModelObjectLabelProvider;
+import org.jboss.tools.common.model.ui.navigator.decorator.DecoratorManager;
+import org.jboss.tools.common.model.ui.navigator.decorator.Variable;
+import org.jboss.tools.common.model.ui.navigator.decorator.XModelObjectDecorator;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class DecoratorTextPreferencesPage extends PreferencePage implements
IWorkbenchPreferencePage, IPreferencePageExt {
+ TreeViewer decorators;
+ Composite editor;
+ Text formatField;
+ ModifyListener formatListener = new ML();
+ Button addVariableButton;
+
+ TreeViewer examples;
+
+ XModelObjectDecorator selection = null;
+
+ Map<XModelObjectDecorator,String> currentValues = new
HashMap<XModelObjectDecorator, String>();
+
+ public DecoratorTextPreferencesPage() {
+ setTitle("Text");
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ init(null);
+ Composite g = new Composite(parent, SWT.NONE);
+ g.setLayout(new GridLayout(1, false));
+
+ Label label = new Label(g, SWT.NONE);
+ label.setText("Select decorator:");
+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ decorators = new TreeViewer(g, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ decorators.setAutoExpandLevel(2);
+ decorators.setLabelProvider(new LabelProvider() {
+ public String getText(Object element) {
+ if(element instanceof XModelObjectDecorator) {
+ XModelObjectDecorator d = (XModelObjectDecorator)element;
+ return d.getName();
+ }
+ return super.getText(element);
+ }
+
+ public Image getImage(Object element) {
+ String entity = null;
+ if(element instanceof XModelObjectDecorator) {
+ XModelObjectDecorator d = (XModelObjectDecorator)element;
+ Set<String> es = d.getEntities();
+ entity = (es == null || es.size() == 0) ? null : es.iterator().next();
+ } else if(element instanceof String) {
+ entity =
DecoratorManager.getInstance().getBaseEntityForPartition(element.toString());
+ }
+ XModelObject o = entity == null ? null :
PreferenceModelUtilities.getPreferenceModel().createModelObject(entity, new
Properties());
+ return (o != null) ? EclipseResourceUtil.getImage(o) : null;
+ }
+
+ });
+ decorators.setContentProvider(new ITreeContentProvider() {
+
+ public Object[] getChildren(Object parentElement) {
+ if(parentElement instanceof String) {
+ Set<XModelObjectDecorator> set =
DecoratorManager.getInstance().getDecoratorsByPartition(parentElement.toString());
+ return set != null ? set.toArray(new XModelObjectDecorator[0]) : new Object[0];
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ if(element instanceof XModelObjectDecorator) {
+ return ((XModelObjectDecorator)element).getPartition();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return element instanceof String;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if(inputElement == DecoratorManager.getInstance()) {
+ return DecoratorManager.getInstance().getPartitions();
+ }
+ return new Object[0];
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+
+ }
+
+ });
+
+ decorators.setInput(DecoratorManager.getInstance());
+
+ decorators.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ onSelectionChanged(event.getSelection());
+ }
+ });
+
+ GridData treeLayoutData = new GridData(GridData.FILL_HORIZONTAL);
+ treeLayoutData.heightHint = 150;
+ decorators.getTree().setLayoutData(treeLayoutData);
+
+ Composite c = new Composite(g, SWT.NONE);
+ editor = c;
+ GridLayout cLayout = new GridLayout(3, false);
+ c.setLayout(cLayout);
+ c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label cLabel = new Label(c, SWT.NONE);
+ cLabel.setText("Format:");
+
+ formatField = new Text(c, SWT.SINGLE | SWT.BORDER);
+ formatField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ addVariableButton = new Button(c, SWT.PUSH);
+ addVariableButton.setText("Add Variable...");
+
+ addVariableButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ addVariable();
+ }
+
+ });
+
+
+ label = new Label(g, SWT.NONE);
+ label.setText("Preview:");
+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ examples = new TreeViewer(g, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+ examples.setContentProvider(new ITreeContentProvider() {
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+ public Object getParent(Object element) {
+ return null;
+ }
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+ public Object[] getElements(Object inputElement) {
+ if(selection != null) {
+ return selection.getExamples();
+ }
+ return new Object[0];
+ }
+ public void dispose() {
+ }
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ }
+
+ });
+ examples.setLabelProvider(new DefaultXModelObjectLabelProvider() {
+ public String getText(Object element) {
+ if(selection == null) {
+ return super.getText(element);
+ }
+ String result = "";
+ if (element instanceof XModelObject) {
+ XModelObject modelObject = (XModelObject)element;
+ XModelObjectDecorator d = selection.getWorkingCopy();
+ d.setValue(formatField.getText());
+ result = d.getLabel(modelObject);
+ } else {
+ result = "?";
+ }
+ return result;
+ }
+
+ });
+
+ treeLayoutData = new GridData(GridData.FILL_HORIZONTAL);
+ treeLayoutData.heightHint = 100;
+ examples.getTree().setLayoutData(treeLayoutData);
+
+ examples.setInput(DecoratorManager.getInstance());
+
+ setSelectedObject(null);
+
+ return g;
+ }
+
+ public void init(IWorkbench workbench) {
+ String[] ps = DecoratorManager.getInstance().getPartitions();
+ for (int i = 0; i < ps.length; i++) {
+ Set<XModelObjectDecorator> set =
DecoratorManager.getInstance().getDecoratorsByPartition(ps[i]);
+ for (XModelObjectDecorator d: set) {
+ currentValues.put(d, d.getValue());
+ }
+ }
+ }
+
+ public boolean performCancel() {
+ return true;
+ }
+
+ public boolean performOk() {
+ boolean change = false;
+ for (XModelObjectDecorator d: currentValues.keySet()) {
+ if(equal(d.getValue(), currentValues.get(d))) continue;
+ change = true;
+ d.setValue(currentValues.get(d));
+ }
+ if(change) {
+ DecoratorManager.getInstance().applyToPreferences();
+ }
+ return super.performOk();
+ }
+
+ private boolean equal(String a, String b) {
+ if(a == null) return b == null;
+ return a.equals(b);
+ }
+
+ public void performDefaults() {
+ for (XModelObjectDecorator d: currentValues.keySet()) {
+ String dv = d.getDefaultValue();
+ if(dv == null || dv.length() == 0) {
+ dv = Variable.NAME.getRuleText();
+ }
+ currentValues.put(d, dv);
+ }
+ if(selection != null) {
+ setText(currentValues.get(selection));
+ }
+ }
+
+ private void onSelectionChanged(ISelection s) {
+ if(!s.isEmpty() && (s instanceof IStructuredSelection)) {
+ Object o = ((IStructuredSelection)s).getFirstElement();
+ if(o instanceof XModelObjectDecorator) {
+ setSelectedObject((XModelObjectDecorator)o);
+ return;
+ }
+ }
+ setSelectedObject(null);
+ }
+
+ private void setSelectedObject(XModelObjectDecorator d) {
+ selection = d;
+ if(d != null) {
+// editor.setVisible(true);
+ formatField.setEnabled(true);
+ addVariableButton.setEnabled(true);
+
+ String text = currentValues.get(d);
+ setText(text);
+
+ } else {
+// editor.setVisible(false);
+ formatField.setEnabled(false);
+ addVariableButton.setEnabled(false);
+ setText("");
+ }
+ examples.refresh(true);
+ }
+
+ private void setText(String text) {
+ if(text == null) text = "";
+ formatField.removeModifyListener(formatListener);
+ formatField.setText(text);
+ formatField.addModifyListener(formatListener);
+ }
+
+ class ML implements ModifyListener {
+ public void modifyText(ModifyEvent e) {
+ if(selection != null) {
+ currentValues.put(selection, formatField.getText());
+ examples.refresh(true);
+ }
+ }
+ }
+
+ private void addVariable() {
+ CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(
+ addVariableButton.getShell(),
+ new LabelProvider(),
+ new ITreeContentProvider() {
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+ public Object getParent(Object element) {
+ return null;
+ }
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+ public Object[] getElements(Object inputElement) {
+ if(selection != null) {
+ return selection.getVariables();
+ }
+ return new Object[0];
+ }
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ }
+ }
+ );
+ dialog.setInput(selection);
+ dialog.setTitle("Select Variable");
+ dialog.create();
+ int result = dialog.open();
+ if(result == Window.OK) {
+ addVariable(dialog.getResult());
+ }
+ }
+
+ private void addVariable(Object[] checked) {
+ if(checked == null || checked.length == 0) return;
+ String text = formatField.getText();
+ int c = formatField.getCaretPosition();
+ if(c < 0 || c > text.length()) c = text.length();
+ StringBuffer sb = new StringBuffer(text.substring(0, c));
+ for (int i = 0; i < checked.length; i++) {
+ Variable v = (Variable)checked[i];
+ sb.append(v.getRuleText());
+ }
+ int cn = sb.length();
+ sb.append(text.substring(c));
+ text = sb.toString();
+ currentValues.put(selection, text);
+ setText(text);
+ formatField.setSelection(cn);
+ }
+
+}