Reporting Functionality - resizing columns to content width
authorHarishankar <v.harishankar@gmail.com>
Thu, 2 Apr 2020 13:44:50 +0000 (19:14 +0530)
committerHarishankar <v.harishankar@gmail.com>
Thu, 2 Apr 2020 13:44:50 +0000 (19:14 +0530)
Functionality to resize columns to content width in the report screen.

src/habeas/MainFrame.form
src/habeas/MainFrame.java
src/habeas/NoticesReportViewDialog.form
src/habeas/NoticesReportViewDialog.java
src/habeas/Utility.java

index b91160d..1531f25 100644 (file)
                 <Property name="text" type="java.lang.String" value="Reports"/>
               </Properties>
               <SubComponents>
+                <MenuItem class="javax.swing.JMenuItem" name="menuNoticesToBeDrafted">
+                  <Properties>
+                    <Property name="text" type="java.lang.String" value="To Be Drafted..."/>
+                  </Properties>
+                  <Events>
+                    <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="menuNoticesToBeDraftedActionPerformed"/>
+                  </Events>
+                </MenuItem>
                 <MenuItem class="javax.swing.JMenuItem" name="menuNoticesClarificationPending">
                   <Properties>
                     <Property name="mnemonic" type="int" value="99"/>
index 3e84430..070a7f7 100644 (file)
@@ -39,6 +39,7 @@ public class MainFrame extends javax.swing.JFrame {
         jSeparator1 = new javax.swing.JPopupMenu.Separator();
         menuGenerateRaisedBills = new javax.swing.JMenuItem();
         menuNoticesReports = new javax.swing.JMenu();
+        menuNoticesToBeDrafted = new javax.swing.JMenuItem();
         menuNoticesClarificationPending = new javax.swing.JMenuItem();
         menuNoticeDraftAwaitingApproval = new javax.swing.JMenuItem();
         menuNoticesSentNotYetDelivered = new javax.swing.JMenuItem();
@@ -99,6 +100,14 @@ public class MainFrame extends javax.swing.JFrame {
         menuNoticesReports.setMnemonic('r');
         menuNoticesReports.setText("Reports");
 
+        menuNoticesToBeDrafted.setText("To Be Drafted...");
+        menuNoticesToBeDrafted.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                menuNoticesToBeDraftedActionPerformed(evt);
+            }
+        });
+        menuNoticesReports.add(menuNoticesToBeDrafted);
+
         menuNoticesClarificationPending.setMnemonic('c');
         menuNoticesClarificationPending.setText("Clarifications pending...");
         menuNoticesClarificationPending.addActionListener(new java.awt.event.ActionListener() {
@@ -271,6 +280,23 @@ public class MainFrame extends javax.swing.JFrame {
         frm.setupReportTable(rep, REPORT_TITLE_CLARIFICATIONS_PENDING, cols, data);
         frm.setVisible(true);
     }//GEN-LAST:event_menuNoticesClarificationPendingActionPerformed
+
+    private void menuNoticesToBeDraftedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNoticesToBeDraftedActionPerformed
+        // TODO add your handling code here:
+        NoticesReportViewDialog frm = new NoticesReportViewDialog(this, false);
+        String cols[] = {"Reference Number", "Description", "Entrustment Date",
+            "Clarification Remarks", "Client" };
+        int rep = 4;
+        ArrayList<Object> data = Utility.getReportData(rep, -1);
+        if (data == null) {
+            JOptionPane.showMessageDialog(this , ERROR_DISPLAYING_REPORT);
+            return;
+        }
+        frm.setupReportTable(rep, REPORT_TITLE_TO_BE_DRAFTED, cols, data);
+        frm.setVisible(true);
+                
+    }//GEN-LAST:event_menuNoticesToBeDraftedActionPerformed
+    private static final String REPORT_TITLE_TO_BE_DRAFTED = "To Be Drafted";
     private static final String REPORT_TITLE_CLARIFICATIONS_PENDING = "Clarifications Pending";
     private static final String REPORT_TITLE_DRAFTS_AWAITING_APPROVAL = "Drafts To Be Approved";
     public static final String REPORT_TITLE_NOTICES_SENT_NOT_DELIVERED = "Notices Sent Not Yet Delivered";
@@ -327,6 +353,7 @@ public class MainFrame extends javax.swing.JFrame {
     private javax.swing.JMenuItem menuNoticesClarificationPending;
     private javax.swing.JMenu menuNoticesReports;
     private javax.swing.JMenuItem menuNoticesSentNotYetDelivered;
+    private javax.swing.JMenuItem menuNoticesToBeDrafted;
     private javax.swing.JMenu menuSettings;
     private javax.swing.JMenuItem menuStationery;
     // End of variables declaration//GEN-END:variables
index 0cb16bc..2503a57 100644 (file)
@@ -56,9 +56,9 @@
               <EmptySpace max="-2" attributes="0"/>
               <Component id="checkFilterByClient" min="-2" pref="196" max="-2" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
-              <Component id="comboClients" min="-2" pref="322" max="-2" attributes="0"/>
+              <Component id="comboClients" max="32767" attributes="0"/>
               <EmptySpace max="-2" attributes="0"/>
-              <Component id="buttonApply" max="32767" attributes="0"/>
+              <Component id="buttonApply" min="-2" pref="106" max="-2" attributes="0"/>
           </Group>
       </Group>
     </DimensionLayout>
             <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
               <Table columnCount="0" rowCount="0"/>
             </Property>
+            <Property name="autoResizeMode" type="int" value="0"/>
             <Property name="cellSelectionEnabled" type="boolean" value="true"/>
             <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
               <TableColumnModel selectionModel="0"/>
             </Property>
+            <Property name="componentPopupMenu" type="javax.swing.JPopupMenu" editor="org.netbeans.modules.form.ComponentChooserEditor">
+              <ComponentRef name="popMenu"/>
+            </Property>
             <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
               <TableHeader reorderingAllowed="true" resizingAllowed="true"/>
             </Property>
index 2636cbc..8852409 100644 (file)
@@ -5,12 +5,17 @@
  */
 package habeas;
 
+import java.awt.Component;
 import java.util.ArrayList;
 import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
+import javax.swing.JTable;
 import javax.swing.filechooser.FileFilter;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableColumnModel;
 
 /**
  *
@@ -77,7 +82,9 @@ public class NoticesReportViewDialog extends javax.swing.JDialog {
 
             }
         ));
+        tableReport.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
         tableReport.setCellSelectionEnabled(true);
+        tableReport.setComponentPopupMenu(popMenu);
         jScrollPane2.setViewportView(tableReport);
 
         checkFilterByClient.setText("Filter by Client");
@@ -103,9 +110,9 @@ public class NoticesReportViewDialog extends javax.swing.JDialog {
                 .addContainerGap()
                 .addComponent(checkFilterByClient, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                .addComponent(comboClients, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addComponent(comboClients, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
-                .addComponent(buttonApply, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -228,7 +235,6 @@ public class NoticesReportViewDialog extends javax.swing.JDialog {
             }
         };
         tableReport.setModel(mdl);
-        tableReport.setComponentPopupMenu(popMenu);
         
         labelReportTitle.setText(title);
         populateReport ();
@@ -242,8 +248,27 @@ public class NoticesReportViewDialog extends javax.swing.JDialog {
             for (int j = 0; j < reportCols.length; j ++)
                 row[j] = reportData.get(i+j);
             mdl.addRow (row);
         }
+        // resize the column widths to content size
+        for (int i = 0; i < tableReport.getColumnCount(); i ++) {
+
+            TableColumn clm = tableReport.getColumnModel().getColumn (i);
+            int preferredWidth = clm.getMinWidth()+10;
+            int maxWidth = 300;
+            int minWidth = 100;
+            for (int r = 0; r < tableReport.getRowCount(); r ++) {
+                TableCellRenderer rend = tableReport.getCellRenderer(r, i);
+                Component c = tableReport.prepareRenderer(rend, r, i);
+                int width = c.getPreferredSize().width + tableReport.getIntercellSpacing().width;
+                preferredWidth = Math.max (preferredWidth, width+10);
+                if (preferredWidth >= maxWidth)
+                {
+                    preferredWidth = maxWidth;
+                    break;
+                }
+            }
+            clm.setPreferredWidth(Math.max(minWidth, preferredWidth));
+        }        
     }
 
     private void populateClients() {
index d54ace3..9df1ab5 100644 (file)
@@ -38,8 +38,11 @@ public class Utility {
             
             "SELECT ReferenceNumber, Description, EntrustmentDate, "
             + "ClarificationRemarks, ClientName FROM legalnotices INNER JOIN clients ON"
-            + " ClientId=clients.id WHERE ClarificationPending=1;"
+            + " ClientId=clients.id WHERE ClarificationPending=1;",
             
+            "SELECT ReferenceNumber, Description, EntrustmentDate, ClarificationRemarks"
+            + ", ClientName from legalnotices INNER JOIN clients ON ClientId=clients.id "
+            + "WHERE DraftCreated=0;"            
     } ;
 
     private static final String[] REPORTS_FILTERED = { "SELECT ReferenceNumber, Description"
@@ -57,7 +60,11 @@ public class Utility {
 
             "SELECT ReferenceNumber, Description, EntrustmentDate, "
             + "ClarificationRemarks, ClientName FROM legalnotices INNER JOIN clients ON"
-            + " ClientId=clients.id WHERE ClarificationPending=1 AND ClientId=?;"            
+            + " ClientId=clients.id WHERE ClarificationPending=1 AND ClientId=?;",
+
+            "SELECT ReferenceNumber, Description, EntrustmentDate, ClarificationRemarks"
+            + ", ClientName from legalnotices INNER JOIN clients ON ClientId=clients.id "
+            + "WHERE DraftCreated=0 AND ClientId=?;"            
     } ;    
     
     static void saveStationerySettings (String left_header,