类org.eclipse.swt.widgets.DirectoryDialog源码实例Demo

下面列出了怎么用org.eclipse.swt.widgets.DirectoryDialog的API类实例代码及写法,或者点击链接到github查看源代码。

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 );
      }
    }
  };
}
 
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 );
      }
    }
  };
}
 
源代码3 项目: nebula   文件: PWDirectoryChooser.java
/**
 * @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);
		}
	});
}
 
源代码4 项目: scava   文件: InstallableView.java
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));
	}
}
 
源代码5 项目: scava   文件: InstallView.java
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));
	}
}
 
源代码6 项目: xds-ide   文件: LocationSelector.java
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);
}
 
源代码7 项目: xds-ide   文件: CompilerWorkingDirectoryBlock.java
/**
 * 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);
        }
    }       
}
 
/**
 * 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));
            }
        }
    }
}
 
源代码9 项目: hadoop-gpu   文件: DFSActionImpl.java
/**
 * 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);

}
 
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 );
      }
    }
  };
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
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;
}
 
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 "/";
  }
}
 
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;
}
 
源代码16 项目: ermaster-b   文件: ExportToHtmlAction.java
/**
 * {@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;
}
 
源代码17 项目: bonita-studio   文件: ExportBarWizardPage.java
/**
 * 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);
    }
}
 
源代码18 项目: thym   文件: HybridProjectImportPage.java
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);
	}
}
 
源代码19 项目: Rel   文件: RestoreDatabaseDialog.java
/**
 * 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");
}
 
源代码20 项目: ermaster-b   文件: Activator.java
/**
 * �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();
}
 
源代码21 项目: birt   文件: ClassPathBlock.java
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;
}
 
源代码22 项目: Pydev   文件: WorkingDirectoryBlock.java
/**
 * 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);
    }
}
 
源代码23 项目: birt   文件: NewReportPageSupport.java
/**
 * 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 );
	}
}
 
源代码24 项目: RDFS   文件: DFSActionImpl.java
/**
 * 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);

}
 
源代码25 项目: RepDev   文件: MainShell.java
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);
		}
	}
}
 
/**
 *  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);
    }
}
 
源代码27 项目: olca-app   文件: FileChooser.java
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();
}
 
源代码28 项目: n4js   文件: SpecConfigAdocPage.java
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;
	}
}
 
源代码29 项目: workspacemechanic   文件: TaskResourceDialog.java
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);
  }
}
 
/**
 * 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);
      }
    }
  };
}
 
 类所在包
 同包方法