[power-architect] r4049 committed - A better fix for bug 3002. A comparator now correctly sorts only the c...

1 view
Skip to first unread message

codesite...@google.com

unread,
Jan 5, 2011, 1:06:19 PM1/5/11
to architec...@googlegroups.com
Revision: 4049
Author: thomaso...@gmail.com
Date: Wed Jan 5 10:05:22 2011
Log: A better fix for bug 3002. A comparator now correctly sorts only the
column that contains the error. The Other Values string is better handled
here as well.
http://code.google.com/p/power-architect/source/detail?r=4049

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

/trunk/src/main/java/ca/sqlpower/architect/swingui/ProfileResultsViewer.java

=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/profile/ColumnValueCount.java
Mon Dec 20 15:21:23 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/profile/ColumnValueCount.java
Wed Jan 5 10:05:22 2011
@@ -19,6 +19,7 @@
package ca.sqlpower.architect.profile;

import java.util.Collections;
+import java.util.Comparator;
import java.util.List;

import ca.sqlpower.object.AbstractSPObject;
@@ -27,6 +28,7 @@
import ca.sqlpower.object.annotation.Constructor;
import ca.sqlpower.object.annotation.ConstructorParameter;
import ca.sqlpower.object.annotation.Mutator;
+import ca.sqlpower.swingui.table.TableModelSortDecorator;

/**
* A simple class for keeping track of a value, the number of occurrences
@@ -49,11 +51,37 @@
* profile. The flag in this class for representing other values
should be
* checked for the official decision if this value count is all of the
other
* values.
- *
- * This is used the the TableModelSortDecorator in the library in
comparing table
- * rows so if you update this here, update it there as well.
*/
public static final String OTHER_VALUE_OBJECT = "Other Values";
+
+ /**
+ * A comparator that correctly sorts the value column of tables now
that the value
+ * column will always contain an entry for other values. Without
sorting with this
+ * comparator a class cast exception will occur if you sort only
numeric values.
+ */
+ public static class ColumnValueComparator implements
Comparator<Object> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int compare(Object o1, Object o2) {
+ if (o1 instanceof String &&
ColumnValueCount.OTHER_VALUE_OBJECT.equals((String)o1)) {
+ return 1;
+ } else if (o2 instanceof String &&
ColumnValueCount.OTHER_VALUE_OBJECT.equals((String)o2)) {
+ return -1;
+ } else if (o1 == null && o2 == null) {
+ return 0;
+ } else if (o1 == null) {
+ return -1;
+ } else if (o2 == null) {
+ return 1;
+ } else {
+ if (o1.getClass().equals(o2.getClass()) &&
Comparable.class.isAssignableFrom(o1.getClass())) {
+ return
TableModelSortDecorator.COMPARABLE_COMAPRATOR.compare(o1, o2);
+ }
+ return
TableModelSortDecorator.LEXICAL_COMPARATOR.compare(o1, o2);
+ }
+ }
+ }

private final Object value;
private final int count;
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ProfileGraphPanel.java
Tue Aug 10 09:55:27 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ProfileGraphPanel.java
Wed Jan 5 10:05:22 2011
@@ -70,6 +70,7 @@
*
*/
public class ProfileGraphPanel {
+
private JLabel rowCountDisplay;

private JLabel title;
@@ -366,6 +367,8 @@

FreqValueCountTableModel freqValueCountTableModel = new
FreqValueCountTableModel(cr);
TableModelSortDecorator sortModel = new
TableModelSortDecorator(freqValueCountTableModel);
+
sortModel.setColumnComparator(freqValueCountTableModel.getColumnClass(2),
+ new ColumnValueCount.ColumnValueComparator());
freqValueTable.setModel(sortModel);
sortModel.setTableHeader(freqValueTable.getTableHeader());
freqValueTable.initColumnSizes();
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ProfileResultsViewer.java
Tue Aug 10 09:55:27 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ProfileResultsViewer.java
Wed Jan 5 10:05:22 2011
@@ -60,6 +60,7 @@
import org.apache.log4j.Logger;

import ca.sqlpower.architect.ArchitectSession;
+import ca.sqlpower.architect.profile.ColumnValueCount;
import ca.sqlpower.architect.profile.ProfileManager;
import ca.sqlpower.architect.profile.ProfileResult;
import ca.sqlpower.architect.profile.TableProfileResult;
@@ -92,7 +93,7 @@
* A class that manages a viewer component for a set of Profile Results.
*/
public class ProfileResultsViewer {
-
+
private static final Logger logger =
Logger.getLogger(ProfileResultsViewer.class);

/**
@@ -476,6 +477,8 @@
JTextField columnSearchField = new JTextField("", 25);
//$NON-NLS-1$
final FancyExportableJTable columnTable = new
FancyExportableJTable(columnTableModel, columnSearchField
.getDocument());
+
columnTable.getTableModelSortDecorator().setColumnComparator(columnTableModel.getColumnClass(2),
+ new ColumnValueCount.ColumnValueComparator());
columnTableModel.addTableModelListener(new
TableModelListener() {
public void tableChanged(TableModelEvent e) {
TableUtils.fitColumnWidths(columnTable, 15);

Reply all
Reply to author
Forward
0 new messages