Java Code Examples for org.eclipse.swt.widgets.FileDialog.setOverwrite()

The following are Jave code examples for showing how to use setOverwrite() of the org.eclipse.swt.widgets.FileDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: neoscada   File: FileSelectionPage.java   View Source Code Vote up 7 votes
protected void updateFile ()
{
    final FileDialog dlg = new FileDialog ( getShell (), SWT.APPLICATION_MODAL | SWT.SAVE );

    dlg.setFilterExtensions ( new String[] { Messages.FileSelectionPage_FilterExtension } );
    dlg.setFilterNames ( new String[] { Messages.FileSelectionPage_FilterName } );
    dlg.setOverwrite ( true );
    dlg.setText ( Messages.FileSelectionPage_FileDialog_Text );

    final String fileName = dlg.open ();
    if ( fileName == null )
    {
        setFile ( null );
        update ();
    }
    else
    {
        setFile ( new File ( fileName ) );
        update ();
    }
}
 
Example 2
Project: TranskribusSwtGui   File: DialogUtil.java   View Source Code Vote up 6 votes
public static ArrayList<String> showOpenFilesDialog(Shell shell, String title, String filterPath, String[] exts) {
	FileDialog fd = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
	fd.setOverwrite(true); // prompt user if file exists!
	fd.setText(title);
	if (filterPath == null)
		filterPath = System.getProperty("user.dir");
	fd.setFilterPath(filterPath);
	if (exts == null)
		exts = new String[]{"*.*"};
	fd.setFilterExtensions(exts);
	
	ArrayList<String> files = new ArrayList<String>();
    if (fd.open() != null) {
      String[] names = fd.getFileNames();
      for (int i = 0, n = names.length; i < n; i++) {
        StringBuffer buf = new StringBuffer(fd.getFilterPath());
        if (buf.charAt(buf.length() - 1) != File.separatorChar)
          buf.append(File.separatorChar);
        buf.append(names[i]);
        files.add(buf.toString());
      }
    }
    System.out.println(files);

	return files;
}
 
Example 3
Project: EarthquakeBulletin   File: MapCanvas.java   View Source Code Vote up 6 votes
private void saveImage() {
	if (canSaveImage()) {
		final FileDialog saveDialog = new FileDialog(canvas.getShell(), SWT.SAVE);
		saveDialog.setFilterExtensions(new String[] { "*.JPG;*.jpg" });
		saveDialog.setFileName(guid.toLowerCase() + ".jpg");
		saveDialog.setOverwrite(true);
		final String fileName = saveDialog.open();
		if (fileName != null && fileName.trim().isEmpty()) {
			try {
				Files.write(Paths.get(fileName), cache.get(guid).getBytes());
			}
			catch (final Exception e) {
				final String message = Messages.get("err.image.save", fileName);
				logger.log(Level.WARNING, message, e);
				EnhancedErrorDialog.openError(canvas.getShell(), Messages.get("lbl.window.title"), message, IStatus.WARNING, e, Images.getMainIcons());
			}
		}
	}
}
 
Example 4
Project: scouter   File: ObjectClassListView.java   View Source Code Vote up 6 votes
public void saveClassFile(String className, final BlobValue bv) {
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()	.getShell();
	FileDialog dialog = new FileDialog(shell, SWT.SAVE);
	dialog.setOverwrite(true);
	dialog.setFileName(className + ".class");
	dialog.setFilterExtensions(new String[] { "*.class", "*.*" });
	dialog.setFilterNames(new String[] { "Class File(*.class)", "All Files" });
	final String fileSelected = dialog.open();
	if (fileSelected != null) {
		ExUtil.asyncRun("Decompile-" + className + TimeUtil.getCurrentTime(serverId), new Runnable() {
			public void run() {
				FileUtil.save(fileSelected, bv.value);
				ConsoleProxy.infoSafe(fileSelected + " saved.");
			}
		});
	}
}
 
