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

The following are Jave code examples for showing how to use setFileName() 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: pmTrans   File: PmTrans.java   View Source Code Vote up 7 votes
protected void importText() {
	if (!textEditor.isDisposed()) {
		FileDialog fd = new FileDialog(shell, SWT.OPEN);
		fd.setText("Open");
		String[] filterExt = { "*.txt;*.TXT" };
		String[] filterNames = { "TXT files" };
		fd.setFilterExtensions(filterExt);
		fd.setFilterNames(filterNames);
		String lastPath = Config.getInstance().getString(Config.LAST_OPEN_TEXT_PATH);
		if (lastPath != null && !lastPath.isEmpty())
			fd.setFileName(lastPath);
		String selected = fd.open();
		if (selected != null) {
			importTextFile(new File(selected));
			Config.getInstance().putValue(Config.LAST_OPEN_TEXT_PATH, selected);
			try {
				Config.getInstance().save();
			} catch (IOException e) {
				// The user do not NEED to know about this...
			}
		}
	}
}
 
Example 2
Project: pmTrans   File: PmTrans.java   View Source Code Vote up 6 votes
protected void openNewAudio() {
	FileDialog fd = new FileDialog(shell, SWT.OPEN);
	fd.setText("Select the audio file");
	String[] filterExt = { "*.wav;*.WAV;*.mp3;*.MP3", "*.*" };
	String[] filterNames = { "WAV and MP3 files", "All files" };
	fd.setFilterExtensions(filterExt);
	fd.setFilterNames(filterNames);
	String lastPath = Config.getInstance().getString(Config.LAST_OPEN_AUDIO_PATH);
	if (lastPath != null && lastPath.isEmpty())
		fd.setFileName(lastPath);
	String selected = fd.open();
	if (selected != null) {
		closePlayer();
		openAudioFile(new File(selected));
		Config.getInstance().putValue(Config.LAST_OPEN_AUDIO_PATH, selected);
		try {
			Config.getInstance().save();
		} catch (IOException e) {
			// The user do not NEED to know about this...
		}
	}
}
 
Example 3
Project: pmTrans   File: PmTrans.java   View Source Code Vote up 6 votes
public void openTranscription() {
	if (!textEditor.isDisposed()) {
		FileDialog fd = new FileDialog(shell, SWT.OPEN);
		fd.setText("Select the transcription file");
		String[] filterExt = { "*.xpmt;*.XPMT" };
		String[] filterNames = { "pmTrans transcription files" };
		fd.setFilterExtensions(filterExt);
		fd.setFilterNames(filterNames);
		String lastPath = Config.getInstance().getString(Config.LAST_OPEN_TEXT_PATH);
		if (lastPath != null && !lastPath.isEmpty())
			fd.setFileName(lastPath);
		String selected = fd.open();
		if (selected != null) {
			openTranscriptionFile(new File(selected));
			Config.getInstance().putValue(Config.LAST_OPEN_TEXT_PATH, selected);
			try {
				Config.getInstance().save();
			} catch (IOException e) {
				// The user do not NEED to know about this...
			}
		}
	}
}
 
Example 4
Project: pmTrans   File: PmTrans.java   View Source Code Vote up 6 votes
protected void exportTextFile() {
	boolean done = false;
	while (!done)
		if (!textEditor.isDisposed()) {
			FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
			fd.setFilterNames(new String[] { "Plain text file (*.txt)", "All Files (*.*)" });
			fd.setFilterExtensions(new String[] { "*.txt", "*.*" });
			String lastPath = Config.getInstance().getString(Config.LAST_EXPORT_TRANSCRIPTION_PATH);
			if (lastPath != null && !lastPath.isEmpty())
				fd.setFileName(lastPath);
			String file = fd.open();
			try {
				if (file != null) {
					Config.getInstance().putValue(Config.LAST_EXPORT_TRANSCRIPTION_PATH, file);
					File destFile = new File(file);
					boolean overwrite = true;
					if (destFile.exists())
						overwrite = MessageDialog.openConfirm(shell, "Overwrite current file?",
								"Would you like to overwrite " + destFile.getName() + "?");
					if (overwrite) {
						textEditor.exportText(new File(file));
						done = true;
					}
				} else
					done = true;
			} catch (Exception e) {
				e.printStackTrace();
				MessageBox diag = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
				diag.setMessage("Unable to export to file " + transcriptionFile.getPath());
				diag.open();
			}
		}
}
 
Example 5
Project: neoscada   File: LocalDataPage.java   View Source Code Vote up 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 6
Project: neoscada   File: RemoteDataPage.java   View Source Code Vote up 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 7
Project: neoscada   File: FileNamePage.java   View Source Code Vote up 6 votes
protected void handleSelectFile ()
{
    final FileDialog dlg = new FileDialog ( getShell (), SWT.SAVE );
    dlg.setFilterExtensions ( new String[] { "*.oscar", "*.*" } ); //$NON-NLS-1$ //$NON-NLS-2$ 
    dlg.setFilterNames ( new String[] { Messages.FileNamePage_OSCARFileType, Messages.FileNamePage_AllTypes } );

    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 );
        getWizard ().getDialogSettings ().put ( "fileNamePage.file", file ); //$NON-NLS-1$
    }
}
 
Example 8
Project: AppleCommander   File: DiskExplorerTab.java   View Source Code Vote up 6 votes
/**
 * Handle SaveAs.
 */
