1 package org.enhydra.shark.swingclient.workflowadmin; 2 3 import java.awt.*; 4 5 import javax.swing.*; 6 7 8 import org.enhydra.shark.api.client.wfmodel.*; 9 10 import org.enhydra.jawe.*; 11 import org.enhydra.jawe.xml.elements.*; 12 import org.enhydra.shark.swingclient.*; 13 import org.enhydra.shark.swingclient.workflowadmin.actions.*; 14 15 22 public class ProcessViewer extends ActionPanel { 23 24 protected org.enhydra.jawe.xml.elements.Package currentPackage; 25 protected WfProcessMgr currentProcessMgr; 26 protected WfProcess currentProcess; 27 protected ProcessGraph currentGraph; 28 protected JScrollPane graphScrollPane; 29 30 public ProcessViewer (Window parent) { 31 super(); 32 super.init(); 33 super.initDialog(parent,"",false,false); 34 } 35 36 protected void createActions () { 37 defaultActions=new Action[] { 38 new ActualSize(this), 39 new ZoomIn(this), 40 new ZoomOut(this), 41 new ViewBlock(this), 42 new UpdateView(this) 43 }; 44 } 45 46 51 protected Component createCenterComponent() { 52 graphScrollPane = new JScrollPane(); 53 JViewport port = graphScrollPane .getViewport(); 54 port.setScrollMode(JViewport.SIMPLE_SCROLL_MODE); 55 56 return graphScrollPane; 57 } 58 59 60 61 public void showDialog () { 62 graphScrollPane.setViewportView(currentGraph); 63 myDialog.pack(); 65 org.enhydra.jawe.Utils.center(myDialog,100,150); 68 setDialogTitle(); 70 myDialog.setVisible(true); 71 } 72 73 74 protected void setDialogTitle () { 75 String pName=null; 76 try { 77 pName=currentProcessMgr.name(); 78 } catch (Exception ex){} 79 80 myDialog.setTitle(pName); 81 } 82 83 84 public ProcessGraph getCurrentGraph () { 85 return currentGraph; 86 } 87 88 public org.enhydra.jawe.xml.elements.Package getCurrentPackage () { 89 return currentPackage; 90 } 91 92 public WfProcess getCurrentProcess () { 93 return currentProcess; 94 } 95 96 public WfProcessMgr getCurrentProcessDef () { 97 return currentProcessMgr; 98 } 99 100 103 public void displayProcess ( 104 org.enhydra.jawe.xml.elements.Package pkg, 105 WfProcessMgr wpm,WfProcess wpr) { 106 107 currentPackage=pkg; 108 currentProcessMgr=wpm; 109 currentProcess=wpr; 110 try { 111 WorkflowProcesses wps=(WorkflowProcesses)pkg.get("WorkflowProcesses"); 112 WorkflowProcess wp=wps.getWorkflowProcess(SharkAdmin.getAdminMiscUtilities().getProcessMgrProcDefId(wpm.name())); 113 currentGraph=(ProcessGraph)((org.enhydra.jawe.graph.Process) 114 JaWE.getInstance().getPackageEditor().getProcessObject(wp)). 115 getImplementationEditor().getGraph(); 116 currentGraph.setEditable(false); 117 currentGraph.setMoveable(false); 118 ((ProcessEditor)currentGraph.getEditor()).setButtonsEnabled(false); 119 graphScrollPane.setViewportView(currentGraph); 121 updateSelection(); 122 } catch (Exception ex) { 123 graphScrollPane.setViewportView(null); 124 } 125 } 126 127 131 public void updateSelection () { 132 if (currentGraph==null) return; 133 currentGraph.clearSelection(); 134 if (currentProcess==null) return; 135 136 try { 137 WfActivityIterator wai=SharkClient.getCommonExpressionBuilder().getOpenActivities(currentProcess.key()); 138 WfActivity[] allRunningActs=wai.get_next_n_sequence(0); 139 Activities acts=(Activities)currentGraph.get("Activities"); 140 for (int i=0; i<allRunningActs.length; i++) { 141 try { 144 String blockId=SharkClient.getAdminMiscUtilities().getBlockActivityId(currentProcess.key(),allRunningActs[i].key()); 145 if (blockId!=null && blockId.trim().length()>0) { 146 continue; 147 } 148 } catch (Exception ex) {} 149 Activity act=acts.getActivity(SharkClient.getAdminMiscUtilities().getActivityDefinitionId(currentProcess.key(),allRunningActs[i].key())); 150 try { 151 WorkflowManager wm=currentGraph.getWorkflowManager(); 152 Object go=wm.getActivity(act.getID()); 153 if (go!=null) { 154 currentGraph.addSelectionCell(go); 155 } 156 } catch (Exception ex) {} 157 } 158 } catch (Exception ex) { 160 System.err.println("Problems while updating selection"); 161 } 162 } 163 164 165 public void setScale(double scale) { 166 scale = Math.max(Math.min(scale,2),0.1); 167 try { 168 currentGraph.setScale(scale); 169 } catch (Exception ex){} 170 } 171 172 public static void main (String [] args) { 174 JFrame f=new JFrame(); 175 ProcessViewer pv=new ProcessViewer(f); 176 f.setBackground(Color.lightGray); 177 f.getContentPane().setLayout(new BorderLayout()); 178 f.getContentPane().add(pv,BorderLayout.CENTER); 179 f.pack(); 180 f.setSize(1000,700); 181 f.setVisible(true); 182 } 183 } 184 | Popular Tags |