Просмотр исходного кода

Tagged 1.1 beta1, the version presented at JFokus.

peter_backlund 17 лет назад
Родитель
Сommit
12642a1e87

+ 0
- 34
register-app/assembly.xml Просмотреть файл

@@ -1,34 +0,0 @@
1
-<?xml version="1.0"?>
2
-
3
-<assembly xmlns="http://maven.apache.org/POM/4.0.0"
4
-          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.0-SNAPSHOT.xsd">
6
-
7
-    <formats>
8
-        <format>zip</format>
9
-    </formats>
10
-    <includeBaseDirectory>true</includeBaseDirectory>
11
-  
12
-    <files>
13
-        <file>
14
-            <source>src/main/resources/app.properties</source>
15
-            <destName>app.properties</destName>
16
-        </file>
17
-    </files>
18
-
19
-    <dependencySets>
20
-      <dependencySet>
21
-        <excludes>
22
-          <exclude>se.citerus:register-app</exclude>
23
-        </excludes>
24
-        <outputDirectory>lib</outputDirectory>
25
-      </dependencySet>
26
-      <dependencySet>
27
-        <includes>
28
-          <include>se.citerus:register-app</include>
29
-        </includes>
30
-        <outputFileNameMapping>IncidentLoggingApplication.${artifact.extension}</outputFileNameMapping>
31
-      </dependencySet>
32
-    </dependencySets>
33
-
34
-</assembly>

+ 0
- 98
register-app/pom.xml Просмотреть файл

@@ -1,98 +0,0 @@
1
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
-
3
-  <modelVersion>4.0.0</modelVersion>
4
-  <groupId>se.citerus</groupId>
5
-  <artifactId>register-app</artifactId>
6
-  <name>register-app</name>
7
-  <version>1.1-SNAPSHOT</version>
8
-  <url>http://dddsample.sf.net</url>
9
-  <scm>
10
-    <developerConnection>scm:svn:https://dddsample.svn.sourceforge.net/svnroot/dddsample</developerConnection>
11
-  </scm>
12
-  <build>
13
-    <plugins>
14
-      <plugin>
15
-        <artifactId>maven-compiler-plugin</artifactId>
16
-        <configuration>
17
-          <source>1.5</source>
18
-          <target>1.5</target>
19
-          <encoding>UTF-8</encoding>
20
-        </configuration>
21
-      </plugin>
22
-      <plugin>
23
-        <artifactId>maven-jar-plugin</artifactId>
24
-        <configuration>
25
-          <archive>
26
-            <manifest>
27
-              <mainClass>se.citerus.App</mainClass>
28
-              <addClasspath>true</addClasspath>
29
-              <classpathPrefix>lib</classpathPrefix>
30
-            </manifest>
31
-          </archive>
32
-        </configuration>
33
-      </plugin>
34
-      <plugin>
35
-        <artifactId>maven-assembly-plugin</artifactId>
36
-        <configuration>
37
-          <descriptors>
38
-            <descriptor>assembly.xml</descriptor>
39
-          </descriptors>
40
-          <finalName>IncidentLoggingApplication</finalName>
41
-        </configuration>
42
-      </plugin>
43
-    </plugins>
44
-  </build>
45
-  <repositories>
46
-    <repository>
47
-      <id>maven2-repository.dev.java.net</id>
48
-      <name>Java.net Repository for Maven</name>
49
-      <url>http://download.java.net/maven/2/</url>
50
-    </repository>
51
-  </repositories>
52
-  <pluginRepositories>
53
-    <pluginRepository>
54
-      <id>maven2-repository.dev.java.net</id>
55
-      <name>Java.net Repository for Maven</name>
56
-      <url>http://download.java.net/maven/2/</url>
57
-    </pluginRepository>
58
-  </pluginRepositories>
59
-  <dependencies>
60
-    <dependency>
61
-      <groupId>junit</groupId>
62
-      <artifactId>junit</artifactId>
63
-      <version>3.8.1</version>
64
-      <scope>test</scope>
65
-    </dependency>
66
-    <dependency>
67
-      <groupId>org.springframework</groupId>
68
-      <artifactId>spring-context</artifactId>
69
-      <version>2.5.6</version>
70
-    </dependency>
71
-    <dependency>
72
-      <groupId>org.springframework</groupId>
73
-      <artifactId>spring-web</artifactId>
74
-      <version>2.5.6</version>
75
-    </dependency>
76
-    <dependency>
77
-      <groupId>org.springframework</groupId>
78
-      <artifactId>spring-aop</artifactId>
79
-      <version>2.5.6</version>
80
-    </dependency>
81
-    <dependency>
82
-      <groupId>com.jgoodies</groupId>
83
-      <artifactId>forms</artifactId>
84
-      <version>1.0.7</version>
85
-    </dependency>
86
-    <dependency>
87
-      <groupId>com.jgoodies</groupId>
88
-      <artifactId>looks</artifactId>
89
-      <version>2.1.2</version>
90
-    </dependency>
91
-    <dependency>
92
-      <groupId>se.citerus</groupId>
93
-      <artifactId>dddsample</artifactId>
94
-      <version>1.1-SNAPSHOT</version>
95
-      <classifier>ws-client</classifier>
96
-    </dependency>
97
-  </dependencies>
98
-</project>

