added a simple method on dist maker that checks if the current version is up to date; also added a listener mechanism to the update process so callers can know when a check was done for the updates; also reversed the order of older versions; also resized some message dialogs

This commit is contained in:
Jon Vandegriff
2013-05-15 20:17:07 +00:00
parent 69919e4660
commit 8b2fed352a
5 changed files with 134 additions and 13 deletions

View File

@@ -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<Release> 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<Release> 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<Release> 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);

View File

@@ -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<String> 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<String> getMessages()
{
return messages;
}
}

View File

@@ -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();
}

View File

@@ -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;
}
}

View File

@@ -90,7 +90,6 @@ public class PickReleasePanel extends GlassPanel implements ActionListener, ZioR
*/
public void setConfiguration(List<Release> itemList)
{
LinkedList<Release> 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<Release> 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";