From 5b12182f8ba1ad6811d37ba582095b45a34fde2f Mon Sep 17 00:00:00 2001 From: Harishankar Date: Tue, 31 Mar 2020 15:00:19 +0530 Subject: [PATCH] Manage Legal Notices - Delete Created the functionality for deleting a legal notice. --- src/habeas/ClarificationDetailsDialog.form | 30 ++++++++-------- src/habeas/ClarificationDetailsDialog.java | 25 ++++++------- src/habeas/Habeas.java | 2 +- src/habeas/ManageNoticesDialog.form | 18 +++++++--- src/habeas/ManageNoticesDialog.java | 41 ++++++++++++++++++---- src/habeas/Utility.java | 16 +++++++++ 6 files changed, 95 insertions(+), 37 deletions(-) diff --git a/src/habeas/ClarificationDetailsDialog.form b/src/habeas/ClarificationDetailsDialog.form index 51f448d..2d6afdf 100644 --- a/src/habeas/ClarificationDetailsDialog.form +++ b/src/habeas/ClarificationDetailsDialog.form @@ -25,21 +25,23 @@ - + - - - - - - - - - - + + + + + + + + + + + + - + @@ -51,8 +53,8 @@ - - + + diff --git a/src/habeas/ClarificationDetailsDialog.java b/src/habeas/ClarificationDetailsDialog.java index cbb64e1..ad58686 100644 --- a/src/habeas/ClarificationDetailsDialog.java +++ b/src/habeas/ClarificationDetailsDialog.java @@ -73,16 +73,17 @@ public class ClarificationDetailsDialog extends javax.swing.JDialog { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createSequentialGroup() - .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(checkClarificationPending, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE))) - .addContainerGap(21, Short.MAX_VALUE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(checkClarificationPending, javax.swing.GroupLayout.DEFAULT_SIZE, 369, Short.MAX_VALUE) + .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -92,8 +93,8 @@ public class ClarificationDetailsDialog extends javax.swing.JDialog { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonApply) .addComponent(buttonCancel)) diff --git a/src/habeas/Habeas.java b/src/habeas/Habeas.java index b8b43d4..b1782f3 100644 --- a/src/habeas/Habeas.java +++ b/src/habeas/Habeas.java @@ -24,7 +24,7 @@ public class Habeas { Utility.retrieveConnectionURL(); try { - UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException ex) { Logger.getLogger(Habeas.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { diff --git a/src/habeas/ManageNoticesDialog.form b/src/habeas/ManageNoticesDialog.form index 75f457f..4d0bbb4 100644 --- a/src/habeas/ManageNoticesDialog.form +++ b/src/habeas/ManageNoticesDialog.form @@ -17,6 +17,15 @@ + + + + + + + + + @@ -45,13 +54,14 @@ - + + + - - + - + diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java index 50928a4..1836c70 100644 --- a/src/habeas/ManageNoticesDialog.java +++ b/src/habeas/ManageNoticesDialog.java @@ -10,6 +10,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Date; +import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; /** @@ -47,10 +48,12 @@ public class ManageNoticesDialog extends javax.swing.JDialog { popMenu = new javax.swing.JPopupMenu(); menuDescription = new javax.swing.JMenuItem(); + menuClarificationDetails = new javax.swing.JMenuItem(); menuDraftStatus = new javax.swing.JMenuItem(); menuDispatchDetails = new javax.swing.JMenuItem(); menuBillDetails = new javax.swing.JMenuItem(); - menuClarificationDetails = new javax.swing.JMenuItem(); + jSeparator1 = new javax.swing.JPopupMenu.Separator(); + menuDelete = new javax.swing.JMenuItem(); jScrollPane1 = new javax.swing.JScrollPane(); tableNotices = new javax.swing.JTable(); @@ -63,6 +66,15 @@ public class ManageNoticesDialog extends javax.swing.JDialog { }); popMenu.add(menuDescription); + menuClarificationDetails.setMnemonic('r'); + menuClarificationDetails.setText("Clarification Details..."); + menuClarificationDetails.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + menuClarificationDetailsActionPerformed(evt); + } + }); + popMenu.add(menuClarificationDetails); + menuDraftStatus.setMnemonic('D'); menuDraftStatus.setText("Draft Status..."); menuDraftStatus.setToolTipText(""); @@ -90,15 +102,15 @@ public class ManageNoticesDialog extends javax.swing.JDialog { } }); popMenu.add(menuBillDetails); + popMenu.add(jSeparator1); - menuClarificationDetails.setMnemonic('r'); - menuClarificationDetails.setText("Clarification Details..."); - menuClarificationDetails.addActionListener(new java.awt.event.ActionListener() { + menuDelete.setText("Delete"); + menuDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - menuClarificationDetailsActionPerformed(evt); + menuDeleteActionPerformed(evt); } }); - popMenu.add(menuClarificationDetails); + popMenu.add(menuDelete); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Manage Notices"); @@ -210,6 +222,21 @@ public class ManageNoticesDialog extends javax.swing.JDialog { frm.setVisible(true); }//GEN-LAST:event_menuClarificationDetailsActionPerformed + private void menuDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDeleteActionPerformed + int selid = getSelectedNotice(); + if (selid == -1) return; + int conf = JOptionPane.showConfirmDialog((Frame)this.getParent(), CONFIRM_DELETE); + if (conf == JOptionPane.YES_OPTION) { + boolean rt = Utility.deleteNotice (selid); + if (rt == false) + JOptionPane.showMessageDialog(this, ERROR_DELETING); + else + populateNotices(); + } + }//GEN-LAST:event_menuDeleteActionPerformed + private static final String ERROR_DELETING = "Error in deleting"; + private static final String CONFIRM_DELETE = "Are you sure you wish to delete?"; + /** * @param args the command line arguments */ @@ -254,8 +281,10 @@ public class ManageNoticesDialog extends javax.swing.JDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JSeparator jSeparator1; private javax.swing.JMenuItem menuBillDetails; private javax.swing.JMenuItem menuClarificationDetails; + private javax.swing.JMenuItem menuDelete; private javax.swing.JMenuItem menuDescription; private javax.swing.JMenuItem menuDispatchDetails; private javax.swing.JMenuItem menuDraftStatus; diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index f7fdae7..aac247c 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -360,6 +360,22 @@ public class Utility { return false; } + } + + static boolean deleteNotice(int r) { + try { + Connection conn = DriverManager.getConnection(JDBC + connectionURL); + PreparedStatement st = conn.prepareStatement("DELETE FROM legalnotices" + + " WHERE id=?;"); + st.setInt(1, r); + 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