Java Code Examples for org.eclipse.swt.widgets.DirectoryDialog

The following examples show how to use org.eclipse.swt.widgets.DirectoryDialog. These examples are extracted from open source projects. 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
public static final SelectionAdapter getSelectionAdapter( final Shell shell, final Text destination ) {
  // Listen to the Browse... button
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      DirectoryDialog dialog = new DirectoryDialog( shell, SWT.OPEN );
      if ( destination.getText() != null ) {
        String fpath = destination.getText();
        // String fpath = StringUtil.environmentSubstitute(destination.getText());
        dialog.setFilterPath( fpath );
      }

      if ( dialog.open() != null ) {
        String str = dialog.getFilterPath();
        destination.setText( str );
      }
    }
  };
}
 
Example 2
Source Project: hop   Source File: DirectoryDialogButtonListenerFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Shell shell, final Text destination ) {
  // Listen to the Browse... button
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      DirectoryDialog dialog = new DirectoryDialog( shell, SWT.OPEN );
      if ( destination.getText() != null ) {
        String fpath = destination.getText();
        // String fpath = StringUtil.environmentSubstitute(destination.getText());
        dialog.setFilterPath( fpath );
      }

      if ( dialog.open() != null ) {
        String str = dialog.getFilterPath();
        destination.setText( str );
      }
    }
  };
}
 
Example 3
Source Project: nebula   Source File: PWDirectoryChooser.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.opal.preferencewindow.widgets.PWChooser#setButtonAction(org.eclipse.swt.widgets.Text,
 *      org.eclipse.swt.widgets.Button)
 */
@Override
protected void setButtonAction(final Text text, final Button button) {

	final String originalDirectory = (String) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
	text.setText(originalDirectory);

	button.addListener(SWT.Selection, event -> {
		final DirectoryDialog dialog = new DirectoryDialog(text.getShell());
		dialog.setMessage(ResourceManager.getLabel(ResourceManager.CHOOSE_DIRECTORY));
		final String result = dialog.open();
		if (result != null) {
			text.setText(result);
			PreferenceWindow.getInstance().setValue(getPropertyKey(), result);
		}
	});
}
 
Example 4
Source Project: scava   Source File: InstallableView.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void onBrowse() {
	DirectoryDialog directoryDialog = new DirectoryDialog(getShell());

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

	String path = directoryDialog.open();
	if (path != null) {
		eventManager.invoke(l -> l.onDestinationChanged(path + File.separator + destinationProjectFolder));
	}
}
 
Example 5
Source Project: scava   Source File: InstallView.java    License: 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 Project: xds-ide   Source File: LocationSelector.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void browseFileSystem() {
    String result = null;
    if (fileMode) {
        result = SWTFactory.browseFile(text.getShell(), false,
                                       Messages.LocationSelector_SelectAFile, 
                                       new String[]{"*" + (fileBrowseExtension == null ? "" : fileBrowseExtension)}, //$NON-NLS-1$ //$NON-NLS-2$
                                       fileBrowsePath);
    } else {
        DirectoryDialog dialog = new DirectoryDialog(text.getShell());
        dialog.setFilterPath(getLocationTxt());
        dialog.setText(Messages.LocationSelector_DirSelection);
        dialog.setMessage(Messages.LocationSelector_ChooseADir+':');
        result = dialog.open();
    }
    if (result != null)
        text.setText(result);
}
 
Example 7
/**
 * 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 8
/**
 * Export analysis to new file.
 */
private void exportAnalysis() {
    TableItem[] selection = fAnalysesTable.getSelection();
    DirectoryDialog dialog = DirectoryDialogFactory.create(Display.getCurrent().getActiveShell(), SWT.SAVE);
    dialog.setText(NLS.bind(Messages.ManageXMLAnalysisDialog_SelectDirectoryExport, selection.length));
    String directoryPath = dialog.open();
    if (directoryPath != null) {
        File directory = new File(directoryPath);
        for (TableItem item : selection) {
            String fileName = item.getText();
            String fileNameXml = XmlUtils.createXmlFileString(fileName);
            String path = new File(directory, fileNameXml).getAbsolutePath();
            if (!XmlUtils.exportXmlFile(fileNameXml, path).isOK()) {
                Activator.logError(NLS.bind(Messages.ManageXMLAnalysisDialog_FailedToExport, fileNameXml));
            }
        }
    }
}
 
