summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/gui/lifecycle/instance/WfVertexFactory.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-06-26 20:57:49 +0200
committerAndrew Branson <andrew.branson@cern.ch>2012-06-26 20:57:49 +0200
commit3069ddf81b3cce2303cc1528e5de4708a798841f (patch)
tree5fd1ca9057f142b862e394a6347727e0b372522f /src/main/java/com/c2kernel/gui/lifecycle/instance/WfVertexFactory.java
parent99eed1e3c7e7292aea91131baeb36f81e23e3e82 (diff)
More GUI refactoring
Diffstat (limited to 'src/main/java/com/c2kernel/gui/lifecycle/instance/WfVertexFactory.java')
-rw-r--r--src/main/java/com/c2kernel/gui/lifecycle/instance/WfVertexFactory.java92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/main/java/com/c2kernel/gui/lifecycle/instance/WfVertexFactory.java b/src/main/java/com/c2kernel/gui/lifecycle/instance/WfVertexFactory.java
new file mode 100644
index 0000000..fa6b427
--- /dev/null
+++ b/src/main/java/com/c2kernel/gui/lifecycle/instance/WfVertexFactory.java
@@ -0,0 +1,92 @@
+package com.c2kernel.gui.lifecycle.instance;
+import java.awt.Point;
+import com.c2kernel.gui.lifecycle.chooser.ActivityChooser;
+import com.c2kernel.gui.lifecycle.chooser.WorkflowDialogue;
+import java.io.Serializable;
+import java.util.HashMap;
+
+import javax.swing.JOptionPane;
+
+import com.c2kernel.graph.model.GraphModelManager;
+import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
+import com.c2kernel.graph.model.VertexFactory;
+import com.c2kernel.lifecycle.ActivityDef;
+import com.c2kernel.lifecycle.instance.Activity;
+import com.c2kernel.lifecycle.instance.CompositeActivity;
+import com.c2kernel.utils.Language;
+import com.c2kernel.utils.LocalObjectLoader;
+import com.c2kernel.utils.Resource;
+public class WfVertexFactory implements VertexFactory, WorkflowDialogue
+{
+ protected CompositeActivity mRootAct = null;
+ @Override
+ public void create(GraphModelManager graphModelManager, Point location, TypeNameAndConstructionInfo typeNameAndConstructionInfo)
+ {
+ String vertexTypeId = null;
+ if (mRootAct != null && typeNameAndConstructionInfo.mInfo instanceof String)
+ {
+ vertexTypeId = (String) typeNameAndConstructionInfo.mInfo;
+ if (vertexTypeId.equals("Atomic") || vertexTypeId.equals("Composite"))
+ {
+ HashMap<String, Serializable> mhm = new HashMap<String, Serializable>();
+ mhm.put("P1", vertexTypeId);
+ mhm.put("P2", location);
+ //************************************************
+ ActivityChooser a =
+ new ActivityChooser(
+ Language.translate("Please enter a Type for the new activity"),
+ Language.translate("New " + vertexTypeId + " Activity"),
+ Resource.findImage("graph/newvertex_large.png").getImage(),
+ this,
+ mhm);
+ a.setVisible(true);
+ }
+ else
+ mRootAct.newChild(vertexTypeId, location);
+ }
+ }
+ @Override
+ public void setCreationContext(Object newContext)
+ {
+ if (newContext != null && newContext instanceof CompositeActivity)
+ mRootAct = (CompositeActivity) newContext;
+ }
+ @Override
+ public void loadThisWorkflow(String newName, HashMap<?, ?> hashMap)
+ {
+ String vertexTypeId = (String) hashMap.get("P1");
+ Point location = (Point) hashMap.get("P2");
+ if (newName == null)
+ return;
+
+
+ String unicName = newName;
+ while (mRootAct.search(mRootAct.getPath() + "/" + unicName) != null)
+ {
+ unicName =
+ (String) JOptionPane.showInputDialog(
+ null,
+ Language.translate("Activity name not unique. Please give another."),
+ Language.translate("New " + vertexTypeId + " Activity"),
+ JOptionPane.QUESTION_MESSAGE,
+ Resource.findImage("graph/newvertex_large.png"),
+ null,
+ null);
+ if (newName.equals(""))
+ return;
+ }
+ Activity act = null;
+ try
+ {
+ ActivityDef actD = LocalObjectLoader.getActDef(newName, "last");
+ act = (Activity)actD.instantiate(unicName);
+ }
+ catch (Exception e)
+ {
+ }
+ if (act == null)
+ mRootAct.newChild(unicName, vertexTypeId, location);
+ else
+ mRootAct.newExistingChild(act, unicName, location);
+ }
+}