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
.addMouseListener(new MouseAdapter() {
30 public void mousePressed(MouseEvent arg0
) {
31 if (arg0
.isPopupTrigger()) {
32 popMenu
.show(arg0
.getComponent(), arg0
.getX(), arg0
.getY());
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.
44 @SuppressWarnings("unchecked")
45 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
46 private void initComponents() {
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();
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 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
);
80 popMenu
.add(menuDispatchDetails
);
82 setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
83 setTitle("Manage Notices");
84 setLocationByPlatform(true);
86 tableNotices
.setModel(new javax
.swing
.table
.DefaultTableModel(
91 "id", "Reference Number", "Description"
94 Class
[] types
= new Class
[] {
95 java
.lang
.Integer
.class, java
.lang
.String
.class, java
.lang
.String
.class
97 boolean[] canEdit
= new boolean [] {
101 public Class
getColumnClass(int columnIndex
) {
102 return types
[columnIndex
];
105 public boolean isCellEditable(int rowIndex
, int columnIndex
) {
106 return canEdit
[columnIndex
];
109 tableNotices
.setSelectionMode(javax
.swing
.ListSelectionModel
.SINGLE_SELECTION
);
110 tableNotices
.setSelectionMode(javax
.swing
.ListSelectionModel
.SINGLE_SELECTION
);
111 jScrollPane1
.setViewportView(tableNotices
);
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
)
119 layout
.setVerticalGroup(
120 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
121 .addComponent(jScrollPane1
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, 317, Short
.MAX_VALUE
)
125 }// </editor-fold>//GEN-END:initComponents
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;
132 DraftStatusDialog frm
= new DraftStatusDialog((Frame
) this.getParent(), true);
133 ArrayList
<Object
> notice
= Utility
.getNoticeDetails (selid
);
134 if (notice
== null) return;
136 frm
.setFields(selid
, (boolean)notice
.get(4), (boolean)notice
.get(5));
137 frm
.setVisible(true);
139 }//GEN-LAST:event_menuDraftStatusActionPerformed
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;
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);
152 }//GEN-LAST:event_menuDescriptionActionPerformed
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;
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
168 * @param args the command line arguments
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
177 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
178 if ("Nimbus".equals(info
.getName())) {
179 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
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
);
194 /* Create and display the dialog */
195 java
.awt
.EventQueue
.invokeLater(new Runnable() {
197 ManageNoticesDialog dialog
= new ManageNoticesDialog(new javax
.swing
.JFrame(), true);
198 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
200 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
204 dialog
.setVisible(true);
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
218 private void populateNotices() {
219 DefaultTableModel mdl
= (DefaultTableModel
) tableNotices
.getModel ();
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),
229 private int getSelectedNotice() {
230 int selid
= tableNotices
.getSelectedRow();
233 DefaultTableModel mdl
= (DefaultTableModel
) tableNotices
.getModel();
234 int rkey
= (int) mdl
.getValueAt(selid
, 0);