diff options
| author | Simon Rettberg | 2015-07-09 19:35:33 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-07-09 19:35:33 +0200 |
| commit | 0942e3c235db308ed73c5d9b0e9f316db868cd94 (patch) | |
| tree | ec8182ebc9980a471a5809bf1dd30ceffd7d30f0 /dozentenmodul/src/main/java/org | |
| parent | [client] pom.xml: Build multiplatform .jar by including all swt versions (diff) | |
| download | tutor-module-0942e3c235db308ed73c5d9b0e9f316db868cd94.tar.gz tutor-module-0942e3c235db308ed73c5d9b0e9f316db868cd94.tar.xz tutor-module-0942e3c235db308ed73c5d9b0e9f316db868cd94.zip | |
[client] Only allow Composites to be passed to openPopup; make Ctrl-Q quit the application
Diffstat (limited to 'dozentenmodul/src/main/java/org')
| -rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GuiManager.java | 47 |
1 files changed, 23 insertions, 24 deletions
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 ed34d1fd..435ac2cc 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 @@ -1,10 +1,8 @@ package org.openslx.dozmod.gui.helper; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import org.apache.log4j.Logger; -import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -13,11 +11,14 @@ 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; @@ -28,8 +29,6 @@ public abstract class GuiManager { 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?"; @@ -65,36 +64,28 @@ public abstract class GuiManager { /** * @param clazz Class to open as a popup over the main window */ - public static void openPopup(Class<?> clazz, boolean modal) { - // TODO find the right style bits for a floating window + public static void openPopup(Class<? extends Composite> clazz, boolean modal) { Shell dialogShell = new Shell(mainShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); - // TODO check if its a composite // populate dialogShell dialogShell.setLayout(new GridLayout(1, false)); LOGGER.debug(clazz.getDeclaredClasses()); Constructor<?> con = null; try { con = clazz.getConstructor(Shell.class); - } catch (NoSuchMethodException | SecurityException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - try { con.newInstance(dialogShell); - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } 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(); - } + if (!display.readAndDispatch()) { + display.sleep(); + } } } } @@ -127,6 +118,15 @@ public abstract class GuiManager { } }); + // 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"); @@ -139,7 +139,6 @@ public abstract class GuiManager { exitItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - mainShell.getDisplay().dispose(); System.exit(0); } }); @@ -151,7 +150,7 @@ public abstract class GuiManager { mainShell.setLayout(new GridLayout(1, true)); // Add LoginWindow as the first window to be shown - addContent(new org.openslx.dozmod.gui.window.LoginWindow(mainShell)); + addContent(new LoginWindow(mainShell)); // center the window on the primary monitor Monitor primary = display.getPrimaryMonitor(); @@ -185,8 +184,8 @@ public abstract class GuiManager { * @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) { + 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) |