protected void saveAs() {
	FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
	fileDialog.setFilterPath(userPreferences.getSaveDirectory());
	fileDialog.setFileName(Host.getFileName(disks[0].getFilename()));
	fileDialog.setText(textBundle.get("SaveDiskImageAsPrompt")); //$NON-NLS-1$
	String fullpath = fileDialog.open();
	userPreferences.setSaveDirectory(fileDialog.getFilterPath());
	if (fullpath == null) {
		return;	// user pressed cancel
	}
	try {
		disks[0].saveAs(fullpath);
		diskWindow.setStandardWindowTitle();
		saveToolItem.setEnabled(disks[0].hasChanged());
	} catch (IOException ex) {
		showSaveError(ex);
	}
}
 
Example 9
Project: applecommander   File: DiskExplorerTab.java   View Source Code Vote up 6 votes
/**
 * Handle SaveAs.
 */
protected void saveAs() {
	FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
	fileDialog.setFilterPath(userPreferences.getSaveDirectory());
	fileDialog.setFileName(Host.getFileName(disks[0].getFilename()));
	fileDialog.setText(textBundle.get("SaveDiskImageAsPrompt")); //$NON-NLS-1$
	String fullpath = fileDialog.open();
	userPreferences.setSaveDirectory(fileDialog.getFilterPath());
	if (fullpath == null) {
		return;	// user pressed cancel
	}
	try {
		disks[0].saveAs(fullpath);
		diskWindow.setStandardWindowTitle();
		saveToolItem.setEnabled(disks[0].hasChanged());
	} catch (IOException ex) {
		showSaveError(ex);
	}
}
 
Example 10
Project: openaudible   File: Application.java   View Source Code Vote up 6 votes
public void exportBookList() {
    try {
        String ext = "*.csv";
        String name = "CSV (Excel) File";
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        dialog.setFilterNames(new String[]{name});
        dialog.setFilterExtensions(new String[]{ext});
        dialog.setFileName("books.csv");
        String path = dialog.open();
        if (path != null) {
            File f = new File(path);
            audibleGUI.audible.export(f);
            if (f.exists())
                logger.info("exported books to: "+f.getAbsolutePath());
        }

    } catch (Exception e) {
        MessageBoxFactory.showError(shell, e.getMessage());
    }

}
 
Example 11
Project: openaudible   File: Application.java   View Source Code Vote up 6 votes
public void exportBookJSON() {
    try {
        String ext = "*.json";
        String name = "JSON File";
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        dialog.setFilterNames(new String[]{name});
        dialog.setFilterExtensions(new String[]{ext});
        dialog.setFileName("books.json");
        String path = dialog.open();
        if (path != null) {
            File f = new File(path);
            audibleGUI.audible.export(f);
            if (f.exists())
                logger.info("exported books to: "+f.getAbsolutePath());
        }

    } catch (Exception e) {
        MessageBoxFactory.showError(shell, e.getMessage());
    }

}
 
Example 12
Project: http4e   File: ExportJMeterAction.java   View Source Code Vote up 6 votes
public void run(){

      try {

         FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);

         fileDialog.setFileName("http4e.jmx");
         fileDialog.setFilterNames(new String[] { "JMeter File *.jmx (Run the script with \"jmeter-t.cmd\")" });
         fileDialog.setFilterExtensions(new String[] { "*.jmx" });
         fileDialog.setText("Save As JMeter script (Run the script with \"jmeter-t.cmd\")");
         fileDialog.setFilterPath(getUserHomeDir());

         String path = fileDialog.open();
         if (path != null) {
            HdViewPart hdView = (HdViewPart) view;
            BaseUtils.writeJMX(path, hdView.getFolderView().getModel());
            updateUserHomeDir(path);
         }

      } catch (Exception e) {
         ExceptionHandler.handle(e);
      }
   }
 
Example 13
Project: http4e   File: ExportHTTP4eAction.java   View Source Code Vote up 6 votes
public void run(){

      try {

         FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.SAVE);

         fileDialog.setFileName("sessions.http4e");
         fileDialog.setFilterNames(new String[] { "HTTP4e File *.http4e (HTTP4e all tab sessions)" });
         fileDialog.setFilterExtensions(new String[] { "*.http4e" });
         fileDialog.setText("Save As HTTP4e replay script");
         fileDialog.setFilterPath(getUserHomeDir());

         String path = fileDialog.open();
         if (path != null) {
            HdViewPart hdView = (HdViewPart) view;
            BaseUtils.writeHttp4eSessions(path, hdView.getFolderView().getModel());
            updateUserHomeDir(path);
         }

      } catch (Exception e) {
         ExceptionHandler.handle(e);
      }
   }
 
