import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class SWTFileOpenSnippet { public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell (display); // Don't show the shell. //shell.open (); FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI); String [] filterNames = new String [] {"All Files (*)"}; String [] filterExtensions = new String [] {"*"}; String filterPath = "c:\\"; dialog.setFilterNames (filterNames); dialog.setFilterExtensions (filterExtensions); dialog.setFilterPath (filterPath); dialog.open(); System.out.println ("Selected files: "); String[] selectedFileNames = dialog.getFileNames(); for(String fileName : selectedFileNames) { System.out.println(" " + fileName); } shell.close(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } }
String[] filenames = dialog.getFileNames(); if ( filenames.length > 0 ) { RepositoryImportProgressDialog ripd =
String[] filenames = dialog.getFileNames(); if ( filenames.length > 0 ) { RepositoryImportProgressDialog ripd =
@Override public void widgetSelected(SelectionEvent e) { String pathPrefix = fd.open(); if (pathPrefix != null) { episodeMap.addFilesToQueue(pathPrefix, fd.getFileNames()); } } });
private void chooseFile() { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.MULTI); dialog.setFilterExtensions(new String[] {"*.jar"}); //$NON-NLS-1$ String res = dialog.open(); if (res != null) { String path = new File(res).getParent(); String[] fileNames = dialog.getFileNames(); for (String fileName : fileNames) { File newJarFile = new File(path, fileName); removeJar(fileName); fJarPaths.add(newJarFile); fTableViewer.add(newJarFile); } updatePageStatus(); } }
String files[] = dialog.getFileNames(); System.out.println(path);
protected IPath chooseAudioFile() { FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE); dialog.setText(Messages.audioPrefSelectFile); dialog.setFilterExtensions(new String[] {"*.au;*.wav"}); dialog.setFilterPath(null); dialog.open(); String[] filenames = dialog.getFileNames(); if (filenames != null && filenames.length > 0) { String filterPath = dialog.getFilterPath(); return new Path(filterPath + java.io.File.separator + filenames[0]); } return null; }
import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; public class SWTFileOpenSnippet { public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell (display); // Don't show the shell. //shell.open (); FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI); String [] filterNames = new String [] {"All Files (*)"}; String [] filterExtensions = new String [] {"*"}; String filterPath = "c:\\"; dialog.setFilterNames (filterNames); dialog.setFilterExtensions (filterExtensions); dialog.setFilterPath (filterPath); dialog.open(); System.out.println ("Selected files: "); String[] selectedFileNames = dialog.getFileNames(); for(String fileName : selectedFileNames) { System.out.println(" " + fileName); } shell.close(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } }
@Override protected boolean browseFileSystem() { FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN | (supportMultipleURIs() ? SWT.MULTI : SWT.SINGLE)); fileDialog.setFilterExtensions(getFilterExtensions()); URI modelURI = getModelImporter().getFirstModelLocationURI(true); if (modelURI != null) { fileDialog.setFileName(modelURI.toFileString()); } if (fileDialog.open() != null && fileDialog.getFileNames().length > 0) { String[] fileNames = fileDialog.getFileNames(); StringBuffer text = new StringBuffer(); for (int i = 0; i < fileNames.length; ++i) { String filePath = fileDialog.getFilterPath() + File.separator + fileNames[i]; text.append(URI.createFileURI(filePath).toString()); text.append(" "); } setURIText(text.toString()); refreshModel(); return true; } return false; }
@Override public void widgetSelected(SelectionEvent e) { FileDialog fDialog = new FileDialog(Utils.findAnyShell(), SWT.OPEN | SWT.MULTI); fDialog.setFilterPath(TorrentOpener.getFilterPathData()); fDialog.setText(MessageText.getString("MainWindow.dialog.choose.file")); if (fDialog.open() != null) { String[] fileNames = fDialog.getFileNames(); File last_file = null; for (String fileName : fileNames) { File f = new File(fDialog.getFilterPath(), fileName); addFilename(f); last_file = f; } if ( last_file != null ){ TorrentOpener.setFilterPathData( last_file.getAbsolutePath()); } } }
/** * Opens a file dialog and adds the selected files to the file table viewer. */ public void widgetSelected(SelectionEvent e) { // open a file dialog FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.MULTI); fd.setText("Choose text files"); fd.setFilterExtensions(new String[] { "*.txt;*.rtf", "*.*"}); fd.setFilterNames(new String[] {"Text Files", "All Files (*)"}); if (fd.open() != null) { for (String fileItem : fd.getFileNames()) { fileTable.add(new File(fd.getFilterPath() + File.separator + fileItem)); } updatePageState(); } } });
@Override public void runSupport() { final Shell shell = Utils.findAnyShell(); if (shell == null) return; FileDialog fDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); fDialog.setFilterPath(getFilterPathTorrent()); fDialog .setFilterExtensions(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD }); fDialog.setFilterNames(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD }); fDialog.setText(MessageText.getString("MainWindow.dialog.choose.file")); String path = setFilterPathTorrent(fDialog.open()); if (path == null) return; TorrentOpener.openTorrentsForTracking(path, fDialog.getFileNames()); } });
@Override public void handleEvent(Event event) { FileDialog fDialog = new FileDialog(shellForChildren, SWT.OPEN | SWT.MULTI); fDialog.setFilterExtensions(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD }); fDialog.setFilterNames(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD }); fDialog.setFilterPath(TorrentOpener.getFilterPathTorrent()); fDialog.setText(MessageText.getString("MainWindow.dialog.choose.file")); String fileName = TorrentOpener.setFilterPathTorrent(fDialog.open()); if (fileName != null) { addTorrentsToWindow(fDialog.getFilterPath(), fDialog.getFileNames()); } } });
@Override public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) { FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI | SWT.SHEET); String rootDir = DebugUIPlugin.getDefault().getDialogSettings().get(ROOT_DIR); dialog.setText(SourceLookupUIMessages.ExternalArchiveSourceContainerBrowser_2); dialog.setFilterExtensions(new String[]{"*.jar;*.zip"}); //$NON-NLS-1$ if (rootDir != null) { dialog.setFilterPath(rootDir); } dialog.open(); String[] fileNames= dialog.getFileNames(); int nChosen= fileNames.length; if (nChosen > 0) { rootDir = dialog.getFilterPath(); IPath filterPath= new Path(rootDir); ISourceContainer[] containers= new ISourceContainer[nChosen]; for (int i= 0; i < nChosen; i++) { IPath path= filterPath.append(fileNames[i]).makeAbsolute(); // TODO: configure auto-detect containers[i]= new ExternalArchiveSourceContainer(path.toOSString(), true); } DebugUIPlugin.getDefault().getDialogSettings().put(ROOT_DIR, rootDir); return containers; } return new ISourceContainer[0]; }
/** * Allows the user to enter external property files */ private void addExternalPropertyFile() { String lastUsedPath; lastUsedPath = dialogSettings.get(IAntUIConstants.DIALOGSTORE_LASTEXTFILE); if (lastUsedPath == null) { lastUsedPath = IAntCoreConstants.EMPTY_STRING; } FileDialog dialog = new FileDialog(fileTableViewer.getControl().getShell(), SWT.MULTI | SWT.SHEET); dialog.setFilterExtensions(new String[] { "*.properties", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ ; dialog.setFilterPath(lastUsedPath); String result = dialog.open(); if (result == null) { return; } IPath filterPath = new Path(dialog.getFilterPath()); String[] results = dialog.getFileNames(); for (int i = 0; i < results.length; i++) { String fileName = results[i]; IPath path = filterPath.append(fileName).makeAbsolute(); ((AntContentProvider) fileTableViewer.getContentProvider()).add(path.toOSString()); } dialogSettings.put(IAntUIConstants.DIALOGSTORE_LASTEXTFILE, filterPath.toOSString()); container.update(); }
@Override public void runSupport() { final Shell shell = Utils.findAnyShell(); if (shell == null) return; FileDialog fDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); fDialog.setFilterPath(getFilterPathTorrent()); fDialog.setFilterExtensions(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD }); fDialog.setFilterNames(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD }); fDialog.setText(MessageText.getString("MainWindow.dialog.choose.file")); String path = setFilterPathTorrent(fDialog.open()); if (path == null) return; UIFunctionsManagerSWT.getUIFunctionsSWT().openTorrentOpenOptions(shell, path, fDialog.getFileNames(), false, false); } });
/** * Open the file selection dialog, and add the return jars as libraries. */ private void add(IStructuredSelection selection) { IDialogSettings dialogSettings= JDIDebugUIPlugin.getDefault().getDialogSettings(); String lastUsedPath= dialogSettings.get(LAST_PATH_SETTING); if (lastUsedPath == null) { lastUsedPath= ""; //$NON-NLS-1$ } FileDialog dialog= new FileDialog(fLibraryViewer.getControl().getShell(), SWT.MULTI); dialog.setText(JREMessages.VMLibraryBlock_10); dialog.setFilterExtensions(new String[] {"*.jar;*.zip"}); //$NON-NLS-1$ dialog.setFilterPath(lastUsedPath); String res= dialog.open(); if (res == null) { return; } String[] fileNames= dialog.getFileNames(); int nChosen= fileNames.length; IPath filterPath= new Path(dialog.getFilterPath()); LibraryLocation[] libs= new LibraryLocation[nChosen]; for (int i= 0; i < nChosen; i++) { libs[i]= new LibraryLocation(filterPath.append(fileNames[i]).makeAbsolute(), Path.EMPTY, Path.EMPTY); } dialogSettings.put(LAST_PATH_SETTING, filterPath.toOSString()); fLibraryContentProvider.add(libs, selection); }
if (defaultFilename != null) dialog.setFileName (defaultFilename); String filename = dialog.open (); files = dialog.getFileNames (); directory = dialog.getFilterPath (); title = defaultFilename = null;
if (defaultFilename != null) dialog.setFileName (defaultFilename); String filename = dialog.open (); files = dialog.getFileNames (); directory = dialog.getFilterPath (); title = defaultFilename = null;
if (defaultFilename != null) dialog.setFileName (defaultFilename); String filename = dialog.open (); files = dialog.getFileNames (); directory = dialog.getFilterPath (); title = defaultFilename = null;