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.
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
;
19 public class ManageNoticesDialog
extends javax
.swing
.JDialog
{
22 * Creates new form ManageNoticesDialog
24 public ManageNoticesDialog(java
.awt
.Frame parent
, boolean modal
) {
28 tableNotices
.add(popMenu
);
29 tableNotices
.addMouseListener(new MouseAdapter() {
31 public void mousePressed(MouseEvent arg0
) {
32 if (arg0
.isPopupTrigger()) {
33 popMenu
.show(arg0
.getComponent(), arg0
.getX(), arg0
.getY());
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.
45 @SuppressWarnings("unchecked")
46 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
47 private void initComponents() {
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();
55 menuDescription
.setText("Description...");
56 menuDescription
.addActionListener(new java
.awt
.event
.ActionListener() {
57 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
58 menuDescriptionActionPerformed(evt
);
61 popMenu
.add(menuDescription
);
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
);
71 popMenu
.add(menuDraftStatus
);
73 setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
74 setTitle("Manage Notices");
75 setLocationByPlatform(true);
77 tableNotices
.setModel(new javax
.swing
.table
.DefaultTableModel(
82 "id", "Reference Number", "Description"
85 Class
[] types
= new Class
[] {
86 java
.lang
.Integer
.class, java
.lang
.String
.class, java
.lang
.String
.class
88 boolean[] canEdit
= new boolean [] {
92 public Class
getColumnClass(int columnIndex
) {
93 return types
[columnIndex
];
96 public boolean isCellEditable(int rowIndex
, int columnIndex
) {
97 return canEdit
[columnIndex
];
100 tableNotices
.setSelectionMode(javax
.swing
.ListSelectionModel
.SINGLE_SELECTION
);
101 tableNotices
.setSelectionMode(javax
.swing
.ListSelectionModel
.SINGLE_SELECTION
);
102 jScrollPane1
.setViewportView(tableNotices
);
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
)
110 layout
.setVerticalGroup(
111 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
112 .addComponent(jScrollPane1
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, 317, Short
.MAX_VALUE
)
116 }// </editor-fold>//GEN-END:initComponents
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;
123 DraftStatusDialog frm
= new DraftStatusDialog((Frame
) this.getParent(), true);
124 ArrayList
<Object
> notice
= Utility
.getNoticeDetails (selid
);
125 if (notice
== null) return;
127 frm
.setFields(selid
, (boolean)notice
.get(4), (boolean)notice
.get(5));
128 frm
.setVisible(true);
130 }//GEN-LAST:event_menuDraftStatusActionPerformed
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);
142 }//GEN-LAST:event_menuDescriptionActionPerformed
145 * @param args the command line arguments
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
154 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
155 if ("Nimbus".equals(info
.getName())) {
156 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
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
);
171 /* Create and display the dialog */
172 java
.awt
.EventQueue
.invokeLater(new Runnable() {
174 ManageNoticesDialog dialog
= new ManageNoticesDialog(new javax
.swing
.JFrame(), true);
175 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
177 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
181 dialog
.setVisible(true);
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
194 private void populateNotices() {
195 DefaultTableModel mdl
= (DefaultTableModel
) tableNotices
.getModel ();
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),
205 private int getSelectedNotice() {
206 int selid
= tableNotices
.getSelectedRow();
209 DefaultTableModel mdl
= (DefaultTableModel
) tableNotices
.getModel();
210 int rkey
= (int) mdl
.getValueAt(selid
, 0);