KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > ProcessViewer


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 /**
16  * The panel that is used to display the WorkflowGraph instances -
17  * the Workflows defined by the ProcessEditor application.
18  *
19  * @author Sasa Bojanic
20  * @version 1.0
21  */

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    /**
47    * Create the center component of this panel. This creates a scroll-
48    * pane for the current graph variable and stores the scrollpane
49    * in the scrollPane variable.
50    */

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    /** Show dialog for editing panel. */
61    public void showDialog () {
62       graphScrollPane.setViewportView(currentGraph);
63       // repack because the graph probably changed
64
myDialog.pack();
65       // set location to be centered
66
//org.webdocwf.util.swingwfapp.Utils.center(myDialog);
67
org.enhydra.jawe.Utils.center(myDialog,100,150);
68       // set title
69
setDialogTitle();
70       myDialog.setVisible(true);
71    }
72
73    /** Sets the dialog title. */
74    protected void setDialogTitle () {
75       String JavaDoc pName=null;
76       try {
77          pName=currentProcessMgr.name();
78       } catch (Exception JavaDoc 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    /**
101    * Displays the wanted process instance in the graph.
102    */

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 //System.out.println("Selected graph="+currentGraph.get("Name").toString());
120
graphScrollPane.setViewportView(currentGraph);
121          updateSelection();
122       } catch (Exception JavaDoc ex) {
123          graphScrollPane.setViewportView(null);
124       }
125    }
126
127    /**
128    * Refreshes graph to select activities of current process insance that
129    * are currently in the open.running state.
130    */

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             // if exception does not occur, it means that it is activity within
142
// the block, so skip it
143
try {
144                String JavaDoc blockId=SharkClient.getAdminMiscUtilities().getBlockActivityId(currentProcess.key(),allRunningActs[i].key());
145                if (blockId!=null && blockId.trim().length()>0) {
146                   continue;
147                }
148             } catch (Exception JavaDoc ex) {}
149             Activity act=acts.getActivity(SharkClient.getAdminMiscUtilities().getActivityDefinitionId(currentProcess.key(),allRunningActs[i].key()));
150             try {
151                WorkflowManager wm=currentGraph.getWorkflowManager();
152                Object JavaDoc go=wm.getActivity(act.getID());
153                if (go!=null) {
154                   currentGraph.addSelectionCell(go);
155                }
156             } catch (Exception JavaDoc ex) {}
157          }
158          //System.out.println("Selection refreshed");
159
} catch (Exception JavaDoc ex) {
160          System.err.println("Problems while updating selection");
161       }
162    }
163
164    /** Sets the value of scale for zooming. */
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 JavaDoc ex){}
170    }
171
172    //******************** TEST
173
public static void main (String JavaDoc[] 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