Example 5
Project: brainfuck   File: BfMainPreferencePage.java   View Source Code Vote up 6 votes
@Override
public void widgetSelected(SelectionEvent e) {
	Shell parentShell = e.display.getActiveShell();
	FileDialog fd = new FileDialog(parentShell, SWT.SAVE);
	fd.setFilterExtensions(new String[]{"*.jar", "*.*"});
	fd.setFilterIndex(0);
	fd.setFileName("BrainfuckInterpreter.jar");
	fd.setOverwrite(true);
	String selectedFile = fd.open();
	if (selectedFile == null) {
		return;
	}
	java.nio.file.Path savePath = Paths.get(selectedFile);
	try {
		InputStream jarStream = FileLocator.openStream(BfActivator.getDefault().getBundle(), new Path("/lib/interpreter.jar"), false);
		Files.copy(jarStream, savePath, StandardCopyOption.REPLACE_EXISTING);
		jarStream.close();
		MessageDialog.openInformation(parentShell, "Saved", "'" + savePath.getFileName() + "' saved successfully");
	} 
	catch (IOException ex) {
		BfActivator.getDefault().logError("Interpreter Jar File could not be saved", ex);
		MessageDialog.openError(parentShell, "File not saved", "Error on saving '" + selectedFile + "'");
	}
}
 
Example 6
Project: n4js   File: ExternalLibraryPreferencePage.java   View Source Code Vote up 5 votes
/**
 * Creates new dialog for target platform export,
 */
private void handleExportButtonSelection(@SuppressWarnings("unused") final SelectionEvent event) {
	final FileDialog dialog = new FileDialog(getShell(), SAVE);
	dialog.setFilterExtensions(new String[] { TP_FILTER_EXTENSION });
	dialog.setFileName(TargetPlatformModel.TP_FILE_NAME);
	dialog.setText("Export N4JS Target Platform");
	dialog.setOverwrite(true);
	final String value = dialog.open();
	if (!isNullOrEmpty(value)) {
		exportTargetPlatform(new File(value));
	}
}
 
Example 7
Project: Hydrograph   File: GenericImportExportFileDialog.java   View Source Code Vote up 5 votes
/**
 * GenericExportFileDialog Constructor.
 * 
 * @param Shell
 */
public GenericImportExportFileDialog(Shell shell, int style) {
	genericImportExportFileDialog = new FileDialog(shell, style);
	genericImportExportFileDialog.setText(title);
	genericImportExportFileDialog.setOverwrite(true); // Dialog will prompt to user if
											// fileName used for saving
											// already exists.
	genericImportExportFileDialog.setFileName(fileName == null ? defaultFileName : fileName);
	genericImportExportFileDialog
			.setFilterExtensions(getFilterExtensions() == null ? defaultFilterExtentions : getFilterExtensions());
	genericImportExportFileDialog.setFilterNames(getFilterNames() == null ? defaultFilterNames : getFilterNames());
}
 
Example 8
Project: Hydrograph   File: GenericExportFileDialog.java   View Source Code Vote up 5 votes
/**
 * GenericExportFileDialog Constructor.
 * 
 * @param Shell
 */
public GenericExportFileDialog(Shell shell) {
	exportFileDialog = new FileDialog(shell, SWT.SAVE);
	exportFileDialog.setText(title);
	exportFileDialog.setOverwrite(true); // Dialog will prompt to user if
											// fileName used for saving
											// already exists.
	exportFileDialog.setFileName(fileName == null ? defaultFileName : fileName);
	exportFileDialog
			.setFilterExtensions(getFilterExtensions() == null ? defaultFilterExtentions : getFilterExtensions());
	exportFileDialog.setFilterNames(getFilterNames() == null ? defaultFilterNames : getFilterNames());
}
 
Example 9
Project: Hydrograph   File: ExportAction.java   View Source Code Vote up 5 votes
private String getPathOfFileDialog(FileDialog fileDialog) {
	fileDialog.setText(EXPORT_FILE);
	String exportDataDefaultpath = readExportDataDefaultPathFromFile();
	if (StringUtils.isBlank(exportDataDefaultpath)) {
		fileDialog.setFilterPath(null);
	} else {
		fileDialog.setFilterPath(exportDataDefaultpath);
	}
	fileDialog.setFileName(DEFAILT_FILE_NAME);
	fileDialog.setOverwrite(true);
	String filePath = fileDialog.open();
	return filePath;
}
 
Example 10
Project: bdf2   File: ExportToImageAction.java   View Source Code Vote up 5 votes
public void run() {
	FileDialog dialog = new FileDialog(getWorkbenchPart().getSite().getShell(), SWT.SAVE);
	dialog.setFilterExtensions(EXTENSIONS);
	dialog.setText(getText());
	dialog.setOverwrite(true);
	dialog.setFileName("NewFile");
	final String savePath = dialog.open();
	if (savePath != null) {
		final int type = dialog.getFilterIndex();
		final DbToolGefEditor editor = (DbToolGefEditor) getWorkbenchPart().getAdapter(GraphicalEditor.class);
		doRun(editor, savePath, type);
	}

}
 
