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