KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > PackageEditor


1 /* PackageEditor.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11 package org.enhydra.jawe;
12
13 import java.awt.*;
14 import java.io.*;
15 import java.util.*;
16
17 import javax.swing.*;
18
19 import org.jgraph.event.*;
20 import org.enhydra.jawe.actions.*;
21 import org.enhydra.jawe.actions.Applications;
22 import org.enhydra.jawe.actions.ExternalPackages;
23 import org.enhydra.jawe.actions.Participants;
24 import org.enhydra.jawe.actions.TypeDeclarations;
25 import org.enhydra.jawe.ldap.*;
26 import org.enhydra.jawe.misc.*;
27 import org.enhydra.jawe.xml.*;
28 import org.enhydra.jawe.xml.elements.*;
29 import org.enhydra.jawe.xml.panels.*;
30
31 /**
32  * PackageEditor class is the main class of application. It creates
33  * toolbars and menubar as given in property file. It Implements
34  * GraphModel listener to listen to changes of workflow model,
35  * GraphSelectionListener to listen to selection changes in workflow,
36  * and is Observer to catch the changes in view model of workflow.
37  * It also realizes Undo support.
38  * <p> All
39  */

40
41 public class PackageEditor extends AbstractEditor {
42
43    private Map pkgIdToGraph;
44    private Map processToProcessObject;
45
46    private org.enhydra.jawe.xml.elements.Package realXMLPackage;
47    private PackageGraph realGraph;
48
49    // indicates if an XML package doesn't have ID
50
private boolean isInitialized=false;
51
52    private JSplitPane splitPane;
53    private PackageTreePanel packageTreePanel;
54    private TextTreePanel packagePrintTreePanel;
55
56    public PackageEditor(XMLComplexElement pkgOrProcess) {
57       super(pkgOrProcess);
58    }
59
60    public PackageTreePanel getPackageTreePanel () {
61       return packageTreePanel;
62    }
63
64    public TextTreePanel getPackagePrintTreePanel () {
65       return packagePrintTreePanel;
66    }
67
68    public boolean isInitialized () {
69       return isInitialized;
70    }
71
72    public boolean isPackageGraphCreated (String JavaDoc pkgId) {
73       if (pkgIdToGraph==null) {
74          pkgIdToGraph=new Hashtable();
75       }
76       return pkgIdToGraph.containsKey(pkgId);
77    }
78
79    public boolean isProcessObjectCreated (WorkflowProcess wp) {
80       if (processToProcessObject==null) {
81          processToProcessObject=new Hashtable();
82       }
83       return processToProcessObject.containsKey(wp);
84    }
85
86    public PackageGraph getPackageGraph (String JavaDoc pkgId) {
87       if (pkgIdToGraph==null) {
88          pkgIdToGraph=new Hashtable();
89       }
90       return (PackageGraph)pkgIdToGraph.get(pkgId);
91    }
92
93    public void putPackageGraphMapping (String JavaDoc pkgId,PackageGraph peg) {
94       if (pkgIdToGraph==null) {
95          pkgIdToGraph=new Hashtable();
96       }
97       pkgIdToGraph.put(pkgId,peg);
98    }
99
100    public Map getPkgIdToGraphMap () {
101       if (pkgIdToGraph==null) {
102          pkgIdToGraph=new Hashtable();
103       }
104       return Collections.unmodifiableMap(pkgIdToGraph);
105    }
106
107    public void removePackageGraphMapping (String JavaDoc pkgId) {
108       if (pkgIdToGraph==null) {
109          pkgIdToGraph=new Hashtable();
110       }
111       pkgIdToGraph.remove(pkgId);
112    }
113
114    public void clearPackageGraphMap() {
115       if (pkgIdToGraph==null) {
116          pkgIdToGraph=new Hashtable();
117       }
118       pkgIdToGraph.clear();
119    }
120
121    public org.enhydra.jawe.graph.Process getProcessObject (WorkflowProcess wp) {
122       if (processToProcessObject==null) {
123          processToProcessObject=new Hashtable();
124       }
125       return (org.enhydra.jawe.graph.Process)processToProcessObject.get(wp);
126    }
127
128    public void putProcessObjectMapping (WorkflowProcess wp,org.enhydra.jawe.graph.Process pr) {
129       if (processToProcessObject==null) {
130          processToProcessObject=new Hashtable();
131       }
132       processToProcessObject.put(wp,pr);
133    }
134
135    public void removeProcessObjectMapping (WorkflowProcess wp) {
136       if (processToProcessObject==null) {
137          processToProcessObject=new Hashtable();
138       }
139       processToProcessObject.remove(wp);
140    }
141
142    public void clearProcessObjectMap() {
143       if (processToProcessObject==null) {
144          processToProcessObject=new Hashtable();
145       }
146       processToProcessObject.clear();
147    }
148
149    /**
150     * Create the center component of this panel. This creates a scroll-
151     * pane for the current graph variable and stores the scrollpane
152     * in the scrollPane variable.
153     */

154    protected Component createCenterComponent() {
155       packageTreePanel=new PackageTreePanel(getXMLPackage(),this,
156                                             ResourceManager.getLanguageDependentString("PackageAndExternalPackagesKey"),false);
157
158       splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
159                                packageTreePanel,super.createCenterComponent());
160
161       return splitPane;
162    }
163
164    /**
165     * Create an editor to represent the given document.
166     */

