KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > modeler > dialog > ValidationResultBrowser


1 package org.objectstyle.cayenne.modeler.dialog;
2
3 import java.awt.Component JavaDoc;
4 import java.util.Iterator JavaDoc;
5
6 import javax.swing.JDialog JavaDoc;
7
8 import org.objectstyle.cayenne.modeler.util.CayenneController;
9 import org.objectstyle.cayenne.swing.BindingBuilder;
10 import org.objectstyle.cayenne.validation.ValidationFailure;
11 import org.objectstyle.cayenne.validation.ValidationResult;
12
13 /**
14  * @author Andrei Adamchik
15  */

16 public class ValidationResultBrowser extends CayenneController {
17
18     protected ValidationResultBrowserView view;
19
20     public ValidationResultBrowser(CayenneController parent) {
21         super(parent);
22
23         this.view = new ValidationResultBrowserView();
24
25         initController();
26     }
27
28     protected void initController() {
29         BindingBuilder builder = new BindingBuilder(
30                 getApplication().getBindingFactory(),
31                 this);
32         builder.bindToAction(view.getCloseButton(), "closeDialogAction()");
33     }
34
35     public Component JavaDoc getView() {
36         return view;
37     }
38
39     public void closeDialogAction() {
40         view.dispose();
41     }
42
43     public void startupAction(
44             String JavaDoc title,
45             String JavaDoc message,
46             ValidationResult validationResult) {
47
48         this.view.setTitle(title);
49         this.view.getMessageLabel().setText(message);
50         this.view.getErrorsDisplay().setText(buildValidationText(validationResult));
51
52         view.pack();
53         view.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
54         view.setModal(true);
55         makeCloseableOnEscape();
56         centerView();
57         view.setVisible(true);
58     }
59
60     /**
61      * Creates validation text for the validation result.
62      */

63     protected String JavaDoc buildValidationText(ValidationResult validationResult) {
64         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
65         String JavaDoc separator = System.getProperty("line.separator");
66
67         Iterator JavaDoc it = validationResult.getFailures().iterator();
68         while (it.hasNext()) {
69
70             if (buffer.length() > 0) {
71                 buffer.append(separator);
72             }
73
74             ValidationFailure failure = (ValidationFailure) it.next();
75             if (failure.getSource() != null) {
76                 buffer.append("[SQL: ").append(failure.getSource()).append("] - ");
77             }
78
79             if (failure.getDescription() != null) {
80                 buffer.append(failure.getDescription());
81             }
82         }
83
84         return buffer.toString();
85     }
86 }
Popular Tags