Java Code Examples for org.eclipse.swt.widgets.DirectoryDialog#open()

The following examples show how to use org.eclipse.swt.widgets.DirectoryDialog#open() . 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: DirectorySelectionDialog.java    From MergeProcessor with Apache License 2.0 6 votes vote down vote up
/**
 * Open the directory dialog and set the selected directory into
 * {@link #textRepository}.
 */
private void openDirectoryDialog() {
	final DirectoryDialog dialog = new DirectoryDialog(textRepository.getShell());
	dialog.setText(directoryDialogTitle == null ? "Select directory" : directoryDialogTitle);
	final String currentText = textRepository.getText();
	if (fileExists(currentText)) {
		dialog.setFilterPath(currentText);
	} else if (fileExists(directoryDialogFilterPath)) {
		dialog.setFilterPath(directoryDialogFilterPath);
	}
	dialog.setMessage(directoryDialogMessage == null ? "Select a directory." : directoryDialogMessage);
	final String directory = dialog.open();
	if (directory != null) {
		textRepository.setText(directory);
		selectedPath = Paths.get(textRepository.getText());
	}
}
 
Example 2
Source File: HybridProjectImportPage.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private void handleBrowseButtonPressed() {
	final DirectoryDialog dialog = new DirectoryDialog(
			directoryPathField.getShell(), SWT.SHEET);
	dialog.setMessage("Select search directory");

	String dirName = directoryPathField.getText().trim();
	if (dirName.isEmpty()) {
		dirName = previouslyBrowsedDirectory;
	}

	if (dirName.isEmpty()) {
		dialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
	} else {
		File path = new File(dirName);
		if (path.exists()) {
			dialog.setFilterPath(new Path(dirName).toOSString());
		}
	}
	
	String selectedDirectory = dialog.open();
	if (selectedDirectory != null) {
		previouslyBrowsedDirectory = selectedDirectory;
		directoryPathField.setText(previouslyBrowsedDirectory);
		updateProjectsList(selectedDirectory);
	}
}
 
Example 3
Source File: ClassPathBlock.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static IPath[] chooseExternalClassFolderEntries( Shell shell )
{
	if ( lastUsedPath == null )
	{
		lastUsedPath = ""; //$NON-NLS-1$
	}
	DirectoryDialog dialog = new DirectoryDialog( shell, SWT.MULTI );
	dialog.setText( Messages.getString( "ClassPathBlock_FolderDialog.text" ) ); //$NON-NLS-1$
	dialog.setMessage( Messages.getString( "ClassPathBlock_FolderDialog.message" ) ); //$NON-NLS-1$
	dialog.setFilterPath( lastUsedPath );

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

	File file = new File( res );
	if ( file.isDirectory( ) )
		return new IPath[]{
			new Path( file.getAbsolutePath( ) )
		};

	return null;
}
 
Example 4
Source File: CompilerWorkingDirectoryBlock.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Show a dialog that lets the user select a working directory
 */
private void handleWorkingDirBrowseButtonSelected() {
    DirectoryDialog dialog = new DirectoryDialog(getShell());
    dialog.setMessage(Messages.CompilerWorkingDirectoryBlock_SelectXcWorkDir); 
    String currentWorkingDir = getOtherDirectoryText();
    if (!currentWorkingDir.trim().equals("")) { //$NON-NLS-1$
        File path = new File(currentWorkingDir);
        if (path.exists()) {
            dialog.setFilterPath(currentWorkingDir);
        }       
    }
    String selectedDirectory = dialog.open();
    if (selectedDirectory != null) {
        setOtherWorkingDirectoryText(selectedDirectory);
        if (actionListener != null) {
            actionListener.actionPerformed(null);
        }
    }       
}
 
Example 5
Source File: InstallView.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
protected void onBrowseBasePath() {
	DirectoryDialog directoryDialog = new DirectoryDialog(getShell());

	File file = new File(lblBasePath.getText());
	while (file != null) {
		if (file.exists() && file.isDirectory()) {
			directoryDialog.setFilterPath(file.getAbsolutePath());
			break;
		}
		file = file.getParentFile();
	}

	String path = directoryDialog.open();
	if (path != null) {
		String normalizedPath = Paths.get(path).toString();
		eventManager.invoke(l -> l.onChangeBasePath(normalizedPath));
	}
}
 
Example 6
Source File: TmxConvert2FileDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * (non-Javadoc)
 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
 */