Example 11
Project: DB-HUD-Maker   File: HUD_Maker.java   View Source Code Vote up 5 votes
public void widgetSelected(SelectionEvent event) {
FileDialog fd = new FileDialog(s, SWT.SAVE);
fd.setText("Save Preset");
fd.setFilterPath("C:/");
fd.setFileName("ShooterUI");
fd.setOverwrite(true);
String[] fileExt = {"*.ini"};
fd.setFilterExtensions(fileExt);
selection = fd.open();
System.out.println(selection);
}
 
Example 12
Project: TranskribusSwtGui   File: DialogUtil.java   View Source Code Vote up 5 votes
public static String showSaveDialog(Shell shell, String title, String filterPath, String[] exts) {
	FileDialog fd = new FileDialog(shell, SWT.SAVE);
	fd.setOverwrite(true); // prompt user if file exists!
	fd.setText(title);
	if (filterPath == null)
		filterPath = System.getProperty("user.dir");
	fd.setFilterPath(filterPath);
	if (exts == null)
		exts = new String[]{"*.*"};
	fd.setFilterExtensions(exts);
	String selected = fd.open();
	return selected;
}
 
Example 13
Project: TranskribusSwtGui   File: DialogUtil.java   View Source Code Vote up 5 votes
public static String showOpenFileDialog(Shell shell, String title, String filterPath, String[] exts) {
	FileDialog fd = new FileDialog(shell, SWT.OPEN);
	fd.setOverwrite(true); // prompt user if file exists!
	fd.setText(title);
	if (filterPath == null)
		filterPath = System.getProperty("user.dir");
	fd.setFilterPath(filterPath);
	if (exts == null)
		exts = new String[]{"*.*"};
	fd.setFilterExtensions(exts);
	String selected = fd.open();
	return selected;
}
 
Example 14
Project: EarthquakeBulletin   File: BulletinExporter.java   View Source Code Vote up 5 votes
private static String openSaveDialog(final Shell shell) {
	final FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
	saveDialog.setFilterExtensions(CSV_FILE_EXTENSIONS);
	saveDialog.setFileName("earthquakebulletin_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + ".csv");
	saveDialog.setOverwrite(true);
	return saveDialog.open();
}
 
Example 15
Project: eavp   File: FXGeometryCanvas.java   View Source Code Vote up 5 votes
@Override
public void exportImage() {

	// Take a snapshot of the current scene
	WritableImage screenshot = viewer.getCanvas().getScene().snapshot(null);

	// Make the array of strings needed to pass to the file dialog.
	String[] extensionStrings = new String[] { ".png" };

	// Create the file save dialog.
	FileDialog fileDialog = new FileDialog(
			Display.getCurrent().getActiveShell(), SWT.SAVE);
	fileDialog.setFilterExtensions(extensionStrings);
	fileDialog.setOverwrite(true);

	// Open the dialog and, if the user inputs a path, write the image to
	// the file
	String path = fileDialog.open();
	if (path != null) {
		File file = new File(path);
		try {
			ImageIO.write(SwingFXUtils.fromFXImage(screenshot, null), "png",
					file);
		} catch (IOException e) {
			logger.error(
					"JavaFX Geometry Canvas encountered an error while "
							+ "attempting to write screenshot to file.");
		}
	}

}
 
Example 16
Project: scouter   File: ObjectDumpFileDetailView.java   View Source Code Vote up 5 votes
private void saveAs() {
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
			.getShell();
	FileDialog dialog = new FileDialog(shell, SWT.SAVE);
	dialog.setOverwrite(true);
	dialog.setFileName(filename);
	dialog.setFilterExtensions(new String[] { "*.txt", "*.*" });
	dialog.setFilterNames(new String[] { "Text File(*.txt)", "All Files" });
	String fileSelected = dialog.open();
	if (fileSelected != null) {
		FileUtil.save(fileSelected, text.getText().getBytes());
	}
}
 
Example 17
Project: scouter   File: ResourceUtils.java   View Source Code Vote up 5 votes
static public String openFileSaveDialog(String [] names, String [] extensions, String path, String defaultName){
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
	FileDialog dialog = new FileDialog(shell, SWT.SAVE);
	dialog.setOverwrite(true);
	dialog.setFilterNames(names);
	dialog.setFilterExtensions(extensions);
	dialog.setFilterPath(path);
	if(defaultName != null){
		dialog.setFileName(defaultName);
	}
	return dialog.open();		
}
 
Example 18
Project: HMM   File: SaveHandler.java   View Source Code Vote up 5 votes
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorInput editorInput = HandlerUtil.getActiveEditorInput(event);
	if(editorInput instanceof AutomationEditorInput) {
		AutomationEditorInput input = (AutomationEditorInput) editorInput;
		Shell shell = HandlerUtil.getActiveShell(event);
		FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
		fileDialog.setText("Save to File");
		fileDialog.setFileName(input.getName());
		fileDialog.setFilterExtensions(new String[] {"*.xml", "*.*"});
		fileDialog.setOverwrite(true);
		String filePath = fileDialog.open();
		if(filePath == null)
			return null;
		File file = new File(filePath);
		try {
			if(file.exists()) {
				if(file.delete() == false)
					throw new IOException("cannot overwrite file: " + file.getPath());
			}
			if(false == file.createNewFile())
				throw new IOException("cannot overwrite file: " + file.getPath());
		} catch (IOException e) {
			e.printStackTrace();
			new ShowMessageUtil().showNormalError(e.getMessage());
			return null;
		}
		new TreeModelXmlUtil().saveToXml(input.getRootModel(), file);
	}
	return null;
}
 
