Manage Legal Notices functionality
authorHarishankar <v.harishankar@gmail.com>
Mon, 30 Mar 2020 10:19:46 +0000 (15:49 +0530)
committerHarishankar <v.harishankar@gmail.com>
Mon, 30 Mar 2020 10:19:46 +0000 (15:49 +0530)
Created the screen for managing legal notice.
Created a popup menu to access individual notices editing options.

src/habeas/CreateNoticeDialog.java
src/habeas/MainFrame.form
src/habeas/MainFrame.java
src/habeas/ManageNoticesDialog.form [new file with mode: 0644]
src/habeas/ManageNoticesDialog.java [new file with mode: 0644]
src/habeas/Utility.java

index 82c70ea..940cb4f 100644 (file)
@@ -20,6 +20,8 @@ public class CreateNoticeDialog extends javax.swing.JDialog {
 
     /**
      * Creates new form CreateNoticeDialog
+     * @param parent
+     * @param modal
      */
     public CreateNoticeDialog(java.awt.Frame parent, boolean modal) {
         super(parent, modal);
index cd41daa..08f47f7 100644 (file)
                 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuCreateNoticeActionPerformed"/>
               </Events>
             </MenuItem>
+            <MenuItem class="javax.swing.JMenuItem" name="menuManageNotices">
+              <Properties>
+                <Property name="mnemonic" type="int" value="77"/>
+                <Property name="text" type="java.lang.String" value="Manage Notices..."/>
+              </Properties>
+              <Events>
+                <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuManageNoticesActionPerformed"/>
+              </Events>
+            </MenuItem>
           </SubComponents>
         </Menu>
         <Menu class="javax.swing.JMenu" name="menuSettings">
index c40672c..a03494b 100644 (file)
@@ -32,6 +32,7 @@ public class MainFrame extends javax.swing.JFrame {
         menuClientMaster = new javax.swing.JMenuItem();
         menuLawyerNotices = new javax.swing.JMenu();
         menuCreateNotice = new javax.swing.JMenuItem();
+        menuManageNotices = new javax.swing.JMenuItem();
         menuSettings = new javax.swing.JMenu();
         menuDatabaseSettings = new javax.swing.JMenuItem();
 
@@ -64,6 +65,15 @@ public class MainFrame extends javax.swing.JFrame {
         });
         menuLawyerNotices.add(menuCreateNotice);
 
+        menuManageNotices.setMnemonic('M');
+        menuManageNotices.setText("Manage Notices...");
+        menuManageNotices.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                menuManageNoticesActionPerformed(evt);
+            }
+        });
+        menuLawyerNotices.add(menuManageNotices);
+
         jMenuBar1.add(menuLawyerNotices);
 
         menuSettings.setMnemonic('S');
@@ -114,6 +124,12 @@ public class MainFrame extends javax.swing.JFrame {
         frm.setVisible(true);
     }//GEN-LAST:event_menuCreateNoticeActionPerformed
 
+    private void menuManageNoticesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuManageNoticesActionPerformed
+        // TODO add your handling code here:
+        ManageNoticesDialog frm = new ManageNoticesDialog(this, true);
+        frm.setVisible(true);
+    }//GEN-LAST:event_menuManageNoticesActionPerformed
+
     /**
      * @param args the command line arguments
      */
