KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ProcessEditor.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 org.enhydra.jawe.graph.*;
14 import org.enhydra.jawe.xml.*;
15 import org.enhydra.jawe.xml.elements.WorkflowProcess;
16 import org.enhydra.jawe.xml.panels.*;
17
18 import org.jgraph.JGraph;
19 import org.jgraph.graph.*;
20 import org.jgraph.event.*;
21
22 import java.awt.*;
23 import java.awt.event.*;
24 import java.beans.*;
25 import java.net.URL JavaDoc;
26 import java.util.*;
27
28 import javax.swing.*;
29 import javax.swing.undo.*;
30 import javax.swing.event.*;
31 import javax.swing.tree.*;
32
33 import java.io.*;
34 import org.enhydra.jawe.actions.*;
35
36 /**
37  * ProcessEditor class is creates toolbars and menubar as given in
38  * property file, and ProcessGraph instance which is used to create
39  * create processes. Implements GraphModel listener to listen to
40  * changes of graph model, GraphSelectionListener to listen to
41  * selection changes in graph, and is Observer to catch the changes
42  * in view model of graph. It also realizes Undo support.
43  */

44
45 public class ProcessEditor extends AbstractEditor {
46
47    protected XMLElementDialog elementEditingDialog=null;
48
49    public XMLElementDialog getElementEditingDialog () {
50       if (elementEditingDialog==null || !elementEditingDialog.isShowing()) {
51          elementEditingDialog=new XMLElementDialog((JDialog)getWindow(),"",false);
52          setALTCursorKeyboardShortcuts(elementEditingDialog.getRootPane());
53       }
54       return elementEditingDialog;
55    }
56
57    /** Creates instance of main application class. */
58    public ProcessEditor(Window dialogOrFrame,
59                         org.enhydra.jawe.xml.elements.WorkflowProcess wp,
60                         AbstractEditor parentEditor) {
61       super(wp);
62
63       this.parentEditor=parentEditor;
64
65       JDialog dialog;
66       if (dialogOrFrame instanceof JDialog) {
67          dialog = new JDialog((JDialog)dialogOrFrame,true);
68       }
69       else {
70          dialog = new JDialog((JFrame)dialogOrFrame,true);
71       }
72       dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
73       dialog.setBackground(Color.lightGray);
74       dialog.getContentPane().setLayout(new BorderLayout());
75       dialog.addWindowListener(createAppCloser());
76       dialog.getContentPane().add("Center",this);
77       dialog.pack();
78       setBounds(dialog,dialogOrFrame);
79    }
80
81    /**
82     * Create an editor to represent the given document.
83     */

84    protected AbstractGraph createGraph() {
85       JaWEGraphModel model = new JaWEGraphModel();
86       graph=new ProcessGraph(model,this);
87       return graph;
88    }
89
90    protected void createActions () {
91       defaultActions = new Action[] {
92          new CheckValidity(this),
93             new ProcessProperties(this),
94             new Participants(this),
95             new Applications(this),
96             new WorkflowRelevantData(this),
97             new FormalParameters(this),
98             new ActivitySetsOverview(this),
99             new ActivitiesOverview(this),
100             new TransitionsOverview(this),
101             new SaveAsJPG(this),
102             new SaveAsSVG(this),
103             undoAction,
104             redoAction,
105             new Cut(this),
106             new Copy(this),
107             new Paste(this),
108             new PasteAt(this),
109             new Delete(this),
110             new EditCell(this),
111             new EditProperties(this),
112             new AddPoint(this),
113             new RemovePoint(this),
114             new SetSelfRouting(this),
115             new SetNoRouting(this),
116             new ActualSize(this),
117             new ZoomIn(this),
118             new ZoomOut(this),
119             new ShowOverview(this),
120             new MoveDownParticipant(this),
121             new MoveUpParticipant(this),
122             new HideWindow(this),
123             new ReferredDocument(this)
124       };
125    }
126
127    //*********************** GRAPH SELECTION LISTENER INTERFACE ******************
128
/** Enables and disables various actions depending of cell selection */
129    public void valueChanged(GraphSelectionEvent e) {
130       // enable/disable actions
131
boolean enabled = !graph.isSelectionEmpty();
132       try {
133          Object JavaDoc cell = graph.getSelectionCell();
134
135          boolean enableEdit=true;
136          if (cell instanceof Subflow) {
137             if (cell instanceof Subflow) {
138                Subflow sbflw=(Subflow)cell;
139                WorkflowProcess wp=sbflw.getReferencedWorkflowProcess(graph.getXMLPackage());
140                if (wp==null) {
141                   enableEdit=false;
142                }
143             }
144          }
145          getAction(Utils.getUnqualifiedClassName(EditCell.class)).setEnabled(enabled &&
146                                                                                 (((cell instanceof Subflow) && enableEdit) ||
147                                                                                     (cell instanceof BlockActivity)));
148          getAction(Utils.getUnqualifiedClassName(EditProperties.class)).setEnabled(enabled);
149          getAction(JaWEConstants.REFERRED_DOCUMENT).setEnabled(enabled &&
150                                                                   cell instanceof Activity &&
151                                                                   !(cell instanceof Start) && !(cell instanceof End));
152
153          if (!(graph.getXMLPackage()!=JaWE.getInstance().getRealXMLPackage() ||
154                   graph.getXMLPackage().isReadOnly())) {
155             getAction(Utils.getUnqualifiedClassName(Cut.class)).setEnabled(enabled);
156             getAction(Utils.getUnqualifiedClassName(Copy.class)).setEnabled(enabled);
157             getAction(Utils.getUnqualifiedClassName(Delete.class)).setEnabled(enabled);
158          }
159          if (enabled && cell!=null && !(cell instanceof Start) &&
160              !(cell instanceof End) &&
161              this.elementEditingDialog!=null &&
162              this.elementEditingDialog.isShowing()) {
163             if (this.elementEditingDialog.getEditingPanel().getOwner()!=
164                    ((WorkflowElement)cell).getPropertyObject()) {
165                getAction(Utils.getUnqualifiedClassName(EditProperties.class)).actionPerformed(null);
166             } else {
167
168             }
169          }
170          if (this.elementEditingDialog!=null && this.elementEditingDialog.isShowing()) {
171             this.elementEditingDialog.requestFocus();
172          }
173
174       } catch (Exception JavaDoc ex) {
175          //
176
}
177
178       update();
179    }
180
181
182    public void setButtonsEnabled (boolean enable) {
183       try {
184          // toolbox
185
Iterator iter = specialButtons.values().iterator();
186          while (iter.hasNext()) {
187             Object JavaDoc item = iter.next();
188             ((Component)item).setEnabled(enable);
189          }
190          // other
191
undoAction.setEnabled(enable);
192          redoAction.setEnabled(enable);
193          getAction(Utils.getUnqualifiedClassName(Cut.class)).setEnabled(enable);
194          getAction(Utils.getUnqualifiedClassName(Copy.class)).setEnabled(enable);
195          getAction(Utils.getUnqualifiedClassName(Paste.class)).setEnabled(enable);
196          getAction(Utils.getUnqualifiedClassName(PasteAt.class)).setEnabled(enable);
197          getAction(Utils.getUnqualifiedClassName(Delete.class)).setEnabled(enable);
198          getAction(Utils.getUnqualifiedClassName(AddPoint.class)).setEnabled(enable);
199          getAction(Utils.getUnqualifiedClassName(RemovePoint.class)).setEnabled(enable);
200          getAction(Utils.getUnqualifiedClassName(SetNoRouting.class)).setEnabled(enable);
201          getAction(Utils.getUnqualifiedClassName(SetSelfRouting.class)).setEnabled(enable);
202          // when opening file
203
} catch (Exception JavaDoc ex) {
204          //
205
}
206    }
207
208
209    /**
210     * Creates AppCloser object.
211     */

212    protected WindowAdapter createAppCloser() {
213       return new ProcessEditor.AppCloser();
214    }
215
216    /**
217     * To shutdown when run as an application.
218     */

219    protected final class AppCloser extends WindowAdapter {
220       public void windowClosing(WindowEvent e) {
221          getAction(Utils.getUnqualifiedClassName(HideWindow.class)).actionPerformed(null);
222       }
223    }
224
225    /**
226     * Gets a title.
227     */

228    public String JavaDoc getTitle () {
229       String JavaDoc title;
230       title=ResourceManager.getLanguageDependentString("ProcessKey")+" - '"+
231          graph.getPropertyObject().toString()+"'";
232
233       return title;
234    }
235
236    /**
237     * Returns string of toolbars for load.
238     */

239    public String JavaDoc toolbarToLoad () {
240       return "processToolbars";
241    }
242
243    /**
244     * Returns string of menubar for load.
245     */

246    public String JavaDoc menubarToLoad () {
247       return "processMenubar";
248    }
249
250 }
251
Popular Tags