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