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

The following examples show how to use org.eclipse.swt.widgets.FileDialog#setFilterPath() . 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: BuildPathDialogAccess.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Shows the UI to configure an external JAR or ZIP archive.
 * The dialog returns the configured or <code>null</code> if the dialog has
 * been canceled. The dialog does not apply any changes.
 *
 * @param shell The parent shell for the dialog.
 * @param initialEntry The path of the initial archive entry.
 * @return Returns the configured external JAR path or <code>null</code> if the dialog has
 * been canceled by the user.
 */
public static IPath configureExternalJAREntry(Shell shell, IPath initialEntry) {
	if (initialEntry == null) {
		throw new IllegalArgumentException();
	}

	String lastUsedPath= initialEntry.removeLastSegments(1).toOSString();

	FileDialog dialog= new FileDialog(shell, SWT.SINGLE);
	dialog.setText(NewWizardMessages.BuildPathDialogAccess_ExtJARArchiveDialog_edit_title);
	dialog.setFilterExtensions(ArchiveFileFilter.JAR_ZIP_FILTER_EXTENSIONS);
	dialog.setFilterPath(lastUsedPath);
	dialog.setFileName(initialEntry.lastSegment());

	String res= dialog.open();
	if (res == null) {
		return null;
	}
	JavaPlugin.getDefault().getDialogSettings().put(IUIConstants.DIALOGSTORE_LASTEXTJAR, dialog.getFilterPath());

	return Path.fromOSString(res).makeAbsolute();
}
 
Example 2
Source File: AbstractTracePackageWizardPage.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open an appropriate file dialog so that the user can specify a file to
 * import/export
 * @param fileDialogStyle
 */
private void handleFilePathBrowseButtonPressed(int fileDialogStyle) {
    FileDialog dialog = TmfFileDialogFactory.create(getContainer().getShell(), fileDialogStyle | SWT.SHEET);
    dialog.setFilterExtensions(new String[] { "*.zip;*.tar.gz;*.tar;*.tgz", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
    dialog.setText(Messages.TracePackage_FileDialogTitle);
    String currentSourceString = getFilePathValue();
    int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator);
    if (lastSeparatorIndex != -1) {
        dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
    }
    String selectedFileName = dialog.open();

    if (selectedFileName != null) {
        setFilePathValue(selectedFileName);
        updateWithFilePathSelection();
    }
}
 
Example 3
Source File: SWTFileChooser.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void choose(UIFileChooserHandler selectionHandler) {
	FileDialog dialog = new FileDialog(this.window.getControl(), this.style);
	if( this.text != null ) {
		dialog.setText(this.text);
	}
	
	dialog.setFileName(this.createFileName());
	dialog.setFilterPath(this.createFilterPath());
	
	if( this.supportedFormats != null ) {
		FilterList filter = new FilterList(this.supportedFormats);
		
		dialog.setFilterNames(filter.getFilterNames());
		dialog.setFilterExtensions(filter.getFilterExtensions());
	}
	String path = dialog.open();
	
	selectionHandler.onSelectFile(path != null ? new File(path) : null); 
}
 
Example 4
Source File: PearFileResourceExportPage.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a file selection dialog to select a pear file as export location and sets the chosen
 * value to the input field.
 */
protected void handleDestinationBrowseButtonPressed() {
  final FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE);
  dialog.setFilterExtensions(new String[] { "*.pear", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
  dialog.setText(PearExportMessages.getString("PearExport.selectDestinationTitle")); //$NON-NLS-1$
  final String destination = getDestinationValue();
  final int lastDirectoryIndex = destination.lastIndexOf(File.separator);
  if (lastDirectoryIndex != -1) {
    dialog.setFilterPath(destination.substring(0, lastDirectoryIndex));
  }

  final String selectedFileName = dialog.open();
  if (selectedFileName != null) {
    fDestinationFileInput.setText(selectedFileName);
    saveDestinationValue(selectedFileName);
  }
}
 
Example 5
Source File: Activator.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * �ۑ��_�C�A���O��\�����܂�
 *
 * @param filePath
 *            �f�t�H���g�̃t�@�C���p�X
 * @param filterExtensions
 *            �g���q
 * @return �ۑ��_�C�A���O�őI�����ꂽ�t�@�C���̃p�X
 */
public static String showSaveDialog(String filePath,
		String[] filterExtensions) {
	String dir = null;
	String fileName = null;

	if (filePath != null && !"".equals(filePath.trim())) {
		File file = new File(filePath.trim());

		dir = file.getParent();
		fileName = file.getName();
	}

	FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getShell(), SWT.SAVE);

	fileDialog.setFilterPath(dir);
	fileDialog.setFileName(fileName);

	fileDialog.setFilterExtensions(filterExtensions);

	return fileDialog.open();
}
 
Example 6
Source File: ClassPathBlock.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static IPath configureExternalJAREntry( Shell shell,
		IPath initialEntry )
{
	if ( initialEntry == null )
	{
		throw new IllegalArgumentException( );
	}

	String lastUsedPath = initialEntry.removeLastSegments( 1 ).toOSString( );

	FileDialog dialog = new FileDialog( shell, SWT.SINGLE );
	dialog.setText( Messages.getString( "ClassPathBlock_FileDialog.edit.text" ) ); //$NON-NLS-1$
	dialog.setFilterExtensions( JAR_ZIP_FILTER_EXTENSIONS );
	dialog.setFilterPath( lastUsedPath );
	dialog.setFileName( initialEntry.lastSegment( ) );

	String res = dialog.open( );
	if ( res == null )
	{
		return null;
	}
	//lastUsedPath = dialog.getFilterPath( );

	return Path.fromOSString( res ).makeAbsolute( );
}
 
Example 7
Source File: ImportLiveHttpHeadersAction.java    From http4e with Apache License 2.0 5 votes vote down vote up
public void run(){

      try {

         FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);

         fileDialog.setFileName("*.*");
         fileDialog.setFilterNames(new String[] { "Import Firefox LiveHTTP Headers *.*" });
         fileDialog.setFilterExtensions(new String[] { "*.*" });
         fileDialog.setText("Import Firefox LiveHTTP Headers");
         fileDialog.setFilterPath(getUserHomeDir());

         String path = fileDialog.open();
         if (path != null) {
            HdViewPart hdView = (HdViewPart) view;
            List<ItemModel> iteModels = BaseUtils.importLiveHttpHeaders(path, hdView.getFolderView().getModel());
            HdViewPart hdViewPart = (HdViewPart)view;
            for (ItemModel im : iteModels) {
               hdViewPart.getFolderView().buildTab(im);
            }
            
            updateUserHomeDir(path);
         }

      } catch (Exception e) {
         ExceptionHandler.handle(e);
      }
   }
 
