diff --git a/src/distMaker/DistMakerEngine.java b/src/distMaker/DistMakerEngine.java index ee159bb..93dbf98 100644 --- a/src/distMaker/DistMakerEngine.java +++ b/src/distMaker/DistMakerEngine.java @@ -17,12 +17,17 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; +import java.util.Collections; +import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.swing.JFrame; import javax.swing.SwingUtilities; +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; + import distMaker.gui.PickReleasePanel; import distMaker.node.Node; import distMaker.platform.AppleUtils; @@ -48,9 +53,9 @@ public class DistMakerEngine parentFrame = aParentFrame; msgPanel = new MessagePanel(parentFrame); - msgPanel.setSize(450, 250); + msgPanel.setSize(700, 400); promptPanel = new PromptPanel(parentFrame); - promptPanel.setSize(400, 200); + promptPanel.setSize(500, 300); initialize(); } @@ -58,7 +63,7 @@ public class DistMakerEngine /** * Method that will notify the user that updates are being checked for */ - public void checkForUpdates() + public void checkForUpdates(UpdateCheckListener listener) { FullTaskPanel taskPanel; File installPath; @@ -94,9 +99,34 @@ public class DistMakerEngine taskPanel.setVisible(true); // Launch the actual checking of updates in a separate worker thread - ThreadUtil.launchRunnable(new FunctionRunnable(this, "checkForUpdatesWorker", taskPanel), "thread-checkForUpdates"); + ThreadUtil.launchRunnable(new FunctionRunnable(this, "checkForUpdatesWorker", taskPanel, listener), "thread-checkForUpdates"); } + /** + * returns + * @return + */ + public UpdateStatus isUpToDate() + { + LoggingTask task = new LoggingTask(); + String appName = currRelease.getName(); + List unsortedReleaseList = DistUtils.getAvailableReleases(task, updateSiteUrl, appName, refCredential); + + if (unsortedReleaseList == null) { + // The update check failed, so return a status of false with a message about the problem + String msg = Joiner.on("; ").join(task.getMessages()); + return new UpdateStatus(msg); + } + // Sort the items, and isolate the newest item + LinkedList fullList = Lists.newLinkedList(unsortedReleaseList); + Collections.sort(fullList); + Release newestRelease = fullList.removeLast(); + + // The check succeeded, so return wether or not the app is up to date. + return new UpdateStatus(newestRelease.equals(currRelease)); + } + + /** * Sets in the credentials used to access the update site. If either argument is null, then the credentials will be * cleared out. @@ -203,7 +233,7 @@ public class DistMakerEngine // Form the PickReleasePanel pickVersionPanel = new PickReleasePanel(parentFrame, currRelease); - pickVersionPanel.setSize(320, 350); + pickVersionPanel.setSize(550, 500); // 320, 350); } /** @@ -212,7 +242,7 @@ public class DistMakerEngine * This method will be called via reflection. */ @SuppressWarnings("unused") - private void checkForUpdatesWorker(FullTaskPanel aTask) + private void checkForUpdatesWorker(FullTaskPanel aTask, UpdateCheckListener listener) { List fullList; Release chosenItem; @@ -237,6 +267,9 @@ public class DistMakerEngine return; } + // a successful test has been done, so notify the listener + listener.checkForNewVersionsPerformed(); + // Hide the taskPanel aTask.setVisible(false); diff --git a/src/distMaker/LoggingTask.java b/src/distMaker/LoggingTask.java new file mode 100644 index 0000000..165aea9 --- /dev/null +++ b/src/distMaker/LoggingTask.java @@ -0,0 +1,38 @@ +package distMaker; + +import java.util.List; + +import com.google.common.collect.Lists; + +import glum.task.SilentTask; + +public class LoggingTask extends SilentTask +{ + private final List messages = Lists.newArrayList(); + + @Override + public void infoAppend(String aMsg) + { + messages.add(aMsg); + super.infoAppend(aMsg); + } + + @Override + public void infoAppendln(String aMsg) + { + messages.add(aMsg); + super.infoAppendln(aMsg); + } + + @Override + public void infoUpdate(String aMsg) + { + messages.add(aMsg); + super.infoUpdate(aMsg); + } + + List getMessages() + { + return messages; + } +} diff --git a/src/distMaker/UpdateCheckListener.java b/src/distMaker/UpdateCheckListener.java new file mode 100644 index 0000000..73d02c4 --- /dev/null +++ b/src/distMaker/UpdateCheckListener.java @@ -0,0 +1,12 @@ +package distMaker; + + +/** + * lets any interested party know that a check for for updates has been done + * + * @author vandejd1 + */ +public interface UpdateCheckListener +{ + void checkForNewVersionsPerformed(); +} diff --git a/src/distMaker/UpdateStatus.java b/src/distMaker/UpdateStatus.java new file mode 100644 index 0000000..9c4ffcd --- /dev/null +++ b/src/distMaker/UpdateStatus.java @@ -0,0 +1,37 @@ +package distMaker; + +public class UpdateStatus +{ + private final boolean isUpToDate; + private final boolean errorDeterminingState; + private final String errorMessage; + + public UpdateStatus(boolean isUpToDate) + { + this.isUpToDate = isUpToDate; + this.errorDeterminingState = false;; + this.errorMessage = ""; + } + + public UpdateStatus(String errorMessage) + { + this.isUpToDate = false; + this.errorDeterminingState = true; + this.errorMessage = errorMessage; + } + + public boolean isUpToDate() + { + return isUpToDate; + } + + public boolean isErrorDeterminingState() + { + return errorDeterminingState; + } + + public String getErrorMessage() + { + return errorMessage; + } +} diff --git a/src/distMaker/gui/PickReleasePanel.java b/src/distMaker/gui/PickReleasePanel.java index 4283d5b..58f4ea4 100644 --- a/src/distMaker/gui/PickReleasePanel.java +++ b/src/distMaker/gui/PickReleasePanel.java @@ -90,7 +90,6 @@ public class PickReleasePanel extends GlassPanel implements ActionListener, ZioR */ public void setConfiguration(List itemList) { - LinkedList fullList; DateUnit dateUnit; // String currBuildStr; String lastBuildStr; @@ -98,9 +97,11 @@ public class PickReleasePanel extends GlassPanel implements ActionListener, ZioR String appName, infoMsg; // Sort the items, and isolate the newest item - fullList = Lists.newLinkedList(itemList); - Collections.sort(fullList); - newestItem = fullList.removeLast(); + LinkedList linkedList; + linkedList = Lists.newLinkedList(itemList); + Collections.sort(linkedList); + Collections.reverse(linkedList); // reverse the list to show most recent versions on top + newestItem = linkedList.removeFirst(); // Retrieve vars of interest appName = installedItem.getName(); @@ -114,7 +115,7 @@ public class PickReleasePanel extends GlassPanel implements ActionListener, ZioR newestRB.setText("Latest: " + lastVerStr + " (" + lastBuildStr + ")"); // Update the list of available items - myItemProcessor.setItems(fullList); + myItemProcessor.setItems(linkedList); // Update the infoTA if (newestItem.equals(installedItem) == true) { @@ -124,8 +125,8 @@ public class PickReleasePanel extends GlassPanel implements ActionListener, ZioR infoMsg += "You may switch to an older release by choosing one of the versions below."; } else { titleL.setText(appName + " needs to be updated."); - infoMsg = "You are running version is " + currVerStr + ". "; - infoMsg += "You may update to the latest release or even to an " + infoMsg = "You are running version " + currVerStr + ". "; + infoMsg += "You may update to the latest release. You may also switch to an " + "older relase by choosing another version below. "; } infoMsg += "\n";