From fdaede7966b1cfd8a38dcc51fa8ec60420b842b4 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Mon, 30 Mar 2020 18:38:14 +0530 Subject: [PATCH] Manage Legal Notices - Description Created the screen for updating description --- src/habeas/DescriptionDialog.form | 149 +++++++++++++++++++ src/habeas/DescriptionDialog.java | 213 ++++++++++++++++++++++++++++ src/habeas/DraftStatusDialog.java | 8 +- src/habeas/ManageNoticesDialog.form | 8 ++ src/habeas/ManageNoticesDialog.java | 26 +++- src/habeas/Utility.java | 19 ++- 6 files changed, 415 insertions(+), 8 deletions(-) create mode 100644 src/habeas/DescriptionDialog.form create mode 100644 src/habeas/DescriptionDialog.java diff --git a/src/habeas/DescriptionDialog.form b/src/habeas/DescriptionDialog.form new file mode 100644 index 0000000..04bfd76 --- /dev/null +++ b/src/habeas/DescriptionDialog.form @@ -0,0 +1,149 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/habeas/DescriptionDialog.java b/src/habeas/DescriptionDialog.java new file mode 100644 index 0000000..b4e70bb --- /dev/null +++ b/src/habeas/DescriptionDialog.java @@ -0,0 +1,213 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package habeas; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import javax.swing.JOptionPane; + +/** + * + * @author hari + */ +public class DescriptionDialog extends javax.swing.JDialog { + + private int selectednotice_id; + + /** + * Creates new form DescriptionDialog + */ + public DescriptionDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + public void setFields (int selid, String reference, + String description, Date entrustmentdate) { + selectednotice_id = selid; + textDescription.setText(description); + DateFormat datfmt = new SimpleDateFormat ("dd/MM/yyyy"); + textEntrustmentDate.setText (datfmt.format(entrustmentdate)); + textReferenceNumber.setText(reference); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + textReferenceNumber = new javax.swing.JTextField(); + jLabel2 = new javax.swing.JLabel(); + textEntrustmentDate = new javax.swing.JTextField(); + jLabel3 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + textDescription = new javax.swing.JTextArea(); + buttonUpdate = new javax.swing.JButton(); + buttonCancel = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Description"); + setLocationByPlatform(true); + + jLabel1.setText("Reference Number"); + + textReferenceNumber.setEditable(false); + + jLabel2.setText("Entrustment Date"); + + textEntrustmentDate.setEditable(false); + + jLabel3.setText("Description"); + + textDescription.setColumns(20); + textDescription.setRows(5); + jScrollPane1.setViewportView(textDescription); + + buttonUpdate.setMnemonic('U'); + buttonUpdate.setText("Update"); + buttonUpdate.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonUpdateActionPerformed(evt); + } + }); + + buttonCancel.setMnemonic('C'); + buttonCancel.setText("Cancel"); + buttonCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonCancelActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textReferenceNumber)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(textEntrustmentDate) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(buttonUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(textReferenceNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(textEntrustmentDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel3) + .addGap(0, 52, Short.MAX_VALUE)) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonUpdate) + .addComponent(buttonCancel)) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed + // TODO add your handling code here: + dispose (); + }//GEN-LAST:event_buttonCancelActionPerformed + + private void buttonUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUpdateActionPerformed + // TODO add your handling code here: + boolean rt = Utility.updateNoticeDescription (selectednotice_id, + textDescription.getText()); + if (rt == false) + JOptionPane.showMessageDialog(this, ERROR_UPDATING); + else + dispose (); + }//GEN-LAST:event_buttonUpdateActionPerformed + private static final String ERROR_UPDATING = "Error in updating"; + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(DescriptionDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(DescriptionDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(DescriptionDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(DescriptionDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + DescriptionDialog dialog = new DescriptionDialog(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonCancel; + private javax.swing.JButton buttonUpdate; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea textDescription; + private javax.swing.JTextField textEntrustmentDate; + private javax.swing.JTextField textReferenceNumber; + // End of variables declaration//GEN-END:variables +} diff --git a/src/habeas/DraftStatusDialog.java b/src/habeas/DraftStatusDialog.java index 0154d47..0322a50 100644 --- a/src/habeas/DraftStatusDialog.java +++ b/src/habeas/DraftStatusDialog.java @@ -24,7 +24,8 @@ public class DraftStatusDialog extends javax.swing.JDialog { initComponents(); } - public void setDraftStatus (boolean created, boolean approved) { + public void setFields (int selid, boolean created, boolean approved) { + selectednotice_id = selid; checkDraftCreated.setSelected(created); checkDraftApproved.setSelected(approved); } @@ -108,7 +109,7 @@ public class DraftStatusDialog extends javax.swing.JDialog { private void buttonUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUpdateActionPerformed // TODO add your handling code here: - boolean rt = Utility.updateLegalNoticeDraftStatus (selectednotice_id, + boolean rt = Utility.updateNoticeDraftStatus (selectednotice_id, checkDraftCreated.isSelected(), checkDraftApproved.isSelected()); if (rt == false) @@ -167,7 +168,4 @@ public class DraftStatusDialog extends javax.swing.JDialog { private javax.swing.JCheckBox checkDraftCreated; // End of variables declaration//GEN-END:variables - void setSelectedNotice(int selid) { - selectednotice_id = selid; - } } diff --git a/src/habeas/ManageNoticesDialog.form b/src/habeas/ManageNoticesDialog.form index 1b16cff..3a5c2f1 100644 --- a/src/habeas/ManageNoticesDialog.form +++ b/src/habeas/ManageNoticesDialog.form @@ -8,6 +8,14 @@ + + + + + + + + diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java index 611f02d..73d73fe 100644 --- a/src/habeas/ManageNoticesDialog.java +++ b/src/habeas/ManageNoticesDialog.java @@ -9,6 +9,7 @@ import java.awt.Frame; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; +import java.util.Date; import javax.swing.table.DefaultTableModel; /** @@ -46,10 +47,19 @@ public class ManageNoticesDialog extends javax.swing.JDialog { private void initComponents() { popMenu = new javax.swing.JPopupMenu(); + menuDescription = new javax.swing.JMenuItem(); menuDraftStatus = new javax.swing.JMenuItem(); jScrollPane1 = new javax.swing.JScrollPane(); tableNotices = new javax.swing.JTable(); + menuDescription.setText("Description..."); + menuDescription.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + menuDescriptionActionPerformed(evt); + } + }); + popMenu.add(menuDescription); + menuDraftStatus.setMnemonic('D'); menuDraftStatus.setText("Draft Status..."); menuDraftStatus.setToolTipText(""); @@ -114,12 +124,23 @@ public class ManageNoticesDialog extends javax.swing.JDialog { ArrayList notice = Utility.getNoticeDetails (selid); if (notice == null) return; - frm.setDraftStatus((boolean)notice.get(4), (boolean)notice.get(5)); - frm.setSelectedNotice (selid); + frm.setFields(selid, (boolean)notice.get(4), (boolean)notice.get(5)); frm.setVisible(true); }//GEN-LAST:event_menuDraftStatusActionPerformed + private void menuDescriptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDescriptionActionPerformed + // TODO add your handling code here: + int selid = getSelectedNotice(); + if (selid == -1) return; + DescriptionDialog frm = new DescriptionDialog((Frame)this.getParent(), true); + ArrayList notice = Utility.getNoticeDetails(selid); + if (notice == null) return; + frm.setFields(selid, (String)notice.get(0), (String)notice.get(1), (Date)notice.get(2)); + frm.setVisible(true); + populateNotices(); + }//GEN-LAST:event_menuDescriptionActionPerformed + /** * @param args the command line arguments */ @@ -164,6 +185,7 @@ public class ManageNoticesDialog extends javax.swing.JDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JMenuItem menuDescription; private javax.swing.JMenuItem menuDraftStatus; private javax.swing.JPopupMenu popMenu; private javax.swing.JTable tableNotices; diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index dd83144..f36623b 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -206,7 +206,7 @@ public class Utility { } private static final String JDBC = "jdbc:sqlite:"; - static boolean updateLegalNoticeDraftStatus(int selectednotice_id, boolean created, boolean approved) { + static boolean updateNoticeDraftStatus(int selectednotice_id, boolean created, boolean approved) { try { Connection conn = DriverManager.getConnection(JDBC + connectionURL); PreparedStatement st = conn.prepareStatement("UPDATE legalnotices " @@ -222,6 +222,23 @@ public class Utility { return false; } + } + + static boolean updateNoticeDescription(int selectednotice_id, String text) { + try { + Connection conn = DriverManager.getConnection(JDBC + connectionURL); + PreparedStatement st = conn.prepareStatement("UPDATE legalnotices " + + "SET Description=? WHERE id=?;"); + st.setString(1, text); + st.setInt(2, selectednotice_id); + st.execute(); + conn.close(); + return true; + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + } public Utility () { -- 2.20.1