1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
13 * Created on 16.12.2005
14 * @author Toni Kalajainen
16 package org.simantics.utils.ui.dialogs;
18 import org.eclipse.jface.dialogs.IDialogConstants;
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.swt.widgets.Shell;
23 import org.simantics.utils.DataContainer;
27 * Tool for making blocking message dialogs queries from non-UI thread
31 public class SafeMessageDialog {
33 /** Yes and No buttons */
34 public final static String[] YES_NO = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
36 public static Integer doMessageDialog(final String title, final Image image, final String message, final int type,
37 final String buttons[], final int defaultIndex) {
38 final DataContainer<Integer> result = new DataContainer<Integer>();
39 Runnable r = new Runnable() {
41 Shell shell = Display.getCurrent().getActiveShell();
42 MessageDialog dialog = new MessageDialog(shell, title, image, message, type, buttons, defaultIndex);
44 result.set(dialog.getReturnCode());
47 Display display = Display.getCurrent();
49 display = Display.getDefault();
52 if (result.get() == null)
58 * method for asking simple yes/no question in a dialog.
60 * @param title the dialog's title, or <code>null</code> if none
61 * @param message the message
62 * @return true if user pressed OK
64 public static boolean openQuestion(String title, String message) {
65 Integer result = doMessageDialog(title, null, message, MessageDialog.QUESTION, YES_NO, 0);