Author: koen.aers(a)jboss.com
Date: 2008-08-08 07:58:05 -0400 (Fri, 08 Aug 2008)
New Revision: 9623
Added:
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/Logger.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/META-INF/MANIFEST.MF
trunk/flow/plugins/org.jboss.tools.flow.common/plugin.xml
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ConnectionEditPart.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultContainerWrapper.java
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultNodeWrapper.java
Log:
added node pluggability
Modified: trunk/flow/plugins/org.jboss.tools.flow.common/META-INF/MANIFEST.MF
===================================================================
--- trunk/flow/plugins/org.jboss.tools.flow.common/META-INF/MANIFEST.MF 2008-08-08
11:57:37 UTC (rev 9622)
+++ trunk/flow/plugins/org.jboss.tools.flow.common/META-INF/MANIFEST.MF 2008-08-08
11:58:05 UTC (rev 9623)
@@ -23,6 +23,7 @@
org.jboss.tools.flow.common.figure,
org.jboss.tools.flow.common.model,
org.jboss.tools.flow.common.policy,
+ org.jboss.tools.flow.common.registry,
org.jboss.tools.flow.common.strategy,
org.jboss.tools.flow.common.wrapper
Bundle-ClassPath: .
Modified: trunk/flow/plugins/org.jboss.tools.flow.common/plugin.xml
===================================================================
--- trunk/flow/plugins/org.jboss.tools.flow.common/plugin.xml 2008-08-08 11:57:37 UTC (rev
9622)
+++ trunk/flow/plugins/org.jboss.tools.flow.common/plugin.xml 2008-08-08 11:58:05 UTC (rev
9623)
@@ -2,5 +2,6 @@
<?eclipse version="3.2"?>
<plugin>
<extension-point id="languages" name="JBoss Tools Flow Language
Extensions" schema="schema/languages.exsd"/>
+ <extension-point id="elements" name="JBoss Tools Flow Language
Elements" schema="schema/elements.exsd"/>
</plugin>
Added: trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd
===================================================================
--- trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd
(rev 0)
+++ trunk/flow/plugins/org.jboss.tools.flow.common/schema/elements.exsd 2008-08-08
11:58:05 UTC (rev 9623)
@@ -0,0 +1,207 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.tools.flow.common"
xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.jboss.tools.flow.common"
id="elements" name="Flow Language Elements"/>
+ </appinfo>
+ <documentation>
+ This extension point provides a way to contribute language elements to a target
flow language.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="element" minOccurs="1"
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="element">
+ <complexType>
+ <choice>
+ <element ref="flow"/>
+ <element ref="container"/>
+ <element ref="node"/>
+ <element ref="connection"/>
+ </choice>
+ <attribute name="id" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="language" type="string"
use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="flow">
+ <complexType>
+ <attribute name="acceptsElementStrategy"
type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.tools.flow.common.strategy.AcceptsElementStrategy"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="node">
+ <complexType>
+ <attribute name="acceptsIncomingConnectionStrategy"
type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.tools.flow.common.strategy.AcceptsIncomingConnectionStrategy"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="acceptsOutgoingConnectionStrategy"
type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.tools.flow.common.strategy.AcceptsOutgoingConnectionStrategy"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="container">
+ <complexType>
+ <attribute name="acceptsElementStrategy"
type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.tools.flow.common.strategy.AcceptsElementStrategy"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="acceptsIncomingConnectionStrategy"
type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.tools.flow.common.strategy.AcceptsIncomingConnectionStrategy"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="acceptsOutgoingConnectionStrategy"
type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java"
basedOn=":org.jboss.tools.flow.common.strategy.AcceptsOutgoingConnectionStrategy"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="connection" type="string">
+ </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>
+
+
+</schema>
Added:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/Logger.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/Logger.java
(rev 0)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/Logger.java 2008-08-08
11:58:05 UTC (rev 9623)
@@ -0,0 +1,37 @@
+package org.jboss.tools.flow.common;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+public class Logger {
+
+ public static void logInfo(String message) {
+ log(IStatus.INFO, IStatus.OK, message, null);
+ }
+
+ public static void logError(Throwable exception) {
+ logError("Unexpected Exception", exception);
+ }
+
+ public static void logError(String message, Throwable exception) {
+ log(IStatus.ERROR, IStatus.OK, message, exception);
+ }
+
+ public static void log(int severity, int code, String message, Throwable exception) {
+ log(createStatus(severity, code, message, exception));
+ }
+
+ public static IStatus createStatus(int severity, int code, String message, Throwable
exception) {
+ return new Status(
+ severity,
+ Activator.getDefault().getBundle().getSymbolicName(),
+ code,
+ message,
+ exception);
+ }
+
+ public static void log(IStatus status) {
+ Activator.getDefault().getLog().log(status);
+ }
+
+}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ConnectionEditPart.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ConnectionEditPart.java 2008-08-08
11:57:37 UTC (rev 9622)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/editpart/ConnectionEditPart.java 2008-08-08
11:58:05 UTC (rev 9623)
@@ -34,6 +34,7 @@
import org.jboss.tools.flow.common.policy.ConnectionBendpointEditPolicy;
import org.jboss.tools.flow.common.policy.ConnectionEditPolicy;
import org.jboss.tools.flow.common.wrapper.AbstractConnectionWrapper;
+import org.jboss.tools.flow.common.wrapper.DefaultConnectionWrapper;
import org.jboss.tools.flow.common.wrapper.ModelEvent;
import org.jboss.tools.flow.common.wrapper.ModelListener;
@@ -42,7 +43,7 @@
*
* @author <a href="mailto:kris_verlaenen@hotmail.com">Kris
Verlaenen</a>
*/
-public abstract class ConnectionEditPart extends AbstractConnectionEditPart implements
ModelListener {
+public class ConnectionEditPart extends AbstractConnectionEditPart implements
ModelListener {
public AbstractConnectionWrapper getElementConnection() {
return (AbstractConnectionWrapper) getModel();
@@ -61,10 +62,10 @@
}
- protected abstract Class<?> getElementConnectionType();
-
-// protected abstract ConnectionFactory getElementConnectionFactory();
-
+ protected Class<?> getElementConnectionType() {
+ return DefaultConnectionWrapper.class;
+ }
+
protected IFigure createFigure() {
PolylineConnection result = new PolylineConnection();
result.setConnectionRouter(new BendpointConnectionRouter());
Added:
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
(rev 0)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/registry/ElementRegistry.java 2008-08-08
11:58:05 UTC (rev 9623)
@@ -0,0 +1,193 @@
+package org.jboss.tools.flow.common.registry;
+
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gef.requests.CreationFactory;
+import org.jboss.tools.flow.common.Logger;
+import org.jboss.tools.flow.common.model.Container;
+import org.jboss.tools.flow.common.model.Flow;
+import org.jboss.tools.flow.common.model.Node;
+import org.jboss.tools.flow.common.strategy.AcceptsElementStrategy;
+import org.jboss.tools.flow.common.strategy.AcceptsIncomingConnectionStrategy;
+import org.jboss.tools.flow.common.strategy.AcceptsOutgoingConnectionStrategy;
+import org.jboss.tools.flow.common.wrapper.DefaultConnectionWrapper;
+import org.jboss.tools.flow.common.wrapper.DefaultContainerWrapper;
+import org.jboss.tools.flow.common.wrapper.DefaultFlowWrapper;
+import org.jboss.tools.flow.common.wrapper.DefaultNodeWrapper;
+import org.jboss.tools.flow.common.wrapper.Wrapper;
+
+public class ElementRegistry {
+
+ 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 =
+ Platform.getExtensionRegistry().getConfigurationElementsFor(elementsExtensionPointId);
+ for (IConfigurationElement configurationElement: configurationElements) {
+ elementMap.put(configurationElement.getAttribute("id"),
configurationElement);
+ }
+ }
+
+ private static Wrapper createWrapper(IConfigurationElement configurationElement)
+ throws CoreException {
+ IConfigurationElement[] children = configurationElement.getChildren();
+ if (children.length != 1) return null;
+ String type = children[0].getName();
+ if ("flow".equals(type)) {
+ return createFlow(configurationElement);
+ } else if ("container".equals(type)) {
+ return createContainer(configurationElement);
+ } else if ("node".equals(type)) {
+ return createNode(configurationElement);
+ } else if ("connection".equals(type)) {
+ return createConnection(configurationElement);
+ } else {
+ return null;
+ }
+ }
+
+ private static Wrapper createConnection(IConfigurationElement configurationElement)
+ throws CoreException {
+ return new DefaultConnectionWrapper();
+ }
+
+ private static Wrapper createNode(IConfigurationElement configurationElement)
+ throws CoreException {
+ Object element = configurationElement.createExecutableExtension("class");
+ if (!(element instanceof Node)) {
+ String message = "Expecting to instantiate a
org.jboss.tools.flow.common.model.Node instance.";
+ Logger.logError(message, new RuntimeException(message));
+ return null;
+ }
+ DefaultNodeWrapper result = new DefaultNodeWrapper();
+ result.setElement(element);
+ AcceptsIncomingConnectionStrategy acceptsIncomingConnectionStrategy =
createAcceptsIncomingConnectionStrategy(configurationElement);
+ if (acceptsIncomingConnectionStrategy != null) {
+ acceptsIncomingConnectionStrategy.setNode((Node)element);
+ result.setAcceptsIncomingConnectionStrategy(acceptsIncomingConnectionStrategy);
+ }
+ AcceptsOutgoingConnectionStrategy acceptsOutgoingConnectionStrategy =
createAcceptsOutgoingConnectionStrategy(configurationElement);
+ if (acceptsOutgoingConnectionStrategy != null) {
+ acceptsOutgoingConnectionStrategy.setNode((Node)element);
+ result.setAcceptsOutgoingConnectionStrategy(acceptsOutgoingConnectionStrategy);
+ }
+ ((Node)element).setName(configurationElement.getAttribute("name"));
+ return result;
+ }
+
+ private static Wrapper createContainer(IConfigurationElement configurationElement)
+ throws CoreException {
+ Object element = configurationElement.createExecutableExtension("class");
+ if (!(element instanceof Container)) {
+ String message = "Expecting to instantiate a
org.jboss.tools.flow.common.model.Container instance.";
+ Logger.logError(message, new RuntimeException(message));
+ return null;
+ }
+ DefaultContainerWrapper result = new DefaultContainerWrapper();
+ result.setElement(element);
+ AcceptsElementStrategy acceptsElementStrategy =
createAcceptsElementStrategy(configurationElement);
+ if (acceptsElementStrategy != null) {
+ acceptsElementStrategy.setContainer((Container)element);
+ result.setAcceptsElementStrategy(acceptsElementStrategy);
+ }
+ AcceptsIncomingConnectionStrategy acceptsIncomingConnectionStrategy =
createAcceptsIncomingConnectionStrategy(configurationElement);
+ if (acceptsIncomingConnectionStrategy != null) {
+ acceptsIncomingConnectionStrategy.setNode((Node)element);
+ result.setAcceptsIncomingConnectionStrategy(acceptsIncomingConnectionStrategy);
+ }
+ AcceptsOutgoingConnectionStrategy acceptsOutgoingConnectionStrategy =
createAcceptsOutgoingConnectionStrategy(configurationElement);
+ if (acceptsOutgoingConnectionStrategy != null) {
+ acceptsOutgoingConnectionStrategy.setNode((Node)element);
+ result.setAcceptsOutgoingConnectionStrategy(acceptsOutgoingConnectionStrategy);
+ }
+ if (element instanceof Node) {
+ ((Node)element).setName(configurationElement.getAttribute("name"));
+ }
+ return result;
+ }
+
+ private static AcceptsIncomingConnectionStrategy
createAcceptsIncomingConnectionStrategy(IConfigurationElement configurationElement)
+ throws CoreException {
+ Object result = null;
+ IConfigurationElement[] children = configurationElement.getChildren();
+ if (children[0].getAttribute("acceptsIncomingConnectionStrategy") != null) {
+ result =
children[0].createExecutableExtension("acceptsIncomingConnectionStrategy");
+ }
+ return (AcceptsIncomingConnectionStrategy)result;
+ }
+
+ private static AcceptsOutgoingConnectionStrategy
createAcceptsOutgoingConnectionStrategy(IConfigurationElement configurationElement)
+ throws CoreException {
+ Object result = null;
+ IConfigurationElement[] children = configurationElement.getChildren();
+ if (children[0].getAttribute("acceptsOutgoingConnectionStrategy") != null) {
+ result =
children[0].createExecutableExtension("acceptsOutgoingConnectionStrategy");
+ }
+ return (AcceptsOutgoingConnectionStrategy)result;
+ }
+
+ private static AcceptsElementStrategy createAcceptsElementStrategy(IConfigurationElement
configurationElement)
+ throws CoreException {
+ Object result = null;
+ IConfigurationElement[] children = configurationElement.getChildren();
+ if (children[0].getAttribute("acceptsElementStrategy") != null) {
+ result = children[0].createExecutableExtension("acceptsElementStrategy");
+ }
+ return (AcceptsElementStrategy)result;
+ }
+
+ private static Wrapper createFlow(IConfigurationElement configurationElement)
+ throws CoreException {
+ Object element = configurationElement.createExecutableExtension("class");
+ if (!(element instanceof Container)) {
+ String message = "Expecting to instantiate a
org.jboss.tools.flow.common.model.Container instance.";
+ Logger.logError(message, new RuntimeException(message));
+ return null;
+ }
+ DefaultFlowWrapper result = new DefaultFlowWrapper();
+ result.setElement(element);
+ AcceptsElementStrategy acceptsElementStrategy =
createAcceptsElementStrategy(configurationElement);
+ if (acceptsElementStrategy != null) {
+ acceptsElementStrategy.setContainer((Container)result.getElement());
+ result.setAcceptsElementStrategy(acceptsElementStrategy);
+ }
+ if (element instanceof Flow) {
+ ((Flow)element).setName(configurationElement.getAttribute("name"));
+ }
+ return result;
+ }
+
+ public static Wrapper createWrapper(String elementId) {
+ if (elementMap == null) {
+ initializeRegistry();
+ }
+ IConfigurationElement configurationElement = elementMap.get(elementId);
+ if (configurationElement != null) {
+ try {
+ return createWrapper(configurationElement);
+ } catch (CoreException e) {
+ Logger.logError("Creating a wrapper for " + elementId + "
failed.", e);
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ public static CreationFactory getCreationFactory(final String elementId) {
+ return new CreationFactory() {
+ public Object getNewObject() {
+ return createWrapper(elementId);
+ }
+ public Object getObjectType() {
+ return elementId;
+ }
+ };
+ }
+
+}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultContainerWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultContainerWrapper.java 2008-08-08
11:57:37 UTC (rev 9622)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultContainerWrapper.java 2008-08-08
11:58:05 UTC (rev 9623)
@@ -7,11 +7,13 @@
import org.jboss.tools.flow.common.model.Container;
import org.jboss.tools.flow.common.model.Flow;
import org.jboss.tools.flow.common.model.Node;
+import org.jboss.tools.flow.common.strategy.AcceptsElementStrategy;
import org.jboss.tools.flow.common.strategy.AcceptsIncomingConnectionStrategy;
import org.jboss.tools.flow.common.strategy.AcceptsOutgoingConnectionStrategy;
public class DefaultContainerWrapper extends AbstractContainerWrapper {
+ private AcceptsElementStrategy acceptsElementStrategy;
private AcceptsIncomingConnectionStrategy incomingConnectionStrategy;
private AcceptsOutgoingConnectionStrategy outgoingConnectionStrategy;
@@ -67,10 +69,20 @@
return (Node)getElement();
}
- public boolean acceptsElement(NodeWrapper element) {
- return getParent().acceptsElement(element);
- }
-
+ public boolean acceptsElement(NodeWrapper wrapper) {
+ if (wrapper == null) {
+ return false;
+ } else if (acceptsElementStrategy != null) {
+ return acceptsElementStrategy.acceptsElement(wrapper.getElement());
+ } else {
+ return getParent().acceptsElement(wrapper);
+ }
+ }
+
+ public void setAcceptsElementStrategy(AcceptsElementStrategy strategy) {
+ this.acceptsElementStrategy = strategy;
+ }
+
public void setAcceptsIncomingConnectionStrategy(AcceptsIncomingConnectionStrategy
strategy) {
this.incomingConnectionStrategy = strategy;
}
Modified:
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultNodeWrapper.java
===================================================================
---
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultNodeWrapper.java 2008-08-08
11:57:37 UTC (rev 9622)
+++
trunk/flow/plugins/org.jboss.tools.flow.common/src/org/jboss/tools/flow/common/wrapper/DefaultNodeWrapper.java 2008-08-08
11:58:05 UTC (rev 9623)
@@ -6,7 +6,7 @@
import org.jboss.tools.flow.common.strategy.AcceptsIncomingConnectionStrategy;
import org.jboss.tools.flow.common.strategy.AcceptsOutgoingConnectionStrategy;
-public abstract class DefaultNodeWrapper extends AbstractNodeWrapper {
+public class DefaultNodeWrapper extends AbstractNodeWrapper {
private AcceptsIncomingConnectionStrategy incomingConnectionStrategy;
private AcceptsOutgoingConnectionStrategy outgoingConnectionStrategy;