Revision: 3559
Author: [email protected]
Date: Wed May 26 14:59:32 2010
Log: Cleaned up the threading in the RevisionsListPanel, and removed the useless Refresh button from the CompareRevisionsPanel.
http://code.google.com/p/power-architect/source/detail?r=3559

Modified:
/trunk/src/main/java/ca/sqlpower/architect/swingui/enterprise/CompareRevisionsPanel.java /trunk/src/main/java/ca/sqlpower/architect/swingui/enterprise/RevisionListPanel.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/enterprise/CompareRevisionsPanel.java Fri Feb 26 12:26:46 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/enterprise/CompareRevisionsPanel.java Wed May 26 14:59:32 2010
@@ -68,17 +68,6 @@

     private final JPanel panel;

-    private final long fromRevision;
-    private final long toRevision;
-
-    private final Action refreshAction = new AbstractAction("Refresh...") {
-        public void actionPerformed(ActionEvent e) {
- revisionsTableLeft.refreshRevisionsList(fromRevision, toRevision); - revisionsTableRight.refreshRevisionsList(fromRevision, toRevision);
-            refreshPanel();
-        }
-    };
-
     private final Action compareAction = new AbstractAction("Compare...") {
         public void actionPerformed(ActionEvent e) {
             this.setEnabled(false);
@@ -87,7 +76,7 @@
                 d.insertString(0, "...", new SimpleAttributeSet());
             } catch (BadLocationException ex) {
                 // Impossible
-                logger.error(ex);
+                throw new RuntimeException(ex);
             }
             comparePane.setStyledDocument(d);
             new Thread(new Runnable() {
@@ -102,8 +91,6 @@
             Action closeAction, long fromRevision, long toRevision) {

         this.session = session;
-        this.fromRevision = fromRevision;
-        this.toRevision = toRevision;

revisionsTableLeft = new RevisionsTable(this.session, fromRevision, toRevision); revisionsTableRight = new RevisionsTable(this.session, fromRevision, toRevision);
@@ -145,7 +132,6 @@
revisionListsBuilder.add(revisionsTableRight.getScrollPane(), cc.xy(3, 3));

DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
-        buttonBarBuilder.append(new JButton(refreshAction));
         buttonBarBuilder.append(new JButton(compareAction));
         buttonBarBuilder.append(new JButton(closeAction));
         buttonBarBuilder.append(autoCompare);
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/enterprise/RevisionListPanel.java Wed May 26 08:47:43 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/enterprise/RevisionListPanel.java Wed May 26 14:59:32 2010
@@ -57,6 +57,8 @@

 public class RevisionListPanel {

+    public static final int DEFAULT_REVISION_RANGE = 100;
+
     private class JLongField {

         private JFormattedTextField field;
@@ -123,12 +125,10 @@

             String message = null;
             if (toVersion.getValue() > currentVersion) {
- message = "Revisions up to " + toVersion.getValue() + " cannot be shown " +
-                "because the current revision is only " + currentVersion;
                 toVersion.setValue(currentVersion);
             } else if (fromVersion.getValue() > toVersion.getValue()) {
message = "Cannot show revisions from a higher version to a lower version";
-                long to = toVersion.getValue() - 100;
+                long to = toVersion.getValue() - DEFAULT_REVISION_RANGE;
                 if (to <= 0) to = 1;
                 fromVersion.setValue(to);
             }
@@ -163,29 +163,37 @@
                     "Revert...", JOptionPane.OK_CANCEL_OPTION);
             if (response == JOptionPane.OK_OPTION) {
                 revertAction.setEnabled(false);
-                new Thread(new Runnable() {
+                swingSession.runInBackground(new Runnable() {
                     public void run() {
                         try {
- int currentVersion = session.revertServerWorkspace(revisionNo);
-                            if (currentVersion == -1) {
- JOptionPane.showMessageDialog(dialogOwner, "The server did not revert" + - " because the target and current revisions are identical");
-                            } else {
- RevisionListPanel.this.currentVersion = currentVersion; - long range = toVersion.getValue() - fromVersion.getValue(); - fromVersion.setValue(currentVersion - range);
-                                toVersion.setValue(currentVersion);
- revisionsTable.refreshRevisionsList(fromVersion.getValue(), toVersion.getValue()); - int last = revisionsTable.getRowCount() - 1; - revisionsTable.getSelectionModel().setSelectionInterval(last, last);
-                            }
+ final int currentVersion = session.revertServerWorkspace(revisionNo);
+                            swingSession.runInForeground(new Runnable() {
+                                public void run() {
+                                    if (currentVersion == -1) {
+ JOptionPane.showMessageDialog(dialogOwner, "The server did not revert" + + " because the target and current revisions are identical");
+                                    } else {
+ // This is doing the refresh action's + // job for it, but this should probably + // auto refresh even when auto-refresh
+                                        // is turned off
+ RevisionListPanel.this.currentVersion = currentVersion; + long range = toVersion.getValue() - fromVersion.getValue(); + fromVersion.setValue(currentVersion - range);
+                                        toVersion.setValue(currentVersion);
+ revisionsTable.refreshRevisionsList(fromVersion.getValue(), toVersion.getValue()); + int last = revisionsTable.getRowCount() - 1; + revisionsTable.getSelectionModel().setSelectionInterval(last, last);
+                                    }
+                                }
+                            });
                         } catch (Throwable t) {
throw new RuntimeException("Error requesting server revert", t);
                         } finally {
                             refreshPanel();
                         }
                     }
-                }).start();
+                });
             }
         }
     };
@@ -253,7 +261,7 @@
                 "pref, 2dlu, default:grow"));

         int currentRevision = session.getUpdater().getRevision();
-        long from = currentRevision - 100;
+        long from = currentRevision - DEFAULT_REVISION_RANGE;
         if (from <= 0) from = 1;
         fromVersion = new JLongField(from);
         toVersion = new JLongField(currentRevision);

Reply via email to