Example 14
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 15
Project: erflute   File: MultiFileFieldEditor.java   View Source Code Vote up 6 votes
private File[] getFile(File startingDirectory) {
    int style = SWT.OPEN;
    if (multiple) {
        style |= SWT.MULTI;
    }
    final FileDialog dialog = new FileDialog(getShell(), style);
    if (startingDirectory != null) {
        dialog.setFileName(startingDirectory.getPath());
    }
    if (extensions != null) {
        dialog.setFilterExtensions(extensions);
    }
    dialog.open();
    final String[] fileNames = dialog.getFileNames();
    if (fileNames.length > 0) {
        final 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 16
Project: mytourbook   File: DialogExportTour.java   View Source Code Vote up 6 votes
private void onSelectBrowseFile() {

		final String fileExtension = _exportExtensionPoint.getFileExtension();

		final FileDialog dialog = new FileDialog(_dlgContainer.getShell(), SWT.SAVE);
		dialog.setText(Messages.dialog_export_file_dialog_text);

		dialog.setFilterPath(getExportPathName());
		dialog.setFilterExtensions(new String[] { fileExtension });
		dialog.setFileName("*." + fileExtension);//$NON-NLS-1$

		final String selectedFilePath = dialog.open();

		if (selectedFilePath != null) {
			setErrorMessage(null);
			_comboFile.setText(new Path(selectedFilePath).toFile().getName());
		}
	}
 
Example 17
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 18
Project: SMVHunter   File: BaseFileHandler.java   View Source Code Vote up 6 votes
/**
 * Prompts the user for a save location and copies a temp file into it.
 * <p/>This <strong>must</strong> be called from the UI Thread.
 * @param localFileName The default local name
 * @param tempFilePath The name of the temp file to copy.
 * @param title The title of the File Save dialog.
 * @return true if success, false on error or cancel.
 */
protected boolean promptAndSave(String localFileName, byte[] data, String title) {
    FileDialog fileDialog = new FileDialog(mParentShell, SWT.SAVE);

    fileDialog.setText(title);
    fileDialog.setFileName(localFileName);

    String localFilePath = fileDialog.open();
    if (localFilePath != null) {
        try {
            saveFile(data, new File(localFilePath));
            return true;
        } catch (IOException e) {
            String errorMsg = e.getMessage();
            displayErrorInUiThread(
                    "Failed to save file '%1$s'%2$s",
                    localFilePath,
                    errorMsg != null ? ":\n" + errorMsg : ".");
        }
    }

    return false;
}
 
Example 19
Project: SMVHunter   File: LogCatPanel.java   View Source Code Vote up 6 votes
/**
 * Display a {@link FileDialog} to the user and obtain the location for the log file.
 * @return path to target file, null if user canceled the dialog
 */
private String getLogFileTargetLocation() {
    FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);

    fd.setText("Save Log..");
    fd.setFileName("log.txt");

    if (mLogFileExportFolder == null) {
        mLogFileExportFolder = System.getProperty("user.home");
    }
    fd.setFilterPath(mLogFileExportFolder);

    fd.setFilterNames(new String[] {
            "Text Files (*.txt)"
    });
    fd.setFilterExtensions(new String[] {
            "*.txt"
    });

    String fName = fd.open();
    if (fName != null) {
        mLogFileExportFolder = fd.getFilterPath();  /* save path to restore on future calls */
    }

    return fName;
}
 
Example 20
Project: areca-backup-release-mirror   File: Application.java   View Source Code Vote up 6 votes
public String showFileDialog(String dir, AbstractWindow parent,
		String fileName, String title, int style) {
	FileDialog fileChooser = new FileDialog(parent.getShell(), style);
	if (dir != null) {
		fileChooser.setFilterPath(dir);
	}
	if (title != null) {
		fileChooser.setText(title);
	} else {
		fileChooser.setText(RM.getLabel("common.choosefile.title"));
	}
	if (fileName != null) {
		fileChooser.setFileName(fileName);
	}
	return fileChooser.open();
}
 
Example 21
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 22
Project: PDFReporter-Studio   File: ExportDialog.java   View Source Code Vote up 6 votes
/**
 * Create a file dialog that can handle only xml files
 * 
 * @param shell
 * @return the file or path selected using this dialog
 */
private String selectPathDialog(Shell shell){
	FileDialog dialog = new FileDialog (shell, SWT.SAVE);
	String [] filterNames = new String [] {"XML files"};  //$NON-NLS-1$
	String [] filterExtensions = new String [] {"*.xml;"};  //$NON-NLS-1$
	String filterPath = "/"; //$NON-NLS-1$
	String platform = SWT.getPlatform();
	if (platform.equals("win32") || platform.equals("wpf")) { //$NON-NLS-1$ //$NON-NLS-2$
		filterNames = new String [] {"XML files"};  //$NON-NLS-1$
		filterExtensions = new String [] {"*.xml;"};  //$NON-NLS-1$
		filterPath = "c:\\"; //$NON-NLS-1$
	}
	dialog.setFilterNames (filterNames);
	dialog.setFilterExtensions (filterExtensions);
	dialog.setFilterPath (filterPath);
	dialog.setFileName ("MyTemplates"); //$NON-NLS-1$
	return dialog.open();
}
 
Example 23
Project: PDFReporter-Studio   File: ImportDialog.java   View Source Code Vote up 6 votes
/**
 * Create a file dialog that can handle only xml files
 * 
 * @param shell
 * @return the file or path selected using this dialog
 */
private String selectPathDialog(Shell shell){
	FileDialog dialog = new FileDialog (shell, SWT.OPEN);
	String [] filterNames = new String [] {"XML files"};  //$NON-NLS-1$
	String [] filterExtensions = new String [] {"*.xml;"};  //$NON-NLS-1$
	String filterPath = "/"; //$NON-NLS-1$
	String platform = SWT.getPlatform();
	if (platform.equals("win32") || platform.equals("wpf")) { //$NON-NLS-1$ //$NON-NLS-2$
		filterNames = new String [] {"XML files"};  //$NON-NLS-1$
		filterExtensions = new String [] {"*.xml;"};  //$NON-NLS-1$
		filterPath = "c:\\"; //$NON-NLS-1$
	}
	dialog.setFilterNames (filterNames);
	dialog.setFilterExtensions (filterExtensions);
	dialog.setFilterPath (filterPath);
	dialog.setFileName (""); //$NON-NLS-1$
	return dialog.open();
}
 
Example 24
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 25
Project: eZooKeeper   File: ZnodeModelFileDataEditor.java   View Source Code Vote up 5 votes
private void startImport() {

        FileDialog fileDialog = new FileDialog(getShell());
        fileDialog.setFileName(_ImportText.getText());
        String newPath = fileDialog.open();
        if (newPath != null) {
            _ImportText.setText(newPath);
            setDirtyInternal(true);
        }
    }
 
Example 26
Project: convertigo-eclipse   File: ProjectFileFieldEditor.java   View Source Code Vote up 5 votes
/**
   * Helper to open the file chooser dialog.
   * @param startingDirectory the directory to open the dialog on.
   * @return File The File the user selected or <code>null</code> if they
   * do not.
   */
  private File getFile(File startingDirectory) {

      FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
      dialog.setText("Select a project file");
      dialog.setFilterExtensions(filterExtensions);
      dialog.setFilterNames(filterNames);
      
      if (!getTextControl().getText().equals("")) {
      	dialog.setFilterPath(getTextControl().getText());
      } else {
      	dialog.setFilterPath(Engine.PROJECTS_PATH);
      }

      if (startingDirectory != null) {
	dialog.setFileName(startingDirectory.getPath());
}

      String file = dialog.open();
      if (file != null) {
          file = file.trim();
          if (file.length() > 0) {
		return new File(file);
	}
      }

      return null;
  }
 
Example 27
Project: convertigo-eclipse   File: FileFieldEditor.java   View Source Code Vote up 5 votes
/**
   * Helper to open the file chooser dialog.
   * @param startingDirectory the directory to open the dialog on.
   * @return File The File the user selected or <code>null</code> if they
   * do not.
   */
  private File getFile(File startingDirectory) {

      FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
      dialog.setText("Select a project file");
      dialog.setFilterExtensions(getFilterExtensions());
      dialog.setFilterNames(getFilterNames());
      
      if (!getTextControl().getText().equals("")) {
      	dialog.setFilterPath(getTextControl().getText());
      } else {
      	dialog.setFilterPath(getFilterPath());
      }

      if (startingDirectory != null) {
	dialog.setFileName(startingDirectory.getPath());
}

      String file = dialog.open();
      if (file != null) {
          file = file.trim();
          if (file.length() > 0) {
		return new File(file);
	}
      }

      return null;
  }
 
Example 28
Project: SWET   File: SimpleToolBarEx.java   View Source Code Vote up 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 29
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 30
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 31
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 32
Project: team-explorer-everywhere   File: QuerySaveControl.java   View Source Code Vote up 5 votes
private void browseLocal() {
    final FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);

    dialog.setFilterNames(new String[] {
        Messages.getString("QuerySaveControl.FileDialogWiqFilter") //$NON-NLS-1$
    });
    dialog.setFilterExtensions(new String[] {
        "*.wiq" //$NON-NLS-1$
    });
    dialog.setFilterPath(saveDirectory.getAbsolutePath());
    dialog.setText(Messages.getString("QuerySaveControl.SaveQueryDialogTitle")); //$NON-NLS-1$
    dialog.setFileName(queryName);

    final String path = dialog.open();

    if (path != null) {
        final File file = new File(path);
        saveDirectory = file.getParentFile();

        String name = file.getName();
        if (name.indexOf(".") != -1) //$NON-NLS-1$
        {
            name = name.substring(0, name.lastIndexOf(".")); //$NON-NLS-1$
        }
        queryName = name;
        ignoreQueryNameChanges = true;
        queryNameText.setText(queryName);
        ignoreQueryNameChanges = false;

        setFileLocationText();
    }
}
 
