KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > monitoring > ProcessMonitor


1 package org.enhydra.shark.swingclient.workflowadmin.monitoring;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.text.SimpleDateFormat JavaDoc;
6 import java.util.*;
7
8 import javax.swing.*;
9 import javax.swing.border.*;
10 import javax.swing.event.*;
11 import javax.swing.table.*;
12 import javax.swing.tree.*;
13
14
15 import org.enhydra.shark.api.client.wfmodel.*;
16 import org.enhydra.shark.swingclient.*;
17 import org.enhydra.shark.swingclient.workflowadmin.*;
18 import org.enhydra.shark.swingclient.workflowadmin.monitoring.actions.*;
19
20 /**
21  * Implements the user interface and program logic to monitor
22  * the instantiated processes.
23  *
24  * @author Sasa Bojanic
25  * @version 1.0
26  */

27 public class ProcessMonitor extends ActionPanel {
28
29    private SharkAdmin workflowAdmin;
30    private ProcessViewer processViewer;
31
32    private static Dimension tDimension=new Dimension(300,200);
33
34    private DefaultTreeModel treeModel;
35    private JTree allItems;
36    private PIMTreeSelectionListener pimSL;
37
38    private DescriptionTableModel processDescription;
39
40    Map actions=new HashMap();
41
42    public ProcessMonitor (SharkAdmin wa) {
43       super();
44       // it is important to initialize workflowAdmin and tree model
45
// before calling init method
46
this.workflowAdmin=wa;
47       this.processViewer=new ProcessViewer(wa.getFrame());
48       this.treeModel=wa.getEngineTreeModel();
49
50       super.init();
51
52
53
54       addFocusListener(new FocusListener () {
55                public void focusGained (FocusEvent fe) {
56                   pimSL.valueChanged(null);
57                }
58                public void focusLost (FocusEvent fe) {
59                   //
60
}
61             });
62    }
63
64    protected void createActions () {
65       defaultActions=new Action[] {
66          new SuspendProcess(this),
67             new ResumeProcess(this),
68             new TerminateProcess(this),
69             new AbortProcess(this),
70             new StartProcess(this),
71             new ShowHistory(this),
72             new ProcessDescription(this),
73             new ProcessVariables(this),
74             new ActivityManagement(this),
75             new WorkflowObjectProperties(this),
76             new DeleteFinishedProcesses(this),
77             new DeleteSelectedProcesses(this),
78             new CheckDeadlines(this),
79             new CheckLimits(this)
80       };
81    }
82
83    /**
84     * Create the center component of this panel. This creates a scroll-
85     * pane for the current graph variable and stores the scrollpane
86     * in the scrollPane variable.
87     */

88    protected Component createCenterComponent() {
89       Component treePanel=createTreePanel();
90       Component tablePanel=createTablePanel();
91       JSplitPane ttPane=new JSplitPane(JSplitPane.VERTICAL_SPLIT,
92                                        treePanel,tablePanel);
93       // ttPane.setBorder(BorderFactory.createEtchedBorder());
94
ttPane.setDividerLocation(350);
95
96       JSplitPane splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
97                                           ttPane,processViewer);
98
99       return splitPane;
100    }
101
102    public void clear () {
103       processDescription.setData(null);
104       processViewer.displayProcess(null,null,null);
105    }
106
107    public synchronized void refresh (boolean mandatoryRefreshing) {
108       if (mandatoryRefreshing || isShowing()) {
109          pimSL.valueChanged(null);
110          processViewer.updateSelection ();
111       }
112    }
113
114    private Component createTreePanel() {
115       JPanel tp=new JPanel();
116       int emptyBorderHSize=8;
117       int emptyBorderVSize=8;
118       Border emptyb=BorderFactory.createEmptyBorder(emptyBorderVSize,emptyBorderHSize,
119                                                     emptyBorderVSize,emptyBorderHSize);
120       Border inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
121       inb=BorderFactory.createTitledBorder(inb,
122                                            ResourceManager.getLanguageDependentString("SelectProcessKey"));
123       tp.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
124       tp.setLayout(new BoxLayout(tp,BoxLayout.Y_AXIS));
125
126       // creating a tree which do not allow cell editing
127
allItems=new JTree(treeModel) {
128          public boolean isCellEditable(int row, int col) {
129             return false;
130          }
131       };
132
133       // adding mouse listener that willl perform action of arising popup menu
134
// with properties action, when right button is clicked
135
allItems.addMouseListener(new MouseAdapter() {
136                public void mousePressed(MouseEvent e) {
137                   if (e.getButton()==MouseEvent.BUTTON3) {
138                      DefaultMutableTreeNode node = (DefaultMutableTreeNode)
139                         allItems.getLastSelectedPathComponent();
140                      if ((node == null) || (node.getUserObject() instanceof String JavaDoc) ||
141                             (node.getUserObject() instanceof WfProcessMgr)) return;
142
143                      JPopupMenu jpm = new JPopupMenu();
144                      // adding Properties action
145
jpm.add(BarFactory.createMenuItem(
146                                 Utils.getUnqualifiedClassName(WorkflowObjectProperties.class),
147                                 commands));
148                      jpm.show(allItems,e.getX(),e.getY());
149                   }
150                }
151             });
152
153
154
155       // setting some tree properties
156
ToolTipManager.sharedInstance().registerComponent(allItems);
157       allItems.getSelectionModel().setSelectionMode
158          (TreeSelectionModel.SINGLE_TREE_SELECTION);
159       //allItems.setRootVisible(false);
160
allItems.setCellRenderer(new EngineTreeRenderer());
161
162       // creates panel
163
JScrollPane allItemsPane=new JScrollPane();
164       allItemsPane.setViewportView(allItems);
165       allItemsPane.setPreferredSize(tDimension);
166
167       tp.add(allItemsPane);
168       tp.add(Box.createVerticalGlue());
169
170       pimSL=new PIMTreeSelectionListener();
171       allItems.addTreeSelectionListener(pimSL);
172
173       return tp;
174    }
175
176    // setting table
177
private Component createTablePanel() {
178       JPanel tp=new JPanel();
179       int emptyBorderHSize=8;
180       int emptyBorderVSize=8;
181       Border emptyb=BorderFactory.createEmptyBorder(emptyBorderVSize,emptyBorderHSize,
182                                                     emptyBorderVSize,emptyBorderHSize);
183       Border inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
184       inb=BorderFactory.createTitledBorder(inb,
185                                            ResourceManager.getLanguageDependentString("ProcessPropertiesKey"));
186
187       tp.setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
188       tp.setLayout(new BoxLayout(tp,BoxLayout.Y_AXIS));
189       JScrollPane tablePane=new JScrollPane();
190       processDescription=new DescriptionTableModel();
191       JTable t=new JTable(processDescription);
192       // setting some table properties
193
t.setColumnSelectionAllowed(false);
194       t.setRowSelectionAllowed(true);
195       t.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
196       t.getTableHeader().setReorderingAllowed(false);
197       t.setPreferredScrollableViewportSize(tDimension);
198       tablePane.setViewportView(t);
199       tp.add(tablePane);
200       tp.add(Box.createVerticalGlue());
201       return tp;
202    }
203
204
205    public SharkAdmin getWorkflowAdmin () {
206       return workflowAdmin;
207    }
208
209    public TreeSelectionListener getTreeSelectionListener () {
210       return pimSL;
211    }
212
213    public ProcessViewer getProcessViewer () {
214       return processViewer;
215    }
216
217    public Object JavaDoc getSelectedUserObject () {
218       DefaultMutableTreeNode dmtn=(DefaultMutableTreeNode)allItems.getLastSelectedPathComponent();
219       if (dmtn!=null) {
220          return dmtn.getUserObject();
221       } else {
222          return null;
223       }
224    }
225
226    class PIMTreeSelectionListener implements TreeSelectionListener {
227       public void valueChanged(TreeSelectionEvent e) {
228          DefaultMutableTreeNode node = (DefaultMutableTreeNode)
229             allItems.getLastSelectedPathComponent();
230
231          if (node == null) return;
232
233          if (node.getUserObject() instanceof WfProcess) {
234             try {
235                DefaultMutableTreeNode mgrN=(DefaultMutableTreeNode)node.getParent();
236                DefaultMutableTreeNode pkgN=(DefaultMutableTreeNode)mgrN.getParent();
237                processDescription.setData((WfProcess)node.getUserObject());
238                processViewer.displayProcess(
239                                               (org.enhydra.jawe.xml.elements.Package)pkgN.getUserObject(),
240                                               (WfProcessMgr)mgrN.getUserObject(),
241                                               (WfProcess)node.getUserObject());
242             } catch (Exception JavaDoc ex) {
243                System.out.println("WRONG SEL");
244                processDescription.setData(null);
245                processViewer.displayProcess(null,null,null);
246             }
247          } else {
248             processDescription.setData(null);
249             processViewer.displayProcess(null,null,null);
250          }
251       }
252    }
253
254
255    class DescriptionTableModel extends DefaultTableModel {
256       DescriptionTableModel () {
257          super(new String JavaDoc[] {
258                   ResourceManager.getLanguageDependentString("PropertyKey"),
259                      ResourceManager.getLanguageDependentString("ValueKey")
260                },3);
261          setValueAt(ResourceManager.getLanguageDependentString("NameKey"),0,0);
262          setValueAt(ResourceManager.getLanguageDependentString("StateKey"),1,0);
263          setValueAt(ResourceManager.getLanguageDependentString("CreatedKey"),2,0);
264       }
265
266       public boolean isCellEditable(int row, int col) {
267          return false;
268       }
269
270       public void setData (WfProcess proc) {
271          try {
272             setValueAt(proc.name(),0,1);
273             String JavaDoc state=ResourceManager.getLanguageDependentString(proc.state());
274             if (state==null) {
275                state=proc.state();
276             }
277             setValueAt(state,1,1);
278             SimpleDateFormat JavaDoc sdf=new SimpleDateFormat JavaDoc("yyyy-MM-dd HH:mm:ss");
279             long t=SharkClient.getAdminMiscUtilities().getProcessCreatedTime(proc.key());
280             String JavaDoc dte=sdf.format(new Date(t));
281             setValueAt(dte,2,1);
282          } catch (Exception JavaDoc ex) {
283             setValueAt("",0,1);
284             setValueAt("",1,1);
285             setValueAt("",2,1);
286          }
287       }
288
289    }
290
291    //******************** TEST
292
public static void main (String JavaDoc[] args) {
293       ProcessMonitor pm=new ProcessMonitor(null);
294       JFrame f=new JFrame();
295       f.setBackground(Color.lightGray);
296       f.getContentPane().setLayout(new BorderLayout());
297       f.getContentPane().add(pm,BorderLayout.CENTER);
298       f.pack();
299       f.setSize(1000,700);
300       f.setVisible(true);
301    }
302 }
303
Popular Tags