net.sf.okapi.common.ui.Dialogs Maven / Gradle / Ivy
The newest version!
/*===========================================================================
Copyright (C) 2008-2011 by the Okapi Framework contributors
-----------------------------------------------------------------------------
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
===========================================================================*/
package net.sf.okapi.common.ui;
import java.io.File;
import net.sf.okapi.common.Util;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
/**
* Helpers methods to wrap commonly used dialog boxes.
*/
public class Dialogs {
/**
* Browses for one or more files.
* @param parent Parent of the dialog.
* @param title Title of the dialog box.
* @param allowMultiple True if the user can select more than one file.
* @param root Directory where to start. Use null for default directory.
* @param filterNames List of filter names (tab-separated) to use. Can be null.
* Example: "Rainbow Projects (*.rnb)\tAll Files (*.*)"
* @param filterExtensions List of filter extensions (tab-separated) to use.
* Can be null. Must be the same number of items as for filterNames.
* Example: "*.rnb\t*.*"
* @return An array of strings, where each string is the full path for one
* of the selected files. Returns null if the user canceled the command or
* an error occurred.
*/
static public String[] browseFilenames (Shell parent,
String title,
boolean allowMultiple,
String root,
String filterNames,
String filterExtensions)
{
FileDialog dlg = new FileDialog(parent, SWT.OPEN | (allowMultiple ? SWT.MULTI : 0));
dlg.setFilterPath(root); // Can be null
if ( filterNames != null ) {
String[] aNames = filterNames.split("\t", -2); //$NON-NLS-1$
dlg.setFilterNames(aNames);
}
if ( filterExtensions != null ) {
String[] aExts = filterExtensions.split("\t", -2); //$NON-NLS-1$
dlg.setFilterExtensions(aExts);
}
dlg.setText(title);
if ( dlg.open() == null ) return null;
String[] aPaths = dlg.getFileNames();
if (!Util.isEmpty(dlg.getFilterPath())) {
for ( int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy