5ccdb15c67df55366c86af68a710fd0687d30f50
[habeas.git] / src / habeas / ManageNoticesDialog.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.awt.Frame;
9 import java.awt.event.MouseAdapter;
10 import java.awt.event.MouseEvent;
11 import java.util.ArrayList;
12 import java.util.Date;
13 import javax.swing.JOptionPane;
14 import javax.swing.table.DefaultTableModel;
15
16 /**
17 *
18 * @author hari
19 */
20 public class ManageNoticesDialog extends javax.swing.JDialog {
21
22 /**
23 * Creates new form ManageNoticesDialog
24 */
25 public ManageNoticesDialog(java.awt.Frame parent, boolean modal) {
26 super(parent, modal);
27 initComponents();
28 populateNotices ();
29 tableNotices.addMouseListener(new MouseAdapter() {
30 @Override
31 public void mousePressed(MouseEvent arg0) {
32 if (arg0.isPopupTrigger()) {
33 popMenu.show(arg0.getComponent(), arg0.getX(), arg0.getY());
34 }
35 }
36
37 });
38 }
39
40 /**
41 * This method is called from within the constructor to initialize the form.
42 * WARNING: Do NOT modify this code. The content of this method is always
43 * regenerated by the Form Editor.
44 */
45 @SuppressWarnings("unchecked")
46 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
47 private void initComponents() {
48
49 popMenu = new javax.swing.JPopupMenu();
50 menuDescription = new javax.swing.JMenuItem();
51 menuClarificationDetails = new javax.swing.JMenuItem();
52 menuDraftStatus = new javax.swing.JMenuItem();
53 menuDispatchDetails = new javax.swing.JMenuItem();
54 menuBillDetails = new javax.swing.JMenuItem();
55 jSeparator1 = new javax.swing.JPopupMenu.Separator();
56 menuView = new javax.swing.JMenuItem();
57 menuDelete = new javax.swing.JMenuItem();
58 jScrollPane1 = new javax.swing.JScrollPane();
59 tableNotices = new javax.swing.JTable();
60
61 menuDescription.setMnemonic('e');
62 menuDescription.setText("Description...");
63 menuDescription.addActionListener(new java.awt.event.ActionListener() {
64 public void actionPerformed(java.awt.event.ActionEvent evt) {
65 menuDescriptionActionPerformed(evt);
66 }
67 });
68 popMenu.add(menuDescription);
69
70 menuClarificationDetails.setMnemonic('r');
71 menuClarificationDetails.setText("Clarification Details...");
72 menuClarificationDetails.addActionListener(new java.awt.event.ActionListener() {
73 public void actionPerformed(java.awt.event.ActionEvent evt) {
74 menuClarificationDetailsActionPerformed(evt);
75 }
76 });
77 popMenu.add(menuClarificationDetails);
78
79 menuDraftStatus.setMnemonic('D');
80 menuDraftStatus.setText("Draft Status...");
81 menuDraftStatus.setToolTipText("");
82 menuDraftStatus.addActionListener(new java.awt.event.ActionListener() {
83 public void actionPerformed(java.awt.event.ActionEvent evt) {
84 menuDraftStatusActionPerformed(evt);
85 }
86 });
87 popMenu.add(menuDraftStatus);
88
89 menuDispatchDetails.setMnemonic('h');
90 menuDispatchDetails.setText("Dispatch Details...");
91 menuDispatchDetails.addActionListener(new java.awt.event.ActionListener() {
92 public void actionPerformed(java.awt.event.ActionEvent evt) {
93 menuDispatchDetailsActionPerformed(evt);
94 }
95 });
96 popMenu.add(menuDispatchDetails);
97
98 menuBillDetails.setMnemonic('B');
99 menuBillDetails.setText("Bill Details...");
100 menuBillDetails.addActionListener(new java.awt.event.ActionListener() {
101 public void actionPerformed(java.awt.event.ActionEvent evt) {
102 menuBillDetailsActionPerformed(evt);
103 }
104 });
105 popMenu.add(menuBillDetails);
106 popMenu.add(jSeparator1);
107
108 menuView.setMnemonic('V');
109 menuView.setText("View...");
110 menuView.addActionListener(new java.awt.event.ActionListener() {
111 public void actionPerformed(java.awt.event.ActionEvent evt) {
112 menuViewActionPerformed(evt);
113 }
114 });
115 popMenu.add(menuView);
116
117 menuDelete.setText("Delete");
118 menuDelete.addActionListener(new java.awt.event.ActionListener() {
119 public void actionPerformed(java.awt.event.ActionEvent evt) {
120 menuDeleteActionPerformed(evt);
121 }
122 });
123 popMenu.add(menuDelete);
124
125 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
126 setTitle("Manage Notices");
127 setLocationByPlatform(true);
128
129 tableNotices.setModel(new javax.swing.table.DefaultTableModel(
130 new Object [][] {
131
132 },
133 new String [] {
134 "id", "Reference Number", "Description"
135 }
136 ) {
137 Class[] types = new Class [] {
138 java.lang.Integer.class, java.lang.String.class, java.lang.String.class
139 };
140 boolean[] canEdit = new boolean [] {
141 false, false, false
142 };
143
144 public Class getColumnClass(int columnIndex) {
145 return types [columnIndex];
146 }
147
148 public boolean isCellEditable(int rowIndex, int columnIndex) {
149 return canEdit [columnIndex];
150 }
151 });
152 tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
153 tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
154 jScrollPane1.setViewportView(tableNotices);
155
156 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
157 getContentPane().setLayout(layout);
158 layout.setHorizontalGroup(
159 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
160 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
161 );
162 layout.setVerticalGroup(
163 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
165 );
166
167 pack();
168 }// </editor-fold>//GEN-END:initComponents
169
170 private void menuDraftStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDraftStatusActionPerformed
171 // TODO add your handling code here:
172 int selid = getSelectedNotice ();
173 if (selid == -1) return;
174
175 DraftStatusDialog frm = new DraftStatusDialog((Frame) this.getParent(), true);
176 ArrayList<Object> notice = Utility.getNoticeDetails (selid);
177 if (notice == null) return;
178
179 frm.setFields(selid, (boolean)notice.get(4), (boolean)notice.get(5));
180 frm.setVisible(true);
181
182 }//GEN-LAST:event_menuDraftStatusActionPerformed
183
184 private void menuDescriptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDescriptionActionPerformed
185 // TODO add your handling code here:
186 int selid = getSelectedNotice();
187 if (selid == -1) return;
188 ArrayList<Object> notice = Utility.getNoticeDetails(selid);
189 if (notice == null) return;
190
191 DescriptionDialog frm = new DescriptionDialog((Frame)this.getParent(), true);
192 frm.setFields(selid, (String)notice.get(0), (String)notice.get(1), (Date)notice.get(2));
193 frm.setVisible(true);
194 populateNotices();
195 }//GEN-LAST:event_menuDescriptionActionPerformed
196
197 private void menuDispatchDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDispatchDetailsActionPerformed
198 // TODO add your handling code here:
199 int selid = getSelectedNotice();
200 if (selid == -1) return;
201 ArrayList<Object> notice = Utility.getNoticeDetails(selid);
202 if (notice == null) return;
203
204 DispatchDetailsDialog frm = new DispatchDetailsDialog((Frame) this.getParent(), true);
205 frm.setFields (selid, (boolean)notice.get(6), (Date)notice.get(7),
206 (String)notice.get(8), (boolean) notice.get(9),(Date) notice.get(10));
207 frm.setVisible(true);
208 }//GEN-LAST:event_menuDispatchDetailsActionPerformed
209
210 private void menuBillDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuBillDetailsActionPerformed
211 // TODO add your handling code here:
212 int selid = getSelectedNotice();
213 if (selid == -1) return;
214 ArrayList<Object> notice = Utility.getNoticeDetails(selid);
215 if (notice == null) return;
216
217 BillDetailsDialog frm = new BillDetailsDialog((Frame) this.getParent(),true);
218 frm.setFields (selid, (String)notice.get(11), (int)notice.get(12), (Date)notice.get(13));
219 frm.setVisible(true);
220 }//GEN-LAST:event_menuBillDetailsActionPerformed
221
222 private void menuClarificationDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuClarificationDetailsActionPerformed
223 // TODO add your handling code here:
224 int selid = getSelectedNotice();
225 if (selid == -1) return;
226 ArrayList<Object> notice = Utility.getNoticeDetails(selid);
227 if (notice == null) return;
228 ClarificationDetailsDialog frm = new ClarificationDetailsDialog(
229 (Frame)this.getParent(), true);
230
231 frm.setFields (selid, (boolean)notice.get(14), (String)notice.get(15));
232 frm.setVisible(true);
233 }//GEN-LAST:event_menuClarificationDetailsActionPerformed
234
235 private void menuDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDeleteActionPerformed
236 int selid = getSelectedNotice();
237 if (selid == -1) return;
238 int conf = JOptionPane.showConfirmDialog((Frame)this.getParent(), CONFIRM_DELETE);
239 if (conf == JOptionPane.YES_OPTION) {
240 boolean rt = Utility.deleteNotice (selid);
241 if (rt == false)
242 JOptionPane.showMessageDialog(this, ERROR_DELETING);
243 else
244 populateNotices();
245 }
246 }//GEN-LAST:event_menuDeleteActionPerformed
247
248 private void menuViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuViewActionPerformed
249 // TODO add your handling code here:
250 int selid = getSelectedNotice();
251 if (selid == -1) return;
252 ArrayList<Object> notice = Utility.getNoticeDetails(selid);
253 if (notice == null) return;
254
255 ViewNoticeDialog frm = new ViewNoticeDialog(
256 (Frame)this.getParent(), true);
257 frm.setFields (selid, (String)notice.get(0),
258 (String)notice.get(1), (Date)notice.get(2),
259 (String)notice.get(16), (boolean)notice.get(4),
260 (boolean)notice.get(5), (boolean)notice.get(6),
261 (Date)notice.get(7), (String)notice.get(8),
262 (boolean)notice.get(9), (Date)notice.get(10),
263 (String)notice.get(11), (int)notice.get(12),
264 (Date)notice.get(13), (boolean)notice.get(14),
265 (String)notice.get(15));
266 frm.setVisible(true);
267
268
269 }//GEN-LAST:event_menuViewActionPerformed
270 private static final String ERROR_DELETING = "Error in deleting";
271 private static final String CONFIRM_DELETE = "Are you sure you wish to delete?";
272
273 /**
274 * @param args the command line arguments
275 */
276 public static void main(String args[]) {
277 /* Set the Nimbus look and feel */
278 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
279 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
280 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
281 */
282 try {
283 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
284 if ("Nimbus".equals(info.getName())) {
285 javax.swing.UIManager.setLookAndFeel(info.getClassName());
286 break;
287 }
288 }
289 } catch (ClassNotFoundException ex) {
290 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
291 } catch (InstantiationException ex) {
292 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
293 } catch (IllegalAccessException ex) {
294 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
295 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
296 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
297 }
298 //</editor-fold>
299
300 /* Create and display the dialog */
301 java.awt.EventQueue.invokeLater(new Runnable() {
302 public void run() {
303 ManageNoticesDialog dialog = new ManageNoticesDialog(new javax.swing.JFrame(), true);
304 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
305 @Override
306 public void windowClosing(java.awt.event.WindowEvent e) {
307 System.exit(0);
308 }
309 });
310 dialog.setVisible(true);
311 }
312 });
313 }
314
315 // Variables declaration - do not modify//GEN-BEGIN:variables
316 private javax.swing.JScrollPane jScrollPane1;
317 private javax.swing.JSeparator jSeparator1;
318 private javax.swing.JMenuItem menuBillDetails;
319 private javax.swing.JMenuItem menuClarificationDetails;
320 private javax.swing.JMenuItem menuDelete;
321 private javax.swing.JMenuItem menuDescription;
322 private javax.swing.JMenuItem menuDispatchDetails;
323 private javax.swing.JMenuItem menuDraftStatus;
324 private javax.swing.JMenuItem menuView;
325 private javax.swing.JPopupMenu popMenu;
326 private javax.swing.JTable tableNotices;
327 // End of variables declaration//GEN-END:variables
328
329 private void populateNotices() {
330 DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel ();
331 mdl.setRowCount(0);
332 ArrayList<Object> notices = Utility.getNotices ();
333 if (notices == null) return;
334 for (int i = 0; i < notices.size(); i += 3) {
335 mdl.addRow (new Object[] { notices.get(i), notices.get(i+1),
336 notices.get(i+2)});
337 }
338 }
339
340 private int getSelectedNotice() {
341 int selid = tableNotices.getSelectedRow();
342 if (selid == -1)
343 return -1;
344 DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel();
345 int rkey = (int) mdl.getValueAt(selid, 0);
346 return rkey;
347 }
348 }