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