+ 0
- 40
register-app/src/main/java/se/citerus/App.java Просмотреть файл

@@ -1,40 +0,0 @@
1
-package se.citerus;
2
-
3
-import org.springframework.context.ApplicationContext;
4
-import org.springframework.context.support.ClassPathXmlApplicationContext;
5
-
6
-import se.citerus.registerapp.RegisterApp;
7
-
8
-/**
9
- * The application main class
10
- *
11
- */
12
-public class App {
13
-  private static RegisterApp app;
14
-  
15
-  public static void main(String[] args) {
16
-    app = getRegisterApp();
17
-    
18
-    //Schedule a job for the event-dispatching thread:
19
-    //creating and showing this application's GUI.
20
-    javax.swing.SwingUtilities.invokeLater(new Runnable() {
21
-        public void run() {
22
-            app.show();
23
-        }
24
-    });
25
-  }
26
-
27
-  private static RegisterApp getRegisterApp() {
28
-    return (RegisterApp)getBean("registerApp");
29
-  }
30
-
31
-  public static Object getBean(String bean){
32
-    ApplicationContext context = getContext(); 
33
-
34
-    return context.getBean(bean);
35
-}
36
-
37
-public static ClassPathXmlApplicationContext getContext() {
38
-    return new ClassPathXmlApplicationContext(new String[] {"context-app.xml"});
39
-}
40
-}

+ 0
- 256
register-app/src/main/java/se/citerus/registerapp/RegisterApp.java Просмотреть файл

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

+ 0
- 14
register-app/src/main/java/se/citerus/registerapp/service/HandlingEventService.java Просмотреть файл

@@ -1,14 +0,0 @@
1
-package se.citerus.registerapp.service;
2
-
3
-public interface HandlingEventService {
4
-  /**
5
-   * Register an cargo handling event.
6
-   *
7
-   * @param completionTime time when event occured, for example a the loading of cargo was completed
8
-   * @param trackingId tracking id of the cargo
9
-   * @param carrierMovementId carrier movement id, if applicable
10
-   * @param unlocode United Nations Location Code for the location where the event occured
11
-   * @param eventType type of event
12
-   */
13
-  void register(String completionTime, String trackingId, String carrierMovementId, String unlocode, String eventType);
14
-}

+ 0
- 41
register-app/src/main/java/se/citerus/registerapp/validation/AbstractFormValidationDecorator.java Просмотреть файл

