1 package com.opensymphony.workflow.designer.editor; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import com.opensymphony.workflow.designer.WorkflowCell; 7 import com.opensymphony.workflow.designer.WorkflowGraphModel; 8 import com.opensymphony.workflow.designer.spi.DefaultFunctionPlugin; 9 import com.opensymphony.workflow.designer.spi.FunctionPlugin; 10 import com.opensymphony.workflow.loader.AbstractDescriptor; 11 import com.opensymphony.workflow.loader.ConfigFunctionDescriptor; 12 import com.opensymphony.workflow.loader.FunctionDescriptor; 13 14 17 public abstract class FunctionEditor 18 { 19 protected WorkflowCell cell; 20 protected WorkflowGraphModel model; 21 22 public FunctionEditor(WorkflowCell cell) 23 { 24 this.cell = cell; 25 } 26 27 public WorkflowGraphModel getModel() 28 { 29 return model; 30 } 31 32 public void setModel(WorkflowGraphModel model) 33 { 34 this.model = model; 35 } 36 37 public FunctionDescriptor add() 38 { 39 ConfigFunctionDescriptor function = getFunction(); 40 if(function == null) 41 { 42 return null; 43 } 44 45 function = editFunction(function); 46 47 if(function != null) 48 { 49 FunctionDescriptor func = new FunctionDescriptor(); 50 func.setParent(getParent()); 52 func.setType(function.getType()); 53 func.setName(function.getName()); 54 func.getArgs().putAll(function.getArgs()); 55 56 return func; 57 } 58 else 59 { 60 return null; 61 } 62 63 } 64 65 public void modify(FunctionDescriptor func) 66 { 67 ConfigFunctionDescriptor function; 68 69 if(func.getName() != null) 70 { 71 function = new ConfigFunctionDescriptor(getModel().getPalette().getPrefunction(func.getName())); 72 } 73 else 74 { 75 function = new ConfigFunctionDescriptor(getModel().getPalette()); 76 function.setType(func.getType()); 77 } 78 79 function.getArgs().putAll(func.getArgs()); 80 81 function = editFunction(function); 82 83 if(function != null) 84 { 85 func.getArgs().putAll(function.getArgs()); 86 } 87 88 } 89 90 private ConfigFunctionDescriptor editFunction(ConfigFunctionDescriptor config) 91 { 92 String clazz = config.getPlugin(); 94 if(clazz == null || clazz.length() == 0) 95 { 96 clazz = "com.opensymphony.workflow.designer.spi.DefaultFunctionPlugin"; 97 } 98 FunctionPlugin funcImpl; 99 try 100 { 101 funcImpl = (FunctionPlugin)Class.forName(clazz).newInstance(); 102 } 103 catch(Exception e1) 104 { 105 e1.printStackTrace(); 106 funcImpl = new DefaultFunctionPlugin(); 107 } 108 109 funcImpl.setFunction(config); 110 111 Map args = new HashMap (); 113 args.put("cell", cell); 114 115 if(!funcImpl.editFunction(args)) 116 { 117 return null; 119 } 120 config = funcImpl.getFunction(); 121 return config; 122 } 123 124 abstract protected AbstractDescriptor getParent(); 125 126 abstract protected ConfigFunctionDescriptor getFunction(); 127 } 128 | Popular Tags |