|
|
@@ -6,7 +6,9 @@ import java.awt.Dimension;
|
|
6
|
6
|
import java.awt.event.ActionEvent;
|
|
7
|
7
|
import java.awt.event.ActionListener;
|
|
8
|
8
|
import java.text.SimpleDateFormat;
|
|
|
9
|
+import java.text.ParseException;
|
|
9
|
10
|
import java.util.Date;
|
|
|
11
|
+import java.util.GregorianCalendar;
|
|
10
|
12
|
|
|
11
|
13
|
import javax.swing.*;
|
|
12
|
14
|
import javax.swing.border.Border;
|
|
|
@@ -14,20 +16,25 @@ import javax.swing.border.CompoundBorder;
|
|
14
|
16
|
import javax.swing.border.LineBorder;
|
|
15
|
17
|
import javax.swing.plaf.basic.BasicBorders;
|
|
16
|
18
|
import javax.swing.text.DefaultFormatter;
|
|
|
19
|
+import javax.xml.datatype.XMLGregorianCalendar;
|
|
17
|
20
|
|
|
18
|
21
|
import se.citerus.registerapp.service.HandlingEventService;
|
|
19
|
22
|
import se.citerus.registerapp.validation.FormValidationDecorator;
|
|
20
|
23
|
import se.citerus.registerapp.validation.FormValidationSwingDecorator;
|
|
21
|
24
|
import se.citerus.registerapp.validation.MandatoryTextFieldValidator;
|
|
|
25
|
+import se.citerus.dddsample.interfaces.handling.ws.HandlingReportService;
|
|
|
26
|
+import se.citerus.dddsample.interfaces.handling.ws.HandlingReport;
|
|
|
27
|
+import se.citerus.dddsample.interfaces.handling.ws.HandlingReportErrors;
|
|
22
|
28
|
|
|
23
|
29
|
import com.jgoodies.forms.builder.DefaultFormBuilder;
|
|
24
|
30
|
import com.jgoodies.forms.debug.FormDebugPanel;
|
|
25
|
31
|
import com.jgoodies.forms.factories.ButtonBarFactory;
|
|
26
|
32
|
import com.jgoodies.forms.layout.FormLayout;
|
|
|
33
|
+import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl;
|
|
27
|
34
|
|
|
28
|
35
|
public class RegisterApp {
|
|
29
|
36
|
private static final DefaultFormatter DEFAULT_FORMATTER = new DefaultFormatter();
|
|
30
|
|
- private static final SimpleDateFormat ISO8601_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:MM:SS.SSS");
|
|
|
37
|
+ private static final SimpleDateFormat ISO8601_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
|
31
|
38
|
private static final String TITLE = "Incident Logging Application";
|
|
32
|
39
|
private JFrame frame;
|
|
33
|
40
|
private JFormattedTextField completionTimeField;
|
|
|
@@ -37,31 +44,38 @@ public class RegisterApp {
|
|
37
|
44
|
//private JFormattedTextField eventTypeField;
|
|
38
|
45
|
private JComboBox eventTypeField;
|
|
39
|
46
|
private JButton registerButton;
|
|
40
|
|
-
|
|
41
|
|
- private HandlingEventService handlingEventService;
|
|
|
47
|
+
|
|
|
48
|
+ private HandlingReportService handlingReportService;
|
|
42
|
49
|
private boolean debugUI;
|
|
43
|
50
|
private FormValidationDecorator validator;
|
|
44
|
51
|
|
|
45
|
52
|
|
|
46
|
|
-
|
|
47
|
|
- /////////////////////////////////////////////////////////////////////////////
|
|
|
53
|
+ /////////////////////////////////////////////////////////////////////////////
|
|
48
|
54
|
// GUI EVENT HANDLING
|
|
49
|
55
|
/////////////////////////////////////////////////////////////////////////////
|
|
50
|
56
|
protected void onRegister(){
|
|
51
|
|
- assert handlingEventService != null : "No HandlingEventService available";
|
|
52
|
|
-
|
|
53
|
|
- handlingEventService.register(ISO8601_DATE_FORMAT.format(completionTimeField.getValue()),
|
|
54
|
|
- getStringValue(trackingIdField),
|
|
55
|
|
- getStringValue(carrierMovementField),
|
|
56
|
|
- getStringValue(locationField),
|
|
57
|
|
- getStringValue(eventTypeField).toUpperCase());
|
|
58
|
|
-
|
|
59
|
|
- clearForm();
|
|
|
57
|
+ assert handlingReportService != null : "No HandlingEventService available";
|
|
|
58
|
+
|
|
|
59
|
+ try {
|
|
|
60
|
+ final HandlingReport report = new HandlingReport();
|
|
|
61
|
+ final GregorianCalendar completionTime = new GregorianCalendar();
|
|
|
62
|
+ completionTime.setTime((Date) completionTimeField.getValue());
|
|
|
63
|
+ report.setCompletionTime(new XMLGregorianCalendarImpl(completionTime));
|
|
|
64
|
+ report.setTrackingIds(new String[] {getStringValue(trackingIdField)});
|
|
|
65
|
+ report.setType(getStringValue(eventTypeField).toUpperCase());
|
|
|
66
|
+ report.setUnLocode(getStringValue(locationField));
|
|
|
67
|
+ report.setVoyageNumber(getStringValue(carrierMovementField));
|
|
|
68
|
+
|
|
|
69
|
+ handlingReportService.submitReport(report);
|
|
|
70
|
+ clearForm();
|
|
|
71
|
+ } catch (HandlingReportErrors handlingReportErrors) {
|
|
|
72
|
+ System.err.println(handlingReportErrors.getMessage());
|
|
|
73
|
+ }
|
|
60
|
74
|
}
|
|
61
|
75
|
|
|
62
|
76
|
private String getStringValue(JComboBox comboBox) {
|
|
63
|
77
|
Object value = comboBox.getSelectedItem();
|
|
64
|
|
-
|
|
|
78
|
+
|
|
65
|
79
|
if (value != null) {
|
|
66
|
80
|
return value.toString();
|
|
67
|
81
|
} else {
|
|
|
@@ -72,15 +86,15 @@ public class RegisterApp {
|
|
72
|
86
|
|
|
73
|
87
|
private String getStringValue(JFormattedTextField formattedTextField) {
|
|
74
|
88
|
Object value = formattedTextField.getValue();
|
|
75
|
|
-
|
|
|
89
|
+
|
|
76
|
90
|
if (value != null) {
|
|
77
|
91
|
return value.toString();
|
|
78
|
92
|
} else {
|
|
79
|
93
|
return null;
|
|
80
|
94
|
}
|
|
81
|
95
|
}
|
|
82
|
|
-
|
|
83
|
|
-
|
|
|
96
|
+
|
|
|
97
|
+
|
|
84
|
98
|
/////////////////////////////////////////////////////////////////////////////
|
|
85
|
99
|
// PUBLIC API
|
|
86
|
100
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
@@ -90,25 +104,25 @@ public class RegisterApp {
|
|
90
|
104
|
} catch (Exception e) {
|
|
91
|
105
|
// Likely PlasticXP is not in the class path; ignore.
|
|
92
|
106
|
}
|
|
93
|
|
-
|
|
|
107
|
+
|
|
94
|
108
|
initComponents();
|
|
95
|
109
|
JComponent panel = createMainPanel();
|
|
96
|
|
-
|
|
97
|
|
-
|
|
|
110
|
+
|
|
|
111
|
+
|
|
98
|
112
|
frame = createFrame(panel);
|
|
99
|
113
|
frame.pack();
|
|
100
|
114
|
centerOnScreen(frame);
|
|
101
|
|
-
|
|
|
115
|
+
|
|
102
|
116
|
initValidation(frame);
|
|
103
|
|
-
|
|
|
117
|
+
|
|
104
|
118
|
frame.setVisible(true);
|
|
105
|
|
-
|
|
|
119
|
+
|
|
106
|
120
|
clearForm();
|
|
107
|
121
|
}
|
|
108
|
122
|
|
|
109
|
123
|
|
|
110
|
|
- public void setHandlingEventService(HandlingEventService handlingEventService) {
|
|
111
|
|
- this.handlingEventService = handlingEventService;
|
|
|
124
|
+ public void setHandlingReportService(HandlingReportService handlingReportService) {
|
|
|
125
|
+ this.handlingReportService = handlingReportService;
|
|
112
|
126
|
}
|
|
113
|
127
|
|
|
114
|
128
|
public void setDebugUI(boolean on){
|
|
|
@@ -129,14 +143,14 @@ public class RegisterApp {
|
|
129
|
143
|
public static Border getMandatoryBorder() {
|
|
130
|
144
|
return new CompoundBorder(new LineBorder(Color.RED), new BasicBorders.MarginBorder());
|
|
131
|
145
|
}
|
|
132
|
|
-
|
|
|
146
|
+
|
|
133
|
147
|
private void initComponents(){
|
|
134
|
148
|
completionTimeField = new JFormattedTextField(ISO8601_DATE_FORMAT);
|
|
135
|
149
|
trackingIdField = new JFormattedTextField(DEFAULT_FORMATTER);
|
|
136
|
150
|
carrierMovementField = new JFormattedTextField(DEFAULT_FORMATTER);
|
|
137
|
151
|
locationField = new JFormattedTextField(DEFAULT_FORMATTER);
|
|
138
|
152
|
eventTypeField = new JComboBox(new String[] {"-- Select --","Receive","Load","Unload","Customs","Claim"});
|
|
139
|
|
-
|
|
|
153
|
+
|
|
140
|
154
|
registerButton = new JButton("Register");
|
|
141
|
155
|
registerButton.addActionListener(new ActionListener(){
|
|
142
|
156
|
public void actionPerformed(ActionEvent e) {
|
|
|
@@ -149,20 +163,20 @@ public class RegisterApp {
|
|
149
|
163
|
|
|
150
|
164
|
/**
|
|
151
|
165
|
* We need to do initialization of validators after the components and their parent frame has been initialized.
|
|
152
|
|
- * @param frame
|
|
153
|
|
- *
|
|
|
166
|
+ * @param frame
|
|
|
167
|
+ *
|
|
154
|
168
|
*/
|
|
155
|
169
|
private void initValidation(JFrame frame){
|
|
156
|
170
|
validator = new FormValidationSwingDecorator(frame);
|
|
157
|
|
-
|
|
|
171
|
+
|
|
158
|
172
|
validator.add(trackingIdField, new MandatoryTextFieldValidator("Tracking id can't be empty"));
|
|
159
|
173
|
validator.add(locationField, new MandatoryTextFieldValidator("Location can't be empty"));
|
|
160
|
174
|
}
|
|
161
|
|
-
|
|
162
|
|
-
|
|
|
175
|
+
|
|
|
176
|
+
|
|
163
|
177
|
/**
|
|
164
|
178
|
* Center a component on the screen.
|
|
165
|
|
- *
|
|
|
179
|
+ *
|
|
166
|
180
|
* @param component the component to be centered
|
|
167
|
181
|
*/
|
|
168
|
182
|
|
|
|
@@ -181,18 +195,18 @@ public class RegisterApp {
|
|
181
|
195
|
f.setTitle(TITLE);
|
|
182
|
196
|
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
|
183
|
197
|
f.getContentPane().add(panel);
|
|
184
|
|
-
|
|
|
198
|
+
|
|
185
|
199
|
return f;
|
|
186
|
200
|
}
|
|
187
|
201
|
|
|
188
|
202
|
private JComponent createMainPanel() {
|
|
189
|
203
|
JComponent fieldPanel = createFieldPanel();
|
|
190
|
204
|
JComponent buttonPanel = createButtonPanel();
|
|
191
|
|
-
|
|
|
205
|
+
|
|
192
|
206
|
DefaultFormBuilder mainBuilder = createBuilder("p");
|
|
193
|
207
|
mainBuilder.append(fieldPanel);
|
|
194
|
208
|
mainBuilder.append(buttonPanel);
|
|
195
|
|
-
|
|
|
209
|
+
|
|
196
|
210
|
return mainBuilder.getPanel();
|
|
197
|
211
|
}
|
|
198
|
212
|
|
|
|
@@ -204,20 +218,20 @@ public class RegisterApp {
|
|
204
|
218
|
|
|
205
|
219
|
private JComponent createFieldPanel() {
|
|
206
|
220
|
DefaultFormBuilder builder = createBuilder("right:pref, 3dlu, 100dlu");
|
|
207
|
|
-
|
|
|
221
|
+
|
|
208
|
222
|
builder.appendSeparator("Completion");
|
|
209
|
223
|
builder.append("Time", completionTimeField); builder.nextLine();
|
|
210
|
|
-
|
|
|
224
|
+
|
|
211
|
225
|
builder.appendSeparator("Cargo");
|
|
212
|
226
|
builder.append("Tracking Id", trackingIdField); builder.nextLine();
|
|
213
|
|
-
|
|
|
227
|
+
|
|
214
|
228
|
builder.appendSeparator("Event");
|
|
215
|
|
- builder.append("Carrier Movement", carrierMovementField); builder.nextLine();
|
|
|
229
|
+ builder.append("Voyage", carrierMovementField); builder.nextLine();
|
|
216
|
230
|
builder.append("Location UN/Locode", locationField); builder.nextLine();
|
|
217
|
231
|
builder.append("Event Type", eventTypeField); builder.nextLine();
|
|
218
|
|
-
|
|
|
232
|
+
|
|
219
|
233
|
builder.appendSeparator("");
|
|
220
|
|
-
|
|
|
234
|
+
|
|
221
|
235
|
return builder.getPanel();
|
|
222
|
236
|
}
|
|
223
|
237
|
|
|
|
@@ -238,5 +252,5 @@ public class RegisterApp {
|
|
238
|
252
|
return new DefaultFormBuilder(layout);
|
|
239
|
253
|
}
|
|
240
|
254
|
}
|
|
241
|
|
-
|
|
|
255
|
+
|
|
242
|
256
|
}
|