@@ -1,41 +0,0 @@
1
-package se.citerus.registerapp.validation;
2
-
3
-import java.awt.event.KeyEvent;
4
-import java.awt.event.KeyListener;
5
-import java.util.HashMap;
6
-import java.util.Map.Entry;
7
-
8
-import javax.swing.JComponent;
9
-
10
-public abstract class AbstractFormValidationDecorator implements FormValidationDecorator{
11
-  private HashMap<JComponent, ComponentValidator> validators = new HashMap<JComponent, ComponentValidator>();
12
-
13
-  public void add(final JComponent component, ComponentValidator validator) {
14
-    this.validators.put(component, validator);
15
-
16
-    component.addKeyListener(new KeyListener(){
17
-      public void keyPressed(KeyEvent e) {
18
-        for (final Entry<JComponent, ComponentValidator> entry : validators.entrySet()) {
19
-          undecorate(entry.getKey());
20
-        }
21
-      }
22
-
23
-      public void keyReleased(KeyEvent e) {}
24
-      public void keyTyped(KeyEvent e) {}
25
-    });
26
-  }
27
-
28
-  public boolean validate() {
29
-    boolean allValidated = true;
30
-    for (final Entry<JComponent, ComponentValidator> entry : validators.entrySet()) {
31
-      if (!entry.getValue().validate(entry.getKey())){
32
-        decorate(entry.getKey(), entry.getValue());
33
-        allValidated = false;
34
-      }
35
-    }
36
-    return allValidated;
37
-  }
38
-  
39
-  public abstract void decorate(JComponent component, ComponentValidator validator);
40
-  public abstract void undecorate(JComponent component);
41
-}

+ 0
- 96
register-app/src/main/java/se/citerus/registerapp/validation/AbstractValidator.java Просмотреть файл

@@ -1,96 +0,0 @@
1
-package se.citerus.registerapp.validation;
2
-
3
-import java.awt.Color;
4
-import java.awt.FlowLayout;
5
-import java.awt.event.KeyEvent;
6
-import java.awt.event.KeyListener;
7
-
8
-import javax.swing.ImageIcon;
9
-import javax.swing.InputVerifier;
10
-import javax.swing.JComponent;
11
-import javax.swing.JFrame;
12
-import javax.swing.JLabel;
13
-import javax.swing.JPanel;
14
-
15
-public abstract class AbstractValidator extends InputVerifier implements KeyListener{
16
-  private static final Color ERROR_COMPONENT_COLOR = Color.PINK;
17
-  private static final Color POPUP_COLOR = new Color(243, 255, 159);
18
-  private JPanel popup;
19
-  private JLabel messageLabel = new JLabel();;
20
-  private JLabel image = new JLabel();
21
-  private JFrame parent;
22
-  private String message;;
23
-
24
-  
25
-  
26
-  public AbstractValidator(String message) {
27
-    this.message = message;
28
-  }
29
-  
30
-  public String getMessage(){
31
-    return message;
32
-  }
33
-
34
-  public AbstractValidator(JFrame parent, JComponent c, String message) {
35
-    c.addKeyListener(this);
36
-    popup = new JPanel();
37
-    this.parent = parent;
38
-    messageLabel = new JLabel(message + " ");
39
-    image = new JLabel(new ImageIcon("/icon/error_16x16.png"));
40
-    initComponents();
41
-  }
42
-
43
-  /**
44
-   * Implement the actual validation logic in this method. The method should
45
-   * return false if data is invalid and true if it is valid.
46
-   * 
47
-   * @param c The JComponent to be validated.
48
-   * @return false if data is invalid. true if it is valid.
49
-   */
50
-  protected abstract boolean validate(JComponent c);
51
-
52
-  @Override
53
-  public boolean verify(JComponent component) {
54
-    if (!validate(component)) {
55
-
56
-//      
57
-//      Dimension compSize = component.getSize();
58
-//      Point compPos = popup.getLocation();
59
-//      
60
-//      component.setBackground(ERROR_COMPONENT_COLOR);
61
-//
62
-//      popup.setLocation(
63
-//          compPos.x - (int) compSize.getWidth() / 2, 
64
-//          compPos.y + (int) compSize.getHeight() / 2);
65
-      
66
-      parent.setGlassPane(popup);
67
-      component.setBackground(ERROR_COMPONENT_COLOR);
68
-      popup.setVisible(true);
69
-      return false;
70
-    } else {
71
-      component.setBackground(Color.WHITE);
72
-      return true;
73
-    }
74
-  }
75
-
76
-  public void keyPressed(KeyEvent e) {
77
-    popup.setVisible(false);    
78
-  }
79
-
80
-  public void keyReleased(KeyEvent e) {}
81
-
82
-  public void keyTyped(KeyEvent e) {}
83
-  
84
-  
85
-  private void initComponents() {
86
-    popup.setLayout(new FlowLayout());
87
-//    popup.setUndecorated(true);
88
-    popup.setBackground(POPUP_COLOR);
89
-    popup.add(image);
90
-    popup.add(messageLabel);
91
-//    popup.setOpaque(false);
92
-//    popup.setFocusableWindowState(false);
93
-  }
94
-
95
-
96
-}