Example 9
Source Project: hadoop-gpu   Source File: DFSActionImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Implement the import action (upload directory from the current machine
 * to HDFS)
 * 
 * @param object
 * @throws SftpException
 * @throws JSchException
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
private void uploadDirectoryToDFS(IStructuredSelection selection)
    throws InvocationTargetException, InterruptedException {

  // Ask the user which local directory to upload
  DirectoryDialog dialog =
      new DirectoryDialog(Display.getCurrent().getActiveShell(), SWT.OPEN
          | SWT.MULTI);
  dialog.setText("Select the local file or directory to upload");

  String dirName = dialog.open();
  final File dir = new File(dirName);
  List<File> files = new ArrayList<File>();
  files.add(dir);

  // TODO enable upload command only when selection is exactly one folder
  final List<DFSFolder> folders =
      filterSelection(DFSFolder.class, selection);
  if (folders.size() >= 1)
    uploadToDFS(folders.get(0), files);

}
 
Example 10
public static final SelectionAdapter getSelectionAdapter( final Shell shell, final Text destination ) {
  // Listen to the Browse... button
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      DirectoryDialog dialog = new DirectoryDialog( shell, SWT.OPEN );
      if ( destination.getText() != null ) {
        String fpath = destination.getText();
        // String fpath = StringUtil.environmentSubstitute(destination.getText());
        dialog.setFilterPath( fpath );
      }

      if ( dialog.open() != null ) {
        String str = dialog.getFilterPath();
        destination.setText( str );
      }
    }
  };
}
 
Example 11
/**
 * Shows the UI to select new external class folder entries.
 * The dialog returns the selected entry paths 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.
 * @return Returns the new external class folder path or <code>null</code> if the dialog has
 * been canceled by the user.
 *
 * @since 3.4
 */
public static IPath[] chooseExternalClassFolderEntries(Shell shell) {
	String lastUsedPath= JavaPlugin.getDefault().getDialogSettings().get(IUIConstants.DIALOGSTORE_LASTEXTJARFOLDER);
	if (lastUsedPath == null) {
		lastUsedPath= ""; //$NON-NLS-1$
	}
	DirectoryDialog dialog= new DirectoryDialog(shell, SWT.MULTI);
	dialog.setText(NewWizardMessages.BuildPathDialogAccess_ExtClassFolderDialog_new_title);
	dialog.setMessage(NewWizardMessages.BuildPathDialogAccess_ExtClassFolderDialog_new_description);
	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 12
/**
 * Shows the UI to configure an external class folder.
 * 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 class folder path or <code>null</code> if the dialog has
 * been canceled by the user.
 *
 * @since 3.4
 */
public static IPath configureExternalClassFolderEntries(Shell shell, IPath initialEntry) {
	DirectoryDialog dialog= new DirectoryDialog(shell, SWT.SINGLE);
	dialog.setText(NewWizardMessages.BuildPathDialogAccess_ExtClassFolderDialog_edit_title);
	dialog.setMessage(NewWizardMessages.BuildPathDialogAccess_ExtClassFolderDialog_edit_description);
	dialog.setFilterPath(initialEntry.toString());

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

	File file= new File(res);
	if (file.isDirectory())
		return new Path(file.getAbsolutePath());

	return null;
}
 
Example 13
private String chooseJavaDocFolder() {
	String initPath= ""; //$NON-NLS-1$
	if (fURLResult != null && "file".equals(fURLResult.getProtocol())) { //$NON-NLS-1$
		initPath= JavaDocLocations.toFile(fURLResult).getPath();
	}
	DirectoryDialog dialog= new DirectoryDialog(fShell);
	dialog.setText(PreferencesMessages.JavadocConfigurationBlock_javadocFolderDialog_label);
	dialog.setMessage(PreferencesMessages.JavadocConfigurationBlock_javadocFolderDialog_message);
	dialog.setFilterPath(initPath);
	String result= dialog.open();
	if (result != null) {
		try {
			URL url= new File(result).toURI().toURL();
			return url.toExternalForm();
		} catch (MalformedURLException e) {
			JavaPlugin.log(e);
		}
	}
	return null;
}
 
Example 14
public String browse() {
  Spoon spoon = spoonSupplier.get();
  CompletableFuture<String> name = new CompletableFuture<>();
  Runnable execute = () -> {
    DirectoryDialog directoryDialog = new DirectoryDialog( spoonSupplier.get().getShell() );
    name.complete( directoryDialog.open() );
  };
  if ( spoon.getShell() != null ) {
    spoon.getShell().getDisplay().asyncExec( execute );
  } else {
    execute.run();
  }
  try {
    return name.get();
  } catch ( Exception e ) {
    return "/";
  }
}
 
Example 15
private IPath chooseExtFolder() {
	IPath currPath= getFilePath();
	if (currPath.segmentCount() == 0) {
		currPath= fEntry.getPath();
	}
	if (ArchiveFileFilter.isArchivePath(currPath, true)) {
		currPath= currPath.removeLastSegments(1);
	}

	DirectoryDialog dialog= new DirectoryDialog(getShell());
	dialog.setMessage(NewWizardMessages.SourceAttachmentBlock_extfolderdialog_message);
	dialog.setText(NewWizardMessages.SourceAttachmentBlock_extfolderdialog_text);
	dialog.setFilterPath(currPath.toOSString());
	String res= dialog.open();
	if (res != null) {
		return Path.fromOSString(res).makeAbsolute();
	}
	return null;
}
 
Example 16
Source Project: ermaster-b   Source File: ExportToHtmlAction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected String getSaveFilePath(IEditorPart editorPart,
		GraphicalViewer viewer) {

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

	DirectoryDialog fileDialog = new DirectoryDialog(editorPart
			.getEditorSite().getShell(), SWT.SAVE);

	IProject project = file.getProject();

	fileDialog.setFilterPath(project.getLocation().toString());
	fileDialog.setMessage(ResourceString
			.getResourceString("dialog.message.export.html.dir.select"));

	String saveFilePath = fileDialog.open();

	if (saveFilePath != null) {
		saveFilePath = saveFilePath + OUTPUT_DIR;
	}

	return saveFilePath;
}
 
Example 17
/**
 * Open an appropriate destination browser so that the user can specify a source
 * to import from
 */
protected void handleDestinationBrowseButtonPressed() {
    final DirectoryDialog dialog = new DirectoryDialog(getContainer().getShell(), SWT.SAVE | SWT.SHEET);
    // dialog.setFilterExtensions(new String[] { "*.bar" }); //$NON-NLS-1$
    dialog.setText(Messages.selectDestinationTitle);
    final String currentSourceString = getDetinationPath();
    final int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator);
    if (lastSeparatorIndex != -1) {
        dialog.setFilterPath(currentSourceString.substring(0,
                lastSeparatorIndex));
    }
    final String selectedFileName = dialog.open();

    if (selectedFileName != null) {
        destinationCombo.setText(selectedFileName);
    }
}
 
