KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > actions > CheckValidity


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

9
10 package org.enhydra.jawe.actions;
11
12 import org.enhydra.jawe.*;
13 import org.enhydra.jawe.misc.*;
14 import org.enhydra.jawe.graph.BlockActivityEditor;
15 import org.enhydra.jawe.graph.Start;
16 import org.enhydra.jawe.graph.End;
17 import org.enhydra.jawe.xml.*;
18 import org.enhydra.jawe.xml.elements.*;
19 import org.enhydra.jawe.xml.panels.*;
20
21 import javax.swing.*;
22 import java.util.*;
23 import java.net.*;
24 import java.awt.event.ActionEvent JavaDoc;
25
26 /**
27  * Class that realizes <B>check validity</B> action on given graph.
28  */

29 public class CheckValidity extends ActionBase {
30
31    private static ImageIcon checkOKIcon;
32
33    public CheckValidity (AbstractEditor editor) {
34       super(editor);
35    }
36
37    public void actionPerformed(ActionEvent JavaDoc e) {
38       if (editor instanceof PackageEditor && !((PackageEditor)editor).isInitialized()) {
39          ((PackageEditor)editor).enterPackageID();
40       }
41       // check graph connections
42

43       boolean isSchemaValidationError=!editor.getGraph().validateAgainsXPDLSchema();
44       boolean isConnectionError=!editor.getGraph().checkConnections(true);
45       boolean isGraphConformanceError=!editor.getGraph().checkGraphConformance(true);
46       boolean isLogicError=!editor.getGraph().checkLogic(true);
47       boolean isModelOK=!(isSchemaValidationError || isConnectionError ||
48             isGraphConformanceError || isLogicError);
49       // gets Hashtable with error messages
50
Map xpdlSchemaValidationErrors=editor.getGraph().getXPDLSchemaValidationErrorMessages();
51       Map connectionErrors=editor.getGraph().getConnectionErrorMessages();
52       List basicGraphConformanceErrors=editor.getGraph().getBasicGraphConformanceErrorMessages();
53       Map graphConformanceErrors=editor.getGraph().getGraphConformanceErrorMessages();
54       Map logicErrors=editor.getGraph().getLogicErrorMessages();
55       // Prints connection error messages contained in a given Hashtable.
56
// Hashtable has activity elements as a keys and it's error
57
// connection messages as a values.
58
String JavaDoc title=ResourceManager.getLanguageDependentString("DialogValidationReport");
59       URL iconURL = ResourceManager.getResource("CheckOKImage");
60       if (iconURL != null) checkOKIcon = new ImageIcon(iconURL);
61
62       if (editor.getWindow() instanceof JFrame) {
63          if (isModelOK){
64             //If the all elements are properly connected
65
JOptionPane.showMessageDialog((JFrame)editor.getWindow(),
66                         ResourceManager.getLanguageDependentString("InformationPackageIsValid"),
67                         title, JOptionPane.INFORMATION_MESSAGE, checkOKIcon);
68          } else {
69             new ValidationErrorDisplay(xpdlSchemaValidationErrors,connectionErrors,
70                   basicGraphConformanceErrors,graphConformanceErrors,logicErrors,
71                   (JFrame)editor.getWindow(),title, false);
72          }
73       } else {
74          if (isModelOK) {
75             String JavaDoc OKMessage;
76             if (editor instanceof BlockActivityEditor) {
77                OKMessage=ResourceManager.getLanguageDependentString("InformationBlockIsValid");
78             } else {
79                OKMessage=ResourceManager.getLanguageDependentString("InformationProcessIsValid");
80             }
81             //If the all elements are properly connected
82
JOptionPane.showMessageDialog((JDialog)editor.getWindow(),
83                         OKMessage, title, JOptionPane.INFORMATION_MESSAGE, checkOKIcon);
84          } else {
85             new ValidationErrorDisplay(xpdlSchemaValidationErrors,connectionErrors,
86                   basicGraphConformanceErrors,graphConformanceErrors,logicErrors,
87                   (JDialog)editor.getWindow(),title, false);
88          }
89       }
90
91       if (isModelOK) {
92          return;
93       }
94       // clears the selection
95
editor.getGraph().clearSelection();
96       // selects wrong connected elements.
97
Set wc=new HashSet(connectionErrors.keySet());
98       wc.addAll(graphConformanceErrors.keySet());
99       wc.addAll(logicErrors.keySet());
100       // Find graph objects
101
WorkflowManager wm=editor.getGraph().getWorkflowManager();
102       Set graphObjects=new HashSet();
103       Iterator it=wc.iterator();
104       while (it.hasNext()) {
105          Object JavaDoc obj=it.next();
106          if (obj instanceof Activity) {
107             Object JavaDoc gAct=wm.getActivity(((Activity)obj).getID());
108             if (gAct!=null) {
109                graphObjects.add(gAct);
110             }
111          } else if ((obj instanceof Start) || (obj instanceof End)) {
112             graphObjects.add(obj);
113          } else if (obj instanceof Transition) {
114             Object JavaDoc gTrans=wm.getTransition(((Transition)obj).getID());
115             if (gTrans!=null) {
116                graphObjects.add(gTrans);
117             }
118          } else if (obj instanceof Participant) {
119             Object JavaDoc gPart=wm.getParticipant(((Participant)obj).getID());
120             if (gPart!=null) {
121                graphObjects.add(gPart);
122             }
123          }
124       }
125       editor.getGraph().setSelectionCells(graphObjects.toArray());
126       editor.valueChanged(null);
127    }
128 }
129
Popular Tags