KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > misc > ValidationErrorDisplay


1 /* ValidationErrorDisplay.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.misc;
12
13 import org.enhydra.jawe.*;
14 import org.enhydra.jawe.graph.Start;
15 import org.enhydra.jawe.graph.End;
16 import org.enhydra.jawe.xml.*;
17 import org.enhydra.jawe.xml.elements.*;
18 import org.enhydra.jawe.xml.elements.Package;
19
20 import javax.swing.*;
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.util.*;
24
25 /**
26 * Dialog class that displays graph's validation error messages. Object of
27 * this class is created by passing a Maps and the List with error messages
28 * to the constructor (along with other required parameters). Keys of given
29 * <code>Map</code>s are elements of the graph that didn't pass validation,
30 * and values are error messages for that elements.
31 */

32 public class ValidationErrorDisplay extends JDialog {
33    private boolean stopped=false;
34
35    /**
36    * Constructs dialog with a given errors, and with a frame as a parent.
37    */

38    public ValidationErrorDisplay (Map parsingErrors, Map connectionErrors,
39    java.util.List JavaDoc basicGraphConformanceErrors,Map graphConformanceErrors,
40    Map logicErrors,JFrame parentFrame,String JavaDoc title, boolean controlsVisible) {
41       super(parentFrame,title,true);
42       showDialog(parsingErrors,connectionErrors,basicGraphConformanceErrors,
43             graphConformanceErrors,logicErrors,parentFrame,controlsVisible);
44    }
45
46    /**
47    * Constructs dialog with a given errors, and with a dialog as a parent.
48    */

49    public ValidationErrorDisplay (Map parsingErrors, Map connectionErrors,
50    java.util.List JavaDoc basicGraphConformanceErrors,Map graphConformanceErrors,
51    Map logicErrors,JDialog parentDialog,String JavaDoc title, boolean controlsVisible) {
52       super(parentDialog,title,true);
53       showDialog(parsingErrors,connectionErrors,basicGraphConformanceErrors,
54             graphConformanceErrors,logicErrors,parentDialog,controlsVisible);
55    }
56
57    /**
58    * Shows error messages in a <code>JEditorPane</code> component.
59    */

60    protected void showDialog(Map parsingErrors, Map connectionErrors,
61    java.util.List JavaDoc basicGraphConformanceErrors,Map graphConformanceErrors,
62    Map logicErrors,Window parentWindow,boolean controlsVisible){
63       JEditorPane text = new JEditorPane("text/html",
64             processErrors(parsingErrors,connectionErrors,basicGraphConformanceErrors,
65             graphConformanceErrors,logicErrors));
66       text.setEditable(false);
67       text.getCaret().setDot(0);
68       JScrollPane sp = new JScrollPane(text);
69       sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
70       sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
71       getContentPane().setLayout(new BorderLayout());
72       getContentPane().add(sp);
73
74
75       if (controlsVisible) {
76          JPanel buttonPanel=new JPanel();
77          buttonPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
78          buttonPanel.setAlignmentY(Component.TOP_ALIGNMENT);
79
80          JButton buttonProceed=new JButton(ResourceManager.getLanguageDependentString("ProceedKey"));
81          java.net.URL JavaDoc u = ResourceManager.getResource("Proceed"+JaWEConstants.IMAGE_SUFFIX);
82          if (u!=null) {
83             buttonProceed.setIcon(new ImageIcon(u));
84          }
85          JButton buttonStop=new JButton(ResourceManager.getLanguageDependentString("StopKey"));
86          u = ResourceManager.getResource("Stop"+JaWEConstants.IMAGE_SUFFIX);
87          if (u!=null) {
88             buttonStop.setIcon(new ImageIcon(u));
89          }
90
91          buttonPanel.add(buttonProceed);
92          buttonPanel.add(buttonStop);
93
94          Container cp=getContentPane();
95          cp.setLayout(new BorderLayout());
96          cp.add(sp,BorderLayout.CENTER);
97          cp.add(buttonPanel,BorderLayout.SOUTH);
98
99          // action listener for confirming
100
buttonProceed.addActionListener(new ActionListener(){
101             public void actionPerformed( ActionEvent ae ){
102                stopped=false;
103                dispose();
104             }
105          });
106
107          // action listener for canceling
108
buttonStop.addActionListener(new ActionListener(){
109             public void actionPerformed( ActionEvent ae ){
110                stopped=true;
111                dispose();
112             }
113          });
114
115          buttonProceed.setDefaultCapable(true);
116          getRootPane().setDefaultButton(buttonProceed);
117       }
118
119
120       getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
121             .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0,false),"Cancel");
122       getRootPane().getActionMap().put("Cancel", new AbstractAction() {
123          public void actionPerformed(ActionEvent e) {
124             dispose();
125          }
126       });
127
128       Utils.center(this,100,150);
129
130       show();
131    }
132
133    /**
134    * Processes given errors, and evaluates a string to be displayed.
135    */

