KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* AbstractGraph.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.actions.*;
14 import org.enhydra.jawe.graph.*;
15 import org.enhydra.jawe.xml.*;
16
17 import org.jgraph.*;
18 import org.jgraph.graph.*;
19 import org.jgraph.plaf.basic.*;
20 import java.awt.*;
21 import java.awt.print.*;
22 import java.awt.event.*;
23 import java.util.*;
24 import java.io.*;
25 import javax.swing.*;
26 import javax.swing.border.*;
27 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
28 import org.enhydra.jawe.PackageEditor;
29
30 /**
31  * Abstract implementation of JGraph.
32  */

33 public abstract class AbstractGraph extends JGraph implements WorkflowElement {
34
35    protected XMLComplexElement xmlObject=null;
36
37    /** WorkflowManager that controls various things */
38    protected transient WorkflowManager workflowManager;
39    /** Reference to editor */
40    protected transient AbstractEditor editor;
41
42    /**
43     */

44    protected Map xpdlSchemaValidationErrors=null;
45
46    /**
47     * The basic xpdl schema validation error.
48     */

49    protected String JavaDoc basicXpdlSchemaValidationError=null;
50
51    /**
52     * Map of activities as a keys and error messages as a values that
53     * represent wrong connected activities.
54     */

55    protected Map graphConnectionErrors=null;
56
57    /**
58     * The basic connection error that is written at the status bar.
59     */

60    protected String JavaDoc basicGraphConnectionError=null;
61
62    /**
63     * Map of activities as a keys and error messages as a values that
64     * represent activities that don't satisfy graph conformance.
65     */

66    protected Map graphConformanceErrors=null;
67
68    /**
69     * The list of basic graph conformance errors. First of them will
70     * be written in the status bar.
71     */

72    protected java.util.List JavaDoc basicGraphConformanceErrors=null;
73
74    /**
75     * Map of xml objects as keys and error messages as a values that
76     * represent some logic error.
77     */

78    protected Map logicErrors=null;
79
80    /**
81     * The basic logic error that is written at the status bar.
82     */

83    protected String JavaDoc basicLogicError=null;
84
85    /**
86     * Constructs workflow graph based on a given model.
87     */

88    public AbstractGraph(GraphModel model,AbstractEditor editor) {
89       selectionModel = new JaWEGraphSelectionModel(this);
90       setLayout(null);
91       // setting marquee handler
92
//marquee=new BasicMarqueeHandler();
93
GraphLayoutCache view = new GraphLayoutCache(this);//HM, JGraph3.4.1
94
setGraphLayoutCache(view);
95       updateUI();
96       if (model == null) {
97          model = new JaWEGraphModel();
98       }
99       setModel(model);
100
101       this.editor=editor;
102       // creating participant manager
103
workflowManager=new WorkflowManager(this);
104       // setting new marquee handler (couldn't be set before
105
// creation of WorkflowManager
106
setMarqueeHandler(new JaWEMarqueeHandler(this));
107
108       // initialization of main graph behaviour
109
initGraphBehavior();
110
111    }
112
113    public AbstractGraph(GraphModel model,GraphLayoutCache view) {
114       super(model,view);
115    }
116
117    public abstract org.enhydra.jawe.xml.elements.Package getXMLPackage ();
118
119    public abstract void setPropertyObject (XMLComplexElement ce);
120
121    public abstract void createWorkflowGraph (Window pFrame);
122
123    /**
124     * Overrides <code>JComponent</code>'s <code>getToolTipText</code>
125     * method in order to allow the graph controller to create a tooltip
126     * for the topmost cell under the mousepointer. This differs from JTree
127     * where the renderers tooltip is used.
128     * <p>
129     * NOTE: For <code>JGraph</code> to properly display tooltips of its
130     * renderers, <code>JGraph</code> must be a registered component with the
131     * <code>ToolTipManager</code>. This can be done by invoking
132     * <code>ToolTipManager.sharedInstance().registerComponent(graph)</code>.
133     * This is not done automatically!
134     * @param event the <code>MouseEvent</code> that initiated the
135     * <code>ToolTip</code> display
136     * @return a string containing the tooltip or <code>null</code>
137     * if <code>event</code> is null
138     */

139    public abstract String JavaDoc getToolTipText(MouseEvent event);
140
141    protected void initGraphBehavior() {
142       setHandleSize(4);
143       setTolerance(4);
144       setSelectNewCells(true);
145       setSizeable(false);
146       setMoveable(false);
147
148       selectionModel.setSelectionMode(GraphSelectionModel.SINGLE_GRAPH_SELECTION);
149
150       refreshGraphConfiguration();
151    }
152
153    public void refreshGraphConfiguration () {
154       JaWEConfig jcfg=JaWEConfig.getInstance();
155       boolean gs=jcfg.getGridStatus();
156       setGridEnabled(gs);
157       setGridVisible(gs);
158       setGridSize(jcfg.getGridSize());
159       setBackground(Utils.getColor(jcfg.getBackgroundColor()));
160       setHighlightColor(Utils.getColor(jcfg.getHighlightColor()));
161       setGridColor(Utils.getColor(jcfg.getGridColor()));
162       setHandleColor(Utils.getColor(jcfg.getHandleColor()));
163       setMarqueeColor(Utils.getColor(jcfg.getMarqueeColor()));
164       setFontSize();
165       ((JaWEMarqueeHandler)getMarqueeHandler()).enableBubblesButtons(JaWEConfig.getInstance().getUseBubblesStatus());
166       updateStartEndBubbles();
167    }
168
169    protected void setFontSize () {
170       boolean isModified=JaWE.getInstance().isModified();
171       Set cellSet=JaWEGraphModel.getAllCellsInModel(getModel());
172       if (cellSet==null) return;
173       //Filter ports out
174
java.util.List JavaDoc list = new ArrayList();
175       for (Iterator i=cellSet.iterator(); i.hasNext();) {
176          Object JavaDoc cell=i.next();
177          if (!(cell instanceof Port)) {
178             list.add(cell);
179          }
180       }
181       Object JavaDoc[] cells = list.toArray();
182
183       Map nested = new Hashtable();
184       for (int i = 0; i < cells.length; i++) {
185          CellView view = getGraphLayoutCache().getMapping(cells[i], false);
186          if (view != null) {
187             Font font = GraphConstants.getFont(view.getAllAttributes());
188             if (font.getSize()==JaWEConfig.getInstance().getFontSize()) {
189                return;
190             }
191             Map attr = GraphConstants.createMap();
192             GraphConstants.setFont(attr, font.deriveFont(JaWEConfig.getInstance().getFontSize()));
193             nested.put(cells[i], attr);
194          }
195       }
196       //getGraphLayoutCache().edit(nested, null, null, null);
197
//graphModel.edit(nested,null,null,null);
198
((JaWEGraphModel)graphModel).editFonts(nested);
199       if (!isModified) {
200          JaWE.getInstance().setModified(false);
201       }
202    }
203
204    protected void updateStartEndBubbles () {
205       if (!JaWEConfig.getInstance().getUseBubblesStatus()) {
206          Set objectsToRemove=new HashSet();
207          Set starts=workflowManager.getStarts();
208          objectsToRemove.addAll(starts);
209          Iterator it=starts.iterator();
210          while (it.hasNext()) {
211             Start s=(Start)it.next();
212             objectsToRemove.addAll(s.getOutgoingTransitions());
213          }
214          Set ends=workflowManager.getEnds();
215          objectsToRemove.addAll(ends);
216          it=ends.iterator();
217          while (it.hasNext()) {
218             End e=(End)it.next();
219             objectsToRemove.addAll(e.getIncomingTransitions());
220          }
221          if (objectsToRemove.size()>0) {
222             ((JaWEGraphModel)graphModel).removeBubbles(objectsToRemove.toArray(),getEditor());
223          }
224       }
225    }
226
227    /**
228     * Overrides super method - don't need to waste a time for this.
229     */

230    public static void addSampleData(GraphModel model) {
231       return;
232    }
233
234    /** To satisfy interface */
235    public void showPropertyDialog (Window parentWindow,AbstractGraph graph) {}
236
237
238    /**
239     * Gets a property object (DTDElement).
240     */

241    public XMLElement getPropertyObject () {
242       return xmlObject;
243    }
244
245    /**
246     * Gets an XPDL object (DTDElement).
247     */

248    public XMLElement getXPDLObject () {
249       return xmlObject;
250    }
251
252    /**
253     * Gets an userObject property which name is given in parameter what.
254     */

255    public XMLElement get (String JavaDoc what) {
256       return ((XMLComplexElement)getPropertyObject()).get(what);
257    }
258
259    /**
260     * Sets an userObject property which name is given in parameter what to
261     * a value given in a parameter value.
262     */

263    public void set (String JavaDoc what,Object JavaDoc value) {
264       ((XMLComplexElement)getPropertyObject()).set(what,value);
265    }
266
267    /**
268     * Gets a tooltip text for element.
269     */

270    public String JavaDoc getTooltip () {
271       return "";
272    }
273
274    /**
275     * Gets an editor object.
276     */

277    public AbstractEditor getEditor() {
278       return editor;
279    }
280
281    /**
282     * Gets the WorkflowManager.
283     */

284    public WorkflowManager getWorkflowManager() {
285       return workflowManager;
286    }
287
288    /**
289     */

290    public Map getXPDLSchemaValidationErrorMessages () {
291       return xpdlSchemaValidationErrors;
292    }
293
294    /**
295     */

296    public String JavaDoc getBasicXPDLSchemaValidationErrorMessage () {
297       return basicXpdlSchemaValidationError;
298    }
299
300    /**
301     * Returns Map of activities as a keys and error message strings
302     * as a value. This Map represents wrong connected activities
303     * and should be called right after checkConnections method, otherwise
304     * you can get wrong results.
305     */

306    public Map getConnectionErrorMessages () {
307       return graphConnectionErrors;
308    }
309
310    /**
311     * Returns the basic connection error for the graph, or null if there are
312     * no errors;
313     */

314    public String JavaDoc getBasicConnectionErrorMessage () {
315       return basicGraphConnectionError;
316    }
317
318    public abstract boolean validateAgainsXPDLSchema ();
319
320    /**
321     * Checks workflow diagram and returns <code>true</code> if there are no
322     * wrong-connected or non-connected activities. When checking on block activity,
323     * there are two type's of check realized internaly by a block activity - the first
324     * is check of it's outer representation, and the second is check of it's
325     * inner representation. The eventual errors are reported as a Map
326     * and consists of wrong connected activities as a keys and String messages
327     * as a values and could be retrieved by a method getConnectionErrorMessages().
328     * <BR>NOTE: You must call method getConnectionErrorMessages right after
329     * calling this check method, otherwise you can get wrong results.
330     */

331    public abstract boolean checkConnections (boolean fullCheck);
332
333    protected abstract boolean checkStartAndEndsConnections (boolean fullCheck);
334
335    protected abstract void updateXMLObjectsBeforeChecking ();
336
337    /**
338     * Returns map of activities as a keys and error message strings
339     * as a value. This map represents activities that does not
340     * satisfy graph conformance, and should be called right after
341     * checkGraphConformance method, otherwiseyou can get wrong results.
342     */

343    public Map getGraphConformanceErrorMessages () {
344       return graphConformanceErrors;
345    }
346
347    /**
348     * Returns the message to be written in statusbar if graph is not conformant.
349     */

350    public java.util.List JavaDoc getBasicGraphConformanceErrorMessages () {
351       return basicGraphConformanceErrors;
352    }
353
354    /**
355     * Checks workflow diagram and returns <code>true</code> if it conforms to
356     * the specified type (fool-blocked, loop-blocked).When checking on block
357     * activity, there are two type's of check realized internaly by a block
358     * activity - the first is check of it's outer representation, and the second
359     * is check of it's inner representation. The errors are reported as a
360     * map and consists of improper activities as a keys and String messages
361     * as a values and could be retrieved by a method getConformanceErrorMessages().
362     * <BR>NOTE: You must call method getGraphConformanceErrorMessages right after
363     * calling this check method, otherwise you can get wrong results.
364     */

365    public abstract boolean checkGraphConformance (boolean fullCheck);
366
367    /**
368     * Returns Map of xml objects as keys and error message strings as values.
369     */

370    public Map getLogicErrorMessages () {
371       return logicErrors;
372    }
373
374    /**
375     * Returns the basic logic error, or null if there are no errors.
376     */

377    public String JavaDoc getBasicLogicErrorMessage () {
378       return basicLogicError;
379    }
380
381    /**
382     * Checks xml model and returns <code>true</code> if there are no
383     * logic errors.
384     */

385    public abstract boolean checkLogic (boolean fullCheck);
386
387    /**
388     * Notification from the <code>UIManager</code> that the L&F has changed.
389     * Replaces the current UI object with the latest version from the
390     * <code>UIManager</code>. Subclassers can override this to support
391     * different GraphUIs.
392     * @see JComponent#updateUI
393     *
394     */

395    public void updateUI() {
396       setUI(new JaWEGraphUI());
397       invalidate();
398    }
399
400    public void setAdditionalKeyboardShortcuts () {
401       getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
402          .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,InputEvent.ALT_DOWN_MASK,false),
403               Utils.getUnqualifiedClassName(EditProperties.class));
404       getActionMap().put(Utils.getUnqualifiedClassName(EditProperties.class),
405                          editor.getAction(Utils.getUnqualifiedClassName(EditProperties.class)));
406
407       editor.setALTCursorKeyboardShortcuts (this);
408    }
409
410 }
411
412
Popular Tags