Example 19
Project: JFaceUtils   File: SystemInformationDialog.java   View Source Code Vote up 5 votes
protected String openSaveDialog(final Shell parent) {
	final FileDialog saveDialog = new FileDialog(parent, SWT.SAVE);
	saveDialog.setFilterExtensions(new String[] { "*.TXT;*.txt" });
	saveDialog.setFileName("sysinfo.txt");
	saveDialog.setOverwrite(true);
	return saveDialog.open();
}
 
Example 20
Project: neoscada   File: ChartActionBarContributor.java   View Source Code Vote up 4 votes
@Override
public void run ()
{
    if ( this.chart == null )
    {
        return;
    }

    final Shell shell = PlatformUI.getWorkbench ().getActiveWorkbenchWindow ().getShell ();

    final FileDialog dlg = new FileDialog ( shell, SWT.SAVE );
    dlg.setFilterExtensions ( new String[] { "*.chart" } );
    dlg.setFilterNames ( new String[] { "Eclipse SCADA Chart Configuration" } );
    dlg.setOverwrite ( true );
    dlg.setText ( "Select the file to store the chart configurationt to" );

    final String file = dlg.open ();

    if ( file != null )
    {
        new Job ( "Perform save" ) {
            @Override
            protected org.eclipse.core.runtime.IStatus run ( final org.eclipse.core.runtime.IProgressMonitor monitor )
            {
                try
                {
                    doSave ( file );
                }
                catch ( final IOException e )
                {
                    return StatusHelper.convertStatus ( Activator.PLUGIN_ID, e );
                }
                finally
                {
                    monitor.done ();
                }
                return Status.OK_STATUS;
            };
        }.schedule ();
    }
}
 
Example 21
Project: scouter   File: ExportWorkspaceAction.java   View Source Code Vote up 4 votes
public void run() {
	if (window != null) {
		String message = "It may be lost that you make change in this session.\n"
				+ "If you want to export all settings made in this session,\n"
				+ "please restart and try again.\n"
				+ "Or if you didn't make any change in this session, just try it";
		if(!MessageDialog.openConfirm(window.getShell(), "Confirm", message)) {
			return;
		}

		FileDialog dialog = new FileDialog(window.getShell(), SWT.SAVE);

		dialog.setFilterNames(new String[] { "scouter export zip files", "zip Files (*.zip)" });
		dialog.setFilterExtensions(new String[] { "*.zip", "*.*" });
		//dialog.setFilterPath("c:\\");
		dialog.setFileName("scouter-client-export-workspace.zip");
		dialog.setOverwrite(true);
		
		String exportFileName = dialog.open();
		
		if(StringUtil.isEmpty(exportFileName)) {
			return;
		}
		
		String workspaceRootName = Platform.getInstanceLocation().getURL().getFile();
		String exportWorkingDirName = workspaceRootName + "/export-working";

		new Thread(() -> {
			ClientFileUtil.deleteDirectory(new File(exportWorkingDirName));
			FileUtil.mkdirs(exportWorkingDirName);

			try {
				ClientFileUtil.copy(new File(workspaceRootName + "/" + ClientFileUtil.XLOG_COLUMN_FILE),
						new File(exportWorkingDirName + "/" + ClientFileUtil.XLOG_COLUMN_FILE));
				ClientFileUtil.copy(new File(workspaceRootName + "/" + ClientFileUtil.GROUP_FILE),
						new File(exportWorkingDirName + "/" + ClientFileUtil.GROUP_FILE));
				ClientFileUtil.copy(new File(workspaceRootName + "/" + ClientFileUtil.WORKSPACE_METADATA_DIR),
						new File(exportWorkingDirName + "/" + ClientFileUtil.WORKSPACE_METADATA_DIR));
				ClientFileUtil.deleteFile(new File(exportWorkingDirName + "/" + ClientFileUtil.WORKSPACE_LOG_FILE));
			} catch (IOException e) {
				e.printStackTrace();
			}

			try {
				ZipUtil.compress(exportWorkingDirName, exportFileName);
				ClientFileUtil.deleteDirectory(new File(exportWorkingDirName));
			} catch (Throwable throwable) {
				throwable.printStackTrace();
			}
		}).start();
	}
}
 
