summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/gui/lifecycle/desc/WfVertexDefFactory.java
blob: f08f9166535472b08a36fe1ecf7792f28e4565ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.c2kernel.gui.lifecycle.desc;
import java.util.HashMap;

import javax.swing.JOptionPane;

import com.c2kernel.graph.model.GraphModelManager;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
import com.c2kernel.graph.model.VertexFactory;
import com.c2kernel.gui.ImageLoader;
import com.c2kernel.gui.MainFrame;
import com.c2kernel.gui.lifecycle.chooser.ActivityChooser;
import com.c2kernel.gui.lifecycle.chooser.WorkflowDialogue;
import com.c2kernel.lifecycle.ActivityDef;
import com.c2kernel.lifecycle.CompositeActivityDef;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.LocalObjectLoader;
import com.c2kernel.utils.Logger;
public class WfVertexDefFactory implements VertexFactory, WorkflowDialogue
{
	protected CompositeActivityDef mCompositeActivityDef = null;
	@Override
	public void create(GraphModelManager graphModelManager, GraphPoint location, TypeNameAndConstructionInfo typeNameAndConstructionInfo)
	{
		String vertexTypeId = null;
		if (mCompositeActivityDef != null && typeNameAndConstructionInfo.mInfo instanceof String)
		{
			vertexTypeId = (String) typeNameAndConstructionInfo.mInfo;
			if (vertexTypeId.equals("Atomic") || vertexTypeId.equals("Composite"))
			{
				// ask for a name
				HashMap<String, Object> mhm = new HashMap<String, Object>();
				mhm.put("P1", vertexTypeId);
				mhm.put("P2", location);
				//************************************************
				ActivityChooser a =
					new ActivityChooser(
						Language.translate("Please enter a Type for the new activityDef"),
						Language.translate("New " + vertexTypeId + " Activity"),
						ImageLoader.findImage("graph/newvertex_large.png").getImage(),
						this,
						mhm);
				a.setVisible(true);
			}
			else
				mCompositeActivityDef.newChild("", vertexTypeId, location);
		}
	}
	@Override
	public void loadThisWorkflow(String newName, HashMap<String, Object> hashMap)
	{
		String vertexTypeId = (String) hashMap.get("P1");
		GraphPoint location = (GraphPoint) hashMap.get("P2");
		if (newName == null || newName.equals(""))
			return;
		Logger.debug(5, newName);
		ActivityDef act = (ActivityDef) mCompositeActivityDef.search(mCompositeActivityDef.getID() + "/" + newName);
		if (act != null)
		{
			String unicName = newName;
			while (unicName == null
				|| unicName == ""
				|| mCompositeActivityDef.search(mCompositeActivityDef.getID() + "/" + unicName) != null)
				unicName =
					(String) JOptionPane.showInputDialog(
						null,
						Language.translate("Please type a Name"),
						Language.translate("New " + vertexTypeId + " Activity"),
						JOptionPane.QUESTION_MESSAGE,
						ImageLoader.findImage("graph/newvertex_large.png"),
						null,
						null);
			act = (ActivityDef) mCompositeActivityDef.search(mCompositeActivityDef.getID() + "/" + newName);
			mCompositeActivityDef.addExistingActivityDef(unicName, act, location);
		}
		else
		{
			try
			{
				act = LocalObjectLoader.getActDef(newName, 0);
			}
			catch (Exception ex)
			{
				MainFrame.exceptionDialog(ex);
				return;
			}
			mCompositeActivityDef.newChild(newName, vertexTypeId, location);
		}
	}
	@Override
	public void setCreationContext(Object newContext)
	{
		if (newContext != null && newContext instanceof CompositeActivityDef)
			mCompositeActivityDef = (CompositeActivityDef) newContext;
	}
}