Merge origin/master
[habeas.git] / src / habeas / DispatchDetailsDialog.java
1 /*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6 package habeas;
7
8 import java.util.Date;
9 import javax.swing.JOptionPane;
10
11 /**
12 *
13 * @author hari
14 */
15 public class DispatchDetailsDialog extends javax.swing.JDialog {
16
17 private int selected_id;
18
19 /**
20 * Creates new form DispatchDetailsDialog
21 */
22 public DispatchDetailsDialog(java.awt.Frame parent, boolean modal) {
23 super(parent, modal);
24 initComponents();
25 }
26
27 /**
28 * This method is called from within the constructor to initialize the form.
29 * WARNING: Do NOT modify this code. The content of this method is always
30 * regenerated by the Form Editor.
31 */
32 @SuppressWarnings("unchecked")
33 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
34 private void initComponents() {
35
36 checkNoticeSent = new javax.swing.JCheckBox();
37 dateSending = new org.jdesktop.swingx.JXDatePicker();
38 jLabel1 = new javax.swing.JLabel();
39 jLabel2 = new javax.swing.JLabel();
40 textRPADReference = new javax.swing.JTextField();
41 checkNoticeDelivered = new javax.swing.JCheckBox();
42 jLabel3 = new javax.swing.JLabel();
43 dateDelivery = new org.jdesktop.swingx.JXDatePicker();
44 buttonApply = new javax.swing.JButton();
45 buttonCancel = new javax.swing.JButton();
46
47 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
48 setTitle("Dispatch Details");
49 setLocationByPlatform(true);
50
51 checkNoticeSent.setText("Notice Sent");
52
53 jLabel1.setText("Date of sending");
54
55 jLabel2.setText("RPAD reference");
56
57 checkNoticeDelivered.setText("Notice delivered");
58
59 jLabel3.setText("Date of delivery");
60
61 buttonApply.setMnemonic('A');
62 buttonApply.setText("Apply");
63 buttonApply.addActionListener(new java.awt.event.ActionListener() {
64 public void actionPerformed(java.awt.event.ActionEvent evt) {
65 buttonApplyActionPerformed(evt);
66 }
67 });
68
69 buttonCancel.setMnemonic('c');
70 buttonCancel.setText("Cancel");
71 buttonCancel.addActionListener(new java.awt.event.ActionListener() {
72 public void actionPerformed(java.awt.event.ActionEvent evt) {
73 buttonCancelActionPerformed(evt);
74 }
75 });
76
77 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
78 getContentPane().setLayout(layout);
79 layout.setHorizontalGroup(
80 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
81 .addGroup(layout.createSequentialGroup()
82 .addContainerGap()
83 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
84 .addComponent(checkNoticeSent, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
85 .addComponent(checkNoticeDelivered, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
86 .addGroup(layout.createSequentialGroup()
87 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
88 .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
89 .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
90 .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 137, Short.MAX_VALUE))
91 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
92 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
93 .addComponent(dateSending, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
94 .addComponent(textRPADReference)
95 .addComponent(dateDelivery, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
96 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
97 .addGap(0, 0, Short.MAX_VALUE)
98 .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
99 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
100 .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)))
101 .addContainerGap())
102 );
103 layout.setVerticalGroup(
104 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
105 .addGroup(layout.createSequentialGroup()
106 .addContainerGap()
107 .addComponent(checkNoticeSent)
108 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
109 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
110 .addComponent(dateSending, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
111 .addComponent(jLabel1))
112 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
113 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
114 .addComponent(jLabel2)
115 .addComponent(textRPADReference, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
116 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
117 .addComponent(checkNoticeDelivered)
118 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
119 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
120 .addComponent(jLabel3)
121 .addComponent(dateDelivery, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
122 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
123 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
124 .addComponent(buttonApply)
125 .addComponent(buttonCancel))
126 .addContainerGap())
127 );
128
129 pack();
130 }// </editor-fold>//GEN-END:initComponents
131
132 private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed
133 // TODO add your handling code here:
134 dispose ();
135 }//GEN-LAST:event_buttonCancelActionPerformed
136
137 private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed
138 // TODO add your handling code here:
139 if (checkNoticeSent.isSelected() &&
140 ("".equals(textRPADReference.getText()) || dateSending.getDate() == null)) {
141 JOptionPane.showMessageDialog(this, MANDATORY_FIELDS_MISSING);
142 return;
143 }
144 if (checkNoticeDelivered.isSelected() && dateDelivery.getDate() == null) {
145 JOptionPane.showMessageDialog(this, MANDATORY_FIELDS_MISSING);
146 return;
147 }
148 boolean rt = Utility.updateNoticeDispatchDetails
149 (selected_id,checkNoticeSent.isSelected(), dateSending.getDate(),
150 textRPADReference.getText(),
151 checkNoticeDelivered.isSelected(), dateDelivery.getDate());
152 if (rt == false)
153 JOptionPane.showMessageDialog(this, ERROR_UPDATING);
154 else
155 dispose ();
156 }//GEN-LAST:event_buttonApplyActionPerformed
157 private static final String ERROR_UPDATING = "Error in updating";
158 private static final String MANDATORY_FIELDS_MISSING = "Mandatory fields missing!";
159
160 /**
161 * @param args the command line arguments
162 */
163 public static void main(String args[]) {
164 /* Set the Nimbus look and feel */
165 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
166 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
167 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
168 */
169 try {
170 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
171 if ("Nimbus".equals(info.getName())) {
172 javax.swing.UIManager.setLookAndFeel(info.getClassName());
173 break;
174 }
175 }
176 } catch (ClassNotFoundException ex) {
177 java.util.logging.Logger.getLogger(DispatchDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
178 } catch (InstantiationException ex) {
179 java.util.logging.Logger.getLogger(DispatchDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
180 } catch (IllegalAccessException ex) {
181 java.util.logging.Logger.getLogger(DispatchDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
182 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
183 java.util.logging.Logger.getLogger(DispatchDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
184 }
185 //</editor-fold>
186
187 /* Create and display the dialog */
188 java.awt.EventQueue.invokeLater(new Runnable() {
189 public void run() {
190 DispatchDetailsDialog dialog = new DispatchDetailsDialog(new javax.swing.JFrame(), true);
191 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
192 @Override
193 public void windowClosing(java.awt.event.WindowEvent e) {
194 System.exit(0);
195 }
196 });
197 dialog.setVisible(true);
198 }
199 });
200 }
201
202 // Variables declaration - do not modify//GEN-BEGIN:variables
203 private javax.swing.JButton buttonApply;
204 private javax.swing.JButton buttonCancel;
205 private javax.swing.JCheckBox checkNoticeDelivered;
206 private javax.swing.JCheckBox checkNoticeSent;
207 private org.jdesktop.swingx.JXDatePicker dateDelivery;
208 private org.jdesktop.swingx.JXDatePicker dateSending;
209 private javax.swing.JLabel jLabel1;
210 private javax.swing.JLabel jLabel2;
211 private javax.swing.JLabel jLabel3;
212 private javax.swing.JTextField textRPADReference;
213 // End of variables declaration//GEN-END:variables
214
215 void setFields(int selid, boolean notice_sent, Date sent_date,
216 String rpad_reference, boolean notice_delivered,
217 Date delivery_date) {
218 selected_id = selid;
219 checkNoticeSent.setSelected(notice_sent);
220 dateSending.setDate(sent_date);
221 checkNoticeDelivered.setSelected(notice_delivered);
222 textRPADReference.setText(rpad_reference);
223 dateDelivery.setDate(delivery_date);
224 }
225 }