Example 8
Source File: Activator.java    From erflute with Apache License 2.0 5 votes vote down vote up
public static String showSaveDialog(String filePath, String[] filterExtensions) {
    String dir = null;
    String fileName = null;
    if (filePath != null && !"".equals(filePath.trim())) {
        final File file = new File(filePath.trim());
        dir = file.getParent();
        fileName = file.getName();
    }
    final FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
    fileDialog.setFilterPath(dir);
    fileDialog.setFileName(fileName);
    fileDialog.setFilterExtensions(filterExtensions);
    return fileDialog.open();
}
 
Example 9
Source File: AbstractImportPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private Optional<String> openFileDialog(Shell shell) {
    final FileDialog fd = new FileDialog(shell, SWT.OPEN | SWT.SINGLE);
    fd.setText(Messages.importLabel);
    fd.setFilterPath(getLastPath());
    fd.setFilterExtensions(getExtensions());
    return Optional.ofNullable(fd.open());
}
 
Example 10
Source File: TreeWithAddRemove.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void addItemWithDialog(FileDialog dialog) {
    dialog.setFilterPath(lastFileDialogPath);
    dialog.open();
    String[] fileNames = dialog.getFileNames();
    String parent = dialog.getFilterPath();
    if (fileNames != null && fileNames.length > 0) {
        for (String s : fileNames) {
            addTreeItem(FileUtils.getFileAbsolutePath(new File(parent, s)));
        }
    }
}
 
Example 11
Source File: SaveXmlAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private FileDialog createFileDialog(IProject project) {
    FileDialog fileDialog = new FileDialog(FindbugsPlugin.getShell(), SWT.APPLICATION_MODAL | SWT.SAVE);
    fileDialog.setText("Select bug result xml for project: " + project.getName());
    String initialFileName = getDialogSettings().get(SAVE_XML_PATH_KEY);
    if (initialFileName != null && initialFileName.length() > 0) {
        File initialFile = new File(initialFileName);
        // have to check if exists, otherwise crazy GTK will ignore preset
        // filter
        if (initialFile.exists()) {
            fileDialog.setFileName(initialFile.getName());
        }
        fileDialog.setFilterPath(initialFile.getParent());
    }
    return fileDialog;
}
 