Example 18
Source Project: thym   Source File: HybridProjectImportPage.java    License: 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 19
Source Project: Rel   Source File: RestoreDatabaseDialog.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create the dialog.
 * @param parent
 * @param style
 */
public RestoreDatabaseDialog(Shell parent) {
	super(parent, SWT.DIALOG_TRIM | SWT.RESIZE);
	setText("Create and Restore Database");
	
	newDatabaseDialog = new DirectoryDialog(parent);
	newDatabaseDialog.setText("Create Database");
	newDatabaseDialog.setMessage("Select a folder to hold a new database.");
	newDatabaseDialog.setFilterPath(System.getProperty("user.home"));

	restoreFileDialog = new FileDialog(Core.getShell(), SWT.OPEN);
	restoreFileDialog.setFilterPath(System.getProperty("user.home"));
	restoreFileDialog.setFilterExtensions(new String[] {"*.rel", "*.*"});
	restoreFileDialog.setFilterNames(new String[] {"Rel script", "All Files"});
	restoreFileDialog.setText("Load Backup");
}
 
Example 20
Source Project: ermaster-b   Source File: Activator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * �f�B���N�g���I���_�C�A���O��\�����܂�
 *
 * @param filePath
 *            �f�t�H���g�̃t�@�C���p�X
 * @return �f�B���N�g���I���_�C�A���O�őI�����ꂽ�f�B���N�g���̃p�X
 */
public static String showDirectoryDialog(String filePath) {
	String fileName = null;

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

	DirectoryDialog dialog = new DirectoryDialog(PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getShell(), SWT.NONE);

	dialog.setFilterPath(fileName);

	return dialog.open();
}
 
Example 21
Source Project: birt   Source File: ClassPathBlock.java    License: 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 22
Source Project: Pydev   Source File: WorkingDirectoryBlock.java    License: 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("Select a working directory for the launch configuration:");
    String currentWorkingDir = getWorkingDirectoryText();
    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) {
        fOtherWorkingText.setText(selectedDirectory);
    }
}
 
Example 23
Source Project: birt   Source File: NewReportPageSupport.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Open an appropriate directory browser
 */