Example 33
Project: team-explorer-everywhere   File: SaveWIQLAction.java   View Source Code Vote up 5 votes
@Override
protected void doRun(final IAction action) {
    final QueryDefinition queryDefinition = (QueryDefinition) selectedQueryItem;
    final StoredQuery query = WorkItemHelpers.createStoredQueryFromDefinition(queryDefinition);

    final FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
    dlg.setFilterNames(new String[] {
        "*.wiq" //$NON-NLS-1$
    });
    dlg.setFilterExtensions(new String[] {
        "*.wiq" //$NON-NLS-1$
    });

    dlg.setText(Messages.getString("SaveWIQLAction.FileDialogTitle")); //$NON-NLS-1$
    dlg.setFileName(query.getName() + ".wiq"); //$NON-NLS-1$

    final String saveFileName = dlg.open();
    if (saveFileName == null) {
        return;
    }

    final String queryText = query.getQueryText();
    final String teamName;
    if (StringUtil.isNullOrEmpty(queryText) || !queryText.contains(WIQLOperators.MACRO_CURRENT_ITERATION)) {
        teamName = null;
    } else {
        teamName = WorkItemHelpers.getCurrentTeamName();
    }

    final WIQDocument wiqDocument = new WIQDocument(
        queryText,
        getContext().getServer().getConnection().getBaseURI().toString(),
        query.getProject().getName(),
        teamName);

    wiqDocument.save(new File(saveFileName));
}
 
Example 34
Project: fluentmark   File: ExportPdfHandler.java   View Source Code Vote up 5 votes
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	FluentMkEditor editor = (FluentMkEditor) HandlerUtil.getActiveEditor(event);
	Shell shell = HandlerUtil.getActiveShell(event);

	IEditorInput input = editor.getEditorInput();
	if (input instanceof IFileEditorInput) {
		IFile file = ((IFileEditorInput) input).getFile();
		IPath path = file.getLocation().removeFileExtension().addFileExtension("pdf");
		String base = path.removeLastSegments(1).toOSString();
		String name = path.lastSegment();

		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
		dialog.setFilterNames(new String[] { "PDF Files", "All Files (*.*)" });
		dialog.setFilterExtensions(new String[] { "*.pdf", "*.*" });
		dialog.setFilterPath(base);
		dialog.setFileName(name);

		String pathname = dialog.open();
		if (pathname != null) {
			PageRoot model = editor.getPageModel(true);
			List<PagePart> parts = model.getPageParts(Kind.CODE_BLOCK);
			String md = editor.getDocument().get();
			PdfGen.save(pathname, parts, new Document(md));
		}
	}
	return null;
}
 