+ 0
- 8
register-app/src/main/java/se/citerus/registerapp/validation/ComponentValidator.java Просмотреть файл

@@ -1,8 +0,0 @@
1
-package se.citerus.registerapp.validation;
2
-
3
-import javax.swing.JComponent;
4
-
5
-public interface ComponentValidator {
6
-  boolean validate(JComponent c);
7
-  String getMessage();
8
-}

+ 0
- 13
register-app/src/main/java/se/citerus/registerapp/validation/FormValidationDecorator.java Просмотреть файл

@@ -1,13 +0,0 @@
1
-package se.citerus.registerapp.validation;
2
-
3
-import javax.swing.JComponent;
4
-
5
-
6
-public interface FormValidationDecorator {
7
-
8
-  void add(final JComponent component, ComponentValidator validator);
9
-
10
-  boolean validate();
11
-
12
-  
13
-}

+ 0
- 118
register-app/src/main/java/se/citerus/registerapp/validation/FormValidationSwingDecorator.java Просмотреть файл

@@ -1,118 +0,0 @@
1
-package se.citerus.registerapp.validation;
2
-
3
-import java.awt.Color;
4
-import java.awt.Dimension;
5
-import java.awt.FlowLayout;
6
-import java.awt.Point;
7
-import java.util.HashMap;
8
-
9
-import javax.swing.ImageIcon;
10
-import javax.swing.JComponent;
11
-import javax.swing.JFrame;
12
-import javax.swing.JLabel;
13
-import javax.swing.JPanel;
14
-
15
-public class FormValidationSwingDecorator extends AbstractFormValidationDecorator{
16
-
17
-  private static final int POPUP_Y_OFFSET = 0;
18
-  private static final int POPUP_X_OFFSET = 12;
19
-  private Color oldColor = Color.WHITE;
20
-  private JFrame form;
21
-  private String message;
22
-  private HashMap<JComponent, JPanel> popups = new HashMap<JComponent, JPanel>();
23
-  private JPanel glassPane = new JPanel();
24
-
25
-  public FormValidationSwingDecorator(JFrame form) {
26
-    assert form != null : "Can't decorate null frame";
27
-    
28
-    this.form = form;
29
-    glassPane.setOpaque(false);
30
-    glassPane.setVisible(false);
31
-    glassPane.setLayout(null);
32
-//    glassPane.setPreferredSize(form.getPreferredSize());
33
-    glassPane.setSize(form.getSize());
34
-    
35
-    form.setGlassPane(glassPane);
36
-    
37
-    
38
-  }
39
-
40
-  public FormValidationSwingDecorator(JFrame form, String message) {
41
-    this(form);
42
-    
43
-    this.message = message;
44
-  }
45
-
46
-  private JPanel createPopupRelativeTo(JComponent component) {
47
-    JPanel popupPane = null;
48
-    
49
-    if (popups.containsKey(component)){
50
-      popupPane = popups.get(component);
51
-    } else {
52
-      popupPane = new JPanel(new FlowLayout());
53
-      glassPane.add(popupPane);
54
-      glassPane.setVisible(true);
55
-      
56
-      popupPane.add(getIconLabel());
57
-      popupPane.add(getMessageLabel());
58
-      popupPane.setLocation(getPopupPositionRelativeTo(component));
59
-      popupPane.setVisible(true);
60
-      popupPane.setOpaque(false);
61
-      popupPane.validate();
62
-      popupPane.setSize(popupPane.getPreferredSize());
63
-     
64
-    }
65
-    
66
-    return popupPane;
67
-  }
68
-
69
-  private Point getPopupPositionRelativeTo(JComponent component) {
70
-    Point compPos = component.getLocation();
71
-    Dimension compDim = component.getSize();
72
-    Point popupPos = new Point(compPos.x + POPUP_X_OFFSET, compPos.y + compDim.height + POPUP_Y_OFFSET);
73
-    
74
-    System.out.println("Comp pos: " + compPos + " - Popup pos: " + popupPos);
75
-    return popupPos;
76
-  }
77
-
78
-  private JLabel getMessageLabel() {
79
-    JLabel label = new JLabel(message != null ? message : "");
80
-    label.setOpaque(false);
81
-    return label;
82
-  }
83
-
84
-  private JLabel getIconLabel() {
85
-    JLabel label = new JLabel();
86
-    
87
-    java.net.URL imageURL = this.getClass().getResource("/icon/error_16x16.png");
88
-    if (imageURL != null){
89
-      ImageIcon icon = new ImageIcon(imageURL);
90
-      label.setIcon(icon);
91
-    } else {
92
-      System.out.println("No icon found");
93
-    }
94
-    
95
-    
96
-    label.setOpaque(false);
97
-    return label;
98
-  }
99
-  
100
-  @Override
101
-  public void decorate(JComponent component, ComponentValidator validator) {
102
-    this.message = validator.getMessage();
103
-    this.oldColor = component.getBackground();
104
-    component.setBackground(Color.PINK);
105
-    JPanel panel = createPopupRelativeTo(component);
106
-    popups.put(component, panel);
107
-    panel.setVisible(true);
108
-  }
109
-
110
-  @Override
111
-  public void undecorate(JComponent component) {
112
-    component.setBackground(oldColor);
113
-    JPanel panel = popups.get(component);
114
-    if (panel != null){
115
-      panel.setVisible(false);
116
-    }
117
-  }
118
-}

