summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/GuiManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/gui/GuiManager.java')
-rw-r--r--dozentenmodul/src/main/java/gui/GuiManager.java55
1 files changed, 34 insertions, 21 deletions
diff --git a/dozentenmodul/src/main/java/gui/GuiManager.java b/dozentenmodul/src/main/java/gui/GuiManager.java
index 762b8433..fb58d386 100644
--- a/dozentenmodul/src/main/java/gui/GuiManager.java
+++ b/dozentenmodul/src/main/java/gui/GuiManager.java
@@ -14,6 +14,8 @@ import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.thrifthelper.ThriftManager.ErrorCallback;
public abstract class GuiManager {
@@ -23,6 +25,10 @@ public abstract class GuiManager {
static Composite contentComposite;
static Display display;
+ static final int THRIFT_ERROR_RETRY_COUNT = 3;
+ static final String THRIFT_ERROR = "Lost connection to the masterserver. Click OK to retry.";
+ static final String THRIFT_FINAL_ERROR = "Could not re-establish connection to the masterserver after "
+ + THRIFT_ERROR_RETRY_COUNT + " tries. Contact an administrator/developer. Exiting application.";
/**
* Add a new composite with content to the main Shell
@@ -39,7 +45,6 @@ public abstract class GuiManager {
gridData.heightHint = 600;
contentComposite.setLayoutData(gridData);
mainShell.setMinimumSize(850, 650);
-
mainShell.layout();
}
@@ -55,28 +60,13 @@ public abstract class GuiManager {
}
// TODO use showMessageBox
- public static void showMessage(final String message) {
- MessageBox msgBox = new MessageBox(mainShell, SWT.ICON_INFORMATION);
+ public static void showMessage(final String message, final int style) {
+ MessageBox msgBox = new MessageBox(mainShell, style);
msgBox.setText("Information");
msgBox.setMessage(message);
int ret = msgBox.open();
+ LOGGER.info("Message box return value: " + ret);
}
-// /**
-// * Generic helper to show a message box to the user, and optionally log the message to the log file.
-// *
-// * @param message Message to display. Can be multi line.
-// * @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.
-// */
-// public static void showMessageBox(String message, MessageType messageType, Logger logger,
-// Throwable exception) {
-// if (logger != null)
-// logger.log(messageType.logPriority, message, exception);
-// if (exception != null)
-// message += "\n\n" + exception.getClass().getSimpleName();
-// JOptionPane.showMessageDialog(mainWindow, message, messageType.title, messageType.optionPaneId);
-// }
public static Display getDisplay(){
return display;
@@ -86,6 +76,29 @@ 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.
+ MessageBox msgBox = new MessageBox(mainShell, SWT.ICON_ERROR);
+ msgBox.setText("Critical error");
+ if (failCount > THRIFT_ERROR_RETRY_COUNT) {
+ msgBox.setMessage(THRIFT_FINAL_ERROR);
+ return false;
+ } else {
+ msgBox.setMessage(THRIFT_ERROR);
+ return true;
+ }
+ }
+ });
+
Menu menuBar = new Menu(mainShell, SWT.BAR);
MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE);
cascadeFileMenu.setText("&File");
@@ -103,15 +116,15 @@ public abstract class GuiManager {
}
});
- mainShell.setText("Dozmod");
+ mainShell.setText("bwSuite");
mainShell.setMenuBar(menuBar);
// Set layout for the mainshell, items added to the shell should get a gridData
mainShell.setLayout(new GridLayout(1, true));
+ showMessage(THRIFT_ERROR, SWT.ICON_ERROR);
addContent(new gui.core.LoginGUI(mainShell));
-
// center the window on the primary monitor
Monitor primary = display.getPrimaryMonitor();
Rectangle bounds = primary.getBounds();