Author: koen.aers(a)jboss.com
Date: 2008-08-12 12:10:55 -0400 (Tue, 12 Aug 2008)
New Revision: 9669
Added:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/DefaultEditPartFactory.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Element.java
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/figure/ElementContainerFigure.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/figure/ElementFigure.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Connection.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Container.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Flow.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Node.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java
Log:
icons, colors and figures are pluggable (initial implementation)
Modified: trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd
===================================================================
--- trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd 2008-08-12
14:23:36 UTC (rev 9668)
+++ trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd 2008-08-12
16:10:55 UTC (rev 9669)
@@ -86,6 +86,16 @@
</documentation>
</annotation>
</attribute>
+ <attribute name="figure" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="resource"/>
+ </appinfo>
+ </annotation>
+ </attribute>
</complexType>
</element>
@@ -106,6 +116,9 @@
<element name="node">
<complexType>
+ <sequence>
+ <element ref="figure" minOccurs="0"
maxOccurs="1"/>
+ </sequence>
<attribute name="acceptsIncomingConnectionStrategy"
type="string">
<annotation>
<documentation>
@@ -167,6 +180,52 @@
<element name="connection" type="string">
</element>
+ <element name="figure">
+ <complexType>
+ <choice minOccurs="0" maxOccurs="1">
+ <element ref="ellipse"/>
+ <element ref="rectangle"/>
+ <element ref="rounded-rectangle"/>
+ </choice>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.tools.flow.common.figure.ElementFigure"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="color" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="icon" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="resource"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="ellipse" type="string">
+ </element>
+
+ <element name="rectangle" type="string">
+ </element>
+
+ <element name="rounded-rectangle" type="string">
+ </element>
+
<annotation>
<appinfo>
<meta.section type="since"/>
Added:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/DefaultEditPartFactory.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/DefaultEditPartFactory.java
(rev 0)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/DefaultEditPartFactory.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -0,0 +1,55 @@
+package org.jboss.tools.flow.common.editpart;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartFactory;
+import org.jboss.tools.flow.common.model.Element;
+import org.jboss.tools.flow.common.registry.ElementRegistry;
+import org.jboss.tools.flow.common.wrapper.Wrapper;
+
+public class DefaultEditPartFactory implements EditPartFactory {
+
+ public EditPart createEditPart(EditPart context, Object model) {
+ EditPart result = null;
+ if (!(model instanceof Wrapper)) return result;
+ Object element = ((Wrapper)model).getElement();
+ if (element != null && element instanceof Element) {
+ result = ElementRegistry.createEditPart((Element)element);
+ }
+// result = createEditPart()
+// if (model instanceof DefaultFlowWrapper) {
+// result = new RootEditPart();
+// } else if (model instanceof DefaultContainerWrapper) {
+// result = new ContainerEditPart();
+// } else if (model instanceof DefaultConnectionWrapper) {
+// result = new ConnectionEditPart();
+// } else if (model instanceof DefaultNodeWrapper && element instanceof
StartState) {
+// result = new StartStateEditPart();
+// } else if (model instanceof DefaultNodeWrapper && element instanceof
State) {
+// result = new StateEditPart();
+// } else if (model instanceof DefaultNodeWrapper && element instanceof
EndState) {
+// result = new EndStateEditPart();
+// } else {
+// throw new IllegalArgumentException(
+// "Unknown model object " + model);
+// }
+ if (result != null) {
+ result.setModel(model);
+ }
+ return result;
+ }
+
+// private EditPart createEditPart(Object element) {
+// if (element instanceof Flow) {
+// return new RootEditPart();
+// } else if (element instanceof Container) {
+// return new ContainerEditPart();
+// } else if (element instanceof Connection) {
+// return new ConnectionEditPart();
+// } else if (element instanceof Node) {
+// return ElementRegistry.createEditPart((Node)element);
+// } else {
+// return null;
+// }
+// }
+
+}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/figure/ElementContainerFigure.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/figure/ElementContainerFigure.java 2008-08-12
14:23:36 UTC (rev 9668)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/figure/ElementContainerFigure.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -27,6 +27,7 @@
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.ScrollPane;
import org.eclipse.draw2d.StackLayout;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
public class ElementContainerFigure extends Figure implements ElementFigure {
@@ -45,6 +46,10 @@
scrollpane.setContents(pane);
setBorder(new LineBorder(1));
}
+
+ public void setColor(Color color) {
+ setBackgroundColor(color);
+ }
public Label getLabel() {
return null;
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/figure/ElementFigure.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/figure/ElementFigure.java 2008-08-12
14:23:36 UTC (rev 9668)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/figure/ElementFigure.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -19,6 +19,7 @@
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
/**
@@ -30,6 +31,8 @@
void setIcon(Image icon);
+ void setColor(Color color);
+
void setText(String text);
void setSelected(boolean b);
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Connection.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Connection.java 2008-08-12
14:23:36 UTC (rev 9668)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Connection.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -21,7 +21,7 @@
*
* @author <a href="mailto:kris_verlaenen@hotmail.com">Kris
Verlaenen</a>
*/
-public interface Connection {
+public interface Connection extends Element {
/**
* Returns the from node of the connection.
@@ -49,8 +49,4 @@
*/
String getToType();
- void setMetaData(String name, Object value);
-
- Object getMetaData(String name);
-
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Container.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Container.java 2008-08-12
14:23:36 UTC (rev 9668)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Container.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -7,7 +7,7 @@
*
* @author <a href="mailto:kris_verlaenen@hotmail.com">Kris
Verlaenen</a>
*/
-public interface Container {
+public interface Container extends Element {
/**
* Returns the nodes of this node container.
Added:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Element.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Element.java
(rev 0)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Element.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -0,0 +1,9 @@
+package org.jboss.tools.flow.common.model;
+
+public interface Element {
+
+ void setMetaData(String name, Object value);
+
+ Object getMetaData(String name);
+
+}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Flow.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Flow.java 2008-08-12
14:23:36 UTC (rev 9668)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Flow.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -92,8 +92,4 @@
*/
String getPackageName();
- void setMetaData(String name, Object value);
-
- Object getMetaData(String name);
-
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Node.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Node.java 2008-08-12
14:23:36 UTC (rev 9668)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/model/Node.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -24,7 +24,7 @@
*
* @author <a href="mailto:kris_verlaenen@hotmail.com">Kris
Verlaenen</a>
*/
-public interface Node {
+public interface Node extends Element {
/**
* Returns the id of the node
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java 2008-08-12
14:23:36 UTC (rev 9668)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java 2008-08-12
16:10:55 UTC (rev 9669)
@@ -1,13 +1,31 @@
package org.jboss.tools.flow.common.registry;
+import java.net.URL;
import java.util.HashMap;
+import java.util.StringTokenizer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.gef.EditPart;
import org.eclipse.gef.requests.CreationFactory;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
import org.jboss.tools.flow.common.Logger;
+import org.jboss.tools.flow.common.editpart.ConnectionEditPart;
+import org.jboss.tools.flow.common.editpart.ContainerEditPart;
+import org.jboss.tools.flow.common.editpart.ElementEditPart;
+import org.jboss.tools.flow.common.editpart.RootEditPart;
+import org.jboss.tools.flow.common.figure.ElementFigure;
+import org.jboss.tools.flow.common.figure.EllipseElementFigure;
+import org.jboss.tools.flow.common.figure.RectangleElementFigure;
+import org.jboss.tools.flow.common.figure.RoundedRectangleElementFigure;
import org.jboss.tools.flow.common.model.Container;
+import org.jboss.tools.flow.common.model.Element;
import org.jboss.tools.flow.common.model.Flow;
import org.jboss.tools.flow.common.model.Node;
import org.jboss.tools.flow.common.strategy.AcceptsElementStrategy;
@@ -21,9 +39,12 @@
public class ElementRegistry {
+ private static final HashMap<String, Image> imageMap = new HashMap<String,
Image>();
+ private static final HashMap<String, Color> colorMap = new HashMap<String,
Color>();
private static final String elementsExtensionPointId =
"org.jboss.tools.flow.common.elements";
private static HashMap<String, IConfigurationElement> elementMap = null;
+
private static void initializeRegistry() {
elementMap = new HashMap<String, IConfigurationElement>();
IConfigurationElement[] configurationElements =
@@ -64,6 +85,7 @@
Logger.logError(message, new RuntimeException(message));
return null;
}
+ ((Node)element).setMetaData("configurationElement", configurationElement);
DefaultNodeWrapper result = new DefaultNodeWrapper();
result.setElement(element);
AcceptsIncomingConnectionStrategy acceptsIncomingConnectionStrategy =
createAcceptsIncomingConnectionStrategy(configurationElement);
@@ -88,6 +110,7 @@
Logger.logError(message, new RuntimeException(message));
return null;
}
+ ((Container)element).setMetaData("configurationElement",
configurationElement);
DefaultContainerWrapper result = new DefaultContainerWrapper();
result.setElement(element);
AcceptsElementStrategy acceptsElementStrategy =
createAcceptsElementStrategy(configurationElement);
@@ -149,6 +172,7 @@
Logger.logError(message, new RuntimeException(message));
return null;
}
+ ((Container)element).setMetaData("configurationElement",
configurationElement);
DefaultFlowWrapper result = new DefaultFlowWrapper();
result.setElement(element);
AcceptsElementStrategy acceptsElementStrategy =
createAcceptsElementStrategy(configurationElement);
@@ -162,6 +186,118 @@
return result;
}
+ public static EditPart createEditPart(Element element) {
+ IConfigurationElement configurationElement =
+ (IConfigurationElement)element.getMetaData("configurationElement");
+ if (configurationElement == null) return null;
+ IConfigurationElement[] children = configurationElement.getChildren();
+ if (children.length != 1) return null;
+ String type = children[0].getName();
+ if ("flow".equals(type)) {
+ return new RootEditPart();
+ } else if ("container".equals(type)) {
+ return new ContainerEditPart();
+ } else if ("node".equals(type)) {
+ return createNodeEditPart(configurationElement);
+ } else if ("connection".equals(type)) {
+ return new ConnectionEditPart();
+ } else {
+ return null;
+ }
+ }
+
+ private static EditPart createNodeEditPart(final IConfigurationElement
configurationElement) {
+ return new ElementEditPart() {
+ protected IFigure createFigure() {
+ ElementFigure result = null;
+ IConfigurationElement figureElement = null;
+ IConfigurationElement[] children =
configurationElement.getChildren("node");
+ if (children.length == 1) {
+ children = children[0].getChildren("figure");
+ if (children.length == 1) {
+ figureElement = children[0];
+ }
+ }
+ if (figureElement == null) {
+ return new RectangleElementFigure();
+ }
+ if (figureElement.getAttribute("class") != null) {
+ try {
+ return (IFigure)figureElement.createExecutableExtension("class");
+ }
+ catch (CoreException e) {
+ return null;
+ }
+ }
+ children = figureElement.getChildren();
+ if (children.length < 1) {
+ result = new RectangleElementFigure();
+ } else if ("ellipse".equals(children[0])){
+ result = new EllipseElementFigure();
+ } else if ("rounded-rectangle".equals(children[0])) {
+ result = new RoundedRectangleElementFigure();
+ } else {
+ result = new RectangleElementFigure();
+ }
+ if (figureElement.getAttribute("icon") != null) {
+ String iconPath = figureElement.getAttribute("icon");
+ URL url =
Platform.getBundle(figureElement.getContributor().getName()).getEntry(iconPath);
+ Image icon = null;
+ if (imageMap.containsKey(url.getPath())) {
+ icon = imageMap.get(url.getPath());
+ } else {
+ icon = ImageDescriptor.createFromURL(url).createImage();
+ imageMap.put(url.getPath(), icon);
+ }
+ result.setIcon(icon);
+ } else if (configurationElement.getAttribute("figure") != null) {
+ String iconPath = configurationElement.getAttribute("icon");
+ URL url =
Platform.getBundle(figureElement.getContributor().getName()).getEntry(iconPath);
+ Image icon = null;
+ if (imageMap.containsKey(url.getPath())) {
+ icon = imageMap.get(url.getPath());
+ } else {
+ icon = ImageDescriptor.createFromURL(url).createImage();
+ imageMap.put(url.getPath(), icon);
+ }
+ result.setIcon(icon);
+ }
+ if (figureElement.getAttribute("color") != null) {
+ String colorString = figureElement.getAttribute("color");
+ Color color = null;
+ if (colorMap.containsKey(colorString)) {
+ color = colorMap.get(colorString);
+ } else {
+ try {
+ StringTokenizer tokenizer = new StringTokenizer(colorString, ",");
+ int[] rgb = new int[3];
+ int i = 0;
+ while (tokenizer.hasMoreTokens()) {
+ rgb[i++] = Integer.parseInt(tokenizer.nextToken());
+ }
+ color = new Color(Display.getCurrent(), rgb[0], rgb[1], rgb[2]);
+ colorMap.put(colorString, color);
+ } catch (NumberFormatException e) {}
+ }
+ result.setColor(color);
+ }
+ Dimension size = new Dimension(result.getSize());
+ if (figureElement.getAttribute("width") != null) {
+ try {
+ size.width = Integer.parseInt(figureElement.getAttribute("width"));
+ } catch (NumberFormatException e) {}
+ }
+ if (figureElement.getAttribute("height") != null) {
+ try {
+ size.height = Integer.parseInt(figureElement.getAttribute("height"));
+ } catch (NumberFormatException e) {}
+ }
+ result.setSize(size);
+ return result;
+ }
+ };
+ }
+
public static Wrapper createWrapper(String elementId) {
if (elementMap == null) {
initializeRegistry();