X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Fdialogs%2FSafeMessageDialog.java;h=b474614a1c2730c7cd7f0e4a484dbb8961f6469b;hb=refs%2Fchanges%2F38%2F238%2F2;hp=db2f7e9d62e16b0a596471de0c668e2bf49f4f84;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/SafeMessageDialog.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/SafeMessageDialog.java index db2f7e9d6..b474614a1 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/SafeMessageDialog.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/SafeMessageDialog.java @@ -1,71 +1,71 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ -/* - * Created on 16.12.2005 - * @author Toni Kalajainen - */ -package org.simantics.utils.ui.dialogs; - -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.simantics.utils.DataContainer; - - -/** - * Tool for making blocking message dialogs queries from non-UI thread - * - * - */ -public class SafeMessageDialog { - - /** Yes and No buttons */ - public final static String[] YES_NO = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; - - public static Integer doMessageDialog(final String title, final Image image, final String message, final int type, - final String buttons[], final int defaultIndex) { - final DataContainer result = new DataContainer(); - Runnable r = new Runnable() { - public void run() { - Shell shell = Display.getCurrent().getActiveShell(); - MessageDialog dialog = new MessageDialog(shell, title, image, message, type, buttons, defaultIndex); - dialog.open(); - result.set(dialog.getReturnCode()); - } - }; - Display display = Display.getCurrent(); - if (display == null) - display = Display.getDefault(); - display.syncExec(r); - - if (result.get() == null) - return null; - return result.get(); - } - - /** - * method for asking simple yes/no question in a dialog. - * - * @param title the dialog's title, or null if none - * @param message the message - * @return true if user pressed OK - */ - public static boolean openQuestion(String title, String message) { - Integer result = doMessageDialog(title, null, message, MessageDialog.QUESTION, YES_NO, 0); - if (result == null) - return false; - return result == 0; - } - -} +/******************************************************************************* + * 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 + *******************************************************************************/ +/* + * Created on 16.12.2005 + * @author Toni Kalajainen + */ +package org.simantics.utils.ui.dialogs; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.simantics.utils.DataContainer; + + +/** + * Tool for making blocking message dialogs queries from non-UI thread + * + * + */ +public class SafeMessageDialog { + + /** Yes and No buttons */ + public final static String[] YES_NO = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }; + + public static Integer doMessageDialog(final String title, final Image image, final String message, final int type, + final String buttons[], final int defaultIndex) { + final DataContainer result = new DataContainer(); + Runnable r = new Runnable() { + public void run() { + Shell shell = Display.getCurrent().getActiveShell(); + MessageDialog dialog = new MessageDialog(shell, title, image, message, type, buttons, defaultIndex); + dialog.open(); + result.set(dialog.getReturnCode()); + } + }; + Display display = Display.getCurrent(); + if (display == null) + display = Display.getDefault(); + display.syncExec(r); + + if (result.get() == null) + return null; + return result.get(); + } + + /** + * method for asking simple yes/no question in a dialog. + * + * @param title the dialog's title, or null if none + * @param message the message + * @return true if user pressed OK + */ + public static boolean openQuestion(String title, String message) { + Integer result = doMessageDialog(title, null, message, MessageDialog.QUESTION, YES_NO, 0); + if (result == null) + return false; + return result == 0; + } + +}