Manage Legal Notices functionality
[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.event.MouseAdapter;
9 import java.awt.event.MouseEvent;
10 import java.awt.event.MouseListener;
11 import java.util.ArrayList;
12 import javax.swing.JMenuItem;
13 import javax.swing.JPopupMenu;
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.add(popMenu);
30 tableNotices.addMouseListener(new MouseAdapter() {
31 @Override
32 public void mousePressed(MouseEvent arg0) {
33 if (arg0.isPopupTrigger()) {
34 popMenu.show(arg0.getComponent(), arg0.getX(), arg0.getY());
35 }
36 }
37
38 });
39 }
40
41 /**
42 * This method is called from within the constructor to initialize the form.
43 * WARNING: Do NOT modify this code. The content of this method is always
44 * regenerated by the Form Editor.
45 */
46 @SuppressWarnings("unchecked")
47 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
48 private void initComponents() {
49
50 popMenu = new javax.swing.JPopupMenu();
51 menuDraftStatus = new javax.swing.JMenuItem();
52 jScrollPane1 = new javax.swing.JScrollPane();
53 tableNotices = new javax.swing.JTable();
54
55 menuDraftStatus.setMnemonic('D');
56 menuDraftStatus.setText("Draft Status...");
57 menuDraftStatus.setToolTipText("");
58 menuDraftStatus.addActionListener(new java.awt.event.ActionListener() {
59 public void actionPerformed(java.awt.event.ActionEvent evt) {
60 menuDraftStatusActionPerformed(evt);
61 }
62 });
63 popMenu.add(menuDraftStatus);
64
65 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
66 setTitle("Manage Notices");
67 setLocationByPlatform(true);
68
69 tableNotices.setModel(new javax.swing.table.DefaultTableModel(
70 new Object [][] {
71
72 },
73 new String [] {
74 "id", "Reference Number", "Description"
75 }
76 ) {
77 Class[] types = new Class [] {
78 java.lang.Integer.class, java.lang.String.class, java.lang.String.class
79 };
80 boolean[] canEdit = new boolean [] {
81 false, false, false
82 };
83
84 public Class getColumnClass(int columnIndex) {
85 return types [columnIndex];
86 }
87
88 public boolean isCellEditable(int rowIndex, int columnIndex) {
89 return canEdit [columnIndex];
90 }
91 });
92 tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
93 tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
94 jScrollPane1.setViewportView(tableNotices);
95
96 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
97 getContentPane().setLayout(layout);
98 layout.setHorizontalGroup(
99 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
100 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
101 );
102 layout.setVerticalGroup(
103 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
105 );
106
107 pack();
108 }// </editor-fold>//GEN-END:initComponents
109
110 private void menuDraftStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDraftStatusActionPerformed
111 // TODO add your handling code here:
112 int selid = getSelectedNotice ();
113 if (selid == -1) return;
114
115 System.out.println (selid);
116
117 }//GEN-LAST:event_menuDraftStatusActionPerformed
118
119 /**
120 * @param args the command line arguments
121 */
122 public static void main(String args[]) {
123 /* Set the Nimbus look and feel */
124 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
125 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
126 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
127 */
128 try {
129 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
130 if ("Nimbus".equals(info.getName())) {
131 javax.swing.UIManager.setLookAndFeel(info.getClassName());
132 break;
133 }
134 }
135 } catch (ClassNotFoundException ex) {
136 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
137 } catch (InstantiationException ex) {
138 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
139 } catch (IllegalAccessException ex) {
140 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
141 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
142 java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
143 }
144 //</editor-fold>
145
146 /* Create and display the dialog */
147 java.awt.EventQueue.invokeLater(new Runnable() {
148 public void run() {
149 ManageNoticesDialog dialog = new ManageNoticesDialog(new javax.swing.JFrame(), true);
150 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
151 @Override
152 public void windowClosing(java.awt.event.WindowEvent e) {
153 System.exit(0);
154 }
155 });
156 dialog.setVisible(true);
157 }
158 });
159 }
160
161 // Variables declaration - do not modify//GEN-BEGIN:variables
162 private javax.swing.JScrollPane jScrollPane1;
163 private javax.swing.JMenuItem menuDraftStatus;
164 private javax.swing.JPopupMenu popMenu;
165 private javax.swing.JTable tableNotices;
166 // End of variables declaration//GEN-END:variables
167
168 private void populateNotices() {
169 DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel ();
170 mdl.setRowCount(0);
171 ArrayList<Object> notices = Utility.getNotices ();
172 if (notices == null) return;
173 for (int i = 0; i < notices.size(); i += 3) {
174 mdl.addRow (new Object[] { notices.get(i), notices.get(i+1),
175 notices.get(i+2)});
176 }
177 }
178
179 private int getSelectedNotice() {
180 int selid = tableNotices.getSelectedRow();
181 if (selid == -1)
182 return -1;
183 DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel();
184 int rkey = (int) mdl.getValueAt(selid, 0);
185 return rkey;
186 }
187 }