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

The following examples show how to use org.eclipse.swt.widgets.FileDialog#setFileName() . 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: ExportHTTP4eAction.java    From http4e with Apache License 2.0 6 votes vote down vote up
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 2
Source File: UserLibraryPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void changeControlPressed(DialogField field) {
	String label= isSave() ? PreferencesMessages.UserLibraryPreferencePage_LoadSaveDialog_filedialog_save_title : PreferencesMessages.UserLibraryPreferencePage_LoadSaveDialog_filedialog_load_title;
	FileDialog dialog= new FileDialog(getShell(), isSave() ? SWT.SAVE : SWT.OPEN);
	dialog.setText(label);
	dialog.setFilterExtensions(new String[] {"*.userlibraries", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
	String lastPath= fLocationField.getText();
	if (lastPath.length() == 0 || !new File(lastPath).exists()) {
		lastPath= fSettings.get(PREF_LASTPATH);
	}
	if (lastPath != null) {
		dialog.setFileName(lastPath);
	}
	String fileName= dialog.open();
	if (fileName != null) {
		fSettings.put(PREF_LASTPATH, fileName);
		fLocationField.setText(fileName);
	}
}
 
Example 3
Source File: MultiFileFieldEditor.java    From erflute with Apache License 2.0 6 votes vote down vote up
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 4
Source File: ExportImageAction.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@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 5
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	FileDialog dialog = new FileDialog(getViewSite().getShell(),
			SWT.OPEN);
	dialog.setFileName(lastSelection);
	String[] filterSuffixPattern = new String[EXTENSIONS.length + 1];
	String[] filterReadableName = new String[EXTENSIONS.length + 1];

	filterSuffixPattern[0] = "*.*"; //$NON-NLS-1$
	filterReadableName[0] = String.format("Embedded DOT Graph (%s)", //$NON-NLS-1$
			filterSuffixPattern[0]);

	for (int i = 1; i <= EXTENSIONS.length; i++) {
		String suffix = EXTENSIONS[i - 1];
		filterSuffixPattern[i] = "*." + suffix; //$NON-NLS-1$
		filterReadableName[i] = String.format(Locale.ENGLISH,
				"%S file (%s)", suffix, //$NON-NLS-1$
				filterSuffixPattern[i]);
	}

	dialog.setFilterExtensions(filterSuffixPattern);
	dialog.setFilterNames(filterReadableName);
	String selection = dialog.open();
	if (selection != null) {
		lastSelection = selection;
		updateGraph(new File(selection));
	}
}
 
Example 6
Source File: InstalledSolidityCompilerPreferencePage.java    From uml2solidity with Eclipse Public License 1.0 5 votes vote down vote up
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 7
Source File: ImportHTTP4eAction.java    From http4e with Apache License 2.0 5 votes vote down vote up
public void run(){

      try {

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

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

         String path = fileDialog.open();
         if (path != null) {
            HdViewPart hdView = (HdViewPart) view;
            List<ItemModel> iteModels = BaseUtils.importHttp4eSessions(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 8
Source File: FileBrowserField.java    From eclipsegraphviz with Eclipse Public License 1.0 5 votes vote down vote up
private File getFile(File startingDirectory) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
    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 9
Source File: ExportActorMappingAction.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    if(path == null){
        FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.SAVE) ;
        dialog.setFileName(process.getName()+"_"+process.getVersion()+"_"+Messages.mapping+".xml") ;
        dialog.setFilterExtensions(new String[]{"*.xml"}) ;
        String filePath = dialog.open() ;
        if(filePath != null){
            exportActorMapping(filePath) ;
        }
    }else{
        exportActorMapping(path+File.separator+"actorMapping.xml") ;
    }
}
 
Example 10
Source File: FileChooser.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
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 11
Source File: WebSearchPreferencePage.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
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 12
Source File: AbstractExportAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
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 13
Source File: PmTrans.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 14
Source File: ExportParametersAction.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@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 15
Source File: Activator.java    From erflute with Apache License 2.0 5 votes vote down vote up
public static String showSaveDialog(String filePath, String[] filterExtensions) {
    String dir = null;
    String fileName = null;
    if (filePath != null && !"".equals(filePath.trim())) {
        final File file = new File(filePath.trim());
        dir = file.getParent();
        fileName = file.getName();
    }
    final FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
    fileDialog.setFilterPath(dir);
    fileDialog.setFileName(fileName);
    fileDialog.setFilterExtensions(filterExtensions);
    return fileDialog.open();
}
 
Example 16
Source File: DashboardComposite.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private boolean saveCSVFileOfSnapshot() {
	final FileDialog fileDialog = new FileDialog(this.getShell(), SWT.SAVE);
	fileDialog.setFilterNames(new String[] { "CSV (comma-separated value) files (*.csv)" });
	fileDialog.setFilterExtensions(new String[] { "*.csv" });
	fileDialog.setFileName(getTimeStamp() + ".csv");

	final String filePath = fileDialog.open();

	// user cancelled
	if (filePath == null) {
		return false;
	}

	final File outputFile = new File(filePath);

	try (FileWriter writer = new FileWriter(outputFile)) {
		final String csvData = DataCollectorCSVExporter.toCSV(key);
		writer.write(csvData);
	} catch (IOException e) {
		// inform user about failure and abort snapshot
		ErrorDialog.openError(this.getShell(), "Failed to save CSV file",
				"Could not save CSV file at specified location " + filePath,
				new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to save CSV file with performance data.",
						e));
		return false;
	}

	return true;
}
 
Example 17
Source File: KeywordTab.java    From cdt-proc with Eclipse Public License 1.0 4 votes vote down vote up
private void exportFile(Shell shell) {
	FileDialog fd= new FileDialog(shell, SWT.SAVE);
	fd.setText("Export " + title);
	fd.setFilterExtensions(new String[] {"*.txt", "*.*"});
	fd.setFileName(fileName);

	String path = fd.open();
	if (path == null) {
		return;
	}

	File file = new File(path);

	if (file.isHidden()) {
		return;
	}

	if (file.exists() && !file.canWrite()) {
		return;
	}

	if (!file.exists() || confirmOverwrite(shell, file)) {
		OutputStream os = null;
		try {
			os = new BufferedOutputStream(new FileOutputStream(file));
			OutputStreamWriter osw = new OutputStreamWriter(os);
			BufferedWriter bw = new BufferedWriter(osw);

			String[] list = listViewer.getList().getItems();
			for (int i = 0; i < list.length; i++) {
				bw.write(list[i]);
				bw.newLine();
			}
			bw.close();
			os.close();
		} catch (IOException e) {
			if (os != null) {
				try {
					os.close();
				} catch (IOException e2) {
					// ignore
				}
			}
			openWriteErrorDialog(shell);
		}
	}
}
 
Example 18
Source File: ExportAsTextHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	String elementName = event.getParameter("elementName");

	IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
	Shell shell = activeEditor.getEditorSite().getShell();
	if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
	if (xliffEditor.isMultiFile()) {
		MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
	}

	IEditorInput input = xliffEditor.getEditorInput();
	URI uri = null;
	if (input instanceof FileEditorInput) {
		uri = ((FileEditorInput) input).getURI();
	} else if (input instanceof FileStoreEditorInput) {
		uri = ((FileStoreEditorInput) input).getURI();
	} else {
		return null;
	}
	File xliff = new File(uri);

	FileDialog fd = new FileDialog(shell, SWT.SAVE);
	String[] names = { "Plain Text Files [*.txt]", "All Files [*.*]" };
	String[] extensions = { "*.txt", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
	fd.setFilterExtensions(extensions);
	fd.setFilterNames(names);

	fd.setFileName(xliff.getName() + ".txt"); //$NON-NLS-1$
	String out = fd.open();
	if (out == null) {
		return null;
	}

	XLFHandler handler = xliffEditor.getXLFHandler();
	boolean result = handler.saveAsText(xliff.getAbsolutePath(), out, elementName);

	if (result) {
		IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
		OpenEditorUtil.OpenFileWithSystemEditor(page, out);
	} else {
		MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
	}

	return null;
}
 
Example 19
Source File: ExportAsTextHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	String elementName = event.getParameter("elementName");

	IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
	Shell shell = activeEditor.getEditorSite().getShell();
	if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
		return null;
	}
	XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
	if (xliffEditor.isMultiFile()) {
		MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
	}

	IEditorInput input = xliffEditor.getEditorInput();
	URI uri = null;
	if (input instanceof FileEditorInput) {
		uri = ((FileEditorInput) input).getURI();
	} else if (input instanceof FileStoreEditorInput) {
		uri = ((FileStoreEditorInput) input).getURI();
	} else {
		return null;
	}
	File xliff = new File(uri);

	FileDialog fd = new FileDialog(shell, SWT.SAVE);
	String[] names = { "Plain Text Files [*.txt]", "All Files [*.*]" };
	String[] extensions = { "*.txt", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
	fd.setFilterExtensions(extensions);
	fd.setFilterNames(names);

	fd.setFileName(xliff.getName() + ".txt"); //$NON-NLS-1$
	String out = fd.open();
	if (out == null) {
		return null;
	}

	XLFHandler handler = xliffEditor.getXLFHandler();
	boolean result = handler.saveAsText(xliff.getAbsolutePath(), out, elementName);

	if (result) {
		IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
		OpenEditorUtil.OpenFileWithSystemEditor(page, out);
	} else {
		MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
	}

	return null;
}
 
Example 20
Source File: AbstractExportAction.java    From ermasterr with Apache License 2.0 3 votes vote down vote up
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();
    }