Author: jfuerth
Date: Tue Sep 30 10:53:46 2008
New Revision: 2735
Modified:
trunk/src/ca/sqlpower/architect/diff/CompareSQL.java
trunk/src/ca/sqlpower/architect/diff/SQLObjectComparator.java
trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java
Log:
Fixed the plumbing in the compare dm panel and the comparesql worker so
that the current table name shows up while the comparison is running. This
was almost working for years; just a few pieces have been missing all along!
Modified: trunk/src/ca/sqlpower/architect/diff/CompareSQL.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/diff/CompareSQL.java (original)
+++ trunk/src/ca/sqlpower/architect/diff/CompareSQL.java Tue Sep 30
10:53:46 2008
@@ -39,7 +39,11 @@
public class CompareSQL implements Monitorable {
- private static final Logger logger = Logger.getLogger(CompareSQL.class);
+ private static final char LEFT_RIGHT_ARROW = '\u2194';
+ private static final char LEFT_ARROW = '\u2190';
+ private static final char RIGHT_ARROW = '\u2192';
+
+ private static final Logger logger =
Logger.getLogger(CompareSQL.class);
/**
* A comparator that compares SQL Objects by name.
@@ -88,7 +92,7 @@
/**
* The table we're working on right now (for the progress monitor).
*/
- private String currentTableName;
+ private String progressMessage;
/**
* A switch to indicate whether indices with be compared.
@@ -173,7 +177,7 @@
// bring the source table up to the same level
as the target
if (comparator.compare(sourceTable, targetTable)
< 0) {
results.add(new
DiffChunk<SQLObject>(sourceTable, DiffType.LEFTONLY));
- incProgress(1);
+ incProgress(1, sourceTable,
targetTable);
//results.addAll(generateColumnDiffs(sourceTable, null));
if (sourceIter.hasNext()) {
sourceTable = (SQLTable)
sourceIter.next();
@@ -186,7 +190,7 @@
// bring the target table up to the same level
as the source
if (comparator.compare(sourceTable, targetTable)
> 0) {
results.add(new DiffChunk<SQLObject>(targetTable,
DiffType.RIGHTONLY));
- incProgress(1);
+ incProgress(1, sourceTable,
targetTable);
// now don't do the columns it's
already handled
//results.addAll(generateColumnDiffs(null, targetTable));
if (targetIter.hasNext()) {
@@ -198,7 +202,7 @@
if (comparator.compare(sourceTable,
targetTable) == 0) {
results.add(new
DiffChunk<SQLObject>(sourceTable, DiffType.SAME));
- incProgress(1);
+ incProgress(1, sourceTable,
targetTable);
// now do the columns
results.addAll(generateColumnDiffs(sourceTable, targetTable));
if (!targetIter.hasNext() &&
!sourceIter.hasNext())
@@ -225,7 +229,7 @@
// If any tables in the sourceList still exist, the
changes are added
while (sourceContinue && !isCancelled()) {
results.add(new
DiffChunk<SQLObject>(sourceTable, DiffType.LEFTONLY));
- incProgress(1);
+ incProgress(1, sourceTable, null);
//results.addAll(generateColumnDiffs(sourceTable, null));
if (sourceIter.hasNext()) {
sourceTable = (SQLTable)
sourceIter.next();
@@ -238,7 +242,7 @@
while (targetContinue && !isCancelled()) {
results.add(new
DiffChunk<SQLObject>(targetTable, DiffType.RIGHTONLY));
- incProgress(1);
+ incProgress(1, null, targetTable);
//results.addAll(generateColumnDiffs(null,
targetTable));
if (targetIter.hasNext()) {
@@ -266,14 +270,14 @@
Set<SQLRelationship> targetRels = new
TreeSet<SQLRelationship>(relComparator);
for (SQLTable t : sourceTables) {
- incProgress(1);
+ incProgress(1, t, null);
if (t.getImportedKeys() != null){
sourceRels.addAll(t.getImportedKeys());
}
}
for (SQLTable t : targetTables) {
- incProgress(1);
+ incProgress(1, null, t);
if (t.getImportedKeys() != null){
targetRels.addAll(t.getImportedKeys());
}
@@ -399,14 +403,14 @@
Set<SQLIndex> targetInds = new TreeSet<SQLIndex>(indComparator);
for (SQLTable t : sourceTables) {
- incProgress(1);
+ incProgress(1, t, null);
if (t.getIndices() != null){
sourceInds.addAll(t.getIndices());
}
}
for (SQLTable t : targetTables) {
- incProgress(1);
+ incProgress(1, null, t);
if (t.getIndices() != null){
targetInds.addAll(t.getIndices());
}
@@ -686,7 +690,7 @@
}
public synchronized String getMessage() {
- return currentTableName;
+ return progressMessage;
}
public synchronized void setCancelled(boolean cancelled) {
@@ -705,7 +709,24 @@
this.progress = progress;
}
- private synchronized void incProgress(int amount) {
+ /**
+ * Increments the progress by the given amount and changes the message
+ * to reflect the current objects being compared.
+ *
+ * @param amount The number of units to increment progress by.
+ * @param lhs The current left-hand object of comparison. Can be null.
+ * @param rhs The current right-hand object of comparison. Can be null.
+ */
+ private synchronized void incProgress(int amount, SQLObject lhs,
SQLObject rhs) {
+ if (lhs != null && rhs != null) {
+ progressMessage = lhs + " " + LEFT_RIGHT_ARROW + " " + rhs;
+ } else if (lhs != null) {
+ progressMessage = LEFT_ARROW + " " + lhs.getName();
+ } else if (rhs != null) {
+ progressMessage = RIGHT_ARROW + " " + rhs.getName();
+ } else {
+ progressMessage = null;
+ }
this.progress += amount;
}
Modified: trunk/src/ca/sqlpower/architect/diff/SQLObjectComparator.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/diff/SQLObjectComparator.java
(original)
+++ trunk/src/ca/sqlpower/architect/diff/SQLObjectComparator.java Tue Sep
30 10:53:46 2008
@@ -20,11 +20,26 @@
import java.io.Serializable;
import java.util.Comparator;
+import java.util.Locale;
import ca.sqlpower.architect.SQLObject;
public class SQLObjectComparator implements Comparator<SQLObject>,
Serializable {
+ /**
+ * Compares two SQLObjects case-insensitively by name only. Case
comparison
+ * is performed with respect to the current default locale. No subtype
+ * checking is performed, so (wlog) a table and a relationship with
the same
+ * name will compare equal to each other.
+ * <p>
+ * Null values are allowed for either side of the comparison, and are
+ * considered to come before non-null values. Nulls are taken as equal
to
+ * each other.
+ */
+ @edu.umd.cs.findbugs.annotations.SuppressWarnings(
+ value={"ES_COMPARING_PARAMETER_STRING_WITH_EQ"},
+ justification="It's just a pre-check for null==null or
reference equality by luck. " +
+ "Falls back to String.compareTo() at the end of
the method.")
public int compare(SQLObject t1, SQLObject t2) {
// if t1 and t2 refer to the same object, or are both null, then they're
equal
if (t1 == t2) return 0;
@@ -34,8 +49,8 @@
//TODO In version 2.0 we want this to be an option
String n1 = t1.getName();
String n2 = t2.getName();
- if (n1 != null) n1 = n1.toLowerCase();
- if (n2 != null) n2 = n2.toLowerCase();
+ if (n1 != null) n1 = n1.toLowerCase(Locale.getDefault());
+ if (n2 != null) n2 = n2.toLowerCase(Locale.getDefault());
if (n1 == n2) return 0;
else if (n1 == null) return -1;
else if (n2 == null) return 1;
Modified: trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java Tue Sep 30
10:53:46 2008
@@ -1193,7 +1193,9 @@
};
new Thread(compareWorker).start();
- ProgressWatcher.watchProgress(progressBar,sourceComp);
+ ProgressWatcher pw = new ProgressWatcher(progressBar, sourceComp,
statusLabel);
+ pw.setHideLabelWhenFinished(true);
+ pw.start();
}
private void reenableGUIComponents() {