Java Code Examples for org.eclipse.swt.SWT#SAVE
The following examples show how to use
org.eclipse.swt.SWT#SAVE .
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: ExportImageAction.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override public void run(IAction action) { FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); dialog.setFileName("Cloud.png"); dialog.setText("Export PNG image to..."); String destFile = dialog.open(); if (destFile == null) return; File f = new File(destFile); if (f.exists()) { boolean confirmed = MessageDialog.openConfirm(getShell(), "File already exists", "The file '" + f.getName() + "' does already exist. Do you want to override it?"); if (!confirmed) return; } ImageLoader il = new ImageLoader(); try { il.data = new ImageData[] { getViewer().getCloud().getImageData() }; il.save(destFile, SWT.IMAGE_PNG); } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: ExportProjectWizardPage.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * Open an appropriate destination browser so that the user can specify a source to import from */ protected void handleDestinationBrowseButtonPressed() { FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE | SWT.SHEET); dialog.setFilterExtensions(new String[] { "*.hszip", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ dialog.setText(DataTransferMessages.ArchiveExport_selectDestinationTitle); String currentSourceString = getDestinationValue(); int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) { dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex)); } String selectedFileName = dialog.open(); if (selectedFileName != null) { setErrorMessage(null); setDestinationValue(selectedFileName); if (getWhiteCheckedResources().size() > 0) { setDescription(null); } } }
Example 3
Source File: PearFileResourceExportPage.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Opens a file selection dialog to select a pear file as export location and sets the chosen * value to the input field. */ protected void handleDestinationBrowseButtonPressed() { final FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE); dialog.setFilterExtensions(new String[] { "*.pear", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ dialog.setText(PearExportMessages.getString("PearExport.selectDestinationTitle")); //$NON-NLS-1$ final String destination = getDestinationValue(); final int lastDirectoryIndex = destination.lastIndexOf(File.separator); if (lastDirectoryIndex != -1) { dialog.setFilterPath(destination.substring(0, lastDirectoryIndex)); } final String selectedFileName = dialog.open(); if (selectedFileName != null) { fDestinationFileInput.setText(selectedFileName); saveDestinationValue(selectedFileName); } }
Example 4
Source File: ChartComposite.java From openstock 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 5
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 6
Source File: FixedFatJarExportPage.java From sarl with Apache License 2.0 | 5 votes |
/** * Open an appropriate ant script browser so that the user can specify a source * to import from */ private void handleAntScriptBrowseButtonPressed() { FileDialog dialog= new FileDialog(getContainer().getShell(), SWT.SAVE); dialog.setFilterExtensions(new String[] { "*." + ANTSCRIPT_EXTENSION }); //$NON-NLS-1$ String currentSourceString= getAntScriptValue(); int lastSeparatorIndex= currentSourceString.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) { dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex)); dialog.setFileName(currentSourceString.substring(lastSeparatorIndex + 1, currentSourceString.length())); } String selectedFileName= dialog.open(); if (selectedFileName != null) fAntScriptNamesCombo.setText(selectedFileName); }
Example 7
Source File: WebSearchPreferencePage.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void exportConfig() { FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); dialog.setFileName("Web_Config.xml"); dialog.open(); String filterPath = dialog.getFilterPath(); if (null == filterPath || filterPath.isEmpty()) { return; } File file = new File(filterPath + File.separator + dialog.getFileName()); boolean config = true; if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); logger.error("", e); } } else { config = MessageDialog.openConfirm(getShell(), Messages.getString("Websearch.WebSearcPreferencePage.tipTitle"), Messages.getString("Websearch.WebSearcPreferencePage.ConfirmInfo")); } if (config) { boolean exportSearchConfig = WebSearchPreferencStore.getIns().exportSearchConfig(file.getAbsolutePath()); if (exportSearchConfig) { MessageDialog.openInformation(getShell(), Messages.getString("Websearch.WebSearcPreferencePage.tipTitle"), Messages.getString("Websearch.WebSearcPreferencePage.exportFinish")); } else { MessageDialog.openInformation(getShell(), Messages.getString("Websearch.WebSearcPreferencePage.tipTitle"), Messages.getString("Websearch.WebSearcPreferencePage.failexport")); } } }
Example 8
Source File: FileChooser.java From mappwidget with Apache License 2.0 | 5 votes |
public String saveFile() { FileDialog dlg = new FileDialog(button.getShell(), SWT.SAVE); dlg.setFileName(text.getText()); dlg.setText(OK); String path = dlg.open(); return path; }
Example 9
Source File: NewTmxFileDialog.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private void browseTmxLc() { FileDialog dlg = new FileDialog(getShell(), SWT.SAVE); String[] filterExt = { "*.tmx", "*.*" }; dlg.setFilterExtensions(filterExt); String filePath = dlg.open(); if (filePath != null) { locationTxt.setText(filePath); } }
Example 10
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 11
Source File: SaveBTAsAction.java From jbt with Apache License 2.0 | 5 votes |
/** * * @see org.eclipse.jface.action.Action#run() */ public void run() { FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(), SWT.SAVE); dialog.setOverwrite(true); dialog.setFilterExtensions(Extensions.getFiltersFromExtensions(Extensions .getBTFileExtensions())); dialog.setText("Save BT as"); dialog.setFileName(this.initialFileName); String fileName = dialog.open(); if (fileName != null) { List<BTEditor> editors = Utilities.getBTEditors(); for (BTEditor editor : editors) { BTEditorInput editorInput = (BTEditorInput) editor.getEditorInput(); if (editorInput.isFromFile() && editorInput.getTreeName().equals(fileName)) { throw new RuntimeException( "There is a behaviour tree already open with the same name (" + fileName + "). Close it first."); } } String targetFileName = Extensions.joinFileNameAndExtension(fileName, Extensions.getBTFileExtensions()[dialog.getFilterIndex()]); new SaveBTAction(this.tree, targetFileName).run(); this.selectedFile = targetFileName; } }
Example 12
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 13
Source File: IncomingFileTransferHandler.java From saros with GNU General Public License v2.0 | 5 votes |
private void handleRequest(XMPPFileTransferRequest request) { String filename = request.getFileName(); long fileSize = request.getFileSize(); if (!MessageDialog.openQuestion( SWTUtils.getShell(), "File Transfer Request", request.getContact().getDisplayableName() + " wants to send a file." + "\nName: " + filename + "\nSize: " + CoreUtils.formatByte(fileSize) + (fileSize < 1000 ? "yte" : "") + "\n\nAccept the file?")) { request.reject(); return; } FileDialog fd = new FileDialog(SWTUtils.getShell(), SWT.SAVE); fd.setText(Messages.SendFileAction_filedialog_text); fd.setOverwrite(true); fd.setFileName(filename); String destination = fd.open(); if (destination == null) { request.reject(); return; } File file = new File(destination); if (file.isDirectory()) { request.reject(); return; } Job job = new IncomingFileTransferJob(request, file); job.setUser(true); job.schedule(); }
Example 14
Source File: SaveConsoleSessionAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override public void run() { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); FileDialog dialog = new FileDialog(window.getShell(), SWT.SAVE); String file = dialog.open(); if (file != null) { FileUtils.writeStrToFile(console.getSession().toString(), file); } }
Example 15
Source File: TypeChecking.java From JDeodorant with MIT License | 5 votes |
private void saveResults() { FileDialog fd = new FileDialog(getSite().getWorkbenchWindow().getShell(), SWT.SAVE); fd.setText("Save Results"); String[] filterExt = { "*.txt" }; fd.setFilterExtensions(filterExt); String selected = fd.open(); if(selected != null) { try { BufferedWriter out = new BufferedWriter(new FileWriter(selected)); Tree tree = treeViewer.getTree(); /*TableColumn[] columns = table.getColumns(); for(int i=0; i<columns.length; i++) { if(i == columns.length-1) out.write(columns[i].getText()); else out.write(columns[i].getText() + "\t"); } out.newLine();*/ for(int i=0; i<tree.getItemCount(); i++) { TreeItem treeItem = tree.getItem(i); TypeCheckEliminationGroup group = (TypeCheckEliminationGroup)treeItem.getData(); for(TypeCheckElimination candidate : group.getCandidates()) { out.write(candidate.toString()); out.newLine(); } } out.close(); } catch (IOException e) { e.printStackTrace(); } } }
Example 16
Source File: MainWindow.java From ProtocolAnalyzer with GNU General Public License v3.0 | 5 votes |
public void saveDataAs() { FileDialog save = new FileDialog(m_Shell, SWT.SAVE); save.setFilterExtensions(extensions); String fileName = save.open(); if (fileName != null) { m_FileName = fileName; } else return; saveData(); }
Example 17
Source File: ExportAsBPMNHandler.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Execute public void export(Shell shell, BonitaToBPMNExporter transformer, IWorkbenchPage activePage, IProgressService progressService, ExceptionDialogHandler exceptionDialogHandler, RepositoryAccessor repositoryAccessor) { ProcessDiagramEditor editor = (ProcessDiagramEditor) activePage.getActiveEditor(); MainProcess diagram = (MainProcess) editor.getDiagramEditPart().resolveSemanticElement(); FileDialog fileDialog = new FileDialog(shell, SWT.SAVE); fileDialog.setFilterExtensions(new String[] { "*.bpmn" }); fileDialog.setFileName(String.format("%s - %s.bpmn", diagram.getName(), diagram.getVersion())); Optional.ofNullable(fileDialog.open()) .ifPresent(targetPath -> { final File destFile = new File(targetPath); boolean overwrite = destFile.exists() && MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.overwriteBPMNFile_title, Messages.bind(Messages.overwriteBPMNFile_message, destFile.getName())); if (!destFile.exists() || overwrite) { try { progressService.run(true, false, monitor -> { monitor.beginTask(Messages.exportingTo + " " + destFile.getName() + "...", IProgressMonitor.UNKNOWN); DiagramRepositoryStore diagramRepoStore = repositoryAccessor .getRepositoryStore(DiagramRepositoryStore.class); ConnectorDefRepositoryStore connectorDefRepoStore = repositoryAccessor .getRepositoryStore(ConnectorDefRepositoryStore.class); IModelSearch modelSearch = new ModelSearch( () -> diagramRepoStore.getAllProcesses(), () -> connectorDefRepoStore.getDefinitions()); transformer.export( new BonitaModelExporterImpl(diagram.eResource(), modelSearch), modelSearch, destFile); }); MultiStatus status = transformer.getStatus(); if (status.getSeverity() < IStatus.ERROR) { new MultiStatusDialog(shell, Messages.exportSuccessfulTitle, Messages.exportSuccessfulMessage, MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, status).open(); } else { new MultiStatusDialog(shell, Messages.exportFailedTitle, Messages.exportFailedMessage, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, status).open(); } } catch (InvocationTargetException | InterruptedException e) { exceptionDialogHandler.openErrorDialog(shell, Messages.exportFailedMessage, e); } } }); }
Example 18
Source File: BuildProcessContributionItem.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
private Optional<String> getPath(Shell shell) { final DirectoryDialog directoryDialog = new DirectoryDialog(shell, SWT.SAVE | SWT.SHEET); directoryDialog.setMessage(Messages.selectDestinationTitle); return Optional.ofNullable(directoryDialog.open()); }
Example 19
Source File: DialogExportAsCppAction.java From jbt with Apache License 2.0 | 4 votes |
/** * * @see org.eclipse.jface.action.Action#run() */ public void run() { BTEditor myEditor = Utilities.getActiveBTEditor(); if (myEditor==null || !myEditor.checkTree()) { StandardDialogs.errorDialog("Tree not saved", "Errors were detected while validating the tree"); } else { /* * Open dialog for asking the user to enter some file names. */ FileDialog dialog = new FileDialog(this.window.getShell(), SWT.SAVE); String[] individualFilters = Extensions.getFiltersFromExtensions(Extensions.getInlFileExtensions()); String[] unifiedFilter = new String[] { Extensions.getUnifiedFilterFromExtensions(Extensions.getInlFileExtensions()) }; String[] filtersToUse = Extensions.joinArrays(individualFilters, unifiedFilter); dialog.setFilterExtensions(filtersToUse); dialog.setText("Export BT to an inline file"); String fileName = dialog.open(); if (fileName != null) { List<BTEditor> editors = Utilities.getBTEditors(); for (BTEditor editor : editors) { BTEditorInput editorInput = (BTEditorInput) editor.getEditorInput(); if (editorInput.isFromFile() && editorInput.getTreeName().equals(fileName)) { throw new RuntimeException( "There is a behaviour tree already open with the same name (" + fileName + "). Close it first."); } } String targetFileName = Extensions.joinFileNameAndExtension(fileName, Extensions.getInlFileExtensions()[dialog.getFilterIndex()]); BT tree = Utilities.getActiveBTEditor().getBT(); new ExportToCppAction(tree, targetFileName).run(); } } }
Example 20
Source File: AbstractExportAction.java From ermaster-b with Apache License 2.0 | 3 votes |
protected String getSaveDirPath(IEditorPart editorPart, GraphicalViewer viewer) { IFile file = ((IFileEditorInput) editorPart.getEditorInput()).getFile(); DirectoryDialog directoryDialog = new DirectoryDialog(editorPart .getEditorSite().getShell(), SWT.SAVE); IProject project = file.getProject(); directoryDialog.setFilterPath(project.getLocation().toString()); return directoryDialog.open(); }