Example 22
Project: SPELL   File: ExportText.java   View Source Code Vote up 4 votes
/***************************************************************************
 * The command has been executed, so extract extract the needed information
 * from the application context.
 **************************************************************************/
public CommandResult execute(ExecutionEvent event)
        throws ExecutionException
{
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	IRuntimeSettings runtime = (IRuntimeSettings) ServiceManager.get(IRuntimeSettings.class);
	String instanceId = (String) runtime.getRuntimeProperty(RuntimeProperty.ID_PROCEDURE_SELECTION);

	try
	{
		IProcedureManager mgr = (IProcedureManager) ServiceManager.get(IProcedureManager.class);
		IProcedure proc = null;
		if (mgr.isLocallyLoaded(instanceId))
		{
			proc = mgr.getProcedure(instanceId);
		}
		else
		{
			proc = mgr.getRemoteProcedure(instanceId);
		}
		FileDialog dialog = new FileDialog(window.getShell(), SWT.SAVE );
		dialog.setText("Export text view file of '" + proc.getProcName() + "'");
		dialog.setOverwrite(true);
		String proposedFilename = proc.getProcId().replaceAll("/", "__")
		                          + ".txt";
		
		dialog.setFileName( proposedFilename );
		String destination = dialog.open();
		if (destination != null && !destination.isEmpty())
		{
			ExportTextJob job = new ExportTextJob( proc, destination );
			CommandHelper.executeInProgress(job, true, true);
			return job.result;
		}
		else
		{
			return CommandResult.NO_EFFECT;
		}
	}
	catch(Exception ex)
	{
		ex.printStackTrace();
		return CommandResult.FAILED;
	}
}
 
Example 23
Project: SPELL   File: ExportLogFile.java   View Source Code Vote up 4 votes
/***************************************************************************
 * The command has been executed, so extract extract the needed information
 * from the application context.
 **************************************************************************/
public CommandResult execute(ExecutionEvent event)
        throws ExecutionException
{
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	IRuntimeSettings runtime = (IRuntimeSettings) ServiceManager.get(IRuntimeSettings.class);
	String instanceId = (String) runtime.getRuntimeProperty(RuntimeProperty.ID_PROCEDURE_SELECTION);

	try
	{
		IProcedureManager mgr = (IProcedureManager) ServiceManager.get(IProcedureManager.class);
		IProcedure proc = null;
		if (mgr.isLocallyLoaded(instanceId))
		{
			proc = mgr.getProcedure(instanceId);
		}
		else
		{
			proc = mgr.getRemoteProcedure(instanceId);
		}
		FileDialog dialog = new FileDialog(window.getShell(), SWT.SAVE );
		dialog.setText("Export log file of '" + proc.getProcName() + "'");
		dialog.setOverwrite(true);
		dialog.setFileName( proc.getProcId() + ".log" );
		String destination = dialog.open();
		if (destination != null && !destination.isEmpty())
		{
			ExportLogFileJob job = new ExportLogFileJob( proc, destination );
			CommandHelper.executeInProgress(job, true, true);
			return job.result;
		}
		else
		{
			return CommandResult.NO_EFFECT;
		}
	}
	catch(Exception ex)
	{
		ex.printStackTrace();
		return CommandResult.FAILED;
	}
}