ソースを参照

Added mandatory text field validator to location

jorgen_falk 18 年 前
コミット
60829c7c82

+ 16
- 4
register-app/src/main/java/se/citerus/registerapp/RegisterApp.java ファイルの表示

@@ -55,13 +55,24 @@ public class RegisterApp {
55 55
     assert handlingEventService != null : "No HandlingEventService available";
56 56
     
57 57
     handlingEventService.register(ISO8601_DATE_FORMAT.format(completionTimeField.getValue()), 
58
-                                  trackingIdField.getValue().toString(), 
59
-                                  carrierMovementField.getValue().toString(), 
60
-                                  locationField.getValue().toString(), 
61
-                                  eventTypeField.getValue().toString());
58
+                                  getStringValue(trackingIdField), 
59
+                                  getStringValue(carrierMovementField), 
60
+                                  getStringValue(locationField), 
61
+                                  getStringValue(eventTypeField));
62 62
     
63 63
     clearForm();
64 64
   }
65
+
66
+
67
+  private String getStringValue(JFormattedTextField formattedTextField) {
68
+    Object value = formattedTextField.getValue();
69
+    
70
+    if (value != null) {
71
+      return value.toString();
72
+    } else {
73
+      return null;
74
+    }
75
+  }
65 76
   
66 77
   
67 78
   /////////////////////////////////////////////////////////////////////////////
@@ -140,6 +151,7 @@ public class RegisterApp {
140 151
     
141 152
     validator.add(eventTypeField, new MandatoryTextFieldValidator("Event type can't be empty"));
142 153
     validator.add(trackingIdField, new MandatoryTextFieldValidator("Tracking id can't be empty"));
154
+    validator.add(locationField, new MandatoryTextFieldValidator("Location can't be empty"));
143 155
   }
144 156
   
145 157
   

+ 3
- 1
register-app/src/main/java/se/citerus/registerapp/validation/AbstractFormValidationDecorator.java ファイルの表示

@@ -15,7 +15,9 @@ public abstract class AbstractFormValidationDecorator implements FormValidationD
15 15
 
16 16
     component.addKeyListener(new KeyListener(){
17 17
       public void keyPressed(KeyEvent e) {
18
-        undecorate(component);
18
+        for (final Entry<JComponent, ComponentValidator> entry : validators.entrySet()) {
19
+          undecorate(entry.getKey());
20
+        }
19 21
       }
20 22
 
21 23
       public void keyReleased(KeyEvent e) {}

+ 8
- 4
register-app/src/main/java/se/citerus/registerapp/validation/FormValidationSwingDecorator.java ファイルの表示

@@ -14,7 +14,7 @@ import javax.swing.JPanel;
14 14
 
15 15
 public class FormValidationSwingDecorator extends AbstractFormValidationDecorator{
16 16
 
17
-  private static final int POPUP_Y_OFFSET = 4;
17
+  private static final int POPUP_Y_OFFSET = 0;
18 18
   private static final int POPUP_X_OFFSET = 12;
19 19
   private Color oldColor = Color.WHITE;
20 20
   private JFrame form;
@@ -31,7 +31,10 @@ public class FormValidationSwingDecorator extends AbstractFormValidationDecorato
31 31
     glassPane.setLayout(null);
32 32
 //    glassPane.setPreferredSize(form.getPreferredSize());
33 33
     glassPane.setSize(form.getSize());
34
+    
34 35
     form.setGlassPane(glassPane);
36
+    
37
+    
35 38
   }
36 39
 
37 40
   public FormValidationSwingDecorator(JFrame form, String message) {
@@ -48,6 +51,7 @@ public class FormValidationSwingDecorator extends AbstractFormValidationDecorato
48 51
     } else {
49 52
       popupPane = new JPanel(new FlowLayout());
50 53
       glassPane.add(popupPane);
54
+      glassPane.setVisible(true);
51 55
       
52 56
       popupPane.add(getIconLabel());
53 57
       popupPane.add(getMessageLabel());
@@ -98,8 +102,9 @@ public class FormValidationSwingDecorator extends AbstractFormValidationDecorato
98 102
     this.message = validator.getMessage();
99 103
     this.oldColor = component.getBackground();
100 104
     component.setBackground(Color.PINK);
101
-    popups.put(component, createPopupRelativeTo(component));
102
-    glassPane.setVisible(true);
105
+    JPanel panel = createPopupRelativeTo(component);
106
+    popups.put(component, panel);
107
+    panel.setVisible(true);
103 108
   }
104 109
 
105 110
   @Override
@@ -109,6 +114,5 @@ public class FormValidationSwingDecorator extends AbstractFormValidationDecorato
109 114
     if (panel != null){
110 115
       panel.setVisible(false);
111 116
     }
112
-    glassPane.setVisible(false);
113 117
   }
114 118
 }