public void save_Event() { FileDialog fd = new FileDialog(ZestDebuggerView.this.getSite().getShell(), SWT.SAVE); fd.setText("Save"); fd.setFilterPath("C:/"); String[] filterExt = {"*.jpg"}; fd.setFilterExtensions(filterExt); String selected = fd.open(); System.out.println(selected); if (selected != null) { GC gc = new GC(viewer.getControl()); org.eclipse.swt.graphics.Rectangle bounds = viewer.getControl().getBounds(); Image image = new Image(viewer.getControl().getDisplay(), bounds); try { gc.copyArea(image, 0, 0); ImageLoader imageLoader = new ImageLoader(); imageLoader.data = new ImageData[] {image.getImageData()}; imageLoader.save(selected, SWT.IMAGE_JPEG); MessageDialog.openInformation( ZestDebuggerView.this.getSite().getShell(), "Success", "The image has been saved successfully"); } catch (Exception e) { e.printStackTrace(); MessageDialog.openError( ZestDebuggerView.this.getSite().getShell(), "Failure", "The image can't be saved"); } finally { image.dispose(); gc.dispose(); } } }
public OutputStream getOutputStream(Shell shell) { FileDialog dialog = new FileDialog(shell, SWT.SAVE); String filterPath; String relativeFileName; int lastIndexOfFileSeparator = defaultFileName.lastIndexOf(File.separator); if (lastIndexOfFileSeparator >= 0) { filterPath = defaultFileName.substring(0, lastIndexOfFileSeparator); relativeFileName = defaultFileName.substring(lastIndexOfFileSeparator + 1); } else { filterPath = "/"; // $NON-NLS-1$ relativeFileName = defaultFileName; } dialog.setFilterPath(filterPath); dialog.setOverwrite(true); dialog.setFileName(relativeFileName); dialog.setFilterNames(defaultFilterNames); dialog.setFilterExtensions(defaultFilterExtensions); String fileName = dialog.open(); if (fileName == null) { return null; } try { return new PrintStream(fileName); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } }
public void run(IAction action) { FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.SAVE); fileDialog.setFilterPath(fileDirectory); fileDialog.setFilterNames(filterName); fileDialog.setFilterExtensions(filterExtension); if (action.isChecked()) { String filename = fileDialog.open(); // check if file Exists. Gaelle 16/03/2009 if (filename != null && recordInThisFile(filename)) { FableJep.record(true); try { FableJep.getFableJep().setScriptFileName(filename); } catch (Throwable e) { e.printStackTrace(); } // action.setText("Stop Recording Script"); action.setToolTipText("Stop recording python actions."); } else { action.setChecked(false); FableJep.record(false); // action.setText("Record Script"); action.setToolTipText("Record python actions in a script."); } } else { FableJep.record(false); // action.setText("Record Script"); action.setToolTipText("Record python actions in a script."); } }
public void selectOutputFile() { FileDialog dlg = new FileDialog(getParentShell(), SWT.SAVE); ArrayList<String> extensionList = new ArrayList<String>(); if (chosenOutputFormat != null && chosenOutputFormat.getFileSuffix() != null) { extensionList.add("*." + chosenOutputFormat.getFileSuffix()); // $NON-NLS-1$ } extensionList.add("*.*"); // $NON-NLS-1$ dlg.setFilterExtensions(extensionList.toArray(new String[extensionList.size()])); dlg.setFileName(getDefaultOutputFilename()); dlg.setOverwrite(true); String path; if (isFilePath()) { path = getOldFolderPath(); } else { path = defaultFolder; } if (LOG.isDebugEnabled()) { LOG.debug("File dialog path set to: " + path); // $NON-NLS-1$ } dlg.setFilterPath(path); String fn = dlg.open(); if (fn != null) { textFile.setText(fn); getButton(IDialogConstants.OK_ID).setEnabled(true); } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); View view = (View) page.findView(View.ID); view.getViewer().refresh(); // open dialog to get path FileDialog filedlg = new FileDialog(window.getShell(), SWT.SAVE); filedlg.setText("Create Sequence Diagram File"); filedlg.setFilterPath("SystemRoot"); filedlg.setFilterExtensions(new String[] {"di"}); String selected = filedlg.open(); // create & initial the sequence diagram MyCreater myCreater = new MyCreater(); myCreater.init(window.getWorkbench(), new StructuredSelection()); // fixed bug IFile iFile = myCreater.create(selected); // create the model SequenceDiagram sdDiagram = new SequenceDiagram(); sdDiagram.setiFile(iFile); sdDiagram.setFilePath( new Path(selected).removeFileExtension().addFileExtension("uml").toOSString()); ModelManager.getInstance().AddModel(sdDiagram); // open the editor myCreater.open(iFile); // refresh the model viewer view.getViewer().refresh(); return null; }
/** Export the selected values from the table to a csv file */ private void export() { FileDialog dialog = new FileDialog(shell, SWT.SAVE); String[] filterNames = new String[] {"CSV Files", "All Files (*)"}; String[] filterExtensions = new String[] {"*.csv;", "*"}; String filterPath = "/"; String platform = SWT.getPlatform(); if (platform.equals("win32") || platform.equals("wpf")) { filterNames = new String[] {"CSV Files", "All Files (*.*)"}; filterExtensions = new String[] {"*.csv", "*.*"}; filterPath = "c:\\"; } dialog.setFilterNames(filterNames); dialog.setFilterExtensions(filterExtensions); dialog.setFilterPath(filterPath); try { dialog.setFileName(this.getCurrentKey() + ".csv"); } catch (Exception e) { dialog.setFileName("export.csv"); } String fileName = dialog.open(); FileOutputStream fos; OutputStreamWriter out; try { fos = new FileOutputStream(fileName); out = new OutputStreamWriter(fos, "UTF-8"); } catch (Exception e) { MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); messageBox.setMessage("Error creating export file " + fileName + " : " + e.getMessage()); messageBox.open(); return; } Vector<TableItem> sel = new Vector<TableItem>(this.dataTable.getSelection().length); sel.addAll(Arrays.asList(this.dataTable.getSelection())); Collections.reverse(sel); for (TableItem item : sel) { String date = item.getText(0); String value = item.getText(1); try { out.write(date + ";" + value + "\n"); } catch (IOException e) { continue; } } try { out.close(); fos.close(); } catch (IOException e) { MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); messageBox.setMessage("Error writing export file " + fileName + " : " + e.getMessage()); messageBox.open(); e.printStackTrace(); } }
private void handleTruststoreBrowse() { FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); fileDialog.setFilterPath(getTruststore()); final String filepath = fileDialog.open(); if (filepath != null) { txtTruststore.setText(filepath); dialogChanged(); } }
private void browseButtonSelected(String title, Text text) { FileDialog dialog = new FileDialog(getShell(), SWT.NONE); dialog.setText(title); String str = text.getText().trim(); int lastSeparatorIndex = str.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) dialog.setFilterPath(str.substring(0, lastSeparatorIndex)); str = dialog.open(); if (str != null) text.setText(str); }
/** * Opens a modal dialogue to select a file from the file system. If the file selection is * cancelled, null is returned. * * @return the file, or null at dialogue cancel */ protected File openFileSelectionDialogue() { FileDialog fd = new FileDialog(btnDatei.getShell(), SWT.OPEN); fd.setText(Messages.TranspTextWizardPage_windowsfiledialogtitle); fd.setFilterPath(null); String[] filterExt = {"*.*"}; // $NON-NLS-1$ fd.setFilterExtensions(filterExt); String selected = fd.open(); if (selected == null) return null; return new File(selected); }
public void saveRWorkspace() { String selected = null; Shell s = new Shell(); FileDialog fd = new FileDialog(s, SWT.SAVE); fd.setText("Save"); if (ApplicationWorkbenchWindowAdvisor.getOS().equals("Windows")) { prefs = Preferences.userNodeForPackage(this.getClass()); String lastOutputDir = prefs.get("R_FILE_DIR", ""); fd.setFilterPath(lastOutputDir); String[] filterExt = {"*.RData"}; fd.setFilterExtensions(filterExt); fd.setOverwrite(true); selected = fd.open(); prefs.put("R_FILE_DIR", fd.getFilterPath()); if (selected != null) { selected = selected.replace("\\", "\\\\"); selected = selected.replace("ä", "ae"); selected = selected.replace("ü", "ue"); selected = selected.replace("ö", "oe"); saveRData(selected); } } else { prefs = Preferences.userNodeForPackage(this.getClass()); String lastOutputDir = prefs.get("R_FILE_DIR", ""); fd.setFilterPath(lastOutputDir); String[] filterExt = {"*.RData"}; fd.setFilterExtensions(filterExt); fd.setOverwrite(true); selected = fd.open(); prefs.put("R_FILE_DIR", fd.getFilterPath()); if (selected != null) { saveRData(selected); } } }
private void selectFile() { FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); fileDialog.setText("Select JSHint library file"); File file = new File(preferences.getCustomLibPath()); fileDialog.setFileName(file.getName()); fileDialog.setFilterPath(file.getParent()); fileDialog.setFilterNames(new String[] {"JavaScript files"}); fileDialog.setFilterExtensions(new String[] {"*.js", ""}); String selectedPath = fileDialog.open(); if (selectedPath != null) { customLibPathText.setText(selectedPath); } }
/** Override this to plugin custom OutputStream. */ protected OutputStream getOutputStream(ExportToExcelCommand command) throws IOException { FileDialog dialog = new FileDialog(command.getShell(), SWT.SAVE); dialog.setFilterPath("/"); dialog.setOverwrite(true); dialog.setFileName("table_export.xls"); dialog.setFilterExtensions(new String[] {"Microsoft Office Excel Workbook(.xls)"}); String fileName = dialog.open(); if (fileName == null) { return null; } return new PrintStream(fileName); }
private File getFilePath(File startingDirectory) { FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN | SWT.SHEET); if (startingDirectory != null) { fileDialog.setFilterPath(startingDirectory.getPath()); } String filePath = fileDialog.open(); if (filePath != null) { filePath = filePath.trim(); if (filePath.length() > 0) { return new File(filePath); } } return null; }
@Override protected void buttonPressed(int buttonId) { if (buttonId == 1) { FileDialog dialog = new FileDialog(this.getShell(), SWT.OPEN); dialog.setText(GprofLaunchMessages.GprofNoGmonDialog_OpenGmon); if (project != null) { dialog.setFilterPath(project.getLocation().toOSString()); } String s = dialog.open(); if (s != null) { gmonPath = s; } } else if (buttonId == 2) { ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider()); dialog.setTitle(GprofLaunchMessages.GprofNoGmonDialog_OpenGmon); dialog.setMessage(GprofLaunchMessages.GprofNoGmonDialog_OpenGmon); dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); dialog.setAllowMultiple(false); dialog.setInitialSelection(project); dialog.setValidator( new ISelectionStatusValidator() { @Override public IStatus validate(Object[] selection) { if (selection.length != 1) { return new Status(IStatus.ERROR, GprofLaunch.PLUGIN_ID, 0, "", null); // $NON-NLS-1$ } if (!(selection[0] instanceof IFile)) { return new Status(IStatus.ERROR, GprofLaunch.PLUGIN_ID, 0, "", null); // $NON-NLS-1$ } return new Status(IStatus.OK, GprofLaunch.PLUGIN_ID, 0, "", null); // $NON-NLS-1$ } }); if (dialog.open() == IDialogConstants.OK_ID) { IResource resource = (IResource) dialog.getFirstResult(); gmonPath = resource.getLocation().toOSString(); } } if (gmonPath == null) { setReturnCode(0); } else { setReturnCode(buttonId); } close(); }
@Override public void run() { final FileDialog fileChooser = new FileDialog(imageCanvas.getShell(), SWT.SAVE); fileChooser.setText("Save .dot file"); fileChooser.setFilterPath(""); fileChooser.setFilterExtensions(new String[] {"*.dot"}); fileChooser.setFilterNames(new String[] {"Graphviz file " + " (dot)"}); final String filename = fileChooser.open(); if (filename != null) { try { FileUtils.copyFile(dotFile, new File(filename)); } catch (final IOException e) { MessageDialog.openError(imageCanvas.getShell(), "Saving error", e.getMessage()); } } }
private String buildFileDialog() { // file field FileDialog fd = new FileDialog(parentShell, SWT.SAVE); fd.setText("Open"); fd.setFilterPath("C:/"); String[] filterExt = {"*.xml", "*.csv", "*.*"}; fd.setFilterExtensions(filterExt); String selected = fd.open(); if (!(fd.getFileName()).equalsIgnoreCase("")) { return fd.getFilterPath() + System.getProperty("file.separator") + fd.getFileName(); } else { return ""; } }
private ArrayList<String> promptJarFiles() { String projectPath = this.getJavaProject().getProject().getLocation().toString(); FileDialog dialog = new FileDialog(getShell(), SWT.MULTI); dialog.setText(JptDbwsEclipseLinkUiMessages.JDBC_DRIVER_WIZARD_PAGE__CHOOSE_A_DRIVER_FILE); dialog.setFilterPath(projectPath); dialog.setFilterExtensions(new String[] {BINDINGS_FILE_FILTER}); dialog.open(); String path = dialog.getFilterPath(); String[] fileNames = dialog.getFileNames(); ArrayList<String> results = new ArrayList<String>(fileNames.length); for (String fileName : fileNames) { results.add(path + File.separator + fileName); } return results; }
public void open() { qprint.verbose("Open pressed"); Shell shell = new Shell(); FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Open"); if (null == workspace) { qprint.error("workspace not defined"); return; } fd.setFilterPath(workspace); String[] filterExt = {"*.txt", "*.log", "*"}; fd.setFilterExtensions(filterExt); String selected = fd.open(); qprint.verbose(selected); // add file to editor }
@Deprecated public void selectTemplateFile() { FileDialog dlg = new FileDialog(getParentShell(), SWT.OPEN); String path; if (defaultTemplateFolder != null && !defaultTemplateFolder.isEmpty()) { path = defaultTemplateFolder; } else if (isTemplateFilePath()) { path = getOldTemplateFolderPath(); } else { path = System.getProperty("user.home"); // $NON-NLS-1$ } if (LOG.isDebugEnabled()) { LOG.debug("Template file dialog path set to: " + path); // $NON-NLS-1$ } dlg.setFilterPath(path); dlg.setFilterExtensions( new String[] { "*.rptdesign", "*.rpt", "*.xml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ dlg.open(); }
protected String getNewInputObject() { FileDialog dialog = new FileDialog(getShell()); if (lastPath != null) { if (new File(lastPath).exists()) dialog.setFilterPath(lastPath); } dialog.setFilterExtensions(new String[] {"*.jar"}); String file = dialog.open(); if (file != null) { file = file.trim(); if (file.length() == 0) return null; lastPath = file; } return file; }
public OpenFile2( Shell shell, String programTitle, CTabFolder tabFolder, CommandCenter commandCenter, Display display) throws Exception { FileDialog fd = new FileDialog(shell, SWT.OPEN); fd.setText("Open"); fd.setFilterPath("./input/"); String[] filterExt = {"*.txt", "*.doc", "*.rtf", "*.*"}; fd.setFilterExtensions(filterExt); String selected = fd.open(); if (selected != null) { String fileName = selected; shell.setText(programTitle + " - " + fileName); ReadFile readFile = new ReadFile(fileName); MSA structure = new MSA(fileName); structure = readFile.getStructure(); System.out.println(structure.getName()); for (CTabItem tabItem : tabFolder.getItems()) { if (tabItem.getText().equals(structure.getName())) { throw new SameObjectException(); } } Worksheet worksheet = new Worksheet(structure, tabFolder, commandCenter, shell, display); tabFolder.setSelection(worksheet); } else { System.out.println("Open File canceled by ESC key"); } }
private void saveImportOrder(List elements) { IDialogSettings dialogSettings = JavaScriptPlugin.getDefault().getDialogSettings(); FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); dialog.setText(PreferencesMessages.ImportOrganizeConfigurationBlock_saveDialog_title); dialog.setFilterExtensions(new String[] {"*.importorder", "*.*"}); // $NON-NLS-1$ //$NON-NLS-2$ dialog.setFileName("example.importorder"); // $NON-NLS-1$ String lastPath = dialogSettings.get(DIALOGSETTING_LASTSAVEPATH); if (lastPath != null) { dialog.setFilterPath(lastPath); } String fileName = dialog.open(); if (fileName != null) { dialogSettings.put(DIALOGSETTING_LASTSAVEPATH, dialog.getFilterPath()); Properties properties = new Properties(); for (int i = 0; i < elements.size(); i++) { ImportOrderEntry entry = (ImportOrderEntry) elements.get(i); properties.setProperty(String.valueOf(i), entry.serialize()); } FileOutputStream fos = null; try { fos = new FileOutputStream(fileName); properties.store(fos, "Organize Import Order"); // $NON-NLS-1$ } catch (IOException e) { JavaScriptPlugin.log(e); String title = PreferencesMessages.ImportOrganizeConfigurationBlock_saveDialog_error_title; String message = PreferencesMessages.ImportOrganizeConfigurationBlock_saveDialog_error_message; MessageDialog.openError(getShell(), title, message); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } }
private List loadImportOrder() { IDialogSettings dialogSettings = JavaScriptPlugin.getDefault().getDialogSettings(); FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); dialog.setText(PreferencesMessages.ImportOrganizeConfigurationBlock_loadDialog_title); dialog.setFilterExtensions(new String[] {"*.importorder", "*.*"}); // $NON-NLS-1$ //$NON-NLS-2$ String lastPath = dialogSettings.get(DIALOGSETTING_LASTLOADPATH); if (lastPath != null) { dialog.setFilterPath(lastPath); } String fileName = dialog.open(); if (fileName != null) { dialogSettings.put(DIALOGSETTING_LASTLOADPATH, dialog.getFilterPath()); Properties properties = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(fileName); properties.load(fis); List res = loadFromProperties(properties); if (res != null) { return res; } } catch (IOException e) { JavaScriptPlugin.log(e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { } } } String title = PreferencesMessages.ImportOrganizeConfigurationBlock_loadDialog_error_title; String message = PreferencesMessages.ImportOrganizeConfigurationBlock_loadDialog_error_message; MessageDialog.openError(getShell(), title, message); } return null; }
private void handleCellData(final Object cellData) { if (cellData instanceof SqlJetMemoryPointer) { // save as file final Shell shell = new Shell(Display.getDefault()); final FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterNames(new String[] {"All Files (*.*)"}); dialog.setFilterExtensions(new String[] {"*.*"}); // Windows dialog.setFilterPath(System.getProperty("user.home")); final String fileName = dialog.open(); if (fileName != null) { final SqlJetMemoryPointer p = (SqlJetMemoryPointer) cellData; final int count = p.remaining(); RandomAccessFile file = null; try { file = new RandomAccessFile(fileName, "rw"); p.writeToFile(file, 0, count); file.close(); } catch (final IOException e) { e.printStackTrace(); } finally { if (file != null) { try { file.close(); } catch (final IOException e) { } } } } } else if (cellData != null) { // copy clipboard final Clipboard cb = new Clipboard(Display.getDefault()); final TextTransfer textTransfer = TextTransfer.getInstance(); cb.setContents(new Object[] {cellData.toString()}, new Transfer[] {textTransfer}); } }
protected void handleDestinationBrowseButtonPressed() { String idealSuffix; FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE); if (isAddMavenScript()) { idealSuffix = OUTPUT_FILE_SUFFIX; } else { idealSuffix = getOutputSuffix(); } dialog.setFilterExtensions(new String[] {'*' + idealSuffix, "*.*"}); // $NON-NLS-1$ File destination = new File(getDestinationValue()); dialog.setFileName(destination.getName()); dialog.setFilterPath(destination.getParent()); String selectedFileName = dialog.open(); if (selectedFileName == null) { return; } if (!selectedFileName.endsWith(idealSuffix)) { selectedFileName += idealSuffix; } checkDestination(selectedFileName); destinationValue = selectedFileName; }
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); if (window == null) { FableUtils.errMsg(this, "Cannot determine the workbench window"); return null; } FileDialog dlg = new FileDialog(window.getShell(), SWT.MULTI); // add directories initialDirData = SampleNavigatorView.getInitialDirectory(); dlg.setFilterPath(initialDirData); String selectedDirectory = dlg.open(); String files[] = dlg.getFileNames(); if (selectedDirectory != null && files != null) { SampleNavigatorView.view.addFiles(files, initialDirData); // listOfSamples // instantiated } return null; }
private void init() throws IOException { FileDialog fd = new FileDialog(GUI.getShell(), SWT.SAVE); fd.setText("Ausgabedatei wählen."); String path = settings.getString("lastdir", System.getProperty("user.home")); if (path != null && path.length() > 0) { fd.setFilterPath(path); } fd.setFileName( new Dateiname( "kontoauszug", "", Einstellungen.getEinstellung().getDateinamenmuster(), "PDF") .get()); fd.setFilterExtensions(new String[] {"*.PDF"}); String s = fd.open(); if (s == null || s.length() == 0) { return; } if (!s.endsWith(".PDF")) { s = s + ".PDF"; } file = new File(s); settings.setAttribute("lastdir", file.getParent()); }
/* * (non-Javadoc) * * @see * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands * .ExecutionEvent) */ @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWindow != null) { FileDialog dlg = new FileDialog(Display.getDefault().getActiveShell(), SWT.MULTI); String initialDirData = SampleNavigatorView.getInitialDirectory(); dlg.setFilterPath(initialDirData); String selectedDirectory = dlg.open(); if (selectedDirectory != null) { int index = selectedDirectory.lastIndexOf(System.getProperty("file.separator")); if (index > 0) { selectedDirectory = selectedDirectory.substring(0, index); } String files[] = dlg.getFileNames(); if (selectedDirectory != null && files != null) { try { activeWindow.getWorkbench().showPerspective(Perspective.ID, activeWindow); SampleNavigatorView sampleView = (SampleNavigatorView) PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .findView(SampleNavigatorView.ID); sampleView.addFiles(files, selectedDirectory); } catch (WorkbenchException ex) { FableUtils.excMsg(this, "ImageViewer cannot be opened", ex); } } } } // Must currently be null return null; }
/** {@inheritDoc} */ @Override protected void openDialog(final Shell parentShell, final String dialogTitle) { if (_onlyWorkSpace) { // sds resource dialog can only handle sds files if (sdsFileResourceOnly()) { SdsResourceSelectionDialog rsd = new SdsResourceSelectionDialog(parentShell); // rsd.setSelectedResource(_path); if (rsd.open() == Window.OK) { if (rsd.getSelectedPath() != null) { _path = rsd.getSelectedPath(); } } } else { ResourceSelectionDialog rsd = new ResourceSelectionDialog(parentShell, "Select a resource", _fileExtensions); rsd.setSelectedResource(_path); if (rsd.open() == Window.OK) { if (rsd.getSelectedResource() != null) { _path = rsd.getSelectedResource(); } } } } else { FileDialog dialog = new FileDialog(parentShell, SWT.OPEN | SWT.MULTI); dialog.setText(dialogTitle); if (_path != null) { _filterPath = _path.toString(); } dialog.setFilterPath(_filterPath); dialog.setFilterExtensions(_fileExtensions); dialog.open(); String name = dialog.getFileName(); _filterPath = dialog.getFilterPath(); _path = new Path(_filterPath + Path.SEPARATOR + name); } }
private String getFilePathByFileDialog(String modelElementName) { FileDialog dialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE); dialog.setFilterNames(FILTER_NAMES); dialog.setFilterExtensions(FILTER_EXTS); String initialPath = PreferenceHelper.getPreference(EXPORT_MODEL_PATH, System.getProperty("user.home")); dialog.setFilterPath(initialPath); dialog.setOverwrite(true); try { // String initialFileName = projectSpace.getProjectName() + "@" // + projectSpace.getBaseVersion().getIdentifier() + ".ucp"; String initialFileName = "ModelElement_" + modelElementName + "." + FILE_EXTENSION; dialog.setFileName(initialFileName); } catch (NullPointerException e) { // do nothing } String filePath = dialog.open(); return filePath; }