Author: jfuerth
Date: Mon Sep 29 14:02:32 2008
New Revision: 2729

Modified:
   trunk/src/ca/sqlpower/architect/swingui/ProfileGraphPanel.java

Log:
Cleaned out some nullcheck code that was weird, wrong, and set a bad example for error handling (logger.error with no visibility to the UI!)

The only place this method was being called was already ensuring the arg is non-null, so I just documented the method to clarify that you can't pass in null.

Modified: trunk/src/ca/sqlpower/architect/swingui/ProfileGraphPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ProfileGraphPanel.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/ProfileGraphPanel.java Mon Sep 29 14:02:32 2008
@@ -155,6 +155,11 @@
         this.displayArea = displayArea;
     }

+    /**
+ * Switches the graph to show the value distribution for the given column.
+     *
+     * @param cr The profile result to display. Must not be null.
+     */
     public void displayProfile(ColumnProfileResult cr) {
         TableProfileResult tr = (TableProfileResult) cr.getParentResult();

@@ -173,47 +178,37 @@
         }
         setTitle(sb.toString());
         nullableLabel.setText(Boolean.toString(c.isDefinitelyNullable()));
-        if (cr == null) {
- ProfilePanel.logger.error("displayProfile called but unable to get ColumnProfileResult for column: "+c);

- // XXX the following code should instead replace chartPanel with a JLabel that contains the error message
-            //     (and also not create a dummy profile result)
-//            cr = new ColumnProfileResult(c, null, null);
-//            cr.setCreateStartTime(0);
-// chartPanel.setChart(ChartFactory.createPieChart("", new DefaultPieDataset(), false, false, false));
-            chartPanel.setChart(null);  // if this works, great!
-        } else {
-            chartPanel.setChart(createTopNChart(cr));
-            nullCountLabel.setText(Integer.toString(cr.getNullCount()));
-            int nullsInRecords = cr.getNullCount();
- double ratio = rowCount > 0 ? nullsInRecords * 100D / rowCount : 0;
-            nullPercentLabel.setText(format(ratio));
- uniqueCountLabel.setText(Integer.toString(cr.getDistinctValueCount())); - double uniqueRatio = rowCount > 0 ? cr.getDistinctValueCount() * 100D / rowCount : 0;
-            uniquePercentLabel.setText(format(uniqueRatio));
-            minLengthLabel.setText(Integer.toString(cr.getMinLength()));
-            maxLengthLabel.setText(Integer.toString(cr.getMaxLength()));
+        chartPanel.setChart(createTopNChart(cr));
+        nullCountLabel.setText(Integer.toString(cr.getNullCount()));
+        int nullsInRecords = cr.getNullCount();
+        double ratio = rowCount > 0 ? nullsInRecords * 100D / rowCount : 0;
+        nullPercentLabel.setText(format(ratio));
+ uniqueCountLabel.setText(Integer.toString(cr.getDistinctValueCount())); + double uniqueRatio = rowCount > 0 ? cr.getDistinctValueCount() * 100D / rowCount : 0;
+        uniquePercentLabel.setText(format(uniqueRatio));
+        minLengthLabel.setText(Integer.toString(cr.getMinLength()));
+        maxLengthLabel.setText(Integer.toString(cr.getMaxLength()));

- minValue.setText(cr.getMinValue() == null ? "" : cr.getMinValue().toString()); - maxValue.setText(cr.getMaxValue() == null ? "" : cr.getMaxValue().toString());
-            Object o = cr.getAvgValue();
-            if (o == null) {
-                avgValue.setText("");
-            } else if (o instanceof BigDecimal) {
-                double d = ((BigDecimal)o).doubleValue();
-                avgValue.setText(format(d));
-            } else {
- ProfilePanel.logger.debug("Got avgValue of type: " + o.getClass().getName());
-                avgValue.setText(cr.getAvgValue().toString());
-            }
+ minValue.setText(cr.getMinValue() == null ? "" : cr.getMinValue().toString()); + maxValue.setText(cr.getMaxValue() == null ? "" : cr.getMaxValue().toString());
+        Object o = cr.getAvgValue();
+        if (o == null) {
+            avgValue.setText("");
+        } else if (o instanceof BigDecimal) {
+            double d = ((BigDecimal)o).doubleValue();
+            avgValue.setText(format(d));
+        } else {
+ ProfilePanel.logger.debug("Got avgValue of type: " + o.getClass().getName());
+            avgValue.setText(cr.getAvgValue().toString());
+        }


- FreqValueCountTableModel freqValueCountTableModel = new FreqValueCountTableModel(cr); - TableModelSortDecorator sortModel = new TableModelSortDecorator(freqValueCountTableModel);
-            freqValueTable.setModel(sortModel);
-            sortModel.setTableHeader(freqValueTable.getTableHeader());
-            freqValueTable.initColumnSizes();
-        }
+ FreqValueCountTableModel freqValueCountTableModel = new FreqValueCountTableModel(cr); + TableModelSortDecorator sortModel = new TableModelSortDecorator(freqValueCountTableModel);
+        freqValueTable.setModel(sortModel);
+        sortModel.setTableHeader(freqValueTable.getTableHeader());
+        freqValueTable.initColumnSizes();
     }

     private JFreeChart createTopNChart(ColumnProfileResult cr){

Reply via email to