KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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             // if exception does not occur, it means that it is activity within
140
// the block, so skip it
141
try {
142                String JavaDoc blockId=SharkClient.getAdminMiscUtilities().getBlockActivityId(currentProcess.key(),allRunningActs[i].key());
143                if (blockId!=null && blockId.trim().length()>0) {
144                   continue;
145                }
146             } catch (Exception JavaDoc 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 JavaDoc go=wm.getActivity(act.getID());
153                if (go!=null) {
154                   currentGraph.addSelectionCell(go);
155                }
156             } catch (Exception JavaDoc ex) {
157                 System.err.println("displayProcess Activity: "+ex);
158             }
159          }
160          //System.out.println("Selection refreshed");
161
} catch (Exception JavaDoc ex) {
162          System.err.println("display Process: Problems while updating selection: "+ex);
163          // ex.printStackTrace();
164
}
165    }
166
167    /** Sets the value of scale for zooming. */
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 JavaDoc ex){}
173    }
174
175    //******************** TEST
176
public static void main (String JavaDoc[] 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