167    protected AbstractGraph createGraph() {
168       realGraph=new PackageGraph(new JaWEGraphModel(),this);
169       return realGraph;
170    }
171
172    protected void createActions () {
173       defaultActions=new Action[] {
174          new New(this),
175             new Open(this),
176             new Reopen(this),
177             new Save(this),
178             new SaveAs(this),
179             new ChangeLanguage(this),
180             new WfXML(this),
181             new Exit(this),
182             new org.enhydra.jawe.actions.Namespaces(this),
183             new PackageProperties(this),
184             new Processes(this),
185             new ExternalPackages(this),
186             new ImportExternalProcess(this),
187             new ImportExternalParticipants(this),
188             new TypeDeclarations(this),
189             new Participants(this),
190             new Applications(this),
191             new WorkflowRelevantData(this),
192             new ReferredDocument(this),
193             new CheckValidity(this),
194             undoAction,
195             redoAction,
196             new Delete(this),
197             new EditCell(this),
198             new EditProperties(this),
199             new MakeCopyOfProcess(this),
200             new HelpTutorial(this),
201             new HelpManual(this),
202             new HelpAbout(this),
203             new Config(this)
204       };
205    }
206
207    //*********************** GRAPH SELECTION LISTENER INTERFACE ******************
208
/** Enables and disables various actions depending of cell selection */
209    public void valueChanged(GraphSelectionEvent e) {
210       // enable/disable actions
211
boolean enabled = !graph.isSelectionEmpty();
212       if (realGraph!=graph) {
213          getToolbarComponent(JaWEConstants.PROCESS_ACTIVITY_TOOL).setEnabled(false);
214          getToolbarComponent(JaWEConstants.AUTOMATIC_START_END_TOOL).setEnabled(false);
215          getAction(Utils.getUnqualifiedClassName(Delete.class)).setEnabled(false);
216          undoAction.setEnabled(false);
217          redoAction.setEnabled(false);
218          getAction(Utils.getUnqualifiedClassName(EditCell.class)).setEnabled(enabled);
219          getAction(Utils.getUnqualifiedClassName(EditProperties.class)).setEnabled(enabled);
220          getAction(Utils.getUnqualifiedClassName(MakeCopyOfProcess.class)).setEnabled(false);
221          return;
222       } else {
223          getToolbarComponent(JaWEConstants.PROCESS_ACTIVITY_TOOL).setEnabled(true);
224          if (JaWEConfig.getInstance().getUseBubblesStatus()) {
225             getToolbarComponent(JaWEConstants.AUTOMATIC_START_END_TOOL).setEnabled(true);
226          }
227       }
228
229       try {
230          getAction(Utils.getUnqualifiedClassName(Delete.class)).setEnabled(enabled);
231          getAction(Utils.getUnqualifiedClassName(EditCell.class)).setEnabled(enabled);
232          getAction(Utils.getUnqualifiedClassName(EditProperties.class)).setEnabled(enabled);
233          getAction(Utils.getUnqualifiedClassName(MakeCopyOfProcess.class)).setEnabled(enabled);
234       } catch (Exception JavaDoc ex) {}
235
236       try {
237          update();
238       } catch (Exception JavaDoc ex) {}
239    }
240    //******************* END OF GRAPH SELECTION LISTENER INTERFACE ***************
241