@Override
public void widgetSelected(SelectionEvent e) {
	DirectoryDialog dialog = new DirectoryDialog(getShell());
	dialog.open();

	String filterPath = dialog.getFilterPath();
	if (null == filterPath || filterPath.isEmpty()) {
		return;
	}
	text.setText(filterPath);
	setOkState();
}
 
Example 7
Source File: AddSdkDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
protected String browseForDirectory() {
  DirectoryDialog dlg = new DirectoryDialog(getShell(), SWT.OPEN);
  dlg.setFilterPath(directoryText.getText().trim());
  dlg.setMessage("Please select the root directory of your SDK installation.");

  return dlg.open();
}
 
Example 8
Source File: WizardFileSystemResourceExportPage2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Open an appropriate destination browser so that the user can specify a source to import from
 */
protected void handleDestinationBrowseButtonPressed() {
	DirectoryDialog dialog = new DirectoryDialog(getContainer().getShell(), SWT.SAVE | SWT.SHEET);
	dialog.setMessage(SELECT_DESTINATION_MESSAGE);
	dialog.setText(SELECT_DESTINATION_TITLE);
	dialog.setFilterPath(getDestinationValue());
	String selectedDirectoryName = dialog.open();

	if (selectedDirectoryName != null) {
		setErrorMessage(null);
		setDestinationValue(selectedDirectoryName);
	}
}
 
Example 9
Source File: VariableCreationDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath chooseExtDirectory() {
	String initPath= getInitPath();

	DirectoryDialog dialog= new DirectoryDialog(getShell());
	dialog.setText(NewWizardMessages.VariableCreationDialog_extdirdialog_text);
	dialog.setMessage(NewWizardMessages.VariableCreationDialog_extdirdialog_message);
	dialog.setFilterPath(initPath);
	String res= dialog.open();
	if (res != null) {
		fDialogSettings.put(IUIConstants.DIALOGSTORE_LASTEXTJAR, dialog.getFilterPath());
		return Path.fromOSString(res);
	}
	return null;
}
 
Example 10
Source File: TreeWithAddRemove.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void addItemWithDialog(DirectoryDialog dialog) {
    dialog.setFilterPath(lastDirectoryDialogPath);
    String filePath = dialog.open();
    if (filePath != null) {
        lastDirectoryDialogPath = filePath;
    }
    addTreeItem(filePath);
}
 
Example 11
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 handleLocationDirectoryButtonPressed() {

	final DirectoryDialog dialog = new DirectoryDialog(directoryPathField.getShell(), SWT.SHEET);
	dialog.setMessage(DataTransferMessages.WizardProjectsImportPage_SelectDialogTitle);

	String dirName = directoryPathField.getText().trim();
	if (dirName.length() == 0) {
		dirName = previouslyBrowsedDirectory;
	}

	if (dirName.length() == 0) {
		dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getLocation().toOSString());
	} else {
		final File path = new File(dirName);
		if (path.exists()) {
			dialog.setFilterPath(new Path(dirName).toOSString());
		}
	}

	final String selectedDirectory = dialog.open();
	if (selectedDirectory != null) {
		previouslyBrowsedDirectory = selectedDirectory;
		directoryPathField.setText(previouslyBrowsedDirectory);
		updateProjectsList(selectedDirectory);
	}

}
 
Example 12
Source File: NodePreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private IPath getDirectory()
{
	DirectoryDialog fileDialog = new DirectoryDialog(getShell(), SWT.OPEN | SWT.SHEET);
	fileDialog.setMessage(MessageFormat.format(Messages.NodePreferencePage_nodejsDirSelectionMessage,
			NODE_JS_ROOT_NAME));
	String dir = fileDialog.open();
	if (!StringUtil.isEmpty(dir))
	{
		return Path.fromOSString(dir);
	}
	return null;
}
 
Example 13
Source File: Activator.java    From erflute with Apache License 2.0 5 votes vote down vote up
public static String showDirectoryDialog(String filePath) {
    String fileName = null;
    if (filePath != null && !"".equals(filePath.trim())) {
        final File file = new File(filePath.trim());
        fileName = file.getPath();
    }
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NONE);
    dialog.setFilterPath(fileName);
    return dialog.open();
}
 
Example 14
Source File: TaskResourceDialog.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
private void getFromDirectory() {
  DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SHEET);
  dialog.setMessage("Task source directories");

  String currentValue = getText().getText();
  if (currentValue != null && new File(currentValue).isDirectory()) {
    dialog.setFilterPath(currentValue);
  }
  String newValue = dialog.open();
  if (newValue != null) {
    getText().setText(newValue);
  }
}
 