@@ -155,6 +171,7 @@ public class MainFrame extends javax.swing.JFrame {
     private javax.swing.JMenuItem menuCreateNotice;
     private javax.swing.JMenuItem menuDatabaseSettings;
     private javax.swing.JMenu menuLawyerNotices;
+    private javax.swing.JMenuItem menuManageNotices;
     private javax.swing.JMenu menuMaster;
     private javax.swing.JMenu menuSettings;
     // End of variables declaration//GEN-END:variables
diff --git a/src/habeas/ManageNoticesDialog.form b/src/habeas/ManageNoticesDialog.form
new file mode 100644 (file)
index 0000000..1b16cff
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.6" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
+  <NonVisualComponents>
+    <Container class="javax.swing.JPopupMenu" name="popMenu">
+
+      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
+        <Property name="useNullLayout" type="boolean" value="true"/>
+      </Layout>
+      <SubComponents>
+        <MenuItem class="javax.swing.JMenuItem" name="menuDraftStatus">
+          <Properties>
+            <Property name="mnemonic" type="int" value="68"/>
+            <Property name="text" type="java.lang.String" value="Draft Status..."/>
+            <Property name="toolTipText" type="java.lang.String" value=""/>
+          </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuDraftStatusActionPerformed"/>
+          </Events>
+        </MenuItem>
+      </SubComponents>
+    </Container>
+  </NonVisualComponents>
+  <Properties>
+    <Property name="defaultCloseOperation" type="int" value="2"/>
+    <Property name="title" type="java.lang.String" value="Manage Notices"/>
+    <Property name="locationByPlatform" type="boolean" value="true"/>
+  </Properties>
+  <SyntheticProperties>
+    <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+    <SyntheticProperty name="generateCenter" type="boolean" value="false"/>
+  </SyntheticProperties>
+  <AuxValues>
+    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+  </AuxValues>
+
+  <Layout>
+    <DimensionLayout dim="0">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <Component id="jScrollPane1" alignment="0" pref="537" max="32767" attributes="0"/>
+      </Group>
+    </DimensionLayout>
+    <DimensionLayout dim="1">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <Component id="jScrollPane1" alignment="0" pref="317" max="32767" attributes="0"/>
+      </Group>
+    </DimensionLayout>
+  </Layout>
+  <SubComponents>
+    <Container class="javax.swing.JScrollPane" name="jScrollPane1">
+      <AuxValues>
+        <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+      </AuxValues>
+
+      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+      <SubComponents>
+        <Component class="javax.swing.JTable" name="tableNotices">
+          <Properties>
+            <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
+              <Table columnCount="3" rowCount="0">
+                <Column editable="false" title="id" type="java.lang.Integer"/>
+                <Column editable="false" title="Reference Number" type="java.lang.String"/>
+                <Column editable="false" title="Description" type="java.lang.String"/>
+              </Table>
+            </Property>
+            <Property name="selectionMode" type="int" value="0"/>
+            <Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor">
+              <JTableSelectionModel selectionMode="0"/>
+            </Property>
+          </Properties>
+        </Component>
+      </SubComponents>
+    </Container>
+  </SubComponents>
+</Form>
diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java
new file mode 100644 (file)
index 0000000..c23923e
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * 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.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.ArrayList;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.table.DefaultTableModel;
+
+/**
+ *
+ * @author hari
+ */
+public class ManageNoticesDialog extends javax.swing.JDialog {
+
+    /**
+     * Creates new form ManageNoticesDialog
+     */
+    public ManageNoticesDialog(java.awt.Frame parent, boolean modal) {
+        super(parent, modal);
+        initComponents();
+        populateNotices ();
+        tableNotices.add(popMenu);
+        tableNotices.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent arg0) {
+                if (arg0.isPopupTrigger()) {
+                    popMenu.show(arg0.getComponent(), arg0.getX(), arg0.getY());
+                }
+            }
+
+        });
+    }
+
+    /**
+     * 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")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        popMenu = new javax.swing.JPopupMenu();
+        menuDraftStatus = new javax.swing.JMenuItem();
+        jScrollPane1 = new javax.swing.JScrollPane();
+        tableNotices = new javax.swing.JTable();
+
+        menuDraftStatus.setMnemonic('D');
+        menuDraftStatus.setText("Draft Status...");
+        menuDraftStatus.setToolTipText("");
+        menuDraftStatus.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                menuDraftStatusActionPerformed(evt);
+            }
+        });
+        popMenu.add(menuDraftStatus);
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+        setTitle("Manage Notices");
+        setLocationByPlatform(true);
+
+        tableNotices.setModel(new javax.swing.table.DefaultTableModel(
+            new Object [][] {
+
+            },
+            new String [] {
+                "id", "Reference Number", "Description"
+            }
+        ) {
+            Class[] types = new Class [] {
+                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
+            };
+            boolean[] canEdit = new boolean [] {
+                false, false, false
+            };
+
+            public Class getColumnClass(int columnIndex) {
+                return types [columnIndex];
+            }
+
+            public boolean isCellEditable(int rowIndex, int columnIndex) {
+                return canEdit [columnIndex];
+            }
+        });
+        tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
+        tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
+        jScrollPane1.setViewportView(tableNotices);
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+        getContentPane().setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
+        );
+
+        pack();
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void menuDraftStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDraftStatusActionPerformed
+        // TODO add your handling code here:
+        int selid = getSelectedNotice ();
+        if (selid == -1) return;
+        
+        System.out.println (selid);
+        
+    }//GEN-LAST:event_menuDraftStatusActionPerformed
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String args[]) {
+        /* Set the Nimbus look and feel */
+        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+        /* 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(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (InstantiationException ex) {
+            java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+            java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        //</editor-fold>
+
+        /* Create and display the dialog */
+        java.awt.EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                ManageNoticesDialog dialog = new ManageNoticesDialog(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.JScrollPane jScrollPane1;
+    private javax.swing.JMenuItem menuDraftStatus;
+    private javax.swing.JPopupMenu popMenu;
+    private javax.swing.JTable tableNotices;
+    // End of variables declaration//GEN-END:variables
+
+    private void populateNotices() {
+        DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel ();
+        mdl.setRowCount(0);        
+        ArrayList<Object> notices = Utility.getNotices ();
+        if (notices == null) return;
+        for (int i = 0; i < notices.size(); i += 3) {
+            mdl.addRow (new Object[] { notices.get(i), notices.get(i+1),
+                notices.get(i+2)});
+        }
+    }
+
+    private int getSelectedNotice() {
+        int selid = tableNotices.getSelectedRow();
+        if (selid == -1)
+            return -1;
+        DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel();
+        int rkey = (int) mdl.getValueAt(selid, 0);
+        return rkey;
+    }
+}
index 8b27e7e..a1148a2 100644 (file)
@@ -118,7 +118,7 @@ public class Utility {
     static boolean addLegalNotice(String reference_number, 
             String description, java.util.Date entrustment_date, DBItem client) {
         if ("".equals(reference_number) || "".equals(description) ||
-                entrustment_date == null)
+                entrustment_date == null || client == null)
             return false;
         try {
             Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL);
@@ -138,6 +138,27 @@ public class Utility {
             return false;
         }
         
+    }
+
+    static ArrayList<Object> getNotices() {
+        ArrayList<Object> notices = new ArrayList<>();
+        try {
+            Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL);
+            Statement st = conn.createStatement();
+            ResultSet rs = st.executeQuery("SELECT id, ReferenceNumber, Description "
+                    + "FROM legalnotices;");
+            while (rs.next()) {
+                notices.add(rs.getInt("id"));
+                notices.add(rs.getString("ReferenceNumber"));
+                notices.add(rs.getString("Description"));
+            }
+            conn.close();
+            return notices;
+        } catch (SQLException ex) {
+            Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex);
+            return null;
+        }
+        
     }
     public Utility () {