242
243    /**
244     * Gets a XML package object currently viewed within editor's graph.
245     */

246    public org.enhydra.jawe.xml.elements.Package getXMLPackage () {
247       return graph.getXMLPackage();
248    }
249
250    /**
251     * Gets a real XML package object (the one of the main XML file).
252     */

253    public org.enhydra.jawe.xml.elements.Package getRealXMLPackage () {
254       return realXMLPackage;
255    }
256
257    public void enterPackageID () {
258       String JavaDoc msg=ResourceManager.getLanguageDependentString(
259          "InformationNotAllowedToDoEnythingBeforeEnteringPackageID");
260       JaWE.getInstance().message(msg,JOptionPane.INFORMATION_MESSAGE);
261
262       XMLElement ID=realXMLPackage.get("Id");
263       ID.setReadOnly(false);
264
265       // setting mandatory conformance class if it is specified and it exists
266
String JavaDoc mcl=JaWE.getInstance().getMandatoryConformanceClass();
267       int mct=XMLUtil.getConformanceClassNo(mcl);
268       if (mct>0) {
269          ConformanceClass cc=(ConformanceClass)getXMLPackage().get("ConformanceClass");
270          cc.set("GraphConformance",ResourceManager.getLanguageDependentString(mcl+"Key"));
271          cc.setReadOnly(true);
272       }
273
274       XMLPanel p=getXMLPackage().getPanel(1);
275       String JavaDoc message;
276
277       XMLElementDialog d=new XMLElementDialog((JFrame)getWindow(),
278                                               ResourceManager.getLanguageDependentString("PackageKey")+" '"+
279                                                  getXMLPackage().get("Id").toString()+"' - "+
280                                                  ResourceManager.getLanguageDependentString("PropertiesKey"));
281
282       d.editXMLElement(p,false,true);
283       getXMLPackage().setIDPrefixForCollections ();
284
285       ID.setReadOnly(true);
286
287       isInitialized=true;
288
289       JaWE.getInstance().getXMLInterface().register(realXMLPackage);
290
291       // now, put an instance of PE to hashtable
292
putPackageGraphMapping(ID.toString(),(PackageGraph)graph);
293
294       getToolbarComponent(JaWEConstants.PROCESS_ACTIVITY_TOOL).setEnabled(true);
295       getToolbarComponent(JaWEConstants.AUTOMATIC_START_END_TOOL).setEnabled(true);
296
297       splitPane.remove(packageTreePanel);
298       packageTreePanel=new PackageTreePanel(getXMLPackage(),this,
299                                             ResourceManager.getLanguageDependentString("PackageAndExternalPackagesKey"),false);
300       splitPane.setLeftComponent(packageTreePanel);
301
302       displayPackage(realXMLPackage);
303       update();
304    }
305
306    public void displayPackage (org.enhydra.jawe.xml.elements.Package pkg) {
307       graph.getSelectionModel().removeGraphSelectionListener(this);
308       graph=getPackageGraph(pkg.get("Id").toString());
309
310       if (graph==null || getXMLPackage()!=pkg) {
311          graph=realGraph;
312       }
313       graph.refreshGraphConfiguration();
314       graph.getSelectionModel().addGraphSelectionListener(this);
315
316       getAction(Utils.getUnqualifiedClassName(ImportExternalProcess.class)).setEnabled(graph==realGraph);
317       getAction(Utils.getUnqualifiedClassName(ImportExternalParticipants.class)).setEnabled(graph==realGraph);
318
319       graphScrollPane.setViewportView(graph);
320       valueChanged(null);
321       statusBar.updateMessage();
322    }
323
324    /**
325     * Indicates whether invalid package can be saved or not.
326     *
327     * @return <tt>true</tt> if package can be saved even if it is invalid, <tt>false</tt> otherwise.
328     */