Example 15
Source File: SWTDirectoryChooser.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void choose(UIDirectoryChooserHandler selectionHandler) {
	DirectoryDialog dialog = new DirectoryDialog(this.window.getControl());
	if( this.text != null ) {
		dialog.setText(this.text);
	}
	
	if( this.defaultPath != null ) {
		dialog.setFilterPath(this.defaultPath.getAbsolutePath());
	}
	
	String path = dialog.open();
	
	selectionHandler.onSelectDirectory(path != null ? new File(path) : null); 
}
 
Example 16
Source File: ExportAction.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
	DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SAVE);
	dialog.setText(Policy.bind("ExportAction.exportTo")); //$NON-NLS-1$
	dialog.setFilterPath(getLastLocation());
	String directory = dialog.open();
	if (directory == null) return;
	saveLocation(directory);
	new ExportOperation(getTargetPart(), getSelectedResources(), directory).run();
}
 
Example 17
Source File: ConfigSectionBackupRestoreSWT.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
private void doManualBackup(BackupManager backup_manager,
		Runnable stats_updater) {
	if (Utils.runIfNotSWTThread(
			() -> doManualBackup(backup_manager, stats_updater))) {
		return;
	}

	if (shell == null) {
		shell = Utils.findAnyShell();
	}
	String def_dir = COConfigurationManager.getStringParameter(
			SCFG_BACKUP_FOLDER_DEFAULT);

	DirectoryDialog dialog = new DirectoryDialog(shell, SWT.APPLICATION_MODAL);

	if (!def_dir.isEmpty()) {
		dialog.setFilterPath(def_dir);
	}

	dialog.setMessage(MessageText.getString("br.backup.folder.info"));
	dialog.setText(MessageText.getString("br.backup.folder.title"));

	String path = dialog.open();

	if (path != null) {

		COConfigurationManager.setParameter(SCFG_BACKUP_FOLDER_DEFAULT, path);

		runBackup(backup_manager, path, stats_updater);
	}
}
 
Example 18
Source File: WizardFileSystemResourceExportPage2.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Open an appropriate destination browser so that the user can specify a source to import from
 */
protected void handleDestinationBrowseButtonPressed() {
	DirectoryDialog dialog = new DirectoryDialog(getContainer().getShell(), SWT.SAVE | SWT.SHEET);
	dialog.setMessage(SELECT_DESTINATION_MESSAGE);
	dialog.setText(SELECT_DESTINATION_TITLE);
	dialog.setFilterPath(getDestinationValue());
	String selectedDirectoryName = dialog.open();

	if (selectedDirectoryName != null) {
		setErrorMessage(null);
		setDestinationValue(selectedDirectoryName);
	}
}
 
Example 19
Source File: ImportWorkspaceControlSupplier.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected String openFileDialog(Shell shell) {
    final DirectoryDialog dd = new DirectoryDialog(shell, SWT.OPEN | SWT.SINGLE);
    dd.setText(Messages.selectABonitaStudioWorkspace);
    dd.setFilterPath(getLastPath());
    return dd.open();
}
 
Example 20
Source File: ProjectContentsLocationArea.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Open an appropriate directory browser
 */
private void handleLocationBrowseButtonPressed()
{

	String selectedDirectory = null;
	String dirName = getPathFromLocationField();

	if (!dirName.equals(IDEResourceInfoUtils.EMPTY_STRING))
	{
		IFileInfo info;
		info = IDEResourceInfoUtils.getFileInfo(dirName);

		if (info == null || !(info.exists()))
			dirName = IDEResourceInfoUtils.EMPTY_STRING;
	}
	else
	{
		String value = getDialogSettings().get(SAVED_LOCATION_ATTR);
		if (value != null)
		{
			dirName = value;
		}
	}

	FileSystemConfiguration config = getSelectedConfiguration();
	if (config == null || config.equals(FileSystemSupportRegistry.getInstance().getDefaultConfiguration()))
	{
		DirectoryDialog dialog = new DirectoryDialog(locationPathField.getShell(), SWT.SHEET);
		dialog.setMessage(IDEWorkbenchMessages.ProjectLocationSelectionDialog_directoryLabel);

		dialog.setFilterPath(dirName);

		selectedDirectory = dialog.open();

	}
	else
	{
		URI uri = getSelectedConfiguration().getContributor().browseFileSystem(dirName, browseButton.getShell());
		if (uri != null)
			selectedDirectory = uri.toString();
	}

	if (selectedDirectory != null)
	{
		updateLocationField(selectedDirectory);
		getDialogSettings().put(SAVED_LOCATION_ATTR, selectedDirectory);
	}
}