Example 35
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 36
Project: eclemma   File: SessionExportPage1.java   View Source Code Vote up 5 votes
private void openFileDialog() {
  FileDialog fd = new FileDialog(getShell(), SWT.SAVE);
  fd.setText(UIMessages.ExportSessionPage1BrowseDialog_title);
  fd.setFileName(destinationcombo.getText());
  String ext = getExportFormat().getFileExtension();
  fd.setFilterExtensions(new String[] { "*." + ext, "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
  String file = fd.open();
  if (file != null) {
    destinationcombo.setText(file);
  }
}
 
Example 37
Project: eclemma   File: SessionImportPage1.java   View Source Code Vote up 5 votes
private void openBrowseDialog() {
  FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
  fd.setText(ImportSessionPage1BrowseDialog_title);
  fd.setFileName(filecombo.getText());
  fd.setFilterExtensions(new String[] { "*.exec", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
  String file = fd.open();
  if (file != null) {
    filecombo.setText(file);
  }
}
 
Example 38
Project: subclipse   File: SaveImageDialog.java   View Source Code Vote up 5 votes
private void selectFile() {
	String extension;
	if (fileTypeCombo.getText().equals("JPEG")) extension = "jpg";
	else extension = fileTypeCombo.getText().toLowerCase();
	FileDialog d = new FileDialog(getShell(), SWT.PRIMARY_MODAL | SWT.SAVE);
	d.setText("Save Revision Graph As");
	d.setFileName(editor.getEditorInput().getName() + "." + extension);
	String file = d.open();
	if(file!=null) {
		IPath path = new Path(file);
		fileText.setText(path.toOSString());
	}						
}
 
Example 39
Project: http4e   File: ImportLiveHttpHeadersAction.java   View Source Code Vote up 5 votes
public void run(){

      try {

         FileDialog fileDialog = new FileDialog(view.getSite().getShell(), SWT.OPEN);

         fileDialog.setFileName("*.*");
         fileDialog.setFilterNames(new String[] { "Import Firefox LiveHTTP Headers *.*" });
         fileDialog.setFilterExtensions(new String[] { "*.*" });
         fileDialog.setText("Import Firefox LiveHTTP Headers");
         fileDialog.setFilterPath(getUserHomeDir());

         String path = fileDialog.open();
         if (path != null) {
            HdViewPart hdView = (HdViewPart) view;
            List<ItemModel> iteModels = BaseUtils.importLiveHttpHeaders(path, hdView.getFolderView().getModel());
            HdViewPart hdViewPart = (HdViewPart)view;
            for (ItemModel im : iteModels) {
               hdViewPart.getFolderView().buildTab(im);
            }
            
            updateUserHomeDir(path);
         }

      } catch (Exception e) {
         ExceptionHandler.handle(e);
      }
   }
 
Example 40
Project: uml2solidity   File: InstalledSolidityCompilerPreferencePage.java   View Source Code Vote up 5 votes
protected void addCompiler() {
	FileDialog fileDialog = new FileDialog(getShell());
	fileDialog.setFileName("solc");
	fileDialog.setText("select solc ");
	String open = fileDialog.open();

	File file = new File(open);
	SolC testSolCFile = testSolCFile(file);
	if (testSolCFile != null) {
		installedSolCs.add(testSolCFile);
		fCompilerList.setInput(installedSolCs);
	}

}
 
Example 41
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 42
Project: fluentmark   File: ExportHtmlHandler.java   View Source Code Vote up 5 votes
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	FluentMkEditor editor = (FluentMkEditor) HandlerUtil.getActiveEditor(event);
	Shell shell = HandlerUtil.getActiveShell(event);

	IEditorInput input = editor.getEditorInput();
	if (input instanceof IFileEditorInput) {
		IFile file = ((IFileEditorInput) input).getFile();
		IPath path = file.getLocation().removeFileExtension().addFileExtension("html");
		String base = path.removeLastSegments(1).toOSString();
		String name = path.lastSegment();

		FileDialog dialog = new FileDialog(shell, SWT.SAVE);
		dialog.setFilterNames(new String[] { "Html Files", "All Files (*.*)" });
		dialog.setFilterExtensions(new String[] { "*.html", "*.*" });
		dialog.setFilterPath(base);
		dialog.setFileName(name);

		String pathname = dialog.open();
		if (pathname != null) {
			String html = editor.getHtmlGen().getPage(HtmlKind.EXPORT);
			FileUtils.write(new File(pathname), html);
		}

		if (FluentMkUI.getDefault().getPreferenceStore().getBoolean(Prefs.EDITOR_HTML_OPEN)) {
			if (Desktop.isDesktopSupported()) {
				try {
					Desktop.getDesktop().open(new File(pathname));
				} catch (Exception e) {
					String msg = "Cannot open " + pathname + " (" + e.getMessage() + ")";
					return new Status(IStatus.ERROR, FluentMkUI.PLUGIN_ID, msg);
				}
			}
		}
	}

	return null;
}
 
Example 43
Project: ermasterr   File: MultiFileFieldEditor.java   View Source Code Vote up 5 votes
private File[] getFile(final File startingDirectory) {

        int style = SWT.OPEN;
        if (multiple) {
            style |= SWT.MULTI;
        }

        final FileDialog dialog = new FileDialog(getShell(), style);
        if (startingDirectory != null) {
            dialog.setFileName(startingDirectory.getPath());
        }
        if (extensions != null) {
            dialog.setFilterExtensions(extensions);
        }
        dialog.open();
        final String[] fileNames = dialog.getFileNames();

        if (fileNames.length > 0) {
            final 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 44
Project: EclipsePlugins   File: NewProjectMainPage.java   View Source Code Vote up 5 votes
private void browse() {
	FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
	dialog.setText("Pick a World to Simulate");
	dialog.setFileName(worldText.getText());
	dialog.setFilterNames(new String[] { "World Files", "All Files (*.*)" });
    dialog.setFilterExtensions(new String[] { "*.world", "*.*" });
	String result = dialog.open();
	if (result != null) {
		worldText.setText(result);
	}
}
 
Example 45
Project: ermaster-k   File: MultiFileFieldEditor.java   View Source Code Vote up 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 46
Project: agui_eclipse_plugin   File: FJExportWizardConfigPage.java   View Source Code Vote up 5 votes
private void handleExternJarnameBrowse() {
	String filename = getJarname();
	String[] filterExt = { "*.jar" };
	FileDialog fileDialog = new FileDialog(getShell(), SWT.SAVE);
	fileDialog.setFileName(filename);
	fileDialog.setText("Save Output as ...");
	try {
		filename = fileDialog.open();
		if (!filename.toLowerCase().endsWith(".jar"))
			filename += ".jar";
		jarnameText.setText(filename);
	} catch (Exception e) {
	}
}
 
Example 47
Project: limpet   File: RCPContext.java   View Source Code Vote up 5 votes
@Override
public String getCsvFilename()
{
  FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
  final String[] filterNames;
  final String[] filterExtensions;
  String filterPath = "";
  if (SWT.getPlatform().equals("win32"))
  {
    filterNames = new String[]
    {"Csv File", "All Files (*.*)"};
    filterExtensions = new String[]
    {"*.csv", "*.*"};
  }
  else
  {
    filterNames = new String[]
    {"Csv File", "All Files (*)"};
    filterExtensions = new String[]
    {"*.csv", "*"};
  }
  dialog.setFilterNames(filterNames);
  dialog.setFilterExtensions(filterExtensions);
  dialog.setFilterPath(filterPath);
  dialog.setFileName("limpet_out.csv");
  return dialog.open();
}
 
Example 48
Project: SMVHunter   File: BaseFileHandler.java   View Source Code Vote up 5 votes
/**
 * Prompts the user for a save location and pulls the remote files into this location.
 * <p/>This <strong>must</strong> be called from the UI Thread.
 * @param sync the {@link SyncService} to use to pull the file from the device
 * @param localFileName The default local name
 * @param remoteFilePath The name of the file to pull off of the device
 * @param title The title of the File Save dialog.
 * @return The result of the pull as a {@link SyncResult} object, or null if the sync
 * didn't happen (canceled by the user).
 * @throws InvocationTargetException
 * @throws InterruptedException
 * @throws SyncException if an error happens during the push of the package on the device.
 * @throws IOException
 */
protected void promptAndPull(final SyncService sync,
        String localFileName, final String remoteFilePath, String title)
        throws InvocationTargetException, InterruptedException, SyncException, TimeoutException,
        IOException {
    FileDialog fileDialog = new FileDialog(mParentShell, SWT.SAVE);

    fileDialog.setText(title);
    fileDialog.setFileName(localFileName);

    final String localFilePath = fileDialog.open();
    if (localFilePath != null) {
        SyncProgressHelper.run(new SyncRunnable() {
            @Override
            public void run(ISyncProgressMonitor monitor) throws SyncException, IOException,
                    TimeoutException {
                sync.pullFile(remoteFilePath, localFilePath, monitor);
            }

            @Override
            public void close() {
                sync.close();
            }
        },
        String.format("Pulling %1$s from the device", remoteFilePath), mParentShell);
    }
}
 
Example 49
Project: IDM-Enh-Trace   File: AbstractTraceComposite.java   View Source Code Vote up 5 votes
private String getSaveFileName(String paramString) {
	FileDialog localFileDialog = new FileDialog(getShell(), 8192);
	String[] arrayOfString = new String[2];
	arrayOfString[0] = "*.rtf";
	arrayOfString[1] = "*.*";
	String str1 = ".rtf";
	localFileDialog.setFilterExtensions(arrayOfString);
	String str2 = paramString;
	if (-1 == str2.indexOf(str1))
		str2 = str2 + str1;
	localFileDialog.setFileName(str2);
	return localFileDialog.open();
}
 
Example 50
Project: depan   File: NewMavenPomOptionPart.java   View Source Code Vote up 5 votes
/**
 * Open a directory and write the name in the given {@link Text} object.
 */
private void handleBrowse() {
  FileDialog dialog = new FileDialog(containingPage.getShell(), SWT.OPEN);
  dialog.setFilterExtensions(POM_FILTER);
  dialog.setFileName("pom.xml");
  // dialog.setFilterPath();
  pathEntry.setText(dialog.open());
  dialogChanged();
}
 
Example 51
Project: erflute   File: AbstractExportAction.java   View Source Code Vote up 5 votes
protected String getSaveFilePath(IEditorPart editorPart, GraphicalViewer viewer) {
    final IFile file = ((IFileEditorInput) editorPart.getEditorInput()).getFile();
    final FileDialog fileDialog = new FileDialog(editorPart.getEditorSite().getShell(), SWT.SAVE);
    final IProject project = file.getProject();
    fileDialog.setFilterPath(project.getLocation().toString());
    final String[] filterExtensions = getFilterExtensions();
    fileDialog.setFilterExtensions(filterExtensions);
    final String fileName = getDiagramFileName(editorPart, viewer);
    fileDialog.setFileName(fileName);
    return fileDialog.open();
}
 
Example 52
Project: JReFrameworker   File: ExportPayloadDropperPage.java   View Source Code Vote up 5 votes
@Override
public void createControl(Composite parent) {
	
	Composite container = new Composite(parent, SWT.NULL);
	setControl(container);
	container.setLayout(new GridLayout(3, false));
	
	Label dropperJarLabel = new Label(container, SWT.NONE);
	dropperJarLabel.setText("Payload Dropper Jar: ");
	
	dropperJarText = new Text(container, SWT.BORDER);
	dropperJarText.setEditable(false);
	dropperJarText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
	
	final FileDialog fileChooser = new FileDialog(container.getShell(), SWT.SAVE);
	fileChooser.setFilterExtensions(new String[] { "*.jar" });
	fileChooser.setFileName("dropper.jar");

	Button browseButton = new Button(container, SWT.NONE);
	browseButton.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			String path = fileChooser.open();
			if (path != null){
				jarPath = path;
				setPageComplete(true);
			}
			dropperJarText.setText(jarPath);
		}
	});
	browseButton.setText("Browse...");
	
	setPageComplete(false);
}
 
Example 53
Project: n4js   File: ImportButtonListener.java   View Source Code Vote up 4 votes
@Override
public void widgetSelected(final SelectionEvent ignored) {
	final MultiStatus multistatus = statusHelper.createMultiStatus("Status of importing target platform.");
	final FileDialog dialog = new FileDialog(UIUtils.getShell(), OPEN);
	dialog.setFilterExtensions(new String[] { TP_FILTER_EXTENSION });
	dialog.setFileName(TargetPlatformModel.TP_FILE_NAME);
	dialog.setText("Import N4JS Target Platform");
	final String value = dialog.open();
	if (!isNullOrEmpty(value)) {

		final File file = new File(value);
		try {
			if (!file.exists()) {
				multistatus.merge(statusHelper.createError("Error while importing target platform file."));
				return;
			}
			final URI platformFileLocation = file.toURI();
			final Map<String, String> packages = TargetPlatformModel
					.npmVersionedPackageNamesFrom(platformFileLocation);

			if (!packages.isEmpty()) {
				try {
					new ProgressMonitorDialog(UIUtils.getShell()).run(true, false, monitor -> {
						multistatus.merge(installAction.apply(packages, monitor));
					});
				} catch (final InvocationTargetException | InterruptedException exc) {
					multistatus.merge(
							statusHelper.createError("Error while installing npm dependency: '" + packages + "'.",
									exc));
				}
			} else {
				MessageDialog.openInformation(UIUtils.getShell(), "Empty target platform file",
						"Specified target platform file contains no packaged to install.");
			}
		} catch (final IOException e) {
			multistatus.merge(statusHelper.createError("Error while importing target platform file.", e));
		} finally {
			if (!multistatus.isOK()) {
				N4JSActivator.getInstance().getLog().log(multistatus);
				getDisplay().asyncExec(() -> openError(
						UIUtils.getShell(),
						"n4tp Install Failed",
						"Error while installing from '" + value
								+ "' target platform file.\nPlease check your Error Log view for the detailed information about the failure."));
			}
		}
	}
}
 
Example 54
Project: javapasswordsafe   File: SaveFileAsAction.java   View Source Code Vote up 4 votes
/**
 * @see org.eclipse.jface.action.Action#run()
 */
@Override
public void run() {
	PasswordSafeJFace app = PasswordSafeJFace.getApp();
	FileDialog fw = new FileDialog(app.getShell(), SWT.SAVE);
	fw.setFilterExtensions(fileExtensions);
	fw.setFilterNames(extensionNames);
	fw.setFileName(Messages.getString("SaveFileAsAction.NewSafeName")); //$NON-NLS-1$
	String newFilename = fw.open();

	if (newFilename == null)
		return;

	try {
		String extension = fileExtensions[fw.getFilterIndex()].substring(1);

		if (!newFilename.endsWith(extension) && (!newFilename.contains("."))) { // allow
																				// other
																				// extensions
			newFilename += extension;
		}
		if (!newFilename.endsWith(PwsS3Storage.FILE_EXTENSION)) {
			app.saveFileAs(newFilename);

		} else {
			S3CredentialsDialog sc = new S3CredentialsDialog(app);
			AccountDetails ad = sc.getAccountDetails();
			if (ad == null) {
				return;
			}

			PwsFile pwsFile = app.getPwsFile();

			pwsFile.setStorage(new PwsS3Storage(newFilename, ad, pwsFile.getPassphrase()));
			app.saveFile();
		}
		// SaveSafeSelectionWizard newSafeWizard = new
		// SaveSafeSelectionWizard ();
		// WizardDialog dlg = new WizardDialog(app.getShell(),
		// newSafeWizard);
		// int rc = dlg.open();
		// if (rc != 1) {

	} catch (IOException e1) {
		app.displayErrorDialog(
				Messages.getString("SaveFileAsAction.ErrorDialog.Title"), e1.getMessage(), e1); //$NON-NLS-1$
	} catch (NoSuchAlgorithmException e) {
		app.displayErrorDialog(
				Messages.getString("SaveFileAsAction.ErrorDialog.Title"), e.getMessage(), e); //$NON-NLS-1$
	}

}
 
Example 55
Project: ermaster-k   File: AbstractExportAction.java   View Source Code Vote up 4 votes
protected String getSaveFilePath(IEditorPart editorPart,
		GraphicalViewer viewer, ExportSetting exportSetting) {

	FileDialog fileDialog = new FileDialog(editorPart.getEditorSite()
			.getShell(), SWT.SAVE);

	fileDialog.setFilterPath(this.getBasePath());

	String[] filterExtensions = this.getFilterExtensions();
	fileDialog.setFilterExtensions(filterExtensions);

	String fileName = this.getDiagramFileName(editorPart);

	fileDialog.setFileName(fileName);

	return fileDialog.open();
}
 
Example 56
Project: SMVHunter   File: NativeHeapPanel.java   View Source Code Vote up 4 votes
/** Export currently displayed snapshot to a file */
private void exportSnapshot() {
    int idx = mSnapshotIndexCombo.getSelectionIndex();
    String snapshotName = mSnapshotIndexCombo.getItem(idx);

    FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(),
            SWT.SAVE);

    fileDialog.setText("Save " + snapshotName);
    fileDialog.setFileName("allocations.txt");

    final String fileName = fileDialog.open();
    if (fileName == null) {
        return;
    }

    final NativeHeapSnapshot snapshot = mNativeHeapSnapshots.get(idx);
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            PrintWriter out;
            try {
                out = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
            } catch (IOException e) {
                displayErrorMessage(e.getMessage());
                return;
            }

            for (NativeAllocationInfo alloc : snapshot.getAllocations()) {
                out.println(alloc.toString());
            }
            out.close();
        }

        private void displayErrorMessage(final String message) {
            Display.getDefault().syncExec(new Runnable() {
                @Override
                public void run() {
                    MessageDialog.openError(Display.getDefault().getActiveShell(),
                            "Failed to export heap data", message);
                }
            });
        }
    });
    t.setName("Saving Heap Data to File...");
    t.start();
}
 
