Manage Legal Notices - Delete
authorHarishankar <v.harishankar@gmail.com>
Tue, 31 Mar 2020 09:30:19 +0000 (15:00 +0530)
committerHarishankar <v.harishankar@gmail.com>
Tue, 31 Mar 2020 09:30:19 +0000 (15:00 +0530)
Created the functionality for deleting a legal notice.

src/habeas/ClarificationDetailsDialog.form
src/habeas/ClarificationDetailsDialog.java
src/habeas/Habeas.java
src/habeas/ManageNoticesDialog.form
src/habeas/ManageNoticesDialog.java
src/habeas/Utility.java

index 51f448d..2d6afdf 100644 (file)
   <Layout>
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <Group type="102" alignment="0" attributes="0">
+          <Group type="102" attributes="0">
               <EmptySpace max="32767" attributes="0"/>
-              <Group type="103" groupAlignment="1" attributes="0">
-                  <Group type="102" attributes="0">
-                      <Component id="buttonApply" min="-2" pref="106" max="-2" attributes="0"/>
-                      <EmptySpace max="-2" attributes="0"/>
-                      <Component id="buttonCancel" min="-2" pref="106" max="-2" attributes="0"/>
-                  </Group>
-                  <Group type="103" groupAlignment="0" max="-2" attributes="0">
-                      <Component id="checkClarificationPending" max="32767" attributes="0"/>
-                      <Component id="jLabel1" max="32767" attributes="0"/>
-                      <Component id="jScrollPane1" pref="369" max="32767" attributes="0"/>
+              <Group type="103" groupAlignment="0" attributes="0">
+                  <Component id="jScrollPane1" min="-2" pref="378" max="-2" attributes="0"/>
+                  <Group type="103" groupAlignment="1" attributes="0">
+                      <Group type="102" attributes="0">
+                          <Component id="buttonApply" min="-2" pref="106" max="-2" attributes="0"/>
+                          <EmptySpace max="-2" attributes="0"/>
+                          <Component id="buttonCancel" min="-2" pref="106" max="-2" attributes="0"/>
+                      </Group>
+                      <Group type="103" groupAlignment="0" max="-2" attributes="0">
+                          <Component id="checkClarificationPending" pref="369" max="32767" attributes="0"/>
+                          <Component id="jLabel1" max="32767" attributes="0"/>
+                      </Group>
                   </Group>
               </Group>
-              <EmptySpace pref="21" max="32767" attributes="0"/>
+              <EmptySpace max="32767" attributes="0"/>
           </Group>
       </Group>
     </DimensionLayout>
@@ -51,8 +53,8 @@
               <EmptySpace type="unrelated" max="-2" attributes="0"/>
               <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
-              <Component id="jScrollPane1" min="-2" pref="96" max="-2" attributes="0"/>
-              <EmptySpace pref="17" max="32767" attributes="0"/>
+              <Component id="jScrollPane1" pref="83" max="32767" attributes="0"/>
+              <EmptySpace type="unrelated" max="-2" attributes="0"/>
               <Group type="103" groupAlignment="3" attributes="0">
                   <Component id="buttonApply" alignment="3" min="-2" max="-2" attributes="0"/>
                   <Component id="buttonCancel" alignment="3" min="-2" max="-2" attributes="0"/>
index cbb64e1..ad58686 100644 (file)
@@ -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))
index b8b43d4..b1782f3 100644 (file)
@@ -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) {
index 75f457f..4d0bbb4 100644 (file)
             <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuDescriptionActionPerformed"/>
           </Events>
         </MenuItem>
+        <MenuItem class="javax.swing.JMenuItem" name="menuClarificationDetails">
+          <Properties>
+            <Property name="mnemonic" type="int" value="114"/>
+            <Property name="text" type="java.lang.String" value="Clarification Details..."/>
+          </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuClarificationDetailsActionPerformed"/>
+          </Events>
+        </MenuItem>
         <MenuItem class="javax.swing.JMenuItem" name="menuDraftStatus">
           <Properties>
             <Property name="mnemonic" type="int" value="68"/>
             <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuBillDetailsActionPerformed"/>
           </Events>
         </MenuItem>
-        <MenuItem class="javax.swing.JMenuItem" name="menuClarificationDetails">
+        <Component class="javax.swing.JPopupMenu$Separator" name="jSeparator1">
+        </Component>
+        <MenuItem class="javax.swing.JMenuItem" name="menuDelete">
           <Properties>
-            <Property name="mnemonic" type="int" value="114"/>
-            <Property name="text" type="java.lang.String" value="Clarification Details..."/>
+            <Property name="text" type="java.lang.String" value="Delete"/>
           </Properties>
           <Events>
-            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuClarificationDetailsActionPerformed"/>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuDeleteActionPerformed"/>
           </Events>
         </MenuItem>
       </SubComponents>
index 50928a4..1836c70 100644 (file)
@@ -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;
index f7fdae7..aac247c 100644 (file)
@@ -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 () {