329    public boolean allowInvalidPackageSaving () {
330       boolean allow=false;
331       RedefinableHeader rh=(RedefinableHeader)getXMLPackage().get("RedefinableHeader");
332       String JavaDoc pStatus=rh.get("PublicationStatus").toValue().toString();
333       if (pStatus.equals("UNDER_TEST") || pStatus.equals("UNDER_REVISION")) {
334          allow=true;
335       }
336       return allow;
337    }
338
339    /**
340     * Shows the specified process. If nothing is specified, creates
341     * the new process.
342     */

343    public WorkflowProcess showProcess (Window parentWindow,
344                                        WorkflowProcess wp,String JavaDoc processID) {
345
346       org.enhydra.jawe.graph.Process pr;
347       if (wp==null) {
348          pr=realGraph.getWorkflowManager().
349             insertProcess(realGraph.getNextInsertionPoint(),true);
350          wp=(WorkflowProcess)pr.getUserObject();
351          wp.set("Id",processID);
352          putProcessObjectMapping(wp,pr);
353          pr.showProcess(parentWindow);
354       } else {
355          pr=getProcessObject(wp);
356          ProcessEditor pe=pr.getImplementationEditor();
357          pe.refreshEditorConfiguration();
358          if (wp.getPackage()!=realXMLPackage || wp.getPackage().isReadOnly()) {
359             pe.setButtonsEnabled(false);
360          }
361          pr.showProcess(parentWindow);
362       }
363       return wp;
364    }
365
366    /**
367     * Gets a title.
368     */

369    public String JavaDoc getTitle () {
370       String JavaDoc title="";
371
372       /*if (JaWE.getInstance().getFilename()!=null) {
373        title+=JaWE.getInstance().getFilename();
374        }*/

375       if (realXMLPackage!=null && realXMLPackage.get("Id").toString().trim().length()>0) {
376          title+=realXMLPackage.get("Id").toString().trim();
377       }
378       else {
379          title+=ResourceManager.getLanguageDependentString("UnnamedKey");
380       }
381       title+=" - JaWE";
382
383       if (JaWE.getInstance().isModified()) {
384          title+="*";
385       }
386       return title;
387    }
388
389    /**
390     * Returns string of toolbars for load.
391     */

392    public String JavaDoc toolbarToLoad () {
393       return "packageToolbars";
394    }
395
396    /**
397     * Returns string of menubar for load.
398     */

399    public String JavaDoc menubarToLoad () {
400       return "packageMenubar";
401    }
402
403    /**
404     * Used to open new document when some other document is beeing edited (called
405     * from New and Open actions).
406     */

