summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java
diff options
context:
space:
mode:
authorJonathan Bauer2015-07-10 09:25:24 +0200
committerJonathan Bauer2015-07-10 09:25:24 +0200
commit4f2026d557d5a5c27b0dcac0881d6c4b57e3dcae (patch)
tree14d6e7460e6b7fc9943ef505282acb9d595a7546 /dozentenmodul/src/main/java
parent[client] Only allow Composites to be passed to openPopup; make Ctrl-Q quit th... (diff)
downloadtutor-module-4f2026d557d5a5c27b0dcac0881d6c4b57e3dcae.tar.gz
tutor-module-4f2026d557d5a5c27b0dcac0881d6c4b57e3dcae.tar.xz
tutor-module-4f2026d557d5a5c27b0dcac0881d6c4b57e3dcae.zip
[client] GuiManager is now MainWindow, old MainWindow is now MainMenuWindow
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/App.java4
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java200
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java1
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java29
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java30
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainWindow.java195
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java4
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java6
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainMenuWindowLayout.java (renamed from dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainWindowLayout.java)4
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java4
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java10
11 files changed, 242 insertions, 245 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java
index abc975b8..505c9a37 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java
@@ -11,7 +11,7 @@ import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.spi.LoggingEvent;
-import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.window.MainWindow;
import org.openslx.dozmod.util.ProxyConfigurator;
import org.openslx.thrifthelper.ThriftManager;
@@ -114,7 +114,7 @@ public class App {
}
// start the GUI
- GuiManager.initGui();
+ MainWindow.initialise();
}
}
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
deleted file mode 100644
index 435ac2cc..00000000
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package org.openslx.dozmod.gui.helper;
-
-import java.lang.reflect.Constructor;
-
-import org.apache.log4j.Logger;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
-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.dozmod.gui.window.LoginWindow;
-import org.openslx.thrifthelper.ThriftManager;
-import org.openslx.thrifthelper.ThriftManager.ErrorCallback;
-
-public abstract class GuiManager {
-
- private final static Logger LOGGER = Logger.getLogger(GuiManager.class);
-
- private static Shell mainShell;
- private static Composite contentComposite;
- private static Display display;
-
- 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
- *
- * @param The composite to add, should be a GUI
- */
- public static void addContent(Composite contentComposite) {
- removeContent();
-
- GuiManager.contentComposite = contentComposite;
-
- // sets the starting preferred size.
- GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
- gridData.widthHint = 800;
- gridData.heightHint = 600;
- contentComposite.setLayoutData(gridData);
- mainShell.setMinimumSize(850, 650);
- mainShell.layout();
-
- }
-
- /**
- * Remove the current content of the main shell
- */
- private static void removeContent() {
- if (contentComposite != null) {
- GuiManager.contentComposite.dispose();
- }
- }
-
- /**
- * @param clazz Class to open as a popup over the main window
- */
- public static void openPopup(Class<? extends Composite> clazz, boolean modal) {
- Shell dialogShell = new Shell(mainShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
- // populate dialogShell
- dialogShell.setLayout(new GridLayout(1, false));
- LOGGER.debug(clazz.getDeclaredClasses());
- Constructor<?> con = null;
- try {
- con = clazz.getConstructor(Shell.class);
- con.newInstance(dialogShell);
- } catch (Exception e1) {
- showMessageBox(mainShell, "Cannot show popup " + clazz.getName(), MessageType.DEBUG, LOGGER, e1);
- return;
- }
-
- dialogShell.layout();
- dialogShell.pack();
- dialogShell.open();
- if (modal) {
- while (!dialogShell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- }
- }
-
- /**
- * @return The instance of SWT display currently in use
- */
- public static Display getDisplay() {
- return display;
- }
-
- /**
- * Initialises the GUI by creating the main window, adding the menu and
- * creating the login mask as the first content window.
- * Further sets up the global thrift error callback to catch any
- * connection errors during the communication with the servers.
- */
- public static void initGui() {
- // init SWT stuffs
- display = new Display();
- mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER);
-
- // Set up thrift error message displaying
- ThriftManager.setErrorCallback(new ErrorCallback() {
-
- @Override
- public boolean thriftError(int failCount, String method, Throwable t) {
- // Ask user if we should retry
- return showMessageBox(mainShell, THRIFT_CONNECTION_ERROR, MessageType.ERROR_RETRY, LOGGER, t);
- }
- });
-
- // Global key listener
- display.addFilter(SWT.KeyDown, new Listener() {
- @Override
- public void handleEvent(Event event) {
- if (event.character == 17) // Ctrl-Q = Quit
- System.exit(0);
- }
- });
-
- Menu menuBar = new Menu(mainShell, SWT.BAR);
- MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE);
- cascadeFileMenu.setText("&File");
-
- Menu fileMenu = new Menu(mainShell, SWT.DROP_DOWN);
- cascadeFileMenu.setMenu(fileMenu);
-
- MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
- exitItem.setText("&Exit");
- exitItem.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- System.exit(0);
- }
- });
-
- 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));
-
- // Add LoginWindow as the first window to be shown
- addContent(new LoginWindow(mainShell));
-
- // center the window on the primary monitor
- Monitor primary = display.getPrimaryMonitor();
- Rectangle bounds = primary.getBounds();
- Rectangle rect = mainShell.getBounds();
-
- int x = bounds.x + (bounds.width - rect.width) / 2;
- int y = bounds.y + (bounds.height - rect.height) / 2;
-
- mainShell.setLocation(x, y);
-
- mainShell.pack();
- mainShell.open();
-
- LOGGER.info("GUI initialised.");
-
- while (!mainShell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- }
-
- /**
- * Generic helper to show a message box to the user, and optionally log the
- * message to the log file.
- *
- * @param parent parent shell this message box belongs to
- * @param message Message to display. Can be multiline.
- * @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 boolean showMessageBox(Shell parent, 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() + " (Siehe Logdatei)";
- MessageBox box = new MessageBox(parent, messageType.style);
- box.setMessage(message);
- box.setText(messageType.title);
- 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/window/DisclaimerWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java
index dbd9c3cb..ea977a7f 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/DisclaimerWindow.java
@@ -5,7 +5,6 @@ import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Shell;
import org.openslx.dozmod.Config;
-import org.openslx.dozmod.gui.helper.GuiManager;
import org.openslx.dozmod.gui.window.layout.DisclaimerWindowLayout;
public class DisclaimerWindow extends DisclaimerWindowLayout{
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
index 39557059..e5d86e31 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LoginWindow.java
@@ -21,7 +21,6 @@ import org.openslx.dozmod.authentication.EcpAuthenticator;
import org.openslx.dozmod.authentication.ShibbolethEcp;
import org.openslx.dozmod.authentication.ShibbolethEcp.ReturnCode;
import org.openslx.dozmod.authentication.TestAccountAuthenticator;
-import org.openslx.dozmod.gui.helper.GuiManager;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.window.layout.LoginWindowLayout;
import org.openslx.dozmod.thrift.OrganizationCache;
@@ -219,7 +218,7 @@ public class LoginWindow extends LoginWindowLayout {
private void doLogin() {
// sanity check on loginType.
if (loginType == null) {
- GuiManager.showMessageBox(this.getShell(),
+ MainWindow.showMessageBox(this.getShell(),
"No login type set, a default should be set! Ignoring...", MessageType.ERROR, LOGGER,
null);
return;
@@ -229,11 +228,11 @@ public class LoginWindow extends LoginWindowLayout {
String password = passwordText.getText();
// login clicked, lets first read the fields
if (username.isEmpty()) {
- GuiManager.showMessageBox(this.getShell(), NO_USERNAME, MessageType.ERROR, null, null);
+ MainWindow.showMessageBox(this.getShell(), NO_USERNAME, MessageType.ERROR, null, null);
return;
}
if (password.isEmpty()) {
- GuiManager.showMessageBox(this.getShell(), NO_PASSWORD, MessageType.ERROR, null, null);
+ MainWindow.showMessageBox(this.getShell(), NO_PASSWORD, MessageType.ERROR, null, null);
return;
}
@@ -248,7 +247,7 @@ public class LoginWindow extends LoginWindowLayout {
public void postLogin(ReturnCode returnCode, UserInfo user, Throwable t) {
// TODO finish this
if (user == null) {
- GuiManager.showMessageBox(me.getShell(), "User information received from the masterserver is corrupt!",
+ MainWindow.showMessageBox(me.getShell(), "User information received from the masterserver is corrupt!",
MessageType.ERROR, LOGGER, null);
return;
}
@@ -257,21 +256,21 @@ public class LoginWindow extends LoginWindowLayout {
postSuccessfulLogin();
break;
case IDENTITY_PROVIDER_ERROR:
- GuiManager.showMessageBox(me.getShell(), "IdP Error", MessageType.ERROR, null, null);
+ MainWindow.showMessageBox(me.getShell(), "IdP Error", MessageType.ERROR, null, null);
break;
case SERVICE_PROVIDER_ERROR:
// here if we have t != null then we have not received a token
// if we have t, then the token is invalid.
- GuiManager.showMessageBox(me.getShell(), "Invalid token from the service provider!", MessageType.ERROR,
+ MainWindow.showMessageBox(me.getShell(), "Invalid token from the service provider!", MessageType.ERROR,
LOGGER, t);
break;
case UNREGISTERED_ERROR:
- GuiManager.showMessageBox(me.getShell(), "You are not registered to bwLehrpool. Please visit "
+ MainWindow.showMessageBox(me.getShell(), "You are not registered to bwLehrpool. Please visit "
+ ShibbolethEcp.getRegistrationUrl() + " and register first.", MessageType.ERROR,
LOGGER, t);
break;
default:
- GuiManager.showMessageBox(me.getShell(), "Internal error!", MessageType.ERROR, null, null);
+ MainWindow.showMessageBox(me.getShell(), "Internal error!", MessageType.ERROR, null, null);
break;
}
}
@@ -287,10 +286,10 @@ public class LoginWindow extends LoginWindowLayout {
authenticator = new TestAccountAuthenticator();
break;
case SAT:
- GuiManager.showMessageBox(this.getShell(), "Not yet implemented", MessageType.ERROR, null, null);
+ MainWindow.showMessageBox(this.getShell(), "Not yet implemented", MessageType.ERROR, null, null);
return;
default:
- GuiManager.showMessageBox(this.getShell(), "No login type selected!", MessageType.ERROR, null,
+ MainWindow.showMessageBox(this.getShell(), "No login type selected!", MessageType.ERROR, null,
null);
return;
}
@@ -299,7 +298,7 @@ public class LoginWindow extends LoginWindowLayout {
try {
authenticator.login(username, password, authenticatorCallback);
} catch (TAuthenticationException e) {
- GuiManager.showMessageBox(me.getShell(), "Authentication failed: " + e.getMessage(),
+ MainWindow.showMessageBox(me.getShell(), "Authentication failed: " + e.getMessage(),
MessageType.ERROR, LOGGER, null);
return;
}
@@ -314,12 +313,12 @@ public class LoginWindow extends LoginWindowLayout {
// TODO HACK HACK
ThriftManager.setSatelliteAddress("132.230.8.113");
- GuiManager.addContent(new MainWindow(getShell()));
+ MainWindow.addContent(new MainMenuWindow(getShell()));
// now read the config to see if the user already agreed to the disclaimer
if (!Config.getDisclaimerAgreement())
- GuiManager.openPopup(DisclaimerWindow.class, true);
+ MainWindow.openPopup(DisclaimerWindow.class, true);
if (!Config.getVmwareLicenseAgreement())
- GuiManager.openPopup(VirtualizerNoticeWindow.class, true);
+ MainWindow.openPopup(VirtualizerNoticeWindow.class, true);
// TODO: See MainWindowLayout comments
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java
new file mode 100644
index 00000000..4c022f3e
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java
@@ -0,0 +1,30 @@
+package org.openslx.dozmod.gui.window;
+
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.openslx.dozmod.gui.window.layout.MainMenuWindowLayout;
+
+public class MainMenuWindow extends MainMenuWindowLayout {
+
+ public MainMenuWindow(Shell mainShell) {
+ super(mainShell);
+ // TODO Auto-generated constructor stub
+ // function for vmButton
+ vmButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ MainWindow.addContent(new ImageListWindow(getShell()));
+ }
+ });
+
+ // function for lecturesButton
+ lecturesButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ //
+ }
+ });
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainWindow.java
index 195f748f..43156049 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainWindow.java
@@ -1,31 +1,200 @@
package org.openslx.dozmod.gui.window;
+import java.lang.reflect.Constructor;
+
+import org.apache.log4j.Logger;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+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.dozmod.gui.helper.GuiManager;
-import org.openslx.dozmod.gui.window.layout.MainWindowLayout;
+import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.thrifthelper.ThriftManager.ErrorCallback;
+
+public abstract class MainWindow {
+
+ private final static Logger LOGGER = Logger.getLogger(MainWindow.class);
+
+ private static Shell mainShell;
+ private static Composite contentComposite;
+ private static Display display;
+
+ 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
+ *
+ * @param The composite to add, should be a GUI
+ */
+ public static void addContent(Composite contentComposite) {
+ removeContent();
+
+ MainWindow.contentComposite = contentComposite;
+
+ // sets the starting preferred size.
+ GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
+ gridData.widthHint = 800;
+ gridData.heightHint = 600;
+ contentComposite.setLayoutData(gridData);
+ mainShell.setMinimumSize(850, 650);
+ mainShell.layout();
+
+ }
+
+ /**
+ * Remove the current content of the main shell
+ */
+ private static void removeContent() {
+ if (contentComposite != null) {
+ MainWindow.contentComposite.dispose();
+ }
+ }
+
+ /**
+ * @param clazz Class to open as a popup over the main window
+ */
+ public static void openPopup(Class<? extends Composite> clazz, boolean modal) {
+ Shell dialogShell = new Shell(mainShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ // populate dialogShell
+ dialogShell.setLayout(new GridLayout(1, false));
+ LOGGER.debug(clazz.getDeclaredClasses());
+ Constructor<?> con = null;
+ try {
+ con = clazz.getConstructor(Shell.class);
+ con.newInstance(dialogShell);
+ } catch (Exception e1) {
+ showMessageBox(mainShell, "Cannot show popup " + clazz.getName(), MessageType.DEBUG, LOGGER, e1);
+ return;
+ }
+
+ dialogShell.layout();
+ dialogShell.pack();
+ dialogShell.open();
+ if (modal) {
+ while (!dialogShell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ }
+ }
+
+ /**
+ * @return The instance of SWT display currently in use
+ */
+ public static Display getDisplay() {
+ return display;
+ }
+
+ /**
+ * Initialises the GUI by creating the main window, adding the menu and
+ * creating the login mask as the first content window.
+ * Further sets up the global thrift error callback to catch any
+ * connection errors during the communication with the servers.
+ */
+ public static void initialise() {
+ // init SWT stuffs
+ display = new Display();
+ mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER);
-public class MainWindow extends MainWindowLayout {
+ // Set up thrift error message displaying
+ ThriftManager.setErrorCallback(new ErrorCallback() {
- public MainWindow(Shell mainShell) {
- super(mainShell);
- // TODO Auto-generated constructor stub
- // function for vmButton
- vmButton.addSelectionListener(new SelectionAdapter() {
@Override
- public void widgetSelected(SelectionEvent e) {
- GuiManager.addContent(new ImageListWindow(getShell()));
+ public boolean thriftError(int failCount, String method, Throwable t) {
+ // Ask user if we should retry
+ return showMessageBox(mainShell, THRIFT_CONNECTION_ERROR, MessageType.ERROR_RETRY, LOGGER, t);
}
});
- // function for lecturesButton
- lecturesButton.addSelectionListener(new SelectionAdapter() {
+ // Global key listener
+ display.addFilter(SWT.KeyDown, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if (event.character == 17) // Ctrl-Q = Quit
+ System.exit(0);
+ }
+ });
+
+ Menu menuBar = new Menu(mainShell, SWT.BAR);
+ MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE);
+ cascadeFileMenu.setText("&File");
+
+ Menu fileMenu = new Menu(mainShell, SWT.DROP_DOWN);
+ cascadeFileMenu.setMenu(fileMenu);
+
+ MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
+ exitItem.setText("&Exit");
+ exitItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- //
+ System.exit(0);
}
});
+
+ 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));
+
+ // Add LoginWindow as the first window to be shown
+ addContent(new LoginWindow(mainShell));
+
+ // center the window on the primary monitor
+ Monitor primary = display.getPrimaryMonitor();
+ Rectangle bounds = primary.getBounds();
+ Rectangle rect = mainShell.getBounds();
+
+ int x = bounds.x + (bounds.width - rect.width) / 2;
+ int y = bounds.y + (bounds.height - rect.height) / 2;
+
+ mainShell.setLocation(x, y);
+
+ mainShell.pack();
+ mainShell.open();
+
+ LOGGER.info("GUI initialised.");
+
+ while (!mainShell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ }
+
+ /**
+ * Generic helper to show a message box to the user, and optionally log the
+ * message to the log file.
+ *
+ * @param parent parent shell this message box belongs to
+ * @param message Message to display. Can be multiline.
+ * @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 boolean showMessageBox(Shell parent, 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() + " (Siehe Logdatei)";
+ MessageBox box = new MessageBox(parent, messageType.style);
+ box.setMessage(message);
+ box.setText(messageType.title);
+ 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/window/layout/ImageListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java
index 28faf60a..c9e7c1da 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java
@@ -15,8 +15,8 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
-import org.openslx.dozmod.gui.helper.GuiManager;
import org.openslx.dozmod.gui.helper.TableHelper;
+import org.openslx.dozmod.gui.window.MainWindow;
public abstract class ImageListWindowLayout extends Composite {
@@ -70,7 +70,7 @@ public abstract class ImageListWindowLayout extends Composite {
infoTitle.setText(infoTitleString);
// set the fond
FontData fontData = infoTitle.getFont().getFontData()[0];
- Font font = new Font(GuiManager.getDisplay(), new FontData(fontData.getName(), fontData
+ Font font = new Font(MainWindow.getDisplay(), new FontData(fontData.getName(), fontData
.getHeight(), SWT.BOLD));
infoTitle.setFont(font);
// the infotext
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
index 943e8c4e..63ee21c2 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java
@@ -12,7 +12,7 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.window.MainWindow;
public abstract class LoginWindowLayout extends Composite {
@@ -157,11 +157,11 @@ public abstract class LoginWindowLayout extends Composite {
// this way, we can be sure to get an image
// (since the ResourceLoader always returns an image,
// even if it cannot load the specified one).
- titleImage = new Image(GuiManager.getDisplay(), getClass()
+ titleImage = new Image(MainWindow.getDisplay(), getClass()
.getResourceAsStream("/img/Logo_bwLehrpool.png"));
ImageData imgData = titleImage.getImageData();
imgData = imgData.scaledTo(imgData.width / 5, imgData.height / 5);
- titleImage = new Image(GuiManager.getDisplay(), imgData);
+ titleImage = new Image(MainWindow.getDisplay(), imgData);
} catch (Exception e) {
System.out.println("Cannot load image");
System.out.println(e.getMessage());
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainMenuWindowLayout.java
index 718c881c..ffb71f70 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/MainMenuWindowLayout.java
@@ -37,7 +37,7 @@ import org.eclipse.swt.widgets.Shell;
* will skip the login screen
*/
-public abstract class MainWindowLayout extends Composite {
+public abstract class MainMenuWindowLayout extends Composite {
// text for info for the vms selection
protected String vmInfo = "Infotext VMs.";
@@ -48,7 +48,7 @@ public abstract class MainWindowLayout extends Composite {
protected Button vmButton;
protected Button lecturesButton;
- public MainWindowLayout(final Shell mainShell) {
+ public MainMenuWindowLayout(final Shell mainShell) {
super(mainShell, SWT.NONE);
this.setLayout(new GridLayout(2, true));
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java
index bec2dc44..e367d468 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/VirtualizerNoticeWindowLayout.java
@@ -9,7 +9,7 @@ import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
-import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.window.MainWindow;
public abstract class VirtualizerNoticeWindowLayout extends Composite {
private final String title = "Hinweis VMWare Player";
@@ -37,7 +37,7 @@ public abstract class VirtualizerNoticeWindowLayout extends Composite {
Label titleLabel = new Label(this, SWT.NONE);
titleLabel.setText(infoTitle);
FontData fontData = titleLabel.getFont().getFontData()[0];
- Font font = new Font(GuiManager.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(),
+ Font font = new Font(MainWindow.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(),
SWT.BOLD));
titleLabel.setFont(font);
// TODO dispose of font?
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
index ad429085..64a416c8 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
@@ -9,7 +9,7 @@ import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
-import org.openslx.dozmod.gui.helper.GuiManager;
+import org.openslx.dozmod.gui.window.MainWindow;
/**
* Helper class for loading resources. This should be error safe loaders with a
@@ -47,13 +47,13 @@ public class ResourceLoader {
* @return the icon
*/
private static Image errorIcon(String errorText) {
- GC gc = new GC(GuiManager.getDisplay());
- Font font = new Font(GuiManager.getDisplay(), "Tahoma", 20, SWT.NORMAL);
+ GC gc = new GC(MainWindow.getDisplay());
+ Font font = new Font(MainWindow.getDisplay(), "Tahoma", 20, SWT.NORMAL);
gc.setFont(font);
// get dimensions of text
- Image image = new Image(GuiManager.getDisplay(), gc.stringExtent(errorText).x, gc.stringExtent(errorText).y);
+ Image image = new Image(MainWindow.getDisplay(), gc.stringExtent(errorText).x, gc.stringExtent(errorText).y);
GC gc2 = new GC(image);
- gc2.setBackground(GuiManager.getDisplay().getSystemColor(SWT.COLOR_CYAN));
+ gc2.setBackground(MainWindow.getDisplay().getSystemColor(SWT.COLOR_CYAN));
gc2.drawText(errorText, 0, 0);
gc2.dispose();
return image;