KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark.swingclient.workflowadmin;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.net.*;
6 import javax.swing.*;
7
8
9 import org.enhydra.shark.utilities.DeadlineChecker;
10 import org.enhydra.shark.utilities.LimitChecker;
11 import org.enhydra.shark.swingclient.*;
12 import org.enhydra.shark.swingclient.workflowadmin.actions.*;
13 import org.enhydra.shark.swingclient.workflowadmin.definition.*;
14 import org.enhydra.shark.swingclient.workflowadmin.instantiation.*;
15 import org.enhydra.shark.swingclient.workflowadmin.monitoring.*;
16 import org.enhydra.shark.swingclient.workflowadmin.application.*;
17 import org.enhydra.shark.swingclient.workflowadmin.report.*;
18 import org.enhydra.shark.swingclient.workflowadmin.repository.*;
19 import org.enhydra.shark.swingclient.workflowadmin.user.*;
20 import org.enhydra.shark.swingclient.workflowadmin.worklist.*;
21 import org.enhydra.shark.swingclient.workflowadmin.cache.*;
22
23 /**
24  * An implementation of client application that realizes
25  * worklist administrator.
26  * <p> The administrator is consisted of process definition management,
27  * the process instantiation management, process monitoring and user
28  * management.
29  *
30  * @author Sasa Bojanic
31  * @version 1.0
32  */

