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 menuBillDetails
= new javax
.swing
.JMenuItem();
53 jScrollPane1
= new javax
.swing
.JScrollPane();
54 tableNotices
= new javax
.swing
.JTable();
56 menuDescription
.setMnemonic('e');
57 menuDescription
.setText("Description...");
58 menuDescription
.addActionListener(new java
.awt
.event
.ActionListener() {
59 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
60 menuDescriptionActionPerformed(evt
);
63 popMenu
.add(menuDescription
);
65 menuDraftStatus
.setMnemonic('D');
66 menuDraftStatus
.setText("Draft Status...");
67 menuDraftStatus
.setToolTipText("");
68 menuDraftStatus
.addActionListener(new java
.awt
.event
.ActionListener() {
69 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
70 menuDraftStatusActionPerformed(evt
);
73 popMenu
.add(menuDraftStatus
);
75 menuDispatchDetails
.setMnemonic('h');
76 menuDispatchDetails
.setText("Dispatch Details...");
77 menuDispatchDetails
.addActionListener(new java
.awt
.event
.ActionListener() {
78 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
79 menuDispatchDetailsActionPerformed(evt
);
82 popMenu
.add(menuDispatchDetails
);
84 menuBillDetails
.setMnemonic('B');
85 menuBillDetails
.setText("Bill Details...");
86 menuBillDetails
.addActionListener(new java
.awt
.event
.ActionListener() {
87 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
88 menuBillDetailsActionPerformed(evt
);
91 popMenu
.add(menuBillDetails
);
93 setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
94 setTitle("Manage Notices");
95 setLocationByPlatform(true);
97 tableNotices
.setModel(new javax
.swing
.table
.DefaultTableModel(
102 "id", "Reference Number", "Description"
105 Class
[] types
= new Class
[] {
106 java
.lang
.Integer
.class, java
.lang
.String
.class, java
.lang
.String
.class
108 boolean[] canEdit
= new boolean [] {
112 public Class
getColumnClass(int columnIndex
) {
113 return types
[columnIndex
];
116 public boolean isCellEditable(int rowIndex
, int columnIndex
) {
117 return canEdit
[columnIndex
];
120 tableNotices
.setSelectionMode(javax
.swing
.ListSelectionModel
.SINGLE_SELECTION
);
121 tableNotices
.setSelectionMode(javax
.swing
.ListSelectionModel
.SINGLE_SELECTION
);
122 jScrollPane1
.setViewportView(tableNotices
);
124 javax
.swing
.GroupLayout layout
= new javax
.swing
.GroupLayout(getContentPane());
125 getContentPane().setLayout(layout
);
126 layout
.setHorizontalGroup(
127 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
128 .addComponent(jScrollPane1
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, 537, Short
.MAX_VALUE
)
130 layout
.setVerticalGroup(
131 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
132 .addComponent(jScrollPane1
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, 317, Short
.MAX_VALUE
)
136 }// </editor-fold>//GEN-END:initComponents
138 private void menuDraftStatusActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_menuDraftStatusActionPerformed
139 // TODO add your handling code here:
140 int selid
= getSelectedNotice ();
141 if (selid
== -1) return;
143 DraftStatusDialog frm
= new DraftStatusDialog((Frame
) this.getParent(), true);
144 ArrayList
<Object
> notice
= Utility
.getNoticeDetails (selid
);
145 if (notice
== null) return;
147 frm
.setFields(selid
, (boolean)notice
.get(4), (boolean)notice
.get(5));
148 frm
.setVisible(true);
150 }//GEN-LAST:event_menuDraftStatusActionPerformed
152 private void menuDescriptionActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_menuDescriptionActionPerformed
153 // TODO add your handling code here:
154 int selid
= getSelectedNotice();
155 if (selid
== -1) return;
156 ArrayList
<Object
> notice
= Utility
.getNoticeDetails(selid
);
157 if (notice
== null) return;
159 DescriptionDialog frm
= new DescriptionDialog((Frame
)this.getParent(), true);
160 frm
.setFields(selid
, (String
)notice
.get(0), (String
)notice
.get(1), (Date
)notice
.get(2));
161 frm
.setVisible(true);
163 }//GEN-LAST:event_menuDescriptionActionPerformed
165 private void menuDispatchDetailsActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_menuDispatchDetailsActionPerformed
166 // TODO add your handling code here:
167 int selid
= getSelectedNotice();
168 if (selid
== -1) return;
169 ArrayList
<Object
> notice
= Utility
.getNoticeDetails(selid
);
170 if (notice
== null) return;
172 DispatchDetailsDialog frm
= new DispatchDetailsDialog((Frame
) this.getParent(), true);
173 frm
.setFields (selid
, (boolean)notice
.get(6), (Date
)notice
.get(7),
174 (String
)notice
.get(8), (boolean) notice
.get(9),(Date
) notice
.get(10));
175 frm
.setVisible(true);
176 }//GEN-LAST:event_menuDispatchDetailsActionPerformed
178 private void menuBillDetailsActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_menuBillDetailsActionPerformed
179 // TODO add your handling code here:
180 int selid
= getSelectedNotice();
181 if (selid
== -1) return;
182 ArrayList
<Object
> notice
= Utility
.getNoticeDetails(selid
);
183 if (notice
== null) return;
185 BillDetailsDialog frm
= new BillDetailsDialog((Frame
) this.getParent(),true);
186 frm
.setFields (selid
, (String
)notice
.get(11), (int)notice
.get(12), (Date
)notice
.get(13));
187 frm
.setVisible(true);
188 }//GEN-LAST:event_menuBillDetailsActionPerformed
191 * @param args the command line arguments
193 public static void main(String args
[]) {
194 /* Set the Nimbus look and feel */
195 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
196 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
197 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
200 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
201 if ("Nimbus".equals(info
.getName())) {
202 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
206 } catch (ClassNotFoundException ex
) {
207 java
.util
.logging
.Logger
.getLogger(ManageNoticesDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
208 } catch (InstantiationException ex
) {
209 java
.util
.logging
.Logger
.getLogger(ManageNoticesDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
210 } catch (IllegalAccessException ex
) {
211 java
.util
.logging
.Logger
.getLogger(ManageNoticesDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
212 } catch (javax
.swing
.UnsupportedLookAndFeelException ex
) {
213 java
.util
.logging
.Logger
.getLogger(ManageNoticesDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
217 /* Create and display the dialog */
218 java
.awt
.EventQueue
.invokeLater(new Runnable() {
220 ManageNoticesDialog dialog
= new ManageNoticesDialog(new javax
.swing
.JFrame(), true);
221 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
223 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
227 dialog
.setVisible(true);
232 // Variables declaration - do not modify//GEN-BEGIN:variables
233 private javax
.swing
.JScrollPane jScrollPane1
;
234 private javax
.swing
.JMenuItem menuBillDetails
;
235 private javax
.swing
.JMenuItem menuDescription
;
236 private javax
.swing
.JMenuItem menuDispatchDetails
;
237 private javax
.swing
.JMenuItem menuDraftStatus
;
238 private javax
.swing
.JPopupMenu popMenu
;
239 private javax
.swing
.JTable tableNotices
;
240 // End of variables declaration//GEN-END:variables
242 private void populateNotices() {
243 DefaultTableModel mdl
= (DefaultTableModel
) tableNotices
.getModel ();
245 ArrayList
<Object
> notices
= Utility
.getNotices ();
246 if (notices
== null) return;
247 for (int i
= 0; i
< notices
.size(); i
+= 3) {
248 mdl
.addRow (new Object
[] { notices
.get(i
), notices
.get(i
+1),
253 private int getSelectedNotice() {
254 int selid
= tableNotices
.getSelectedRow();
257 DefaultTableModel mdl
= (DefaultTableModel
) tableNotices
.getModel();
258 int rkey
= (int) mdl
.getValueAt(selid
, 0);