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