Source Code Cross Referenced for SimpleDomainValidationExample.java in  » Swing-Library » jgoodies-validation » com » jgoodies » validation » tutorial » basics » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jgoodies validation » com.jgoodies.validation.tutorial.basics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2003-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions are met:
006:         *
007:         *  o Redistributions of source code must retain the above copyright notice,
008:         *    this list of conditions and the following disclaimer.
009:         *
010:         *  o Redistributions in binary form must reproduce the above copyright notice,
011:         *    this list of conditions and the following disclaimer in the documentation
012:         *    and/or other materials provided with the distribution.
013:         *
014:         *  o Neither the name of JGoodies Karsten Lentzsch nor the names of
015:         *    its contributors may be used to endorse or promote products derived
016:         *    from this software without specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029:         */
030:
031:        package com.jgoodies.validation.tutorial.basics;
032:
033:        import java.awt.event.ActionEvent;
034:        import java.text.DateFormat;
035:        import java.util.Date;
036:
037:        import javax.swing.*;
038:
039:        import com.jgoodies.forms.builder.DefaultFormBuilder;
040:        import com.jgoodies.forms.builder.PanelBuilder;
041:        import com.jgoodies.forms.factories.ButtonBarFactory;
042:        import com.jgoodies.forms.layout.CellConstraints;
043:        import com.jgoodies.forms.layout.FormLayout;
044:        import com.jgoodies.forms.layout.RowSpec;
045:        import com.jgoodies.validation.ValidationResult;
046:        import com.jgoodies.validation.tutorial.shared.Order;
047:        import com.jgoodies.validation.tutorial.util.TutorialUtils;
048:        import com.jgoodies.validation.tutorial.validator.OrderValidator;
049:
050:        /**
051:         * A simple validation example that uses a "copying" binding,
052:         * not the JGoodies Binding. The domain Order object is validated
053:         * using an OrderValidator. On OK pressed, a modal dialog shows
054:         * the validation errors and warnings - if any.
055:         *
056:         * @author Karsten Lentzsch
057:         * @version $Revision: 1.6 $
058:         */
059:        public final class SimpleDomainValidationExample {
060:
061:            private Order order;
062:
063:            private JTextField orderNoField;
064:            private JFormattedTextField orderDateField;
065:            private JFormattedTextField deliveryDateField;
066:            private JTextArea deliveryNotesArea;
067:            private JButton okButton;
068:            private JButton closeButton;
069:
070:            /**
071:             * Launches this example: creates a JFrame, adds the built
072:             * example panel, packs the frame and finally makes it visible.
073:             *
074:             * @param args  runtime arguments (ignored)
075:             */
076:            public static void main(String[] args) {
077:                try {
078:                    UIManager
079:                            .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
080:                } catch (Exception e) {
081:                    // Likely Plastic is not in the classpath; ignore it.
082:                }
083:                JFrame frame = new JFrame();
084:                frame.setTitle("Basic :: Simple Domain Validation");
085:                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
086:                JComponent panel = new SimpleDomainValidationExample()
087:                        .buildPanel();
088:                frame.getContentPane().add(panel);
089:                frame.pack();
090:                TutorialUtils.locateOnOpticalScreenCenter(frame);
091:                frame.setVisible(true);
092:            }
093:
094:            // Instance Creation ******************************************************
095:
096:            private void init() {
097:                order = new Order();
098:            }
099:
100:            // Component Creation and Initialization **********************************
101:
102:            /**
103:             *  Creates and initializes the UI components.
104:             */
105:            protected void initComponents() {
106:                orderNoField = new JTextField();
107:                DateFormat dateFormat = DateFormat
108:                        .getDateInstance(DateFormat.SHORT);
109:                orderDateField = new JFormattedTextField(dateFormat);
110:                deliveryDateField = new JFormattedTextField(dateFormat);
111:                deliveryNotesArea = new JTextArea();
112:
113:                okButton = new JButton(new OKAction());
114:                closeButton = new JButton(TutorialUtils.getCloseAction());
115:            }
116:
117:            // Building ***************************************************************
118:
119:            /**
120:             * Builds the whole editor.
121:             *
122:             * @return the editor panel with a report area at the bottom
123:             */
124:            public JComponent buildPanel() {
125:                init();
126:                initComponents();
127:                updateView();
128:                return buildPanelWithReportInBottom();
129:            }
130:
131:            /**
132:             * Builds the whole editor.
133:             *
134:             * @return the editor panel with a report area at the bottom
135:             */
136:            private JComponent buildPanelWithReportInBottom() {
137:                FormLayout layout = new FormLayout("fill:default:grow",
138:                        "pref, 6dlu:grow, pref");
139:
140:                PanelBuilder builder = new PanelBuilder(layout);
141:                builder.setDefaultDialogBorder();
142:
143:                CellConstraints cc = new CellConstraints();
144:                builder.add(buildEditorPanel(), cc.xy(1, 1));
145:                builder.add(buildButtonBar(), cc.xy(1, 3));
146:                return builder.getPanel();
147:            }
148:
149:            private JComponent buildEditorPanel() {
150:                FormLayout layout = new FormLayout(
151:                        "right:pref, 4dlu, 40dlu, 2dlu, 40dlu, 82dlu:grow");
152:
153:                DefaultFormBuilder builder = new DefaultFormBuilder(layout);
154:                builder.setRowGroupingEnabled(true);
155:
156:                CellConstraints cc = new CellConstraints();
157:
158:                builder.appendSeparator("Order");
159:                builder.append("Order No", orderNoField, 3);
160:                builder.append("Order-/Delivery Date", orderDateField,
161:                        deliveryDateField);
162:                builder.nextLine();
163:
164:                builder.append("Notes");
165:                builder.appendRow(new RowSpec("17dlu")); // Assumes line is 14, gap is 3
166:                builder.add(new JScrollPane(deliveryNotesArea), cc.xywh(builder
167:                        .getColumn(), builder.getRow(), 4, 2));
168:
169:                // Append a small gap at the bottom so the overlay icon is visible
170:                builder.nextLine();
171:                builder.appendRow(new RowSpec("2px"));
172:
173:                return builder.getPanel();
174:            }
175:
176:            private JComponent buildButtonBar() {
177:                return ButtonBarFactory.buildOKCancelBar(okButton, closeButton);
178:            }
179:
180:            // Synchronizing Model and View *******************************************
181:
182:            private void updateView() {
183:                orderNoField.setText(getOrder().getOrderNo());
184:                orderDateField.setValue(getOrder().getOrderDate());
185:                deliveryDateField.setValue(getOrder().getDeliveryDate());
186:                deliveryNotesArea.setText(getOrder().getDeliveryNotes());
187:            }
188:
189:            private void updateModel() {
190:                getOrder().setOrderNo(orderNoField.getText());
191:                getOrder().setOrderDate((Date) orderDateField.getValue());
192:                getOrder().setDeliveryDate((Date) deliveryDateField.getValue());
193:                getOrder().setDeliveryNotes(deliveryNotesArea.getText());
194:            }
195:
196:            private Order getOrder() {
197:                return order;
198:            }
199:
200:            // Event Handling *********************************************************
201:
202:            /**
203:             * Validates the GUI state and updates the model only,
204:             * if the GUI state has no errors (it may have warnings).
205:             */
206:            private final class OKAction extends AbstractAction {
207:
208:                OKAction() {
209:                    super ("OK");
210:                }
211:
212:                public void actionPerformed(ActionEvent e) {
213:                    updateModel();
214:                    ValidationResult validationResult = new OrderValidator()
215:                            .validate(order);
216:                    if (validationResult.hasErrors()) {
217:                        TutorialUtils.showValidationMessage(e,
218:                                "To save the order, fix the following errors:",
219:                                validationResult);
220:                        return;
221:                    }
222:                    if (validationResult.hasWarnings()) {
223:                        TutorialUtils.showValidationMessage(e,
224:                                "Note: some order fields are invalid.",
225:                                validationResult);
226:                    }
227:                    System.out.println("Data saved");
228:                }
229:
230:            }
231:
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.