Merge origin/master
[habeas.git] / src / habeas / BillDetailsDialog.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.util.Date;
9 import javax.swing.JOptionPane;
10
11 /**
12 *
13 * @author hari
14 */
15 public class BillDetailsDialog extends javax.swing.JDialog {
16
17 private int selected_id;
18
19 /**
20 * Creates new form BillDetailsDialog
21 */
22 public BillDetailsDialog(java.awt.Frame parent, boolean modal) {
23 super(parent, modal);
24 initComponents();
25 }
26
27 /**
28 * This method is called from within the constructor to initialize the form.
29 * WARNING: Do NOT modify this code. The content of this method is always
30 * regenerated by the Form Editor.
31 */
32 @SuppressWarnings("unchecked")
33 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
34 private void initComponents() {
35
36 jLabel1 = new javax.swing.JLabel();
37 comboBillStatus = new javax.swing.JComboBox<>();
38 jLabel2 = new javax.swing.JLabel();
39 jLabel3 = new javax.swing.JLabel();
40 dateBill = new org.jdesktop.swingx.JXDatePicker();
41 valBillAmount = new javax.swing.JFormattedTextField();
42 buttonApply = new javax.swing.JButton();
43 buttonCancel = new javax.swing.JButton();
44
45 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
46 setTitle("Bill Details");
47 setLocationByPlatform(true);
48
49 jLabel1.setText("Bill Status");
50
51 comboBillStatus.setEditable(true);
52 comboBillStatus.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "PENDING", "RAISED", "AWAITING PAYMENT", "PAID" }));
53
54 jLabel2.setText("Bill Date");
55
56 jLabel3.setText("Bill Amount");
57
58 valBillAmount.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
59
60 buttonApply.setMnemonic('A');
61 buttonApply.setText("Apply");
62 buttonApply.addActionListener(new java.awt.event.ActionListener() {
63 public void actionPerformed(java.awt.event.ActionEvent evt) {
64 buttonApplyActionPerformed(evt);
65 }
66 });
67
68 buttonCancel.setMnemonic('C');
69 buttonCancel.setText("Cancel");
70 buttonCancel.addActionListener(new java.awt.event.ActionListener() {
71 public void actionPerformed(java.awt.event.ActionEvent evt) {
72 buttonCancelActionPerformed(evt);
73 }
74 });
75
76 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
77 getContentPane().setLayout(layout);
78 layout.setHorizontalGroup(
79 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
80 .addGroup(layout.createSequentialGroup()
81 .addContainerGap()
82 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
83 .addGroup(layout.createSequentialGroup()
84 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
85 .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
86 .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
87 .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
88 .addGap(18, 18, 18)
89 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
90 .addComponent(comboBillStatus, 0, 301, Short.MAX_VALUE)
91 .addComponent(dateBill, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
92 .addComponent(valBillAmount)))
93 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
94 .addGap(0, 0, Short.MAX_VALUE)
95 .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
96 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
97 .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
98 .addContainerGap())
99 );
100 layout.setVerticalGroup(
101 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
102 .addGroup(layout.createSequentialGroup()
103 .addContainerGap()
104 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
105 .addComponent(jLabel1)
106 .addComponent(comboBillStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
107 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
108 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
109 .addComponent(jLabel2)
110 .addComponent(dateBill, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
111 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
112 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
113 .addComponent(jLabel3)
114 .addComponent(valBillAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
115 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
116 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
117 .addComponent(buttonApply)
118 .addComponent(buttonCancel))
119 .addContainerGap())
120 );
121
122 pack();
123 }// </editor-fold>//GEN-END:initComponents
124
125 private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed
126 // TODO add your handling code here:
127 dispose ();
128 }//GEN-LAST:event_buttonCancelActionPerformed
129
130 private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed
131 // TODO add your handling code here:
132 String bill_status = (String)comboBillStatus.getSelectedItem();
133 if (! "PENDING".equals(bill_status) && (dateBill.getDate() == null ||
134 valBillAmount.getValue() == null)) {
135 JOptionPane.showMessageDialog(this, MANDATORY_FIELDS_MISSING);
136 return;
137 }
138
139 boolean rt = Utility.updateNoticeBillDetails (selected_id, bill_status,
140 dateBill.getDate(), (int)valBillAmount.getValue());
141 if (rt == false)
142 JOptionPane.showMessageDialog(this, ERROR_UPDATING);
143 else
144 dispose ();
145 }//GEN-LAST:event_buttonApplyActionPerformed
146 private static final String MANDATORY_FIELDS_MISSING = "Mandatory fields missing";
147 private static final String ERROR_UPDATING = "Error in updating";
148
149 /**
150 * @param args the command line arguments
151 */
152 public static void main(String args[]) {
153 /* Set the Nimbus look and feel */
154 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
155 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
156 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
157 */
158 try {
159 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
160 if ("Nimbus".equals(info.getName())) {
161 javax.swing.UIManager.setLookAndFeel(info.getClassName());
162 break;
163 }
164 }
165 } catch (ClassNotFoundException ex) {
166 java.util.logging.Logger.getLogger(BillDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
167 } catch (InstantiationException ex) {
168 java.util.logging.Logger.getLogger(BillDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
169 } catch (IllegalAccessException ex) {
170 java.util.logging.Logger.getLogger(BillDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
171 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
172 java.util.logging.Logger.getLogger(BillDetailsDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
173 }
174 //</editor-fold>
175
176 /* Create and display the dialog */
177 java.awt.EventQueue.invokeLater(new Runnable() {
178 public void run() {
179 BillDetailsDialog dialog = new BillDetailsDialog(new javax.swing.JFrame(), true);
180 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
181 @Override
182 public void windowClosing(java.awt.event.WindowEvent e) {
183 System.exit(0);
184 }
185 });
186 dialog.setVisible(true);
187 }
188 });
189 }
190
191 // Variables declaration - do not modify//GEN-BEGIN:variables
192 private javax.swing.JButton buttonApply;
193 private javax.swing.JButton buttonCancel;
194 private javax.swing.JComboBox<String> comboBillStatus;
195 private org.jdesktop.swingx.JXDatePicker dateBill;
196 private javax.swing.JLabel jLabel1;
197 private javax.swing.JLabel jLabel2;
198 private javax.swing.JLabel jLabel3;
199 private javax.swing.JFormattedTextField valBillAmount;
200 // End of variables declaration//GEN-END:variables
201
202 void setFields(int selid, String bill_status, int bill_amount, Date bill_date) {
203 selected_id = selid;
204 comboBillStatus.setSelectedItem(bill_status);
205 dateBill.setDate(bill_date);
206 valBillAmount.setValue(bill_amount);
207
208 }
209 }