+ 0
- 25
register-app/src/main/java/se/citerus/registerapp/validation/MandatoryTextFieldValidator.java Просмотреть файл

@@ -1,25 +0,0 @@
1
-package se.citerus.registerapp.validation;
2
-
3
-import javax.swing.JComponent;
4
-import javax.swing.JTextField;
5
-
6
-public class MandatoryTextFieldValidator implements ComponentValidator {
7
-  private String message;
8
-
9
-  public MandatoryTextFieldValidator(String message) {
10
-    this.message = message;
11
-  }
12
-
13
-  public boolean validate(JComponent c) {
14
-    JTextField field = (JTextField) c;
15
-    
16
-    boolean valid = !"".equals(field.getText());
17
-    
18
-    return valid;
19
-  }
20
-
21
-  public String getMessage() {
22
-    return message;
23
-  }
24
-
25
-}

+ 0
- 1
register-app/src/main/resources/app.properties Просмотреть файл

@@ -1 +0,0 @@
1
-wsdl.url=http://localhost:8080/dddsample/ws/RegisterEvent?wsdl

+ 0
- 32
register-app/src/main/resources/context-app.xml Просмотреть файл

@@ -1,32 +0,0 @@
1
-<?xml version="1.0"?>
2
-
3
-<beans xmlns="http://www.springframework.org/schema/beans"
4
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6
-
7
-  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
8
-    <property name="locations" value="file:app.properties"/>
9
-    <property name="order" value="1"/>
10
-    <property name="ignoreResourceNotFound" value="true"/>
11
-    <property name="ignoreUnresolvablePlaceholders" value="true"/>
12
-  </bean>
13
-
14
-  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
15
-    <property name="locations" value="classpath:app.properties"/>
16
-    <property name="order" value="2"/>
17
-  </bean>
18
-
19
-  <bean id="registerApp" class="se.citerus.registerapp.RegisterApp">
20
-    <property name="handlingReportService" ref="handlingReportService"/>
21
-    <property name="debugUI" value="false" />
22
-  </bean>
23
-
24
-  <bean id="handlingReportService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
25
-    <property name="serviceInterface" value="se.citerus.dddsample.interfaces.handling.ws.HandlingReportService" />
26
-    <property name="wsdlDocumentUrl" value="${wsdl.url}" />
27
-    <property name="namespaceUri" value="http://impl.ws.handling.interfaces.dddsample.citerus.se/" />
28
-    <property name="serviceName" value="HandlingReportServiceImplService" />
29
-    <property name="portName" value="HandlingReportServiceImplPort" />
30
-  </bean>
31
-
32
-</beans>