Example 57
Project: mytourbook   File: TourBookView.java   View Source Code Vote up 4 votes
void actionExportViewCSV() {

		// get selected items
		final ITreeSelection selection = (ITreeSelection) _tourViewer.getSelection();

		if (selection.size() == 0) {
			return;
		}

		final String defaultExportFilePath = _state.get(STATE_CSV_EXPORT_PATH);

		final String defaultExportFileName = CSV_EXPORT_DEFAULT_FILE_NAME
				+ TimeTools.now().format(TimeTools.Formatter_FileName)
				+ UI.SYMBOL_DOT
				+ Util.CSV_FILE_EXTENSION;

		/*
		 * get export filename
		 */
		final FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
		dialog.setText(Messages.dialog_export_file_dialog_text);

		dialog.setFilterPath(defaultExportFilePath);
		dialog.setFilterExtensions(new String[] { Util.CSV_FILE_EXTENSION });
		dialog.setFileName(defaultExportFileName);

		final String selectedFilePath = dialog.open();
		if (selectedFilePath == null) {
			return;
		}

		final File exportFilePath = new Path(selectedFilePath).toFile();

		// keep export path
		_state.put(STATE_CSV_EXPORT_PATH, exportFilePath.getPath());

		if (exportFilePath.exists()) {
			if (net.tourbook.ui.UI.confirmOverwrite(exportFilePath) == false) {
				// don't overwrite file, nothing more to do
				return;
			}
		}

		exportCSV(selection, selectedFilePath);

//		// DEBUGGING: USING DEFAULT PATH
//		final IPath path = new Path(defaultExportFilePath).removeLastSegments(1).append(defaultExportFileName);
//
//		exportCSV(selection, path.toOSString());
	}
 
