Author: koen.aers(a)jboss.com
Date: 2009-04-29 18:10:48 -0400 (Wed, 29 Apr 2009)
New Revision: 14969
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/plugin.xml
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlDeserializer.java
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlSerializer.java
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/handler/AddSwimlaneHandler.java
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/properties/AssignmentSection.java
Log:
serialization/deserialization of swimlanes
Modified: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/plugin.xml
===================================================================
--- trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/plugin.xml 2009-04-29 22:07:49 UTC (rev
14968)
+++ trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/plugin.xml 2009-04-29 22:10:48 UTC (rev
14969)
@@ -210,6 +210,13 @@
language="org.jboss.tools.flow.jpdl4">
<connection></connection>
</element>
+ <element
+ class="org.jboss.tools.flow.jpdl4.model.Swimlane"
+ figure="icons/16/swimlane.gif"
+ id="org.jboss.tools.flow.jpdl4.swimlane"
+ label="swimlane"
+ language="org.jboss.tools.flow.jpdl4">
+ </element>
</extension>
<extension
point="org.eclipse.ui.newWizards">
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlDeserializer.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlDeserializer.java 2009-04-29
22:07:49 UTC (rev 14968)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlDeserializer.java 2009-04-29
22:10:48 UTC (rev 14969)
@@ -12,6 +12,7 @@
import org.jboss.tools.flow.common.properties.IPropertyId;
import org.jboss.tools.flow.common.registry.ElementRegistry;
import org.jboss.tools.flow.common.wrapper.ConnectionWrapper;
+import org.jboss.tools.flow.common.wrapper.DefaultWrapper;
import org.jboss.tools.flow.common.wrapper.FlowWrapper;
import org.jboss.tools.flow.common.wrapper.NodeWrapper;
import org.jboss.tools.flow.common.wrapper.Wrapper;
@@ -19,6 +20,7 @@
import org.jboss.tools.flow.jpdl4.model.Assignment;
import org.jboss.tools.flow.jpdl4.model.AssignmentPropertySource;
import org.jboss.tools.flow.jpdl4.model.HumanTask;
+import org.jboss.tools.flow.jpdl4.model.Swimlane;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -64,22 +66,42 @@
}
class HumanTaskAttributeHandler extends NodeAttributeHandler {
+ AssignmentAttributeHandler assignmentAttributeHandler = new
AssignmentAttributeHandler();
public void deserializeAttributes(Wrapper wrapper, Element element) {
super.deserializeAttributes(wrapper, element);
- String assignee = element.getAttribute(HumanTask.ASSIGNEE);
+ assignmentAttributeHandler.deserializeAttributes(wrapper, element);
+ }
+
+ }
+
+ class SwimlaneAttributeHandler extends DefaultAttributeDeserializer {
+ AssignmentAttributeHandler assignmentAttributeHandler = new
AssignmentAttributeHandler();
+ public void deserializeAttributes(Wrapper wrapper, Element element) {
+ super.deserializeAttributes(wrapper, element);
+ String name = element.getAttribute("name");
+ if (!"".equals(name) && name != null) {
+ wrapper.setPropertyValue(IPropertyId.NAME, name);
+ }
+ assignmentAttributeHandler.deserializeAttributes(wrapper, element);
+ }
+ }
+
+ class AssignmentAttributeHandler implements AttributeDeserializer {
+ public void deserializeAttributes(Wrapper wrapper, Element element) {
+ String assignee = element.getAttribute(Assignment.ASSIGNEE);
if (!"".equals(assignee)) {
wrapper.setPropertyValue(
Assignment.ASSIGNMENT_TYPE,
- AssignmentPropertySource.getAssignmentTypesIndex(HumanTask.ASSIGNEE));
- wrapper.setPropertyValue(HumanTask.ASSIGNMENT_EXPRESSION, assignee);
+ AssignmentPropertySource.getAssignmentTypesIndex(Assignment.ASSIGNEE));
+ wrapper.setPropertyValue(Assignment.ASSIGNMENT_EXPRESSION, assignee);
return;
}
- String candidateGroups = element.getAttribute(HumanTask.CANDIDATE_GROUPS);
+ String candidateGroups = element.getAttribute(Assignment.CANDIDATE_GROUPS);
if (!"".equals(candidateGroups)) {
wrapper.setPropertyValue(
Assignment.ASSIGNMENT_TYPE,
- AssignmentPropertySource.getAssignmentTypesIndex(HumanTask.CANDIDATE_GROUPS));
- wrapper.setPropertyValue(HumanTask.ASSIGNMENT_EXPRESSION, candidateGroups);
+ AssignmentPropertySource.getAssignmentTypesIndex(Assignment.CANDIDATE_GROUPS));
+ wrapper.setPropertyValue(Assignment.ASSIGNMENT_EXPRESSION, candidateGroups);
return;
}
String swimlane = element.getAttribute(HumanTask.SWIMLANE);
@@ -111,8 +133,11 @@
FlowWrapper flowWrapper = (FlowWrapper)parent;
if (node instanceof Element) {
result = createWrapper((Element)node);
- if (result != null && result instanceof NodeWrapper) {
+ if (result == null) return null;
+ if (result instanceof NodeWrapper) {
flowWrapper.addElement((NodeWrapper)result);
+ } else if (result.getElement() instanceof Swimlane) {
+ flowWrapper.addChild("swimlane", result);
}
}
return result;
@@ -223,10 +248,20 @@
return getNodeAttributeHandler(wrapper);
} else if (wrapper instanceof ConnectionWrapper) {
return new ConnectionAttributeHandler();
+ } else if (wrapper instanceof DefaultWrapper) {
+ return getDefaultAttributeHandler(wrapper);
}
return null;
}
+ private AttributeDeserializer getDefaultAttributeHandler(Wrapper wrapper) {
+ Object element = wrapper.getElement();
+ if (element instanceof Swimlane) {
+ return new SwimlaneAttributeHandler();
+ }
+ return null;
+ }
+
private AttributeDeserializer getNodeAttributeHandler(Wrapper wrapper) {
Object element = wrapper.getElement();
if (element instanceof HumanTask) {
@@ -262,6 +297,7 @@
else if ("join".equals(nodeName)) return
"org.jboss.tools.flow.jpdl4.parallelJoinGateway";
else if ("fork".equals(nodeName)) return
"org.jboss.tools.flow.jpdl4.parallelForkGateway";
else if ("transition".equals(nodeName)) return
"org.jboss.tools.flow.jpdl4.sequenceFlow";
+ else if ("swimlane".equals(nodeName)) return
"org.jboss.tools.flow.jpdl4.swimlane";
else return null;
}
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlSerializer.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlSerializer.java 2009-04-29
22:07:49 UTC (rev 14968)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlSerializer.java 2009-04-29
22:10:48 UTC (rev 14969)
@@ -21,6 +21,7 @@
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.jboss.tools.flow.common.model.Element;
+import org.jboss.tools.flow.common.properties.IPropertyId;
import org.jboss.tools.flow.common.wrapper.ConnectionWrapper;
import org.jboss.tools.flow.common.wrapper.ContainerWrapper;
import org.jboss.tools.flow.common.wrapper.FlowWrapper;
@@ -28,6 +29,7 @@
import org.jboss.tools.flow.common.wrapper.NodeWrapper;
import org.jboss.tools.flow.common.wrapper.Wrapper;
import org.jboss.tools.flow.jpdl4.Logger;
+import org.jboss.tools.flow.jpdl4.model.Assignment;
import org.jboss.tools.flow.jpdl4.model.CancelEndEvent;
import org.jboss.tools.flow.jpdl4.model.ErrorEndEvent;
import org.jboss.tools.flow.jpdl4.model.ExclusiveGateway;
@@ -44,6 +46,7 @@
import org.jboss.tools.flow.jpdl4.model.SqlTask;
import org.jboss.tools.flow.jpdl4.model.StartEvent;
import org.jboss.tools.flow.jpdl4.model.SuperState;
+import org.jboss.tools.flow.jpdl4.model.Swimlane;
import org.jboss.tools.flow.jpdl4.model.TerminateEndEvent;
import org.jboss.tools.flow.jpdl4.model.WaitTask;
import org.w3c.dom.NamedNodeMap;
@@ -179,6 +182,7 @@
else if ("org.jboss.tools.flow.jpdl4.parallelJoinGateway".equals(elementId))
return "join";
else if ("org.jboss.tools.flow.jpdl4.parallelForkGateway".equals(elementId))
return "fork";
else if ("org.jboss.tools.flow.jpdl4.sequenceFlow".equals(elementId)) return
"transition";
+ else if ("org.jboss.tools.flow.jpdl4.swimlane".equals(elementId)) return
"swimlane";
else return null;
}
@@ -283,9 +287,9 @@
class HumanTaskSerializer extends ProcessNodeWrapperSerializer {
protected List<String> getAttributesToSave() {
List<String> result = super.getAttributesToSave();
- result.add(HumanTask.ASSIGNEE);
- result.add(HumanTask.CANDIDATE_GROUPS);
- result.add(HumanTask.SWIMLANE);
+ result.add(Assignment.ASSIGNEE);
+ result.add(Assignment.CANDIDATE_GROUPS);
+ result.add(Assignment.SWIMLANE);
return result;
}
protected void appendAttributeToSave(String attributeName, StringBuffer buffer,
Wrapper wrapper) {
@@ -313,6 +317,49 @@
}
}
+ class SwimlaneWrapperSerializer extends AbstractWrapperSerializer {
+ protected List<String> getAttributesToSave() {
+ ArrayList<String> result = new ArrayList<String>();
+ result.add("name");
+ result.add(Assignment.ASSIGNEE);
+ result.add(Assignment.CANDIDATE_GROUPS);
+ result.add(Assignment.SWIMLANE);
+ return result;
+ }
+ protected void appendAttributeToSave(String attributeName, StringBuffer buffer,
Wrapper wrapper) {
+ Element element = wrapper.getElement();
+ if (!(element instanceof Swimlane)) return;
+ if (Assignment.ASSIGNEE.equals(attributeName)) {
+ appendExpression(Assignment.ASSIGNEE, buffer, wrapper);
+ } else if (Assignment.CANDIDATE_GROUPS.equals(attributeName)) {
+ appendExpression(Assignment.CANDIDATE_GROUPS, buffer, wrapper);
+ } else if (Assignment.SWIMLANE.equals(attributeName)) {
+ appendExpression(Assignment.SWIMLANE, buffer, wrapper);
+ } else if ("name".equals(attributeName)){
+ appendName(buffer, wrapper);
+ }
+ }
+ protected void appendName(StringBuffer buffer, Wrapper wrapper) {
+ String value = (String)wrapper.getPropertyValue(IPropertyId.NAME);
+ if (value == null || "".equals(value)) return;
+ buffer.append(" name=\"" + value + "\"");
+ }
+ protected void appendExpression(String type, StringBuffer buffer, Wrapper wrapper)
{
+ Object assignmentType = wrapper.getPropertyValue(HumanTask.ASSIGNMENT_TYPE);
+ if (!(assignmentType instanceof Integer)) return;
+ if (type.equals(HumanTask.ASSIGNMENT_TYPES[(Integer)assignmentType])) {
+ Object value = wrapper.getPropertyValue(HumanTask.ASSIGNMENT_EXPRESSION);
+ if (value == null || "".equals(value)) return;
+ buffer.append(" " + type + "=\"" + value +
"\"");
+ }
+ }
+ public void appendOpening(StringBuffer buffer, Wrapper wrapper, int level) {
+ appendLeadingNodes(buffer, wrapper, level);
+ buffer.append("<swimlane");
+ appendAttributes(buffer, wrapper, level);
+ }
+ }
+
class ProcessWrapperSerializer extends AbstractWrapperSerializer {
public void appendOpening(StringBuffer buffer, Wrapper wrapper, int level) {
buffer.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n\n");
@@ -387,12 +434,24 @@
new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
} else if (element instanceof Process) {
new ProcessWrapperSerializer().appendOpening(buffer, wrapper, level);
+ } else if (element instanceof Swimlane) {
+ new SwimlaneWrapperSerializer().appendOpening(buffer, wrapper, level);
}
}
@SuppressWarnings("unchecked")
private void appendBody(StringBuffer buffer, Wrapper wrapper, int level) {
+ if (wrapper instanceof FlowWrapper) {
+ FlowWrapper flowWrapper = (FlowWrapper)wrapper;
+ List<Element> swimlanes = flowWrapper.getChildren("swimlane");
+ if (swimlanes != null) {
+ for (Element swimlane : swimlanes) {
+ if (!(swimlane instanceof Wrapper)) continue;
+ appendToBuffer(buffer, (Wrapper)swimlane, level+1);
+ }
+ }
+ }
if (wrapper instanceof ContainerWrapper) {
ContainerWrapper containerWrapper = (ContainerWrapper)wrapper;
List<NodeWrapper> children = containerWrapper.getNodeWrappers();
@@ -460,7 +519,9 @@
buffer.append("</join>");
} else if (element instanceof Process) {
buffer.append("</process>");
- }
+ } else if (element instanceof Swimlane) {
+ buffer.append("</swimlane>");
+ }
}
private boolean isEmpty(String str) {
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/handler/AddSwimlaneHandler.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/handler/AddSwimlaneHandler.java 2009-04-29
22:07:49 UTC (rev 14968)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/handler/AddSwimlaneHandler.java 2009-04-29
22:10:48 UTC (rev 14969)
@@ -12,9 +12,8 @@
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jboss.tools.flow.common.command.AddChildCommand;
-import org.jboss.tools.flow.common.wrapper.DefaultWrapper;
+import org.jboss.tools.flow.common.registry.ElementRegistry;
import org.jboss.tools.flow.common.wrapper.Wrapper;
-import org.jboss.tools.flow.jpdl4.model.Swimlane;
public class AddSwimlaneHandler extends AbstractHandler implements IHandler {
@@ -36,8 +35,7 @@
if (object == null || !(object instanceof CommandStack)) return null;
CommandStack commandStack = (CommandStack)object;
AddChildCommand addChildCommand = new AddChildCommand();
- Wrapper child = new DefaultWrapper();
- child.setElement(new Swimlane());
+ Wrapper child =
ElementRegistry.createWrapper("org.jboss.tools.flow.jpdl4.swimlane");
addChildCommand.setChild(child);
addChildCommand.setType("swimlane");
addChildCommand.setParent(parent);
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/properties/AssignmentSection.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/properties/AssignmentSection.java 2009-04-29
22:07:49 UTC (rev 14968)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/properties/AssignmentSection.java 2009-04-29
22:10:48 UTC (rev 14969)
@@ -13,6 +13,7 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+import org.jboss.tools.flow.jpdl4.model.Assignment;
import org.jboss.tools.flow.jpdl4.model.HumanTask;
public class AssignmentSection extends JpdlPropertySection {
@@ -25,13 +26,13 @@
private SelectionListener typeComboSelectionListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
changeProperty(HumanTask.ASSIGNMENT_TYPE, typeCombo.getSelectionIndex());
- expressionText.setEnabled(!HumanTask.NONE.equals(typeCombo.getText()));
+ expressionText.setEnabled(!Assignment.NONE.equals(typeCombo.getText()));
}
};
private ModifyListener expressionTextModifyListener = new ModifyListener() {
public void modifyText(ModifyEvent e) {
- changeProperty(HumanTask.ASSIGNMENT_EXPRESSION, expressionText.getText());
+ changeProperty(Assignment.ASSIGNMENT_EXPRESSION, expressionText.getText());
}
};