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