Двоичные данные
register-app/src/main/resources/icon/error_16x16.png Просмотреть файл


+ 0
- 23
register-app/src/main/resources/log4j.properties Просмотреть файл

@@ -1,23 +0,0 @@
1
-# For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!
2
-# For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.
3
-log4j.rootLogger=info, stdout, logfile
4
-
5
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
6
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
7
-log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
8
-
9
-log4j.appender.logfile=org.apache.log4j.RollingFileAppender
10
-log4j.appender.logfile.File=${java.io.tmpdir}/registration-app.log
11
-log4j.appender.logfile.MaxFileSize=512KB
12
-# Keep three backup files.
13
-log4j.appender.logfile.MaxBackupIndex=3
14
-# Pattern to output: date priority [category] - message
15
-log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
16
-log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
17
-
18
-log4j.logger.se.citerus.dddsample=debug
19
-log4j.logger.net.sf.ehcache.config.ConfigurationFactory=error
20
-log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=debug
21
-
22
-#log4j.logger.org.springframework.orm=debug
23
-#log4j.logger.org.springframework.transaction=debug

+ 0
- 38
register-app/src/test/java/se/citerus/AppTest.java Просмотреть файл

@@ -1,38 +0,0 @@
1
-package se.citerus;
2
-
3
-import junit.framework.Test;
4
-import junit.framework.TestCase;
5
-import junit.framework.TestSuite;
6
-
7
-/**
8
- * Unit test for simple App.
9
- */
10
-public class AppTest 
11
-    extends TestCase
12
-{
13
-    /**
14
-     * Create the test case
15
-     *
16
-     * @param testName name of the test case
17
-     */
18
-    public AppTest( String testName )
19
-    {
20
-        super( testName );
21
-    }
22
-
23
-    /**
24
-     * @return the suite of tests being tested
25
-     */
26
-    public static Test suite()
27
-    {
28
-        return new TestSuite( AppTest.class );
29
-    }
30
-
31
-    /**
32
-     * Rigourous Test :-)
33
-     */
34
-    public void testApp()
35
-    {
36
-        assertTrue( true );
37
-    }
38
-}

+ 0
- 120
register-app/src/test/java/se/citerus/registerapp/validation/ValidationTest.java Просмотреть файл

