Manage Legal Notices - Delete
[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 menuDelete = new javax.swing.JMenuItem();
57 jScrollPane1 = new javax.swing.JScrollPane();
58 tableNotices = new javax.swing.JTable();
59
60 menuDescription.setMnemonic('e');
61 menuDescription.setText("Description...");
62 menuDescription.addActionListener(new java.awt.event.ActionListener() {
63 public void actionPerformed(java.awt.event.ActionEvent evt) {
64 menuDescriptionActionPerformed(evt);
65 }
66 });
67 popMenu.add(menuDescription);
68
69 menuClarificationDetails.setMnemonic('r');
70 menuClarificationDetails.setText("Clarification Details...");
71 menuClarificationDetails.addActionListener(new java.awt.event.ActionListener() {
72 public void actionPerformed(java.awt.event.ActionEvent evt) {
73 menuClarificationDetailsActionPerformed(evt);
74 }
75 });
76 popMenu.add(menuClarificationDetails);
77
78 menuDraftStatus.setMnemonic('D');
79 menuDraftStatus.setText("Draft Status...");
80 menuDraftStatus.setToolTipText("");
81 menuDraftStatus.addActionListener(new java.awt.event.ActionListener() {
82 public void actionPerformed(java.awt.event.ActionEvent evt) {
83 menuDraftStatusActionPerformed(evt);
84 }
85 });
86 popMenu.add(menuDraftStatus);
87
88 menuDispatchDetails.setMnemonic('h');
89 menuDispatchDetails.setText("Dispatch Details...");
90 menuDispatchDetails.addActionListener(new java.awt.event.ActionListener() {
91 public void actionPerformed(java.awt.event.ActionEvent evt) {
92 menuDispatchDetailsActionPerformed(evt);
93 }
94 });
95 popMenu.add(menuDispatchDetails);
96
97 menuBillDetails.setMnemonic('B');
98 menuBillDetails.setText("Bill Details...");
99 menuBillDetails.addActionListener(new java.awt.event.ActionListener() {
100 public void actionPerformed(java.awt.event.ActionEvent evt) {
101 menuBillDetailsActionPerformed(evt);
102 }
103 });
104 popMenu.add(menuBillDetails);
105 popMenu.add(jSeparator1);
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 private static final String ERROR_DELETING = "Error in deleting";
238 private static final String CONFIRM_DELETE = "Are you sure you wish to delete?";
239
240 /**
241 * @param args the command line arguments
242 */
243 public static void main(String args[]) {
244 /* Set the Nimbus look and feel */
245 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
246 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
247 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
248 */
249 try {
250 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
251 if ("Nimbus".equals(info.getName())) {
252 javax.swing.UIManager.setLookAndFeel(info.getClassName());
253 break;
254 }
255 }
256 } catch (ClassNotFoundException ex) {
257 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
258 } catch (InstantiationException ex) {
259 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
260 } catch (IllegalAccessException ex) {
261 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
262 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
263 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
264 }
265 //</editor-fold>
266
267 /* Create and display the dialog */
268 java.awt.EventQueue.invokeLater(new Runnable() {
269 public void run() {
270 ManageNoticesDialog dialog = new ManageNoticesDialog(new javax.swing.JFrame(), true);
271 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
272 @Override
273 public void windowClosing(java.awt.event.WindowEvent e) {
274 System.exit(0);
275 }
276 });
277 dialog.setVisible(true);
278 }
279 });
280 }
281
282 // Variables declaration - do not modify//GEN-BEGIN:variables
283 private javax.swing.JScrollPane jScrollPane1;
284 private javax.swing.JSeparator jSeparator1;
285 private javax.swing.JMenuItem menuBillDetails;
286 private javax.swing.JMenuItem menuClarificationDetails;
287 private javax.swing.JMenuItem menuDelete;
288 private javax.swing.JMenuItem menuDescription;
289 private javax.swing.JMenuItem menuDispatchDetails;
290 private javax.swing.JMenuItem menuDraftStatus;
291 private javax.swing.JPopupMenu popMenu;
292 private javax.swing.JTable tableNotices;
293 // End of variables declaration//GEN-END:variables
294
295 private void populateNotices() {
296 DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel ();
297 mdl.setRowCount(0);
298 ArrayList<Object> notices = Utility.getNotices ();
299 if (notices == null) return;
300 for (int i = 0; i < notices.size(); i += 3) {
301 mdl.addRow (new Object[] { notices.get(i), notices.get(i+1),
302 notices.get(i+2)});
303 }
304 }
305
306 private int getSelectedNotice() {
307 int selid = tableNotices.getSelectedRow();
308 if (selid == -1)
309 return -1;
310 DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel();
311 int rkey = (int) mdl.getValueAt(selid, 0);
312 return rkey;
313 }
314 }