407    public void setNewPackage (
408       org.enhydra.jawe.xml.elements.Package pkg,
409       boolean clearOtherPackages) {
410       if (clearOtherPackages) {
411          clearPackageGraphMap();
412          clearProcessObjectMap();
413       }
414       if (pkg!=null) {
415          putPackageGraphMapping(pkg.get("Id").toString(),(PackageGraph)graph);
416       }
417
418       //HM, 3.8.04: do this to create a new JaWEGraphUI, else we run into NullP-Exceptions in JGraph 3.4.1
419
// after creating new document and trying to add a process at package level
420
graph.updateUI();
421
422       realXMLPackage=pkg;
423       graph.setPropertyObject(pkg);
424
425       // set graph
426
graph.clearSelection();
427       graph.paintImmediately(graph.getBounds());
428
429       graph.getModel().removeGraphModelListener(this);
430       graph.getModel().removeUndoableEditListener(undoHandler);
431       graph.setModel(new JaWEGraphModel());
432
433       // disable ccp,..
434
valueChanged(null);
435       // The !clearOtherPackages is checked, and if it is false, we consider
436
// that the package was opened through the network, so we allow
437
// creation of graphs (this is the case of using JaWE within our
438
// workflow admin. application)
439
if (JaWE.getInstance().getFilename()!=null &&
440              (new File(JaWE.getInstance().getFilename()).exists() || !clearOtherPackages)) {
441          isInitialized=true;
442          Window w=getWindow();
443          graph.createWorkflowGraph(w);
444          // Create graphs for all external packages
445
createGraphsForExternalPackages(realXMLPackage);
446       } else {
447          isInitialized=false;
448       }
449
450       if (splitPane!=null) {
451
452          splitPane.remove(packageTreePanel);
453          packageTreePanel=new PackageTreePanel(getXMLPackage(),this,
454                                                ResourceManager.getLanguageDependentString("PackageAndExternalPackagesKey"),false);
455          splitPane.setLeftComponent(packageTreePanel);
456       }
457
458       try {
459          displayPackage(realXMLPackage);
460       } catch(Exception JavaDoc ex) {}
461       JaWE.getInstance().setModified(false);
462       graph.getModel().addGraphModelListener(this);
463       graph.getModel().addUndoableEditListener(undoHandler);
464       resetUndoManager();
465
466
467       try {
468          getWindow().requestFocus();
469       } catch (Exception JavaDoc ex) {}
470
471       if (!isInitialized) {
472          getToolbarComponent(JaWEConstants.PROCESS_ACTIVITY_TOOL).setEnabled(false);
473          getToolbarComponent(JaWEConstants.AUTOMATIC_START_END_TOOL).setEnabled(false);
474       }
475
476    }
477
478    /**
479     * Creates the graph for all external packages of given package. This
480     * also creates the graphs for all processes contained in these
481     * external packages.
482     */

483    public void createGraphsForExternalPackages(
484       org.enhydra.jawe.xml.elements.Package pkg) {
485       Set ems=pkg.getAllExternalPackages();
486       org.enhydra.jawe.xml.elements.Package ep;
487       Iterator it=ems.iterator();
488       while (it.hasNext()) {
489          ep=(org.enhydra.jawe.xml.elements.Package)it.next();
490          createGraphForPackage(ep,true);
491       }
492    }
493
494    /**
495     * Creates the graph for the model and all of it's processes.
496     */

497    public void createGraphForPackage (
498       org.enhydra.jawe.xml.elements.Package pkg,
499       boolean isReadOnly) {
500       Window w=getWindow();
501       if (!isPackageGraphCreated(pkg.get("Id").toString())) {
502          // THE POSTION OF THE NEXT LINE CHANGED 19.02.03 - IMPORTANT
503
// FOR EXTERNAL PACKAGES - WORKFLOW MANAGER DOESN'T ADD THE
504
// GRAPH REFERENCES TO THE PARTICIPANTS THAT ARE DISPLAYED
505
// WITHIN READ-ONLY PACKAGE, SO THIS LINE MUST COME FIRST
506
pkg.setReadOnly(isReadOnly);
507          PackageGraph peg=new PackageGraph(new JaWEGraphModel(),this);
508          // registers graph's tooltip listener
509
ToolTipManager.sharedInstance().registerComponent(peg);
510          peg.setPropertyObject(pkg);
511          peg.setAdditionalKeyboardShortcuts();
512          peg.createWorkflowGraph(w);
513          putPackageGraphMapping(pkg.get("Id").toString(),peg);
514       }
515    }
516
517 }
518
519
Popular Tags