diff options
author | Simon Rettberg | 2015-07-15 11:56:41 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-15 11:56:41 +0200 |
commit | f1240b0ddef62b03da3ca9d87812e3be2ff36e15 (patch) | |
tree | 3d65208981043fd7e4ca2c61d462d6c602175d95 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java | |
parent | [client] Use vmx parser to check validity of VM (work in progress) (diff) | |
download | tutor-module-f1240b0ddef62b03da3ca9d87812e3be2ff36e15.tar.gz tutor-module-f1240b0ddef62b03da3ca9d87812e3be2ff36e15.tar.xz tutor-module-f1240b0ddef62b03da3ca9d87812e3be2ff36e15.zip |
[client] Clean up SWT resources when exiting
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java index 07cfd292..c7135d66 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -6,8 +6,6 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; @@ -19,9 +17,8 @@ import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.openslx.dozmod.Config; +import org.openslx.dozmod.gui.Gui.GuiCallable; import org.openslx.dozmod.gui.helper.CompositePage; -import org.openslx.dozmod.gui.helper.Gui; -import org.openslx.dozmod.gui.helper.Gui.GuiCallable; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.window.DisclaimerWindow; import org.openslx.dozmod.gui.window.ImageListWindow; @@ -31,12 +28,14 @@ import org.openslx.dozmod.gui.window.VirtualizerNoticeWindow; import org.openslx.dozmod.thrift.Session; import org.openslx.thrifthelper.ThriftManager; import org.openslx.thrifthelper.ThriftManager.ErrorCallback; +import org.openslx.util.QuickTimer; public abstract class MainWindow { private final static Logger LOGGER = Logger.getLogger(MainWindow.class); private static final Shell mainShell; + private static CompositePage currentPage; private static final Map<Class<? extends CompositePage>, CompositePage> pages = new ConcurrentHashMap<>(); @@ -61,7 +60,8 @@ public abstract class MainWindow { if (currentPage == null) { showMessageBox("Tried to show unknown page " + clazz.getSimpleName(), MessageType.ERROR, LOGGER, null); - System.exit(1); + Gui.exit(1); + return; } // sets the starting preferred size. @@ -72,8 +72,12 @@ public abstract class MainWindow { } /** + * * @param clazz Class to open as a popup over the main window. * MUST be a subclass of Composite. + * @param modal modal mode - other windows will be blocked until this popup + * is closed + * @param noclose don't allow closing the popup via the (X) in the title bar */ public static void openPopup(Class<? extends Composite> clazz, boolean modal, boolean noclose) { int style = SWT.TITLE | SWT.BORDER | SWT.RESIZE; @@ -81,7 +85,7 @@ public abstract class MainWindow { style |= SWT.APPLICATION_MODAL; if (!noclose) style |= SWT.CLOSE; - Shell dialogShell = new Shell(mainShell, style); + Shell dialogShell = Gui.newShell(mainShell, style); // populate dialogShell dialogShell.setLayout(new GridLayout(1, false)); LOGGER.debug(clazz.getDeclaredClasses()); @@ -113,14 +117,14 @@ public abstract class MainWindow { } /** - * Initialises the GUI by creating the main window, adding the menu and + * Initializes 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. */ static { // init SWT stuff - mainShell = new Shell(Gui.display, SWT.SHELL_TRIM | SWT.CENTER); + mainShell = Gui.newShell(SWT.SHELL_TRIM | SWT.CENTER); // Catch the close button (X) mainShell.addListener(SWT.Close, new Listener() { @@ -163,16 +167,10 @@ public abstract class MainWindow { Gui.display.addFilter(SWT.KeyDown, new Listener() { @Override public void handleEvent(Event event) { - if (event.character == 17) // Ctrl-Q = Quit + if (event.character == 17) { // Ctrl-Q = Quit askApplicationQuit(); - } - }); - - mainShell.addDisposeListener(new DisposeListener() { - - @Override - public void widgetDisposed(DisposeEvent e) { - askApplicationQuit(); + event.doit = false; + } } }); @@ -204,23 +202,15 @@ public abstract class MainWindow { } /** - * Run the GUI mainloop as long as the main window exists. - */ - public static void mainloop() { - while (!mainShell.isDisposed()) { - if (!Gui.display.readAndDispatch()) - Gui.display.sleep(); - } - } - - /** * Request application quit. Will show a message box asking the user for * confirmation. */ protected static void askApplicationQuit() { // TODO: Only ask if an upload or download is running,, wizard is open etc.. - if (showMessageBox("Are you sure you want to quit?", MessageType.QUESTION_YESNO, null, null)) - System.exit(0); + if (showMessageBox("Are you sure you want to quit?", MessageType.QUESTION_YESNO, null, null)) { + QuickTimer.cancel(); + Gui.exit(0); + } } /** @@ -300,4 +290,8 @@ public abstract class MainWindow { return Gui.showMessageBox(mainShell, message, messageType, logger, exception); } + public static void open() { + mainShell.open(); + } + } |