下面列出了org.eclipse.swt.widgets.DirectoryDialog#setFilterPath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void changeControlPressed(DialogField field) {
final DirectoryDialog dialog= new DirectoryDialog(getShell());
dialog.setMessage(NewWizardMessages.AddSourceFolderWizardPage_directory_message);
String directoryName = fLinkLocation.getText().trim();
if (directoryName.length() == 0) {
String prevLocation= JavaPlugin.getDefault().getDialogSettings().get(DIALOGSTORE_LAST_EXTERNAL_LOC);
if (prevLocation != null) {
directoryName= prevLocation;
}
}
if (directoryName.length() > 0) {
final File path = new File(directoryName);
if (path.exists())
dialog.setFilterPath(directoryName);
}
final String selectedDirectory = dialog.open();
if (selectedDirectory != null) {
fLinkLocation.setText(selectedDirectory);
fRootDialogField.setText(selectedDirectory.substring(selectedDirectory.lastIndexOf(File.separatorChar) + 1));
JavaPlugin.getDefault().getDialogSettings().put(DIALOGSTORE_LAST_EXTERNAL_LOC, selectedDirectory);
if (fAdapter != null) {
fAdapter.dialogFieldChanged(fRootDialogField);
}
}
}
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));
}
}
public static IPath configureExternalClassFolderEntries( Shell shell,
IPath initialEntry )
{
DirectoryDialog dialog = new DirectoryDialog( shell, SWT.SINGLE );
dialog.setText( Messages.getString( "ClassPathBlock_FolderDialog.edit.text" ) ); //$NON-NLS-1$
dialog.setMessage( Messages.getString( "ClassPathBlock_FolderDialog.edit.message" ) ); //$NON-NLS-1$
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;
}
/**
* 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");
}
/**
* 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;
}
/**
* 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);
}
}
}
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 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;
}
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 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 void addItemWithDialog(DirectoryDialog dialog) {
dialog.setFilterPath(lastDirectoryDialogPath);
String filePath = dialog.open();
if (filePath != null) {
lastDirectoryDialogPath = filePath;
}
addTreeItem(filePath);
}
protected String getSaveDirPath(IEditorPart editorPart, GraphicalViewer viewer) {
final IFile file = ((IFileEditorInput) editorPart.getEditorInput()).getFile();
final DirectoryDialog directoryDialog = new DirectoryDialog(editorPart.getEditorSite().getShell(), SWT.SAVE);
final IProject project = file.getProject();
directoryDialog.setFilterPath(project.getLocation().toString());
return directoryDialog.open();
}
public static String browseDirectory(Shell shell, String text, String message, String preferredPath) {
DirectoryDialog fd = new DirectoryDialog(shell);
fd.setText(text);
fd.setMessage(message);
fd.setFilterPath(mkPrefPath(preferredPath));
String res = fd.open();
if (res != null)
lastBrowsePath = res;
return res; // null => cancel
}
/**
* Allows users to select a directory with a use scan in it
*
* @param prevLocation
* @return the new directory or <code>null</code> if the dialog was
* cancelled
*/
String getDirectory(String prevLocation) {
DirectoryDialog dialog = new DirectoryDialog(this.preferencePage.getShell());
dialog.setMessage("Select the library path location");
if (prevLocation != null) {
dialog.setFilterPath(prevLocation);
}
final String open = dialog.open();
if (open != null) {
return open + File.separator;
}
return null;
}
@Override
public void widgetSelected(SelectionEvent event) {
if (event.widget == _dirBtn) {
DirectoryDialog dlg = new DirectoryDialog(getShell());
dlg.setFilterPath(getDirectory());
dlg.setMessage("Choose a deployment directory for your application:"); // $NLX-DirectoryBluemixWizardPage.Chooseadeploymentdirectoryforyour-1$
String loc = dlg.open();
if (StringUtil.isNotEmpty(loc)) {
_dirText.setText(loc);
}
}
}
private void showDirectoryDialog() {
DirectoryDialog directoryDialog = new DirectoryDialog(getShell(), SWT.OPEN);
directoryDialog.setFilterPath("Choose SDK Directory");
directoryDialog.setMessage("Please select the root directory of your SDK installation.");
String pathToDir = directoryDialog.open();
if (pathToDir != null) {
textPath.setText(pathToDir);
}
}
/**
* 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);
}
}
/**
* The browse button has been selected. Select the location.
*/
protected void handleLocationDirectoryButtonPressed()
{
DirectoryDialog dialog = new DirectoryDialog(directoryPathField.getShell());
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
{
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);
}
setProjectName();
setPageComplete(directoryPathField.getText() != null);
}
public static String showDirectoryDialog(final String filePath, final String message) {
String fileName = null;
if (filePath != null && !"".equals(filePath.trim())) {
final File file = new File(filePath.trim());
fileName = file.getPath();
}
final DirectoryDialog dialog = new DirectoryDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.NONE);
dialog.setMessage(ResourceString.getResourceString(message));
dialog.setFilterPath(fileName);
return dialog.open();
}
protected String getSaveDirPath(final IEditorPart editorPart, final GraphicalViewer viewer) {
final DirectoryDialog directoryDialog = new DirectoryDialog(editorPart.getEditorSite().getShell(), SWT.SAVE);
directoryDialog.setFilterPath(getBasePath());
return directoryDialog.open();
}