dangsn
2024-12-26 4e9ff2ce6a830bb2340d7c8612c72eea0c5a553e
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
package com.vci.client.workflow.editor;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
 
import javax.swing.JComponent;
 
import com.mxgraph.model.mxCell;
import com.mxgraph.view.mxGraph;
import com.vci.client.workflow.editor.ui.DecisionPanel;
import com.vci.client.workflow.editor.ui.FlowInfoPanel;
import com.vci.client.workflow.editor.ui.MailPanel;
import com.vci.client.workflow.editor.ui.StartEndPanel;
import com.vci.client.workflow.editor.ui.SubProcesslPanel;
import com.vci.client.workflow.editor.ui.TaskNewPanel;
import com.vci.client.workflow.editor.ui.TaskPanel;
import com.vci.client.workflow.editor.ui.TransitionPanel;
import com.vci.corba.common.VCIError;
 
public class ProcessComponentFactory {
 
    public static JComponent getComponent(mxGraph graph, mxCell cell) throws VCIError {
        Object value = cell.getValue();
        if (value == null) {
            return new FlowInfoPanel(graph);
        } else if (value instanceof JComponent) {
            return (JComponent) value;
        } else if (value instanceof FlowNode) {
            // 克隆一份
            FlowNode node = (FlowNode) ((FlowNode) value).clone();
            if (cell.isEdge()) {
                return new TransitionPanel(graph, node);
            }
            if (node.getType().equals(FlowConstants.XMLTASK)) {
                Properties properties = new Properties();
                try {
                    ClassLoader cl = TaskNewPanel.class.getClassLoader();
                    InputStream in = cl.getResourceAsStream("flow-custom.properties");
                    properties.load(in);
                    String flag = (String) properties.get("workflow.template");
                    if ("1".equals(flag)) {
                        // 任务节点属性面板
                        try {
                            return new TaskPanel(graph, node);
                        } catch (VCIError e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    } else if ("2".equals(flag)) {
                        // 任务节点属性面板
                        try {
                            return new TaskNewPanel(graph, node);
                        } catch (VCIError e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
 
            } else if (node.getType().equals(FlowConstants.XMLSTART) || node.getType().equals(FlowConstants.XMLEND)
            // || node.getType().startsWith(FlowConstants.TRANSITION)
                    || node.getType().startsWith(FlowConstants.XMLFORK)
                    || node.getType().startsWith(FlowConstants.XMLJOIN)) {
                return new StartEndPanel(graph, node);
            } else if (node.getType().equals(FlowConstants.DECISION)) {
                DecisionPanel decisionPanel = new DecisionPanel(graph, node);
                return decisionPanel;
            } else if (node.getType().startsWith(FlowConstants.TRANSITION)) {
                return new TransitionPanel(graph, node);
            } else if (node.getType().startsWith(FlowConstants.MAIL)) {
                return new MailPanel(graph, node);
            } else if (node.getType().startsWith(FlowConstants.SUBPROCESS)) {
                return new SubProcesslPanel(graph, node);
            }
            return (JComponent) value;
        } else if (value instanceof String) {
            FlowNode node = new FlowNode("", "");
//            return new StartEndPanel(graph, node);
            return new TransitionPanel(graph, node);
        }
        return null;
    }
 
}