diff options
| author | Simon Rettberg | 2015-07-09 13:49:25 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-07-09 13:49:25 +0200 |
| commit | d9b4390a90bdbe2fb14fadc5176ff397337641a3 (patch) | |
| tree | d006023a952e3265b79433fc2f54b932bd054ff5 | |
| parent | Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff) | |
| download | tutor-module-d9b4390a90bdbe2fb14fadc5176ff397337641a3.tar.gz tutor-module-d9b4390a90bdbe2fb14fadc5176ff397337641a3.tar.xz tutor-module-d9b4390a90bdbe2fb14fadc5176ff397337641a3.zip | |
[client] Support message boxes with feedback; ask user whether to retry on thrift transport error
3 files changed, 16 insertions, 22 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index c9fc369e..abc975b8 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -13,6 +13,7 @@ import org.apache.log4j.PatternLayout; import org.apache.log4j.spi.LoggingEvent; import org.openslx.dozmod.gui.helper.GuiManager; import org.openslx.dozmod.util.ProxyConfigurator; +import org.openslx.thrifthelper.ThriftManager; public class App { @@ -99,6 +100,10 @@ public class App { return; } + // setup global thrift connection error handler before anything else + // Set master server to use (TODO: make configurable via command line) + ThriftManager.setMasterServerAddress("bwlp-masterserver.ruf.uni-freiburg.de"); + setupLogger(); // initialise the proxy settings diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java index 28da0824..c1084fb1 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java @@ -28,10 +28,7 @@ public abstract class GuiManager { private static Composite contentComposite; private static Display display; - private static final int THRIFT_RECONNECT_MAX_TRIES = 3; - private static final String THRIFT_CONNECTION_ERROR = "Lost connection to the masterserver."; - private static final String THRIFT_CONNECTION_DEAD = "Could not re-establish connection to the masterserver after " - + THRIFT_RECONNECT_MAX_TRIES + " tries. Contact an administrator/developer. Exiting application."; + private static final String THRIFT_CONNECTION_ERROR = "Lost connection to the masterserver. Do you want to retry?"; /** * Add a new composite with content to the main Shell @@ -109,26 +106,13 @@ public abstract class GuiManager { display = new Display(); mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER); - // setup global thrift connection error handler before anything else - // Set master server to use (TODO: make configurable via command line) - ThriftManager.setMasterServerAddress("bwlp-masterserver.ruf.uni-freiburg.de"); - // Set up thrift error message displaying ThriftManager.setErrorCallback(new ErrorCallback() { @Override public boolean thriftError(int failCount, String method, Throwable t) { - // first check if we failed 3 reconnects, if so just let the user know - // that we are closing the application due to connection problems. - if (failCount > THRIFT_RECONNECT_MAX_TRIES) { - showMessageBox(mainShell, THRIFT_CONNECTION_DEAD, MessageType.ERROR, LOGGER, t); - return false; - // System.exit(1); ? - } else { - showMessageBox(mainShell, THRIFT_CONNECTION_ERROR, MessageType.ERROR, LOGGER, t); - // TODO how to actualy reconnect? - return true; - } + // Ask user if we should retry + return showMessageBox(mainShell, THRIFT_CONNECTION_ERROR, MessageType.ERROR_RETRY, LOGGER, t); } }); @@ -188,8 +172,9 @@ public abstract class GuiManager { * @param messageType Type of message (warning, information) * @param logger Logger instance to log to. Can be null. * @param exception Exception related to this message. Can be null. + * @return true if OK, YES or RETRY was clicked, false for CANCEL or NO */ - public static void showMessageBox(Shell parent, String message, MessageType messageType, Logger logger, + public static boolean showMessageBox(Shell parent, String message, MessageType messageType, Logger logger, Throwable exception) { if (logger != null) logger.log(messageType.logPriority, message, exception); @@ -198,7 +183,8 @@ public abstract class GuiManager { MessageBox box = new MessageBox(parent, messageType.style); box.setMessage(message); box.setText(messageType.title); - box.open(); + int ret = box.open(); + return ret == SWT.OK || ret == SWT.RETRY || ret == SWT.YES; } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java index 9c2ae0b7..d05ac9b9 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/MessageType.java @@ -7,7 +7,10 @@ public enum MessageType { DEBUG(SWT.ICON_INFORMATION, "Debug", Level.DEBUG), INFO(SWT.ICON_INFORMATION, "Hinweis", Level.INFO), WARNING(SWT.ICON_WARNING, "Warnung", Level.WARN), - ERROR(SWT.ICON_ERROR, "Fehler", Level.ERROR); + WARNING_RETRY(SWT.ICON_WARNING | SWT.CANCEL | SWT.RETRY, "Fehler", Level.ERROR), + ERROR(SWT.ICON_ERROR, "Fehler", Level.ERROR), + ERROR_RETRY(SWT.ICON_ERROR | SWT.CANCEL | SWT.RETRY, "Fehler", Level.ERROR), + QUESTION_YESNO(SWT.ICON_QUESTION | SWT.YES | SWT.NO, "Frage", Level.INFO); public final String title; public final int style; |
