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