136    protected String JavaDoc processErrors(Map parsingErrors,Map connectionErrors,
137    java.util.List JavaDoc basicGraphConformanceErrors,Map graphConformanceErrors,
138    Map logicErrors) {
139       String JavaDoc errMsg="<html>";
140
141       // Connections
142
String JavaDoc subtitle;
143       if (getParent() instanceof JFrame) {
144          subtitle=ResourceManager.getLanguageDependentString("XPDLSchemaKey");
145          errMsg+="<font size=6 face=\"sans-serif\" color=\"green\"><b><i><u>"+subtitle+"</u></i></b></font><br><br>";
146
147          if (parsingErrors!=null) {
148             Iterator it=parsingErrors.entrySet().iterator();
149             while (it.hasNext()) {
150                Map.Entry me=(Map.Entry)it.next();
151                String JavaDoc pkgFile=(String JavaDoc)me.getKey();
152                Set errorsForPkg=(Set)me.getValue();
153                if (pkgFile.length()>0) {
154                   errMsg+="<font size=5 face=\"sans-serif\" color=\"blue\"><b><i><u>"+
155                         pkgFile+"</u></i></b></font><br><br>";
156                }
157                errMsg+="<font size=4 face=\"sans-serif\" color=\"#FF0000\"><i>";
158
159                Iterator it2=errorsForPkg.iterator();
160                while (it2.hasNext()) {
161                   String JavaDoc msg=it2.next().toString();
162                   errMsg+=msg+"<br>";
163                }
164
165                errMsg+="</i></font><br><br>";
166             }
167          }
168          if (parsingErrors==null || parsingErrors.size()==0) {
169             String JavaDoc msg=ResourceManager.
170                   getLanguageDependentString("MessageThereAreNoXPDLSchemaValidationErrors");
171             errMsg+="<br><font size=4 face=\"sans-serif\" color=\"#0033CC\">"+msg+"</font><br><br>";
172          }
173
174       }
175
176       // Connections
177
subtitle=ResourceManager.getLanguageDependentString("ConnectionsKey");
178       errMsg+="<font size=6 face=\"sans-serif\" color=\"green\"><b><i><u>"+subtitle+"</u></i></b></font><br><br>";
179
180       if (connectionErrors!=null) {
181          Iterator it=connectionErrors.entrySet().iterator();
182          while (it.hasNext()) {
183             Map.Entry me=(Map.Entry)it.next();
184             Object JavaDoc obj=me.getKey();
185             String JavaDoc msg=me.getValue().toString();
186             errMsg+="<font size=4 face=\"sans-serif\" color=\"#0033CC\">";
187             errMsg=appendErrorMessage(obj,errMsg);
188             //errMsg+="</font>";
189
errMsg+="<blockquote>";
190             errMsg+="<font size=\"4\" face=\"sans-serif\">";
191             errMsg+="<em>"+msg+"</em><br>";
192             errMsg+="</font></p></blockquote>";
193          }
194       }
195       if (connectionErrors==null || connectionErrors.size()==0) {
196          String JavaDoc msg=ResourceManager.
197             getLanguageDependentString("MessageAllElementsAreProperlyConnected");
198          errMsg+="<br><font size=4 face=\"sans-serif\" color=\"#0033CC\">"+msg+"</font><br><br>";
199       }
200
201       // Graph conformance
202
subtitle=ResourceManager.getLanguageDependentString("GraphConformanceKey");
203       errMsg+="<font size=6 face=\"sans-serif\" color=\"green\"><b><i><u>"+subtitle+"</u></i></b></font><br>";
204
205       if (basicGraphConformanceErrors!=null) {
206          Iterator it=basicGraphConformanceErrors.iterator();
207          while (it.hasNext()) {
208             String JavaDoc msg=(String JavaDoc)it.next();
209             errMsg+="<font size=4 face=\"sans-serif\" color=\"#FF0000\">"+msg+"</font>";
210             errMsg+="<br>";
211          }
212       }
213
214       if (graphConformanceErrors!=null && graphConformanceErrors.size()>0) {
215          if (basicGraphConformanceErrors!=null && basicGraphConformanceErrors.size()>0) {
216             errMsg+="<br><br>";
217          } else {
218             errMsg+="<br>";
219          }
220       }
221
222       if (graphConformanceErrors!=null) {
223          Iterator it=graphConformanceErrors.entrySet().iterator();
224          while (it.hasNext()) {
225             Map.Entry me=(Map.Entry)it.next();
226             Object JavaDoc obj=me.getKey();
227             String JavaDoc msg=me.getValue().toString();
228             errMsg+="<font size=4 face=\"sans-serif\" color=\"#0033CC\">";
229             errMsg=appendErrorMessage(obj,errMsg);
230             //errMsg+="</font>";
231
errMsg+="<blockquote>";
232             errMsg+="<font size=\"4\" face=\"sans-serif\">";
233             errMsg+="<em>"+msg+"</em><br>";
234             errMsg+="</font></p></blockquote>";
235          }
236       }
237
238       if ((basicGraphConformanceErrors==null || basicGraphConformanceErrors.size()==0) &&
239       (graphConformanceErrors==null || graphConformanceErrors.size()==0)) {
240          String JavaDoc msg;
241          if (getParent() instanceof JFrame) {
242             msg=ResourceManager.
243                getLanguageDependentString("MessagePackageGraphsConformsToTheGivenGraphConformanceClass");
244          } else {
245             msg=ResourceManager.
246                getLanguageDependentString("MessageProcessGraphConformsToTheGivenGraphConformanceClass");
247          }
248          errMsg+="<br><font size=4 face=\"sans-serif\" color=\"#0033CC\">"+msg+"</font><br><br>";
249       }
250
251       if (basicGraphConformanceErrors!=null && basicGraphConformanceErrors.size()>0 &&
252             (graphConformanceErrors==null || graphConformanceErrors.size()==0)) {
253          errMsg+="<br>";
254       }
255
256       // Logic
257
subtitle=ResourceManager.getLanguageDependentString("LogicKey");
258       errMsg+="<font size=6 face=\"sans-serif\" color=\"green\"><b><i><u>"+subtitle+"</u></i></b></font><br><br>";
259
260       if (logicErrors!=null) {
261          Iterator it=logicErrors.entrySet().iterator();
262          while (it.hasNext()) {
263             Map.Entry me=(Map.Entry)it.next();
264             Object JavaDoc obj=me.getKey();
265             String JavaDoc msg=me.getValue().toString();
266             errMsg+="<font size=4 face=\"sans-serif\" color=\"#0033CC\">";
267             errMsg=appendErrorMessage(obj,errMsg);
268             //errMsg+="</font>";
269
errMsg+="<blockquote>";
270             errMsg+="<font size=\"4\" face=\"sans-serif\">";
271             errMsg+="<em>"+msg+"</em><br>";
272             errMsg+="</font></p></blockquote>";
273          }
274       }
275       if (logicErrors==null || logicErrors.size()==0) {
276          String JavaDoc msg=ResourceManager.
277             getLanguageDependentString("MessageThereAreNoLogicErrors");
278          errMsg+="<br><font size=4 face=\"sans-serif\" color=\"#0033CC\">"+msg+"</font><br><br>";
279       }
280
281
282       if (((connectionErrors!=null && connectionErrors.size()>0) ||
283       (graphConformanceErrors!=null && graphConformanceErrors.size()>0)) &&
284       (getParent() instanceof JDialog)) {
285          errMsg+="<br><br>";
286          errMsg+="<font size=\"4\" face=\"sans-serif\"><strong><em>"+
287             ResourceManager.
288                getLanguageDependentString("MessageAllInvalidGraphObjectsWillBeSelectedAfterExitingDialog")+
289                   "</strong></em></font>";
290       }
291
292       errMsg+="</html>";
293
294       return errMsg;
295    }
296
297    private String JavaDoc appendErrorMessage (Object JavaDoc obj,String JavaDoc errMsg) {
298       if ((obj instanceof XMLCollectionElement) || (obj instanceof Package JavaDoc)) {
299          XMLComplexElement xmlCe=(XMLComplexElement)obj;
300          if (obj instanceof WorkflowProcess) {
301             if(getParent() instanceof JDialog) return errMsg;
302             errMsg+="<u><strong>"+ResourceManager.
303                   getLanguageDependentString("ProcessKey")+":</strong></u> </font>";
304          } else if (obj instanceof Activity) {
305             Activity act=(Activity)obj;
306             if (act.getSubflow()!=null) {
307                errMsg+="<u><strong>"+ResourceManager.
308                      getLanguageDependentString("SubFlowKey")+":</strong></u> </font>";
309             } else if (act.getBlockActivity()!=null) {
310                errMsg+="<u><strong>"+ResourceManager.
311                      getLanguageDependentString("BlockActivityKey")+":</strong></u> </font>";
312             } else if (act.getTools()!=null) {
313                errMsg+="<u><strong>"+ResourceManager.
314                      getLanguageDependentString("GenericKey")+":</strong></u> </font>";
315             } else {
316                errMsg+="<u><strong>"+ResourceManager.
317                      getLanguageDependentString("RouteKey")+":</strong></u> </font>";
318             }
319          } else {
320             errMsg+="<u><strong>"+((XMLElement)obj).toLabel()+":</strong></u> </font>";
321          }
322          try {
323             errMsg+="<font size=\"4\" face=\"sans-serif\">"
324                +ResourceManager.getLanguageDependentString("IdKey")+"= <font color=\"#FF0000\">"
325                +xmlCe.get("Id")+"</font>, ";
326             errMsg+=ResourceManager.getLanguageDependentString("NameKey")+
327                "= <font color=\"#FF0000\">"+xmlCe.get("Name").toString()+"</font></font>";
328          } catch (Exception JavaDoc ex) {}
329       } else if (obj instanceof XMLElement) {
330          errMsg+="<u><strong>"+((XMLElement)obj).toLabel()+":</strong></u> </font>";
331       } else if ((obj instanceof Start) || (obj instanceof End)) {
332          org.enhydra.jawe.graph.Activity sOrE=(org.enhydra.jawe.graph.Activity)obj;
333          if (obj instanceof Start) {
334             errMsg+="<u><strong>"+ResourceManager.
335                   getLanguageDependentString("StartKey")+":</strong></u> </font>";
336          } else if (obj instanceof End) {
337             errMsg+="<u><strong>"+ResourceManager.
338                   getLanguageDependentString("EndKey")+":</strong></u> </font>";
339          }
340       } else {
341       }
342       return errMsg;
343    }
344
345    public boolean hasBeenStoped () {
346       return stopped;
347    }
348 }
349
Popular Tags