X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FDialogs.java;h=47dab1963baad6013181b57e0bb058ed3cf2b44d;hp=59fa17ce2514f4bbd8a43c50f28064ca5e6a38d2;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/Dialogs.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/Dialogs.java index 59fa17ce2..47dab1963 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/Dialogs.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/Dialogs.java @@ -1,86 +1,86 @@ -/******************************************************************************* - * Copyright (c) 2012 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.browsing.ui.swt; - -import java.util.function.Consumer; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.DirectoryDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.utils.datastructures.UnaryFunction; - -public class Dialogs { - - public static void invoke(final UnaryFunction function, final Consumer callback) { - - Display.getDefault().asyncExec(new Runnable() { - - @SuppressWarnings("unchecked") - @Override - public void run() { - - SimanticsDialog dialog = function.call(Display.getCurrent().getActiveShell()); - - dialog.open(); - if(Window.CANCEL == dialog.getReturnCode()) callback.accept(null); - else callback.accept((T)dialog.getSelection()); - - } - - }); - - } - - public static String file(Shell shell, int style, String extension) { - - FileDialog dialog = new FileDialog(shell, style); - dialog.setFilterExtensions(new String[] { extension }); - String newFileName = dialog.open(); - return newFileName; - - } - - public static String directory(Shell shell, int style, String filterPath) { - - DirectoryDialog dialog = new DirectoryDialog(shell, style); - if(filterPath != null) dialog.setFilterPath(filterPath); - String newFileName = dialog.open(); - return newFileName; - - } - - public static String file(int style, String extension) { - return file(Display.getDefault().getActiveShell(), style, extension); - } - - public static String file(Shell shell, String extension) { - return file(shell, SWT.OPEN, extension); - } - - public static String file(ExecutionEvent event, String extension) { - return file(HandlerUtil.getActiveShell(event), extension); - } - - public static String file(ExecutionEvent event, int style, String extension) { - return file(HandlerUtil.getActiveShell(event), style, extension); - } - - public static String directory(int style, String filterPath) { - return directory(Display.getDefault().getActiveShell(), style, filterPath); - } - -} +/******************************************************************************* + * Copyright (c) 2012 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.browsing.ui.swt; + +import java.util.function.Consumer; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; +import org.simantics.utils.datastructures.UnaryFunction; + +public class Dialogs { + + public static void invoke(final UnaryFunction function, final Consumer callback) { + + Display.getDefault().asyncExec(new Runnable() { + + @SuppressWarnings("unchecked") + @Override + public void run() { + + SimanticsDialog dialog = function.call(Display.getCurrent().getActiveShell()); + + dialog.open(); + if(Window.CANCEL == dialog.getReturnCode()) callback.accept(null); + else callback.accept((T)dialog.getSelection()); + + } + + }); + + } + + public static String file(Shell shell, int style, String extension) { + + FileDialog dialog = new FileDialog(shell, style); + dialog.setFilterExtensions(new String[] { extension }); + String newFileName = dialog.open(); + return newFileName; + + } + + public static String directory(Shell shell, int style, String filterPath) { + + DirectoryDialog dialog = new DirectoryDialog(shell, style); + if(filterPath != null) dialog.setFilterPath(filterPath); + String newFileName = dialog.open(); + return newFileName; + + } + + public static String file(int style, String extension) { + return file(Display.getDefault().getActiveShell(), style, extension); + } + + public static String file(Shell shell, String extension) { + return file(shell, SWT.OPEN, extension); + } + + public static String file(ExecutionEvent event, String extension) { + return file(HandlerUtil.getActiveShell(event), extension); + } + + public static String file(ExecutionEvent event, int style, String extension) { + return file(HandlerUtil.getActiveShell(event), style, extension); + } + + public static String directory(int style, String filterPath) { + return directory(Display.getDefault().getActiveShell(), style, filterPath); + } + +}