33 public class SharkAdmin extends SharkClient {
34
35    private JTabbedPane tabbedPane;
36
37    private EngineTreeModel engineTreeModel;
38    private RepositoryManagement repositoryManagement;
39    private PackageManagement packageManagement;
40    private ProcessInstantiationManagement processInstantiationManagement;
41    private ProcessMonitor processMonitor;
42    private UserManagement userManagement;
43    private ApplicationMappingManagement applicationMapping;
44    private CacheManagement cacheManagement;
45    private WorklistManagement worklistManagement;
46    private ReportManagement reportManagement;
47
48    private DeadlineChecker deadlineChecker;
49    private LimitChecker limitChecker;
50
51    private long deadlineCheckingTime=30000;
52    private long limitCheckingTime=30000;
53
54    //************************** CONSTRUCTOR ***************************
55
/** Creates instance of main application class. */
56    public SharkAdmin (JFrame frame) {
57       super(frame);
58    }
59    //************************* END OF WORKFLOWADMIN CONSTRUCTOR ********
60

61    protected void createActions () {
62       super.createActions();
63       Action[] newActions=new Action[defaultActions.length+3];
64       System.arraycopy(defaultActions,0,newActions,0,defaultActions.length);
65       newActions[defaultActions.length]=new AutomaticallyCheckDeadlines(this);
66       newActions[defaultActions.length+1]=new AutomaticallyCheckLimits(this);
67       newActions[defaultActions.length+2]=new ShowHideFinishedProcesses(this);
68       defaultActions=newActions;
69    }
70
71    protected Component createCenterComponent () {
72       engineTreeModel=new EngineTreeModel(this);
73       repositoryManagement=new RepositoryManagement(this);
74       packageManagement=new PackageManagement(this);
75       processInstantiationManagement=new ProcessInstantiationManagement(this);
76       processMonitor=new ProcessMonitor(this);
77       userManagement=new UserManagement(this);
78       applicationMapping=new ApplicationMappingManagement(this);
79       cacheManagement=new CacheManagement(this);
80       worklistManagement=new WorklistManagement(this);
81       reportManagement=new ReportManagement(this);
82
83       // creating tabbed panel
84
tabbedPane=new JTabbedPane();
85       tabbedPane.addTab(
86                         ResourceManager.getLanguageDependentString("RepositoryManagementKey"),
87                         repositoryManagement);
88       tabbedPane.addTab(
89                         ResourceManager.getLanguageDependentString("PackageManagementKey"),
90                         packageManagement);
91       tabbedPane.addTab(
92                         ResourceManager.getLanguageDependentString("ProcessInstantiationManagementKey"),
93                         processInstantiationManagement);
94       tabbedPane.addTab(ResourceManager.getLanguageDependentString("ProcessMonitorKey"),processMonitor);
95       tabbedPane.addTab(ResourceManager.getLanguageDependentString("UserManagementKey"),userManagement);
96       tabbedPane.addTab(ResourceManager.getLanguageDependentString("ApplicationMappingKey"),applicationMapping);
97       tabbedPane.addTab(ResourceManager.getLanguageDependentString("CacheManagementKey"),cacheManagement);
98       tabbedPane.addTab(ResourceManager.getLanguageDependentString("WorklistManagementKey"),worklistManagement);
99       //tabbedPane.addTab(ResourceManager.getLanguageDependentString("ReportManagementKey"),reportManagement);
100
tabbedPane.setVisible(false);
101
102       return tabbedPane;
103    }
104
105    /** The order of refreshment is important, first the
106     * engine tree model has to be refreshed. Also, the
107     * method must be synchronized because other instances
108     * uses EngineTreeModel.getRemovedAfterRefresh() and
109     * EngineTreeModel.getAddedAfterRefresh() methods
110     */

111    public synchronized void refresh (boolean mandatoryRefreshing) {
112       tabbedPane.setVisible(true);
113       engineTreeModel.refresh(mandatoryRefreshing);
114       packageManagement.refresh(mandatoryRefreshing);
115       processInstantiationManagement.refresh(mandatoryRefreshing);
116       processMonitor.refresh(mandatoryRefreshing);
117       repositoryManagement.refresh(mandatoryRefreshing);
118       userManagement.refresh(mandatoryRefreshing);
119       applicationMapping.refresh(mandatoryRefreshing);
120       cacheManagement.refresh(mandatoryRefreshing);
121       worklistManagement.refresh(mandatoryRefreshing);
122       reportManagement.refresh(mandatoryRefreshing);
123    }
124
125    public void refreshAfterUpdate () {
126       stopRefresher();
127       // THIS IS PRECAUTION - the thread that refreshes admin can be
128
// running, so we wait until the refresher thread finishs its
129
// work, and then we clear the components
130
while (isRefresherActive());
131       engineTreeModel.clear();
132       repositoryManagement.refresh(false);
133       packageManagement.refresh(true);
134       processInstantiationManagement.clear();
135       processInstantiationManagement.refresh(true);
136       processMonitor.clear();
137       userManagement.clear();
138       applicationMapping.clear();
139       cacheManagement.clear();
140       worklistManagement.clear();
141       reportManagement.clear();
142       startRefresher();
143       refresh(true);
144    }
145
146    /** The order of clearing is important, first the
147     * engine tree model has to be cleared.
148     */

149    public void clearComponents() {
150       try {
151          setTitle();
152          tabbedPane.setVisible(false);
153          tabbedPane.setSelectedIndex(0);
154          stopRefresher();
155          // THIS IS PRECAUTION - the thread that refreshes admin can be
156
// running, so we wait until the refresher thread finishs its
157
// work, and then we clear the components
158
while (isRefresherActive());
159          engineTreeModel.clear();
160          repositoryManagement.clear();
161          packageManagement.refresh(true);
162          processInstantiationManagement.clear();
163          processInstantiationManagement.refresh(true);
164          processMonitor.clear();
165          userManagement.clear();
166          applicationMapping.clear();
167          cacheManagement.clear();
168          worklistManagement.clear();
169          reportManagement.clear();
170       } catch (Exception JavaDoc ex) {ex.printStackTrace();}
171    }
172
173    protected String JavaDoc getAppTitleResourceString() {
174       return "WorkflowAdminTitle";
175    }
176
177    protected String JavaDoc getLogoResourceString() {
178       return "workflowadminLogo";
179    }
180
181    protected String JavaDoc getIconResourceString() {
182       return "workflowadminIcon";
183    }
184    protected String JavaDoc getMenubarResourceString() {
185       return "adminmainmenubar";
186    }
187
188    protected String JavaDoc getRefreshingRateString () {
189       return "RefreshingRateInSecondsForWorkflowAdmin";
190    }
191
192    public EngineTreeModel getEngineTreeModel() {
193       return engineTreeModel;
194    }
195
196    public RepositoryManagement getRepositoryManagement () {
197       return repositoryManagement;
198    }
199
200    public PackageManagement getPackageManagement () {
201       return packageManagement;
202    }
203
204    public ProcessInstantiationManagement getProcessInstantiationManagement () {
205       return processInstantiationManagement;
206    }
207
208    public ProcessMonitor getProcessMonitor () {
209       return processMonitor;
210    }
211
212    public UserManagement getUserManagement () {
213       return userManagement;
214    }
215
216    public ApplicationMappingManagement getApplicationMapping () {
217       return applicationMapping;
218    }
219
220    public CacheManagement getCacheManagement () {
221       return cacheManagement;
222    }
223
224    public WorklistManagement getWorklistManagement () {
225       return worklistManagement;
226    }
227
228    public ReportManagement getReportManagement () {
229       return reportManagement;
230    }
231
232    public void enableControls (boolean enable) {
233       super.enableControls(enable);
234       tabbedPane.setEnabled(enable);
235    }
236
237    public void showXPDLErrorsReport (String JavaDoc xpdlErrors) {
238       try {
239          String JavaDoc title=ResourceManager.getLanguageDependentString("XPDLErrorReportKey");
240          final JDialog report=new JDialog(myFrame,title,true);
241          JEditorPane text = new JEditorPane("text/html",xpdlErrors);
242          text.setEditable(false);
243          text.getCaret().setDot(0);
244          JScrollPane sp = new JScrollPane(text);
245          sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
246          sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
247          report.getContentPane().setLayout(new BorderLayout());
248          report.getContentPane().add(sp);
249
250          JPanel buttonPanel=new JPanel();
251          buttonPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
252          buttonPanel.setAlignmentY(Component.TOP_ALIGNMENT);
253
254          JButton buttonOK=new JButton(ResourceManager.getLanguageDependentString("OKKey"));
255          java.net.URL JavaDoc u = ResourceManager.getResource("OKImage");
256          if (u!=null) {
257             buttonOK.setIcon(new ImageIcon(u));
258          }
259          buttonPanel.add(buttonOK);
260
261          Container cp=report.getContentPane();
262          cp.setLayout(new BorderLayout());
263          cp.add(sp,BorderLayout.CENTER);
264          cp.add(buttonPanel,BorderLayout.SOUTH);
265
266          // action listener for confirming
267
buttonOK.addActionListener(new ActionListener(){
268                   public void actionPerformed( ActionEvent ae ){
269                      report.dispose();
270                   }
271                });
272
273          buttonOK.setDefaultCapable(true);
274          report.getRootPane().setDefaultButton(buttonOK);
275
276
277          report.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
278          .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0,false),"Cancel");
279          report.getRootPane().getActionMap().put("Cancel", new AbstractAction() {
280                   public void actionPerformed(ActionEvent e) {
281                      report.dispose();
282                   }
283                });
284
285          org.enhydra.jawe.Utils.center(report,100,150);
286
287          report.show();
288       } catch (Exception JavaDoc ex) {ex.printStackTrace();}
289    }
290
291    public void showOrHideFinishedProcesses () {
292       engineTreeModel.setShowFinishedProcesses(
293                                                !engineTreeModel.getShowFinishedProcesses());
294    }
295
296    public void setAutomaticDeadlineCheck (boolean checkAutomatically) {
297       if (deadlineChecker==null) {
298          deadlineChecker=new DeadlineChecker(getDeadlineAdmin(),deadlineCheckingTime);
299       }
300       if (checkAutomatically) {
301          deadlineChecker.startChecker();
302       } else {
303          deadlineChecker.stopChecker();
304       }
305    }
306
307    public void setAutomaticLimitCheck (boolean checkAutomatically) {
308       if (limitChecker==null) {
309          limitChecker=new LimitChecker(getLimitAdmin(),limitCheckingTime);
310       }
311       if (checkAutomatically) {
312          limitChecker.startChecker();
313       } else {
314          limitChecker.stopChecker();
315       }
316    }
317
318
319    /** Main method. */
320    public static void main(String JavaDoc[] args) throws Exception JavaDoc {
321       // Checks if java version is >= 1.4.1
322
String JavaDoc vers = System.getProperty("java.version");
323       if (vers.compareTo("1.4") < 0) {
324          System.out.println("!!!WARNING: Shark Workflow Administrator must be run with a " +
325                             "1.4 or higher version VM!!!");
326          System.exit(1);
327       }
328       if (args!=null && args.length>0) {
329          configFileName=args[0];
330       }
331       SharkAdmin sa=new SharkAdmin(new JFrame());
332
333       // initialize deadline timer
334
if (args!=null && args.length>1) {
335          sa.deadlineCheckingTime=Long.parseLong(args[1]);
336       }
337
338       // initialize limit timer
339
String JavaDoc ldelay=null;
340       if (args!=null && args.length>2) {
341          sa.limitCheckingTime=Long.parseLong(args[2]);
342       }
343    }
344
345
346 }
347
348
Popular Tags