From: Harishankar Date: Mon, 30 Mar 2020 10:19:46 +0000 (+0530) Subject: Manage Legal Notices functionality X-Git-Url: https://harishankar.org/repos/?p=habeas.git;a=commitdiff_plain;h=2ec9a68e727e3b67f003b43acd8593660fc90d26 Manage Legal Notices functionality Created the screen for managing legal notice. Created a popup menu to access individual notices editing options. --- diff --git a/src/habeas/CreateNoticeDialog.java b/src/habeas/CreateNoticeDialog.java index 82c70ea..940cb4f 100644 --- a/src/habeas/CreateNoticeDialog.java +++ b/src/habeas/CreateNoticeDialog.java @@ -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); diff --git a/src/habeas/MainFrame.form b/src/habeas/MainFrame.form index cd41daa..08f47f7 100644 --- a/src/habeas/MainFrame.form +++ b/src/habeas/MainFrame.form @@ -35,6 +35,15 @@ + + + + + + + + + diff --git a/src/habeas/MainFrame.java b/src/habeas/MainFrame.java index c40672c..a03494b 100644 --- a/src/habeas/MainFrame.java +++ b/src/habeas/MainFrame.java @@ -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 index 0000000..1b16cff --- /dev/null +++ b/src/habeas/ManageNoticesDialog.form @@ -0,0 +1,83 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+
+
+
+
+
diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java new file mode 100644 index 0000000..c23923e --- /dev/null +++ b/src/habeas/ManageNoticesDialog.java @@ -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") + // //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(); + }// //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 */ + // + /* 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); + } + // + + /* 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 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; + } +} diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index 8b27e7e..a1148a2 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -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 getNotices() { + ArrayList 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 () {