KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > actions > CellFactory


1 package com.opensymphony.workflow.designer.actions;
2
3 import java.awt.*;
4 import javax.swing.*;
5
6 import com.opensymphony.workflow.designer.*;
7 import com.opensymphony.workflow.designer.dnd.DragData;
8 import com.opensymphony.workflow.loader.*;
9 import org.jgraph.graph.GraphConstants;
10
11 /**
12  * @author Gulei
13  */

14 public class CellFactory
15 {
16   public static void createCell(WorkflowDescriptor workflow, WorkflowGraphModel model, Point location, DragData data)
17   {
18     if(data.equals(DragData.JOIN))
19     {
20       createJoin(workflow, model, location);
21     }
22     else if(data.equals(DragData.SPLIT))
23     {
24       createSplit(workflow, model, location);
25     }
26     else if(data.equals(DragData.STEP))
27     {
28       createStep(workflow, model, location);
29     }
30   }
31
32   public static void createStep(WorkflowDescriptor workflow, WorkflowGraphModel model, Point location)
33   {
34     // create new step
35
String JavaDoc name = JOptionPane.showInputDialog(ResourceManager.getString("step.add.name"));
36     if(name == null || name.trim().length() == 0) return;
37
38     StepDescriptor step = DescriptorBuilder.createStep(name, Utils.getNextId(model.getContext()));
39     step.setParent(workflow);
40     workflow.addStep(step);
41
42     StepCell cell = new StepCell(step);
43     WorkflowPort port = new WorkflowPort();
44     cell.add(port);
45     Rectangle bounds = (Rectangle)cell.getAttributes().get(GraphConstants.BOUNDS);
46     bounds.x = location.x;
47     bounds.y = location.y;
48     model.insertStepCell(cell, null, null, null);
49   }
50
51   public static void createJoin(WorkflowDescriptor workflow, WorkflowGraphModel model, Point location)
52   {
53     JoinDescriptor join = DescriptorBuilder.createJoin(Utils.getNextId(model.getContext()));
54     join.setParent(workflow);
55     workflow.addJoin(join);
56
57     JoinCell cell = new JoinCell(join);
58     WorkflowPort port = new WorkflowPort();
59     cell.add(port);
60     Rectangle bounds = (Rectangle)cell.getAttributes().get(GraphConstants.BOUNDS);
61     bounds.x = location.x;
62     bounds.y = location.y;
63     model.insertJoinCell(cell, null, null, null);
64   }
65
66   public static void createSplit(WorkflowDescriptor workflow, WorkflowGraphModel model, Point location)
67   {
68     SplitDescriptor split = DescriptorBuilder.createSplit(Utils.getNextId(model.getContext()));
69     split.setParent(workflow);
70     workflow.addSplit(split);
71
72     SplitCell cell = new SplitCell(split);
73     WorkflowPort port = new WorkflowPort();
74     cell.add(port);
75     Rectangle bounds = (Rectangle)cell.getAttributes().get(GraphConstants.BOUNDS);
76     bounds.x = location.x;
77     bounds.y = location.y;
78     model.insertSplitCell(cell, null, null, null);
79   }
80
81 }
82
Popular Tags