private void handleLocationBrowseButtonPressed( )
{
	DirectoryDialog dialog = new DirectoryDialog( locationPathField.getShell( ) );
	dialog.setMessage( LABEL_SELECT_A_DIRECTORY );

	String dirName = getFileLocationFullPath( ).toOSString( );
	if ( !dirName.equals( "" ) )//$NON-NLS-1$
	{
		File path = new File( dirName );
		if ( path.exists( ) )
		{
			dialog.setFilterPath( new Path( dirName ).toOSString( ) );
		}
	}

	String selectedDirectory = dialog.open( );
	if ( selectedDirectory != null )
	{
		customLocationFieldValue = selectedDirectory;
		locationPathField.setText( customLocationFieldValue );
	}
}
 
Example 24
Source Project: RDFS   Source File: DFSActionImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Implement the import action (upload directory from the current machine
 * to HDFS)
 * 
 * @param object
 * @throws SftpException
 * @throws JSchException
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
private void uploadDirectoryToDFS(IStructuredSelection selection)
    throws InvocationTargetException, InterruptedException {

  // Ask the user which local directory to upload
  DirectoryDialog dialog =
      new DirectoryDialog(Display.getCurrent().getActiveShell(), SWT.OPEN
          | SWT.MULTI);
  dialog.setText("Select the local file or directory to upload");

  String dirName = dialog.open();
  final File dir = new File(dirName);
  List<File> files = new ArrayList<File>();
  files.add(dir);

  // TODO enable upload command only when selection is exactly one folder
  final List<DFSFolder> folders =
      filterSelection(DFSFolder.class, selection);
  if (folders.size() >= 1)
    uploadToDFS(folders.get(0), files);

}
 
Example 25
Source Project: RepDev   Source File: MainShell.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void addFolder() {
	DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NONE);
	dialog.setMessage("Select a folder to mount in RepDev");
	String dir;

	if ((dir = dialog.open()) != null) {
		boolean exists = false;

		for (TreeItem current : tree.getItems()) {
			if (current.getData() instanceof String && ((String) current.getData()).equals(dir))
				exists = true;
		}

		if (!exists) {
			TreeItem item = new TreeItem(tree, SWT.NONE);
			item.setText(dir.substring(dir.lastIndexOf("\\")));
			item.setImage(RepDevMain.smallFolderImage);
			item.setData(dir);
			new TreeItem(item, SWT.NONE).setText("Loading...");
			Config.getMountedDirs().add(dir);
		}
	}
}
 
Example 26
/**
 *  Open an appropriate directory browser
 */
private void handleLocationBrowseButtonPressed() {
    DirectoryDialog dialog = new DirectoryDialog(locationPathField.getShell());
    dialog.setMessage("Select the project contents directory.");

    String dirName = getProjectLocationFieldValue();
    if (!dirName.equals("")) { //$NON-NLS-1$
        File path = new File(dirName);
        if (path.exists()) {
            dialog.setFilterPath(new Path(dirName).toOSString());
        }
    }

    String selectedDirectory = dialog.open();
    if (selectedDirectory != null) {
        customLocationFieldValue = selectedDirectory;
        locationPathField.setText(customLocationFieldValue);
    }
}
 
Example 27
Source Project: olca-app   Source File: FileChooser.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private static String openDirectoryDialog(Shell shell, String filterPath,
		int swtFlag) {
	DirectoryDialog dialog = new DirectoryDialog(shell, swtFlag);
	dialog.setText(M.SelectADirectory);
	if (filterPath != null)
		dialog.setFilterPath(filterPath);
	return dialog.open();
}
 
Example 28
Source Project: n4js   Source File: SpecConfigAdocPage.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void selectDocRoot(Event e) {
	switch (e.type) {
	case SWT.Selection:
		DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent().getActiveShell(), SWT.OPEN | SWT.MULTI);
		dialog.setText("Select the documentation root directory");
		String result = dialog.open();
		if (result != null && !result.isEmpty()) {
			txtDocRootDirName.setText(result);
			saveProperty(result);
			checkPageComplete();
		}
		break;
	}
}
 
Example 29
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 30
/**
 * A listener that opens a folder selection dialog when the button is pressed and sets the text
 * when the dialog was closed if a selection was made.
 */
private SelectionListener folderSelectionListener(final Shell shell) {
  return new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent event) {
      DirectoryDialog dialog = new DirectoryDialog(shell);
      dialog.setMessage(Messages.getString("select.project.location")); //$NON-NLS-1$
      String result = dialog.open();
      if (!Strings.isNullOrEmpty(result)) {
        locationInput.setText(result);
      }
    }
  };
}