Example 58
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;
	}
}
 
Example 59
Project: screenshot   File: ScreenShotDialog.java   View Source Code Vote up 4 votes
private void saveImage(Shell shell) {
        FileDialog dlg = new FileDialog(shell, SWT.SAVE);

        Calendar now = Calendar.getInstance();
        String fileName = String.format("device-%tF-%tH%tM%tS.png",
                now, now, now, now);

        dlg.setText("Save image...");
        dlg.setFileName(fileName);

        String lastDir = "D:\\";
//        String lastDir = DdmUiPreferences.getStore().getString("lastImageSaveDir");
//        if (lastDir.length() == 0) {
//            lastDir = DdmUiPreferences.getStore().getString("imageSaveDir");
//        }
        dlg.setFilterPath(lastDir);
        dlg.setFilterNames(new String[] {
            "PNG Files (*.png)"
        });
        dlg.setFilterExtensions(new String[] {
            "*.png" //$NON-NLS-1$
        });

        fileName = dlg.open();
        if (fileName != null) {
            // FileDialog.getFilterPath() does NOT always return the current
            // directory of the FileDialog; on the Mac it sometimes just returns
            // the value the dialog was initialized with. It does however return
            // the full path as its return value, so just pick the path from
            // there.
            if (!fileName.endsWith(".png")) {
                fileName = fileName + ".png";
            }

//            String saveDir = new File(fileName).getParent();
//            if (saveDir != null) {
//                DdmUiPreferences.getStore().setValue("lastImageSaveDir", saveDir);
//            }

            Log.d("ddms", "Saving image to " + fileName);
            ImageData imageData = mImageLabel.getImage().getImageData();

            try {
                org.eclipse.swt.graphics.ImageLoader loader =
                        new org.eclipse.swt.graphics.ImageLoader();

                loader.data = new ImageData[] { imageData };
                loader.save(fileName, SWT.IMAGE_PNG);
            }
            catch (SWTException e) {
                Log.w("ddms", "Unable to save " + fileName + ": " + e.getMessage());
            }
        }
    }
 
Example 60
Project: ermasterr   File: AbstractExportAction.java   View Source Code Vote up 3 votes
protected String getSaveFilePath(final IEditorPart editorPart, final GraphicalViewer viewer, final ExportSetting exportSetting) {

        final FileDialog fileDialog = new FileDialog(editorPart.getEditorSite().getShell(), SWT.SAVE);

        fileDialog.setFilterPath(getBasePath());

        final String[] filterExtensions = getFilterExtensions();
        fileDialog.setFilterExtensions(filterExtensions);

        final String fileName = getDiagramFileName(editorPart);

        fileDialog.setFileName(fileName);

        return fileDialog.open();
    }