Example 12
Source File: PathsProvider.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private FileDialog createFileDialog(Shell parentShell) {
    FileDialog dialog = new FileDialog(parentShell, SWT.OPEN | SWT.MULTI);
    configureDialog(dialog);

    IPath lastUsed = getLastUsedPath();
    String filterPath = null;
    if (lastUsed != null && lastUsed.toFile().isDirectory()) {
        filterPath = lastUsed.toOSString();
        dialog.setFilterPath(filterPath);
    }
    return dialog;
}
 
Example 13
Source File: LibraryPathComposite.java    From tlaplus with MIT License 5 votes vote down vote up
String getZipArchiveFile(String prevLocation) {
	final FileDialog dialog = new FileDialog(this.preferencePage.getShell());
	dialog.setFilterExtensions(new String[] {"*.jar", "*.zip"});
	if (prevLocation != null) {
		dialog.setFilterPath(prevLocation);
	}
	final String open = dialog.open();
	if (open != null) {
		return open;
	}
	return null;
}
 
Example 14
Source File: ImportProjectWizardPage.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The browse button has been selected. Select the location.
 */
protected void handleLocationArchiveButtonPressed() {

	final FileDialog dialog = new FileDialog(archivePathField.getShell(), SWT.SHEET);
	dialog.setFilterExtensions(FILE_IMPORT_MASK);
	dialog.setText(DataTransferMessages.WizardProjectsImportPage_SelectArchiveDialogTitle);

	String fileName = archivePathField.getText().trim();
	if (fileName.length() == 0) {
		fileName = previouslyBrowsedArchive;
	}

	if (fileName.length() == 0) {
		dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getLocation().toOSString());
	} else {
		final File path = new File(fileName).getParentFile();
		if (path != null && path.exists()) {
			dialog.setFilterPath(path.toString());
		}
	}

	final String selectedArchive = dialog.open();
	if (selectedArchive != null) {
		previouslyBrowsedArchive = selectedArchive;
		archivePathField.setText(previouslyBrowsedArchive);
		updateProjectsList(selectedArchive);
	}

}
 
Example 15
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 16
Source File: ImportFromFileAction.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
protected String getLoadFilePath(IEditorPart editorPart) {

		IFile file = ((IFileEditorInput) editorPart.getEditorInput()).getFile();

		FileDialog fileDialog = new FileDialog(editorPart.getEditorSite()
				.getShell(), SWT.OPEN);

		IProject project = file.getProject();

		fileDialog.setFilterPath(project.getLocation().toString());

		String[] filterExtensions = this.getFilterExtensions();
		fileDialog.setFilterExtensions(filterExtensions);

		return fileDialog.open();
	}
 
Example 17
Source File: FileListEditor.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected String getNewInputObject() {

    final FileDialog dialog = new FileDialog(getShell());

    if (lastPath != null) {
        if (new File(lastPath).exists()) {
            dialog.setFilterPath(lastPath);
        }
    }

    final String[] filterExtensions = new String[] {extention};
    dialog.setFilterExtensions(filterExtensions);

    final String filePath = dialog.open();
    if (filePath != null) {
        final File file = new File(filePath);
        final String fileName = file.getName();

        if (contains(fileName)) {
            final MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
            messageBox.setText(ResourceString.getResourceString("dialog.title.warning"));
            messageBox.setMessage(ResourceString.getResourceString("dialog.message.update.file"));

            if (messageBox.open() == SWT.CANCEL) {
                return null;
            }

            namePathMap.put(fileName, filePath);
            return null;
        }

        namePathMap.put(fileName, filePath);
        try {
            lastPath = file.getParentFile().getCanonicalPath();
        } catch (final IOException e) {}

        return fileName;
    }

    return null;
}
 
Example 18
Source File: JavaCamelJobScriptsExportWSWizardPage.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
/**
 * Open an appropriate destination browser so that the user can specify a source to import from.
 */
