Java Code Examples for org.eclipse.swt.widgets.FileDialog#setFilterExtensions()
The following examples show how to use
org.eclipse.swt.widgets.FileDialog#setFilterExtensions() .
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: RemoteDataPage.java From neoscada with Eclipse Public License 1.0 | 6 votes |
protected void handleLoadLocal () { final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN ); dlg.setFilterExtensions ( new String[] { "*.oscar", "*.json", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ dlg.setFilterNames ( new String[] { Messages.LocalDataPage_OSCARFilterDescription, Messages.LocalDataPage_JSONFilterDescription, Messages.LocalDataPage_AllFilterDescription } ); final String selectedFileName = getWizard ().getDialogSettings ().get ( "localDataPage.file" ); //$NON-NLS-1$ if ( selectedFileName != null && selectedFileName.length () > 0 ) { dlg.setFileName ( selectedFileName ); } dlg.setFilterIndex ( 0 ); final String file = dlg.open (); if ( file != null ) { getWizard ().getDialogSettings ().put ( "localDataPage.file", file ); //$NON-NLS-1$ loadFromLocalFile ( file ); } }
Example 2
Source File: LocalDataPage.java From neoscada with Eclipse Public License 1.0 | 6 votes |
protected void selectFile () { final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN ); dlg.setFilterExtensions ( new String[] { "*.oscar", "*.json", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ dlg.setFilterNames ( new String[] { Messages.LocalDataPage_OSCARFilterDescription, Messages.LocalDataPage_JSONFilterDescription, Messages.LocalDataPage_AllFilterDescription } ); if ( this.fileName.getText ().length () > 0 ) { dlg.setFileName ( this.fileName.getText () ); } dlg.setFilterIndex ( 0 ); final String file = dlg.open (); if ( file != null ) { this.fileName.setText ( file ); loadFile (); } }
Example 3
Source File: ChartComposite.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Opens a file chooser and gives the user an opportunity to save the chart * in PNG format. * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { FileDialog fileDialog = new FileDialog(this.canvas.getShell(), SWT.SAVE); String[] extensions = {"*.png"}; fileDialog.setFilterExtensions(extensions); String filename = fileDialog.open(); if (filename != null) { if (isEnforceFileExtensions()) { if (!filename.endsWith(".png")) { filename = filename + ".png"; } } //TODO replace getSize by getBounds ? ChartUtilities.saveChartAsPNG(new File(filename), this.chart, this.canvas.getSize().x, this.canvas.getSize().y); } }
Example 4
Source File: XSLTransformationDialog.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 打开文件对话框 * @param txt * 显示路径文本框 * @param style * 对话框样式 * @param title * 对话框标题 * @param extensions * @param filterNames * ; */ private void openFileDialog(Text txt, int style, String title, String[] extensions, String[] filterNames) { FileDialog dialog = new FileDialog(getShell(), style); dialog.setText(title); dialog.setFilterExtensions(extensions); dialog.setFilterNames(filterNames); String fileSep = System.getProperty("file.separator"); if (txt.getText() != null && !txt.getText().trim().equals("")) { dialog.setFilterPath(txt.getText().substring(0, txt.getText().lastIndexOf(fileSep))); dialog.setFileName(txt.getText().substring(txt.getText().lastIndexOf(fileSep) + 1)); } else { dialog.setFilterPath(System.getProperty("user.home")); } String path = dialog.open(); if (path != null) { txt.setText(path); } }
Example 5
Source File: MultiFileFieldEditor.java From ermaster-b with Apache License 2.0 | 5 votes |
private File[] getFile(File startingDirectory) { int style = SWT.OPEN; if (multiple) { style |= SWT.MULTI; } FileDialog dialog = new FileDialog(getShell(), style); if (startingDirectory != null) { dialog.setFileName(startingDirectory.getPath()); } if (extensions != null) { dialog.setFilterExtensions(extensions); } dialog.open(); String[] fileNames = dialog.getFileNames(); if (fileNames.length > 0) { File[] files = new File[fileNames.length]; for (int i = 0; i < fileNames.length; i++) { files[i] = new File(dialog.getFilterPath(), fileNames[i]); } return files; } return null; }
Example 6
Source File: ImportFromFileAction.java From erflute with Apache License 2.0 | 5 votes |
protected String getLoadFilePath(IEditorPart editorPart) { final IFile file = ((IFileEditorInput) editorPart.getEditorInput()).getFile(); final FileDialog fileDialog = new FileDialog(editorPart.getEditorSite().getShell(), SWT.OPEN); final IProject project = file.getProject(); fileDialog.setFilterPath(project.getLocation().toString()); final String[] filterExtensions = getFilterExtensions(); fileDialog.setFilterExtensions(filterExtensions); return fileDialog.open(); }
Example 7
Source File: ExportParametersAction.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public void run() { if(path == null){ final FileDialog fd = new FileDialog(Display.getDefault().getActiveShell(), SWT.SAVE) ; fd.setFileName(process.getName()+"_"+process.getVersion()+"_"+Messages.parameters+".properties") ; fd.setFilterExtensions(new String[]{"*.properties"}) ; path = fd.open() ; exportParameters(); ; }else{ path = path + File.separator + "parameters.properties"; exportParameters(); } }
Example 8
Source File: ModifyDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void saveButtonPressed() { Profile selected= new CustomProfile(fProfileNameField.getText(), new HashMap<String, String>(fWorkingValues), fProfile.getVersion(), fProfileManager.getProfileVersioner().getProfileKind()); final FileDialog dialog= new FileDialog(getShell(), SWT.SAVE); dialog.setText(FormatterMessages.CodingStyleConfigurationBlock_save_profile_dialog_title); dialog.setFilterExtensions(new String [] {"*.xml"}); //$NON-NLS-1$ final String lastPath= JavaPlugin.getDefault().getDialogSettings().get(fLastSaveLoadPathKey + ".savepath"); //$NON-NLS-1$ if (lastPath != null) { dialog.setFilterPath(lastPath); } final String path= dialog.open(); if (path == null) return; JavaPlugin.getDefault().getDialogSettings().put(fLastSaveLoadPathKey + ".savepath", dialog.getFilterPath()); //$NON-NLS-1$ final File file= new File(path); if (file.exists() && !MessageDialog.openQuestion(getShell(), FormatterMessages.CodingStyleConfigurationBlock_save_profile_overwrite_title, Messages.format(FormatterMessages.CodingStyleConfigurationBlock_save_profile_overwrite_message, BasicElementLabels.getPathLabel(file)))) { return; } String encoding= ProfileStore.ENCODING; final IContentType type= Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.xml"); //$NON-NLS-1$ if (type != null) encoding= type.getDefaultCharset(); final Collection<Profile> profiles= new ArrayList<Profile>(); profiles.add(selected); try { fProfileStore.writeProfilesToFile(profiles, file, encoding); } catch (CoreException e) { final String title= FormatterMessages.CodingStyleConfigurationBlock_save_profile_error_title; final String message= FormatterMessages.CodingStyleConfigurationBlock_save_profile_error_message; ExceptionHandler.handle(e, getShell(), title, message); } }
Example 9
Source File: FileOpen.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); final FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setFilterExtensions(new String[] { "*.gaml", "*.experiment", "*.*" }); dialog.setFilterNames(new String[] { "GAML model files", "GAML experiment files", "All Files" }); final String fileSelected = dialog.open(); if (fileSelected != null && GamlFileExtension.isAny(fileSelected)) { // Perform Action, like open the file. WorkspaceModelsManager.instance.openModelPassedAsArgument(fileSelected); } return null; }
Example 10
Source File: ImportBosArchiveControlSupplier.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected String openFileDialog(Shell shell) { final FileDialog fd = new FileDialog(shell, SWT.OPEN | SWT.SINGLE); fd.setText(Messages.importProcessTitle); fd.setFilterPath(getLastPath()); fd.setFilterExtensions(new String[] { BOS_EXTENSION }); return fd.open(); }
Example 11
Source File: AbstractExportAction.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected Optional<String> getPath(Shell shell, IRepositoryFileStore fStore) { final FileDialog fd = new FileDialog(shell, SWT.SAVE | SWT.SHEET); fd.setFileName(fStore.getName()); fd.setFilterExtensions(new String[] { "*.xml" }); fd.setText(getExportTitle()); return Optional.ofNullable(fd.open()); }
Example 12
Source File: ImportFileWizardPage.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
protected String openFileDialog() { final FileDialog fd = new FileDialog(getShell(), SWT.OPEN | SWT.SINGLE); fd.setText(Messages.importProcessTitle); fd.setFilterPath(getLastPath()); final String filterExtensions = importFileData.getImporterFactory().getFilterExtensions(); final String[] filterExt = filterExtensions.split(","); fd.setFilterExtensions(filterExt); return fd.open(); }
Example 13
Source File: AbstractPictureControl.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Configure the {@link FileDialog} to set the file extension, the text, * etc. This method can be override to custome the configuration. * * @param fd */ protected void configure(FileDialog fd) { fd.setText(resources.getString(PICTURE_CONTROL_FILEDIALOG_TEXT)); if (extensions != null) { fd.setFilterExtensions(extensions); } }
Example 14
Source File: OpenFileFlow.java From Universal-FE-Randomizer with MIT License | 5 votes |
@Override public void handleEvent(Event event) { // TODO Auto-generated method stub FileDialog openDialog = new FileDialog(parent, SWT.OPEN); openDialog.setFilterExtensions(new String[] {"*.gba;*.smc;*.sfc;*.iso", "*"}); openDialog.setFilterNames(new String[] {"*.gba, *.smc, *.sfc, *.iso", "All Files (*.*)"}); delegate.onSelectedFile(openDialog.open()); }
Example 15
Source File: RTFCleanerDialog.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * 处理 RTF 文件 ; */ private void handleFile() { FileDialog dialog = new FileDialog(getShell(), SWT.MULTI); dialog.setText(Messages.getString("dialog.RTFCleanerDialog.dialogTitle")); String[] extensions = { "*.rtf", "*" }; String[] filters = { Messages.getString("dialog.RTFCleanerDialog.filters1"), Messages.getString("dialog.RTFCleanerDialog.filters2") }; dialog.setFilterExtensions(extensions); dialog.setFilterNames(filters); dialog.setFilterPath(System.getProperty("user.home")); dialog.open(); String[] arrSource = dialog.getFileNames(); if (arrSource == null || arrSource.length == 0) { return; } int errors = 0; for (int i = 0; i < arrSource.length; i++) { File f = new File(dialog.getFilterPath() + System.getProperty("file.separator") + arrSource[i]); //$NON-NLS-1$ Hashtable<String, String> params = new Hashtable<String, String>(); params.put("source", f.getAbsolutePath()); //$NON-NLS-1$ params.put("output", f.getAbsolutePath()); //$NON-NLS-1$ Vector<String> result = RTFCleaner.run(params); if (!"0".equals(result.get(0))) { //$NON-NLS-1$ String msg = MessageFormat.format(Messages.getString("dialog.RTFCleanerDialog.msg1"), arrSource[i]) + (String) result.get(1); MessageDialog.openInformation(getShell(), Messages.getString("dialog.RTFCleanerDialog.msgTitle"), msg); errors++; } } if (errors < arrSource.length) { MessageDialog.openInformation(getShell(), Messages.getString("dialog.RTFCleanerDialog.msgTitle"), Messages.getString("dialog.RTFCleanerDialog.msg2")); } }
Example 16
Source File: SimpleToolBarEx.java From SWET with MIT License | 5 votes |
private void saveWorkspace(Shell shell) { FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterNames(new String[] { "YAML Files", "All Files (*.*)" }); dialog.setFilterExtensions(new String[] { "*.yaml", "*.*" }); String homeDir = System.getProperty("user.home"); dialog.setFilterPath(homeDir); // Windows path String path = null; if (configFilePath != null) { dialog.setFileName(configFilePath); path = new String(configFilePath); } // configFilePath = dialog.open(); if (configFilePath != null) { System.out.println("Save to: " + configFilePath); if (config == null) { config = new Configuration(); } logger.info("Saving unordered test data"); config.setElements(testData); // Save unordered, order by step index when generating script, drawing // buttons etc. logger.info("Save configuration YAML in " + configFilePath); YamlHelper.saveConfiguration(config, configFilePath); } else { logger.warn("Save dialog returns no path info."); if (path != null) { configFilePath = new String(path); } } }
Example 17
Source File: ExportAsHtmlHandler.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { String elementName = event.getParameter("elementName"); IEditorPart activeEditor = HandlerUtil.getActiveEditor(event); Shell shell = activeEditor.getEditorSite().getShell(); if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) { return null; } XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor; if (xliffEditor.isMultiFile()) { MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。"); } IEditorInput input = xliffEditor.getEditorInput(); URI uri = null; if (input instanceof FileEditorInput) { uri = ((FileEditorInput) input).getURI(); } else if (input instanceof FileStoreEditorInput) { uri = ((FileStoreEditorInput) input).getURI(); } else { return null; } File xliff = new File(uri); FileDialog fd = new FileDialog(shell, SWT.SAVE); String[] names = { "HTML Files [*.html]", "All Files [*.*]" }; String[] extensions = { "*.html", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$ fd.setFilterExtensions(extensions); fd.setFilterNames(names); fd.setFileName(xliff.getName() + ".html"); //$NON-NLS-1$ String out = fd.open(); if (out == null) { return null; } XLFHandler handler = xliffEditor.getXLFHandler(); boolean result = handler.saveAsHtml(xliff.getAbsolutePath(), out, elementName); if (result) { IWorkbenchPage page = xliffEditor.getEditorSite().getPage(); OpenEditorUtil.OpenFileWithSystemEditor(page, out); } else { MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。"); } return null; }
Example 18
Source File: FileListEditor.java From ermasterr with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override protected String getNewInputObject() { final FileDialog dialog = new FileDialog(getShell()); if (lastPath != null) { if (new File(lastPath).exists()) { dialog.setFilterPath(lastPath); } } final String[] filterExtensions = new String[] {extention}; dialog.setFilterExtensions(filterExtensions); final String filePath = dialog.open(); if (filePath != null) { final File file = new File(filePath); final String fileName = file.getName(); if (contains(fileName)) { final MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_WARNING | SWT.OK | SWT.CANCEL); messageBox.setText(ResourceString.getResourceString("dialog.title.warning")); messageBox.setMessage(ResourceString.getResourceString("dialog.message.update.file")); if (messageBox.open() == SWT.CANCEL) { return null; } namePathMap.put(fileName, filePath); return null; } namePathMap.put(fileName, filePath); try { lastPath = file.getParentFile().getCanonicalPath(); } catch (final IOException e) {} return fileName; } return null; }
Example 19
Source File: UserLibraryPreferencePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private CPListElement[] doOpenExternalJarFileDialog(CPListElement existing, Object parent) { String lastUsedPath; if (existing != null) { lastUsedPath= existing.getPath().removeLastSegments(1).toOSString(); } else { lastUsedPath= fDialogSettings.get(IUIConstants.DIALOGSTORE_LASTEXTJAR); if (lastUsedPath == null) { lastUsedPath= ""; //$NON-NLS-1$ } } String title= (existing == null) ? PreferencesMessages.UserLibraryPreferencePage_browsejar_new_title : PreferencesMessages.UserLibraryPreferencePage_browsejar_edit_title; FileDialog dialog= new FileDialog(getShell(), existing == null ? SWT.MULTI : SWT.SINGLE); dialog.setText(title); dialog.setFilterExtensions(ArchiveFileFilter.ALL_ARCHIVES_FILTER_EXTENSIONS); dialog.setFilterPath(lastUsedPath); if (existing != null) { dialog.setFileName(existing.getPath().lastSegment()); } String res= dialog.open(); if (res == null) { return null; } String[] fileNames= dialog.getFileNames(); int nChosen= fileNames.length; IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); IPath filterPath= Path.fromOSString(dialog.getFilterPath()); CPListElement[] elems= new CPListElement[nChosen]; for (int i= 0; i < nChosen; i++) { IPath path= filterPath.append(fileNames[i]).makeAbsolute(); IFile file= root.getFileForLocation(path); // support internal JARs: bug 133191 if (file != null) { path= file.getFullPath(); } CPListElement curr= new CPListElement(parent, null, IClasspathEntry.CPE_LIBRARY, path, file); curr.setAttribute(CPListElement.SOURCEATTACHMENT, BuildPathSupport.guessSourceAttachment(curr)); curr.setAttribute(CPListElement.JAVADOC, BuildPathSupport.guessJavadocLocation(curr)); elems[i]= curr; } fDialogSettings.put(IUIConstants.DIALOGSTORE_LASTEXTJAR, dialog.getFilterPath()); return elems; }
Example 20
Source File: CompositeBrowseForFile.java From CogniCrypt with Eclipse Public License 2.0 | 3 votes |
/** * Open the file dialog and return the file path as a string. * * @param fileTypes * @param stringOnFileDialog * @return The path selected */ private String openFileDialog(final String[] fileTypes, final String stringOnFileDialog) { final FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); fileDialog.setFilterExtensions(fileTypes); fileDialog.setText(stringOnFileDialog); return fileDialog.open(); }