Manage Legal Notices - Bill Details
[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 jScrollPane1 = new javax.swing.JScrollPane();
54 tableNotices = new javax.swing.JTable();
55
56 menuDescription.setMnemonic('e');
57 menuDescription.setText("Description...");
58 menuDescription.addActionListener(new java.awt.event.ActionListener() {
59 public void actionPerformed(java.awt.event.ActionEvent evt) {
60 menuDescriptionActionPerformed(evt);
61 }
62 });
63 popMenu.add(menuDescription);
64
65 menuDraftStatus.setMnemonic('D');
66 menuDraftStatus.setText("Draft Status...");
67 menuDraftStatus.setToolTipText("");
68 menuDraftStatus.addActionListener(new java.awt.event.ActionListener() {
69 public void actionPerformed(java.awt.event.ActionEvent evt) {
70 menuDraftStatusActionPerformed(evt);
71 }
72 });
73 popMenu.add(menuDraftStatus);
74
75 menuDispatchDetails.setMnemonic('h');
76 menuDispatchDetails.setText("Dispatch Details...");
77 menuDispatchDetails.addActionListener(new java.awt.event.ActionListener() {
78 public void actionPerformed(java.awt.event.ActionEvent evt) {
79 menuDispatchDetailsActionPerformed(evt);
80 }
81 });
82 popMenu.add(menuDispatchDetails);
83
84 menuBillDetails.setMnemonic('B');
85 menuBillDetails.setText("Bill Details...");
86 menuBillDetails.addActionListener(new java.awt.event.ActionListener() {
87 public void actionPerformed(java.awt.event.ActionEvent evt) {
88 menuBillDetailsActionPerformed(evt);
89 }
90 });
91 popMenu.add(menuBillDetails);
92
93 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
94 setTitle("Manage Notices");
95 setLocationByPlatform(true);
96
97 tableNotices.setModel(new javax.swing.table.DefaultTableModel(
98 new Object [][] {
99
100 },
101 new String [] {
102 "id", "Reference Number", "Description"
103 }
104 ) {
105 Class[] types = new Class [] {
106 java.lang.Integer.class, java.lang.String.class, java.lang.String.class
107 };
108 boolean[] canEdit = new boolean [] {
109 false, false, false
110 };
111
112 public Class getColumnClass(int columnIndex) {
113 return types [columnIndex];
114 }
115
116 public boolean isCellEditable(int rowIndex, int columnIndex) {
117 return canEdit [columnIndex];
118 }
119 });
120 tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
121 tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
122 jScrollPane1.setViewportView(tableNotices);
123
124 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
125 getContentPane().setLayout(layout);
126 layout.setHorizontalGroup(
127 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
129 );
130 layout.setVerticalGroup(
131 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
132 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
133 );
134
135 pack();
136 }// </editor-fold>//GEN-END:initComponents
137
138 private void menuDraftStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDraftStatusActionPerformed
139 // TODO add your handling code here:
140 int selid = getSelectedNotice ();
141 if (selid == -1) return;
142
143 DraftStatusDialog frm = new DraftStatusDialog((Frame) this.getParent(), true);
144 ArrayList<Object> notice = Utility.getNoticeDetails (selid);
145 if (notice == null) return;
146
147 frm.setFields(selid, (boolean)notice.get(4), (boolean)notice.get(5));
148 frm.setVisible(true);
149
150 }//GEN-LAST:event_menuDraftStatusActionPerformed
151
152 private void menuDescriptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDescriptionActionPerformed
153 // TODO add your handling code here:
154 int selid = getSelectedNotice();
155 if (selid == -1) return;
156 ArrayList<Object> notice = Utility.getNoticeDetails(selid);
157 if (notice == null) return;
158
159 DescriptionDialog frm = new DescriptionDialog((Frame)this.getParent(), true);
160 frm.setFields(selid, (String)notice.get(0), (String)notice.get(1), (Date)notice.get(2));
161 frm.setVisible(true);
162 populateNotices();
163 }//GEN-LAST:event_menuDescriptionActionPerformed
164
165 private void menuDispatchDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDispatchDetailsActionPerformed
166 // TODO add your handling code here:
167 int selid = getSelectedNotice();
168 if (selid == -1) return;
169 ArrayList<Object> notice = Utility.getNoticeDetails(selid);
170 if (notice == null) return;
171
172 DispatchDetailsDialog frm = new DispatchDetailsDialog((Frame) this.getParent(), true);
173 frm.setFields (selid, (boolean)notice.get(6), (Date)notice.get(7),
174 (String)notice.get(8), (boolean) notice.get(9),(Date) notice.get(10));
175 frm.setVisible(true);
176 }//GEN-LAST:event_menuDispatchDetailsActionPerformed
177
178 private void menuBillDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuBillDetailsActionPerformed
179 // TODO add your handling code here:
180 int selid = getSelectedNotice();
181 if (selid == -1) return;
182 ArrayList<Object> notice = Utility.getNoticeDetails(selid);
183 if (notice == null) return;
184
185 BillDetailsDialog frm = new BillDetailsDialog((Frame) this.getParent(),true);
186 frm.setFields (selid, (String)notice.get(11), (int)notice.get(12), (Date)notice.get(13));
187 frm.setVisible(true);
188 }//GEN-LAST:event_menuBillDetailsActionPerformed
189
190 /**
191 * @param args the command line arguments
192 */
193 public static void main(String args[]) {
194 /* Set the Nimbus look and feel */
195 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
196 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
197 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
198 */
199 try {
200 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
201 if ("Nimbus".equals(info.getName())) {
202 javax.swing.UIManager.setLookAndFeel(info.getClassName());
203 break;
204 }
205 }
206 } catch (ClassNotFoundException ex) {
207 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
208 } catch (InstantiationException ex) {
209 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
210 } catch (IllegalAccessException ex) {
211 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
212 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
213 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
214 }
215 //</editor-fold>
216
217 /* Create and display the dialog */
218 java.awt.EventQueue.invokeLater(new Runnable() {
219 public void run() {
220 ManageNoticesDialog dialog = new ManageNoticesDialog(new javax.swing.JFrame(), true);
221 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
222 @Override
223 public void windowClosing(java.awt.event.WindowEvent e) {
224 System.exit(0);
225 }
226 });
227 dialog.setVisible(true);
228 }
229 });
230 }
231
232 // Variables declaration - do not modify//GEN-BEGIN:variables
233 private javax.swing.JScrollPane jScrollPane1;
234 private javax.swing.JMenuItem menuBillDetails;
235 private javax.swing.JMenuItem menuDescription;
236 private javax.swing.JMenuItem menuDispatchDetails;
237 private javax.swing.JMenuItem menuDraftStatus;
238 private javax.swing.JPopupMenu popMenu;
239 private javax.swing.JTable tableNotices;
240 // End of variables declaration//GEN-END:variables
241
242 private void populateNotices() {
243 DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel ();
244 mdl.setRowCount(0);
245 ArrayList<Object> notices = Utility.getNotices ();
246 if (notices == null) return;
247 for (int i = 0; i < notices.size(); i += 3) {
248 mdl.addRow (new Object[] { notices.get(i), notices.get(i+1),
249 notices.get(i+2)});
250 }
251 }
252
253 private int getSelectedNotice() {
254 int selid = tableNotices.getSelectedRow();
255 if (selid == -1)
256 return -1;
257 DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel();
258 int rkey = (int) mdl.getValueAt(selid, 0);
259 return rkey;
260 }
261 }