Java Code Examples for org.eclipse.swt.widgets.FileDialog#setFilterIndex()

The following examples show how to use org.eclipse.swt.widgets.FileDialog#setFilterIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalDataPage.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void selectFile ()
{
    final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN );
    dlg.setFilterExtensions ( new String[] { "*.oscar", "*.json", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    dlg.setFilterNames ( new String[] { Messages.LocalDataPage_OSCARFilterDescription, Messages.LocalDataPage_JSONFilterDescription, Messages.LocalDataPage_AllFilterDescription } );

    if ( this.fileName.getText ().length () > 0 )
    {
        dlg.setFileName ( this.fileName.getText () );
    }
    dlg.setFilterIndex ( 0 );

    final String file = dlg.open ();
    if ( file != null )
    {
        this.fileName.setText ( file );
        loadFile ();
    }
}
 
Example 2
Source File: RemoteDataPage.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void handleLoadLocal ()
{
    final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN );
    dlg.setFilterExtensions ( new String[] { "*.oscar", "*.json", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    dlg.setFilterNames ( new String[] { Messages.LocalDataPage_OSCARFilterDescription, Messages.LocalDataPage_JSONFilterDescription, Messages.LocalDataPage_AllFilterDescription } );

    final String selectedFileName = getWizard ().getDialogSettings ().get ( "localDataPage.file" ); //$NON-NLS-1$

    if ( selectedFileName != null && selectedFileName.length () > 0 )
    {
        dlg.setFileName ( selectedFileName );
    }
    dlg.setFilterIndex ( 0 );

    final String file = dlg.open ();
    if ( file != null )
    {
        getWizard ().getDialogSettings ().put ( "localDataPage.file", file ); //$NON-NLS-1$
        loadFromLocalFile ( file );
    }
}
 
Example 3
Source File: FileNamePage.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void handleSelectFile ()
{
    final FileDialog dlg = new FileDialog ( getShell (), SWT.SAVE );
    dlg.setFilterExtensions ( new String[] { "*.oscar", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ 
    dlg.setFilterNames ( new String[] { Messages.FileNamePage_OSCARFileType, Messages.FileNamePage_AllTypes } );

    if ( this.fileName.getText ().length () > 0 )
    {
        dlg.setFileName ( this.fileName.getText () );
    }
    dlg.setFilterIndex ( 0 );

    final String file = dlg.open ();
    if ( file != null )
    {
        this.fileName.setText ( file );
        getWizard ().getDialogSettings ().put ( "fileNamePage.file", file ); //$NON-NLS-1$
    }
}
 
Example 4
Source File: SwtAppleCommander.java    From AppleCommander with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Open a file.
 */
protected void openFile() {
	FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
	FilenameFilter[] fileFilters = Disk.getFilenameFilters();
	String[] names = new String[fileFilters.length];
	String[] extensions = new String[fileFilters.length];
	for (int i=0; i<fileFilters.length; i++) {
		names[i] = fileFilters[i].getNames();
		extensions[i] = makeExtensionCaseInsensitive(fileFilters[i].getExtensions());
	}
	fileDialog.setFilterNames(names);
	fileDialog.setFilterExtensions(extensions);
	fileDialog.setFilterPath(userPreferences.getDiskImageDirectory());
	fileDialog.setFilterIndex(0);
	String fullpath = fileDialog.open();
	
	if (fullpath != null) {
		userPreferences.setDiskImageDirectory(fileDialog.getFilterPath());
		try {
			Disk disk = new Disk(fullpath);
			FormattedDisk[] formattedDisks = disk.getFormattedDisks();
			DiskWindow window = new DiskWindow(shell, formattedDisks, imageManager);
			window.open();
		} catch (DiskUnrecognizedException e) {
			showUnrecognizedDiskFormatMessage(fullpath);
		} catch (Exception ignored) {
			ignored.printStackTrace();
			showUnexpectedErrorMessage(fullpath);
		}
	}
}
 
Example 5
Source File: MainWindow.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a file open dialog.
 *
 * @param shell
 * @param filter
 * @return
 */
public String showOpenFileDialog(final Shell shell, String filter) {
    final FileDialog dialog = new FileDialog(shell, SWT.OPEN);
    dialog.setFilterExtensions(new String[] { filter });
    dialog.setFilterIndex(0);
    String file = dialog.open();
    if (file == null) {
        return null;
    } else if (!new File(file).exists()) {
        showInfoDialog(shell, Resources.getMessage("MainWindow.5"), Resources.getMessage("MainWindow.14")); //$NON-NLS-1$ //$NON-NLS-2$
        return null;
    } else {
        return file;
    }
}
 
Example 6
Source File: FileOpenViewActionDelegate.java    From LogViewer with Eclipse Public License 2.0 4 votes vote down vote up
public void run(LogViewer view, Shell shell) {

		fileOpened = false;

		// log file type
		String typeStr = null;
		String nameStr = null;
		type = LogFileType.LOGFILE_SYSTEM_FILE;

		/*
		String conStr = "Console: ";
	    LogFileTypeDialog typeDialog = new LogFileTypeDialog(shell);
	    typeDialog.setBlockOnOpen(true);
		int retval = typeDialog.open();
		if(retval == EncodingDialog.OK) {
			typeStr = typeDialog.getValue();
			if (typeStr.indexOf(conStr) == 0) {
				type = LogFileType.LOGFILE_ECLIPSE_CONSOLE;
				typeStr = typeStr.substring(conStr.length());
			}
		} else {
			return;
		}
		*/

		if (type == LogFileType.LOGFILE_SYSTEM_FILE) {
		    // load filter extensions
			String filterExtensions = LogViewerPlugin.getDefault().getPreferenceStore().getString(ILogViewerConstants.PREF_FILTER_EXTENSIONS);
			// opening file(s) in log view
		    FileDialog dialog = new FileDialog(shell,SWT.OPEN|SWT.MULTI);
		    String[] extensions = {
		    		filterExtensions,
		    		"*.*"
		    };

	    	//
		    if (parentPath == null) {
		    	Object[] file_list = FileHistoryTracker.getInstance().getFiles().toArray();
		    	if (file_list.length >= 1)
		    	{
		    		HistoryFile history_file = (HistoryFile)(file_list[file_list.length - 1]);
		    		File file = new File(history_file.getPath());
		    		if (file.isDirectory()) {
		    			parentPath = file.toString();
		    		} else {
		    			parentPath = file.getParent();
		    		}
		    	}
		    }
		    dialog.setFilterPath(parentPath);
		    dialog.setFilterExtensions(extensions);
		    dialog.setFilterIndex(0);
		    String path = dialog.open();
		    if (path != null) {
		    	File tempFile = new File(path);
		    	path = tempFile.isDirectory() ? tempFile.toString() : tempFile.getParent();
		    	String selectedFiles[] = dialog.getFileNames();
		    	for (int i=0;i<selectedFiles.length;i++) {
		    		String fileStr = path.endsWith(File.separator) ? path + selectedFiles[i] : path + File.separator + selectedFiles[i];
		    		if (!view.checkAndOpenFile(type,fileStr, null, true))
		    	        fileOpened = true;
		    	}
		    }
		} else if (type == LogFileType.LOGFILE_ECLIPSE_CONSOLE) {
    		if (!view.checkAndOpenFile(type, typeStr, nameStr, true))
    	        fileOpened = true;
		}
	}
 
Example 7
Source File: MainWindow.java    From arx with Apache License 2.0 3 votes vote down vote up
/**
 * Shows a file save dialog.
 *
 * @param shell
 * @param filter
 * @return
 */
public String showSaveFileDialog(final Shell shell, String filter) {
    final FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    dialog.setFilterExtensions(new String[] { filter });
    dialog.setFilterIndex(0);
    return dialog.open();
}