summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/Gui.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-13 10:45:52 +0200
committerSimon Rettberg2015-07-13 10:45:52 +0200
commit404b4b414aad1a1bd8c07bddba2a96c023070060 (patch)
tree329856fa4168558412d807a261a74aa3ea6e821d /dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/Gui.java
parent[client] Add helper methods for executing stuff in the gui thread from other ... (diff)
downloadtutor-module-404b4b414aad1a1bd8c07bddba2a96c023070060.tar.gz
tutor-module-404b4b414aad1a1bd8c07bddba2a96c023070060.tar.xz
tutor-module-404b4b414aad1a1bd8c07bddba2a96c023070060.zip
[client] Formatting, moved generic showMessageBox to Gui class
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/Gui.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/Gui.java47
1 files changed, 40 insertions, 7 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/Gui.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/Gui.java
index 0868861d..386a06ae 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/Gui.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/Gui.java
@@ -3,14 +3,16 @@ package org.openslx.dozmod.gui.helper;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.log4j.Logger;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
public class Gui {
-
+
private static final Logger LOGGER = Logger.getLogger(Gui.class);
/**
@@ -122,10 +124,11 @@ public class Gui {
return getMonitorFromPoint(new Point(rect.x + rect.width / 2, rect.y + rect.height / 2),
defaultToPrimary);
}
-
+
/**
- * Run given task in the GUI thread, blocking the calling thread until the task is done.
- *
+ * Run given task in the GUI thread, blocking the calling thread until the
+ * task is done.
+ *
* @param task Task to run
* @return return value of the task
*/
@@ -143,18 +146,48 @@ public class Gui {
});
return null;
}
-
+
+ /**
+ * Run given task as soon as possible in the GUI thread, but don't block
+ * calling thread.
+ *
+ * @param task Task to run
+ */
public static void asyncExec(final Runnable task) {
display.asyncExec(task);
}
-
+
/**
* Pretty much the same as Callable, but no exceptions are allowed.
- *
+ *
* @param <T> return value
*/
public static interface GuiCallable<T> {
T run();
}
+ /**
+ * 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;
+ }
+
}