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; } }