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