@@ -1,120 +0,0 @@
1
-package se.citerus.registerapp.validation;
2
-
3
-import java.awt.event.ActionEvent;
4
-import java.awt.event.ActionListener;
5
-
6
-import javax.swing.JButton;
7
-import javax.swing.JComponent;
8
-import javax.swing.JFrame;
9
-import javax.swing.JTextField;
10
-
11
-import junit.framework.TestCase;
12
-
13
-public class ValidationTest extends TestCase {
14
-  private boolean actionPerformed;
15
-
16
-  public void testValidationScenario() throws Exception {
17
-    JFrame frame = new JFrame();
18
-    
19
-    final FormValidationDecorator validationDecorator = new FormValidationSwingDecorator(frame);
20
-    
21
-    JTextField field1 = new JTextField();
22
-    JTextField field2 = new JTextField();
23
-    JButton button = new JButton();
24
-    frame.add(field1);
25
-    frame.add(field2);
26
-    frame.add(button);
27
-    
28
-    
29
-    ValidatorMock validator1 = createValidator("No Way!", true);
30
-    validationDecorator.add(field1, validator1);
31
-    
32
-    ValidatorMock validator2 = createValidator("My Way!", true);
33
-    validationDecorator.add(field2, validator2);
34
-    
35
-   button.addActionListener(new ActionListener(){
36
-    public void actionPerformed(ActionEvent e) {
37
-      if (validationDecorator.validate()){
38
-        onAction();
39
-      }
40
-    }
41
-   });
42
-   
43
-   
44
-   
45
-   field1.setText("Field1");
46
-   field2.setText("");
47
-   button.doClick();
48
-   assertTrue("Field1 not validated", validator1.isValidated());
49
-   assertTrue("Field2 not validated", validator2.isValidated());
50
-   assertTrue("Button action not performed", actionPerformed);
51
-  }
52
-  
53
-  public void testValidationFailure() throws Exception {
54
-    JFrame frame = new JFrame();
55
-    final FormValidationDecorator validator = new FormValidationSwingDecorator(frame);
56
-    
57
-    JTextField field1 = new JTextField();
58
-    JTextField field2 = new JTextField();
59
-    JButton button = new JButton();
60
-    frame.add(field1);
61
-    frame.add(field2);
62
-    frame.add(button);
63
-    
64
-    ValidatorMock validator1 = createValidator("No Way!", true);
65
-    validator.add(field1, validator1);
66
-    
67
-    ValidatorMock validator2 = createValidator("My Way!", false);
68
-    validator.add(field2, validator2);
69
-    
70
-   button.addActionListener(new ActionListener(){
71
-    public void actionPerformed(ActionEvent e) {
72
-      if (validator.validate()){
73
-        onAction();
74
-      }
75
-    }
76
-   });
77
-   
78
-   field1.setText("Field1");
79
-   field2.setText("");
80
-   button.doClick();
81
-   assertTrue("Field1 not validated", validator1.isValidated());
82
-   assertTrue("Field2 not validated", validator2.isValidated());
83
-   assertFalse("Button action should not be performed", actionPerformed);
84
-  }
85
-  
86
-
87
-  private ValidatorMock createValidator(String message, boolean result) {
88
-    return new ValidatorMock(message, result);
89
-  }
90
-
91
-  protected void onAction() {
92
-    this.actionPerformed = true;
93
-    // Do some action...
94
-  }
95
-  
96
-  private static final class ValidatorMock implements ComponentValidator{
97
-    private final boolean result;
98
-    private boolean validated;
99
-    private String message;
100
-    
101
-    public ValidatorMock(String message, boolean result) {
102
-      this.message = message;
103
-      this.result = result;
104
-    }
105
-
106
-    public boolean validate(JComponent c) {
107
-      validated = true;
108
-      return result;
109
-    }
110
-
111
-    public boolean isValidated() {
112
-      return validated;
113
-    }
114
-
115
-    public String getMessage() {
116
-      return message;
117
-    }
118
-    
119
-  }
120
-}

+ 0
- 2
register-app/startApp.sh Просмотреть файл

@@ -1,2 +0,0 @@
1
-#!/bin/sh
2
-java -classpath .:target/register-app-1.0-SNAPSHOT-jar-with-dependencies.jar se.citerus.App