@Override
protected void handleDestinationBrowseButtonPressed() {
    FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE);

    if (EXPORTTYPE_SPRING_BOOT.equals(exportTypeCombo.getText())) {
        if (exportAsZip) {
            dialog.setFilterExtensions(new String[] { "*" + FileConstants.ZIP_FILE_SUFFIX, "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            dialog.setFilterExtensions(new String[] { "*.jar", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
        }
    } else {
        dialog.setFilterExtensions(new String[] { "*.kar", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
    }
    dialog.setText(""); //$NON-NLS-1$
    // this is changed by me shenhaize
    dialog.setFileName(this.getDefaultFileName().get(0));
    String currentSourceString = getDestinationValue();
    int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator);
    if (lastSeparatorIndex != -1) {
        dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
    }

    String selectedFileName = dialog.open();
    if (selectedFileName == null) {
        return;
    }
    String idealSuffix;
    if (EXPORTTYPE_SPRING_BOOT.equals(exportTypeCombo.getText())) {
        if (exportAsZip) {
            idealSuffix = FileConstants.ZIP_FILE_SUFFIX;
        } else {
            idealSuffix = FileConstants.JAR_FILE_SUFFIX;
        }
    } else {
        idealSuffix = getOutputSuffix();
    }
    if (!selectedFileName.endsWith(idealSuffix)) {
        selectedFileName += idealSuffix;
    }
    // when user change the name of job,will add the version auto
    if (selectedFileName != null && !selectedFileName.endsWith(this.getSelectedJobVersion() + idealSuffix)) {
        String b = selectedFileName.substring(0, (selectedFileName.length() - 4));
        File file = new File(b);

        String str = file.getName();

        String s = this.getDefaultFileName().get(0);

        if (str.equals(s)) {
            selectedFileName = b + "_" + this.getDefaultFileName().get(1) + idealSuffix; //$NON-NLS-1$
        } else {
            selectedFileName = b + idealSuffix;
        }

    }
    if (selectedFileName != null) {
        setErrorMessage(null);
        setDestinationValue(selectedFileName);

        if (getDialogSettings() != null) {
            IDialogSettings section = getDialogSettings().getSection(DESTINATION_FILE);
            if (section == null) {
                section = getDialogSettings().addNewSection(DESTINATION_FILE);
            }
            section.put(DESTINATION_FILE, selectedFileName);
        }

    }
}
 
Example 19
Source File: UsageSettings.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
private MenuManager createMenu(TableViewer tableViewer){
	MenuManager menuManager = new MenuManager();
	
	Action clearAction = new Action("Leeren") { //$NON-NLS-1$
		{
			setImageDescriptor(Images.IMG_DELETE.getImageDescriptor());
			setToolTipText("Statistik Leeren"); //$NON-NLS-1$
		}
		
		@Override
		public void run(){
			StatisticsManager.INSTANCE.getStatistics().getStatistics().clear();
			tableViewer.refresh();
		}
	};
		
	Action exportAction = new Action("Exportieren") { //$NON-NLS-1$
		{
			setImageDescriptor(Images.IMG_EXPORT.getImageDescriptor());
			setToolTipText("Statistik Exportieren"); //$NON-NLS-1$
		}
		
		@Override
		public void run(){
			FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
			dialog.setFilterNames(new String[] {
				"xml"
			});
			dialog.setFilterExtensions(new String[] {
				"*.xml"
			});
			dialog.setOverwrite(true);
			dialog.setFilterPath(CoreHub.getWritableUserDir().getAbsolutePath()); // Windows path
			dialog.setFileName("statistics_export.xml");
			String path = dialog.open();
			if (path != null) {
				try {
					StatisticsManager.INSTANCE.exportStatisticsToFile(path);
				} catch (IOException e) {
					LoggerFactory.getLogger(UsageSettings.class)
						.error("statistics export error", e);
					MessageDialog.openError(getShell(), "Fehler",
						"Statistik Export nicht möglich. [" + e.getMessage() + "]");
				}
			}
		}
	};
		
	menuManager.add(clearAction);
	menuManager.add(exportAction);
	return menuManager;
}
 
Example 20
Source File: ImportFromFileAction.java    From ermasterr with Apache License 2.0 3 votes vote down vote up
protected String getLoadFilePath(final IEditorPart editorPart) {

        final FileDialog fileDialog = new FileDialog(editorPart.getEditorSite().getShell(), SWT.OPEN);

        fileDialog.setFilterPath(getBasePath());

        final String[] filterExtensions = getFilterExtensions();
        fileDialog.setFilterExtensions(filterExtensions);

        return fileDialog.open();
    }