-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.utils.ui.dialogs;\r
-\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Shell;\r
-\r
-/**\r
- * This class is shows message in dialog. This class can be instantiated from\r
- * any thread.\r
- * \r
- * @author Toni Kalajainen\r
- */\r
-public class ShowMessage implements Runnable {\r
-\r
- public enum MessageType {\r
- ERROR, CONFIRM, INFORMATION, QUESTION, WARNING\r
- };\r
-\r
- private String title;\r
-\r
- private String message;\r
-\r
- private MessageType type;\r
- \r
- private Display display;\r
-\r
- public ShowMessage(String title, String message, MessageType type) {\r
- this.title = title;\r
- this.message = message;\r
- this.type = type;\r
- this.display = getDisplay();\r
- display.asyncExec(this);\r
- }\r
-\r
- public ShowMessage(Display display, String title, String message, MessageType type) {\r
- this.title = title;\r
- this.message = message;\r
- this.type = type;\r
- this.display = display;\r
- display.asyncExec(this);\r
- }\r
-\r
- public ShowMessage(String title, String message, MessageType type, boolean sync) {\r
- this.title = title;\r
- this.message = message;\r
- this.type = type;\r
- this.display = getDisplay();\r
- if (sync)\r
- display.syncExec(this);\r
- else\r
- display.asyncExec(this);\r
- }\r
-\r
- public ShowMessage(Display display, String title, String message, MessageType type, boolean sync) {\r
- this.title = title;\r
- this.message = message;\r
- this.type = type;\r
- this.display = display;\r
- if (sync)\r
- display.syncExec(this);\r
- else\r
- display.asyncExec(this);\r
- }\r
- \r
- public Display getDisplay() {\r
- if (display!=null) return display;\r
- Display d = Display.getCurrent();\r
- if (d!=null) return d;\r
- return Display.getDefault(); \r
- }\r
- \r
- public void run() {\r
- Shell shell = display.getActiveShell();\r
- if (type == MessageType.ERROR)\r
- MessageDialog.openError(shell, title, message);\r
- if (type == MessageType.CONFIRM)\r
- MessageDialog.openConfirm(shell, title, message);\r
- if (type == MessageType.INFORMATION)\r
- MessageDialog.openInformation(shell, title, message);\r
- if (type == MessageType.QUESTION)\r
- MessageDialog.openQuestion(shell, title, message);\r
- if (type == MessageType.WARNING)\r
- MessageDialog.openWarning(shell, title, message); \r
- }\r
-\r
- public static void showError(Display display, String title, String message) {\r
- new ShowMessage(display, title, message, MessageType.ERROR); \r
- }\r
- \r
- public static void showError(String title, String message) {\r
- new ShowMessage(title, message, MessageType.ERROR); \r
- }\r
- \r
- public static void showStatus(IStatus status) {\r
- MessageType type = MessageType.INFORMATION;\r
- String title = "";\r
- if (status.getSeverity() == IStatus.OK) {\r
- type = MessageType.INFORMATION;\r
- title = "Status OK";\r
- }\r
- if (status.getSeverity() == IStatus.WARNING) {\r
- type = MessageType.WARNING;\r
- title = "Status Warning";\r
- }\r
- if (status.getSeverity() == IStatus.ERROR) {\r
- type = MessageType.ERROR;\r
- title = "Status Error";\r
- }\r
- if (status.getSeverity() == IStatus.CANCEL) {\r
- type = MessageType.INFORMATION;\r
- title = "Status Cancel";\r
- }\r
- if (status.getSeverity() == IStatus.INFO) {\r
- type = MessageType.INFORMATION;\r
- title = "Status Info";\r
- } \r
- new ShowMessage(title, status.getMessage(), type);\r
- }\r
- \r
- public static void showWarning(Display display, String title, String message) {\r
- new ShowMessage(display, title, message, MessageType.WARNING); \r
- }\r
- \r
- public static void showWarning(String title, String message) {\r
- new ShowMessage(title, message, MessageType.WARNING); \r
- }\r
-\r
- public static void showInformation(Display display, String title, String message) {\r
- new ShowMessage(display, title, message, MessageType.INFORMATION); \r
- }\r
- \r
- public static void showInformation(String title, String message) {\r
- new ShowMessage(title, message, MessageType.INFORMATION); \r
- }\r
- \r
-\r
- \r
- public static void syncShowError(Display display, String title, String message) {\r
- new ShowMessage(display, title, message, MessageType.ERROR, true); \r
- }\r
- \r
- public static void syncShowError(String title, String message) {\r
- new ShowMessage(title, message, MessageType.ERROR, true); \r
- }\r
- \r
- public static void syncShowWarning(Display display, String title, String message) {\r
- new ShowMessage(display, title, message, MessageType.WARNING, true); \r
- }\r
- \r
- public static void syncShowWarning(String title, String message) {\r
- new ShowMessage(title, message, MessageType.WARNING, true); \r
- }\r
-\r
- public static void syncShowInformation(Display display, String title, String message) {\r
- new ShowMessage(display, title, message, MessageType.INFORMATION, true); \r
- }\r
- \r
- public static void syncShowInformation(String title, String message) {\r
- new ShowMessage(title, message, MessageType.INFORMATION, true); \r
- }\r
- \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.utils.ui.dialogs;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This class is shows message in dialog. This class can be instantiated from
+ * any thread.
+ *
+ * @author Toni Kalajainen
+ */
+public class ShowMessage implements Runnable {
+
+ public enum MessageType {
+ ERROR, CONFIRM, INFORMATION, QUESTION, WARNING
+ };
+
+ private String title;
+
+ private String message;
+
+ private MessageType type;
+
+ private Display display;
+
+ public ShowMessage(String title, String message, MessageType type) {
+ this.title = title;
+ this.message = message;
+ this.type = type;
+ this.display = getDisplay();
+ display.asyncExec(this);
+ }
+
+ public ShowMessage(Display display, String title, String message, MessageType type) {
+ this.title = title;
+ this.message = message;
+ this.type = type;
+ this.display = display;
+ display.asyncExec(this);
+ }
+
+ public ShowMessage(String title, String message, MessageType type, boolean sync) {
+ this.title = title;
+ this.message = message;
+ this.type = type;
+ this.display = getDisplay();
+ if (sync)
+ display.syncExec(this);
+ else
+ display.asyncExec(this);
+ }
+
+ public ShowMessage(Display display, String title, String message, MessageType type, boolean sync) {
+ this.title = title;
+ this.message = message;
+ this.type = type;
+ this.display = display;
+ if (sync)
+ display.syncExec(this);
+ else
+ display.asyncExec(this);
+ }
+
+ public Display getDisplay() {
+ if (display!=null) return display;
+ Display d = Display.getCurrent();
+ if (d!=null) return d;
+ return Display.getDefault();
+ }
+
+ public void run() {
+ Shell shell = display.getActiveShell();
+ if (type == MessageType.ERROR)
+ MessageDialog.openError(shell, title, message);
+ if (type == MessageType.CONFIRM)
+ MessageDialog.openConfirm(shell, title, message);
+ if (type == MessageType.INFORMATION)
+ MessageDialog.openInformation(shell, title, message);
+ if (type == MessageType.QUESTION)
+ MessageDialog.openQuestion(shell, title, message);
+ if (type == MessageType.WARNING)
+ MessageDialog.openWarning(shell, title, message);
+ }
+
+ public static void showError(Display display, String title, String message) {
+ new ShowMessage(display, title, message, MessageType.ERROR);
+ }
+
+ public static void showError(String title, String message) {
+ new ShowMessage(title, message, MessageType.ERROR);
+ }
+
+ public static void showStatus(IStatus status) {
+ MessageType type = MessageType.INFORMATION;
+ String title = "";
+ if (status.getSeverity() == IStatus.OK) {
+ type = MessageType.INFORMATION;
+ title = "Status OK";
+ }
+ if (status.getSeverity() == IStatus.WARNING) {
+ type = MessageType.WARNING;
+ title = "Status Warning";
+ }
+ if (status.getSeverity() == IStatus.ERROR) {
+ type = MessageType.ERROR;
+ title = "Status Error";
+ }
+ if (status.getSeverity() == IStatus.CANCEL) {
+ type = MessageType.INFORMATION;
+ title = "Status Cancel";
+ }
+ if (status.getSeverity() == IStatus.INFO) {
+ type = MessageType.INFORMATION;
+ title = "Status Info";
+ }
+ new ShowMessage(title, status.getMessage(), type);
+ }
+
+ public static void showWarning(Display display, String title, String message) {
+ new ShowMessage(display, title, message, MessageType.WARNING);
+ }
+
+ public static void showWarning(String title, String message) {
+ new ShowMessage(title, message, MessageType.WARNING);
+ }
+
+ public static void showInformation(Display display, String title, String message) {
+ new ShowMessage(display, title, message, MessageType.INFORMATION);
+ }
+
+ public static void showInformation(String title, String message) {
+ new ShowMessage(title, message, MessageType.INFORMATION);
+ }
+
+
+
+ public static void syncShowError(Display display, String title, String message) {
+ new ShowMessage(display, title, message, MessageType.ERROR, true);
+ }
+
+ public static void syncShowError(String title, String message) {
+ new ShowMessage(title, message, MessageType.ERROR, true);
+ }
+
+ public static void syncShowWarning(Display display, String title, String message) {
+ new ShowMessage(display, title, message, MessageType.WARNING, true);
+ }
+
+ public static void syncShowWarning(String title, String message) {
+ new ShowMessage(title, message, MessageType.WARNING, true);
+ }
+
+ public static void syncShowInformation(Display display, String title, String message) {
+ new ShowMessage(display, title, message, MessageType.INFORMATION, true);
+ }
+
+ public static void syncShowInformation(String title, String message) {
+ new ShowMessage(title, message, MessageType.INFORMATION, true);
+ }
+
+}