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

The following examples show how to use org.eclipse.swt.widgets.FileDialog#setText() . 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: BlockExporter.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public void finalizeExport() throws XChangeException{
	FileDialog fd = new FileDialog(UiDesk.getTopShell(), SWT.SAVE);
	fd.setText(Messages.BlockContainer_Blockbeschreibung);
	fd.setFilterExtensions(new String[] {
		"*.xchange" //$NON-NLS-1$
	});
	fd.setFilterNames(new String[] {
		Messages.BlockContainer_xchangefiles
	});
	String filename = fd.open();
	if (filename != null) {
		Format format = Format.getPrettyFormat();
		format.setEncoding("utf-8"); //$NON-NLS-1$
		XMLOutputter xmlo = new XMLOutputter(format);
		String xmlAspect = xmlo.outputString(getDocument());
		try {
			FileOutputStream fos = new FileOutputStream(filename);
			fos.write(xmlAspect.getBytes());
			fos.close();
		} catch (Exception ex) {
			ExHandler.handle(ex);
			throw new XChangeException("Output failed " + ex.getMessage());
		}
	}
	
}
 
Example 2
Source File: ExportToFileAction.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	IFigure contents = railroadView.getContents();
	if (contents != null) {
		FileDialog fileDialog = new FileDialog(this.railroadView.getSite().getShell(), SWT.SAVE);
		fileDialog.setFilterExtensions(new String[] { "*.png" });
		fileDialog.setText("Choose diagram file");
		String fileName = fileDialog.open();
		if (fileName == null) {
			return;
		}
		Dimension preferredSize = contents.getPreferredSize();
		Image image = new Image(Display.getDefault(), preferredSize.width + 2 * PADDING, preferredSize.height + 2
				* PADDING);
		GC gc = new GC(image);
		SWTGraphics graphics = new SWTGraphics(gc);
		graphics.translate(PADDING, PADDING);
		graphics.translate(contents.getBounds().getLocation().getNegated());
		contents.paint(graphics);
		ImageData imageData = image.getImageData();
		ImageLoader imageLoader = new ImageLoader();
		imageLoader.data = new ImageData[] { imageData };
		imageLoader.save(fileName, SWT.IMAGE_PNG);
	}
}
 
Example 3
Source File: XSLTransformationDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 打开文件对话框
 * @param txt
 *            显示路径文本框
 * @param style
 *            对话框样式
 * @param title
 *            对话框标题
 * @param extensions
 * @param filterNames
 *            ;
 */
private void openFileDialog(Text txt, int style, String title, String[] extensions, String[] filterNames) {
	FileDialog dialog = new FileDialog(getShell(), style);
	dialog.setText(title);
	dialog.setFilterExtensions(extensions);
	dialog.setFilterNames(filterNames);
	String fileSep = System.getProperty("file.separator");
	if (txt.getText() != null && !txt.getText().trim().equals("")) {
		dialog.setFilterPath(txt.getText().substring(0, txt.getText().lastIndexOf(fileSep)));
		dialog.setFileName(txt.getText().substring(txt.getText().lastIndexOf(fileSep) + 1));
	} else {
		dialog.setFilterPath(System.getProperty("user.home"));
	}
	String path = dialog.open();
	if (path != null) {
		txt.setText(path);
	}
}
 
Example 4
Source File: JavadocConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String chooseArchive() {
	if (fWorkspaceRadio.isSelected()) {
		return chooseWorkspaceArchive();
	}

	IPath currPath= new Path(fArchiveField.getText());
	if (ArchiveFileFilter.isArchivePath(currPath, true)) {
		currPath= currPath.removeLastSegments(1);
	}

	FileDialog dialog= new FileDialog(fShell, SWT.OPEN);
	dialog.setFilterExtensions(ArchiveFileFilter.JAR_ZIP_FILTER_EXTENSIONS);
	dialog.setText(PreferencesMessages.JavadocConfigurationBlock_zipImportSource_title);
	dialog.setFilterPath(currPath.toOSString());

	return dialog.open();
}
 
Example 5
Source File: XMLAnalysesManagerPreferencePage.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Import new analysis.
 */
private void importAnalysis() {
    FileDialog dialog = TmfFileDialogFactory.create(Display.getCurrent().getActiveShell(), SWT.OPEN | SWT.MULTI);
    dialog.setText(Messages.ManageXMLAnalysisDialog_SelectFilesImport);
    dialog.setFilterNames(new String[] { Messages.ManageXMLAnalysisDialog_ImportXmlFile + " (" + XML_FILTER_EXTENSION + ")" }); //$NON-NLS-1$ //$NON-NLS-2$
    dialog.setFilterExtensions(new String[] { XML_FILTER_EXTENSION });
    dialog.open();
    String directoryPath = dialog.getFilterPath();
    if (!directoryPath.isEmpty()) {
        File directory = new File(directoryPath);
        String[] files = dialog.getFileNames();
        Collection<String> filesToProcess = Lists.newArrayList();
        for (String fileName : files) {
            File file = new File(directory, fileName);
            if (loadXmlFile(file, true)) {
                filesToProcess.add(file.getName());
            }
        }
        if (!filesToProcess.isEmpty()) {
            fillAnalysesTable();
            Collection<TmfCommonProjectElement> elements = deleteSupplementaryFiles(filesToProcess);
            XmlAnalysisModuleSource.notifyModuleChange();
            refreshProject(elements);
        }
    }
}
 
Example 6
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 7
Source File: PmTrans.java    From pmTrans with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 8
Source File: ImportProjectWizardPage.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The browse button has been selected. Select the location.
 */
protected void handleLocationArchiveButtonPressed() {

	final FileDialog dialog = new FileDialog(archivePathField.getShell(), SWT.SHEET);
	dialog.setFilterExtensions(FILE_IMPORT_MASK);
	dialog.setText(DataTransferMessages.WizardProjectsImportPage_SelectArchiveDialogTitle);

	String fileName = archivePathField.getText().trim();
	if (fileName.length() == 0) {
		fileName = previouslyBrowsedArchive;
	}

	if (fileName.length() == 0) {
		dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getLocation().toOSString());
	} else {
		final File path = new File(fileName).getParentFile();
		if (path != null && path.exists()) {
			dialog.setFilterPath(path.toString());
		}
	}

	final String selectedArchive = dialog.open();
	if (selectedArchive != null) {
		previouslyBrowsedArchive = selectedArchive;
		archivePathField.setText(previouslyBrowsedArchive);
		updateProjectsList(selectedArchive);
	}

}
 
Example 9
Source File: ImportBosArchiveControlSupplier.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected String openFileDialog(Shell shell) {
    final FileDialog fd = new FileDialog(shell, SWT.OPEN | SWT.SINGLE);
    fd.setText(Messages.importProcessTitle);
    fd.setFilterPath(getLastPath());
    fd.setFilterExtensions(new String[] { BOS_EXTENSION });
    return fd.open();
}
 
Example 10
Source File: ImportProjectWizardPage2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
protected void handleBrowseBtnPressed() {
	FileDialog dialog = new FileDialog(filePathTxt.getShell(), SWT.SHEET);
	dialog.setFilterExtensions(FILE_IMPORT_MASK);
	dialog.setText(Messages.getString("importProjectWizardPage.SelectArchiveDialogTitle"));

	String fileName = filePathTxt.getText().trim();
	if (fileName.length() == 0) {
		fileName = previouslyBrowsedPath;
	}

	if (fileName.length() == 0) {
		// IDEWorkbenchPlugin.getPluginWorkspace()
		dialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
	} else {
		File path = new File(fileName).getParentFile();
		if (path != null && path.exists()) {
			dialog.setFilterPath(path.toString());
		}
	}

	String selectedArchive = dialog.open();
	if (selectedArchive != null) {
		previouslyBrowsedPath = selectedArchive;
		filePathTxt.setText(previouslyBrowsedPath);
		
		// 先择新的项目包时,清除重复树中的所有内容
		checkedRepeatElementMap.clear();
		repeatElementTree.refresh(true);
		
		updateProjectsList(selectedArchive);
		// 初始化时全部初始化
		selectElementTree.expandAll();
		selectElementTreeBtnSelectFunction(true);
	}
}
 
Example 11
Source File: AttachManager.java    From http4e with Apache License 2.0 5 votes vote down vote up
public void widgetSelected( SelectionEvent event){
      FileDialog fd = new FileDialog(parent.getShell(), SWT.OPEN);
      fd.setText("Add File Content to Body");
      // fd.setFilterPath("C:/");
      fd.setFilterExtensions(CoreConstants.FILE_FILTER_EXT);
      String file = fd.open();
      
      if (file != null) {
         parent.setText(CoreConstants.FILE_PREFIX + file);
         model.fireExecute(new ModelEvent(ModelEvent.BODY_FOCUS_LOST, model));
//       force body to refresh itself
         model.fireExecute(new ModelEvent(ModelEvent.PARAMS_FOCUS_LOST, model)); 
      }
   }
 
Example 12
Source File: RTFCleanerDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 处理 RTF 文件 ;
 */
private void handleFile() {
	FileDialog dialog = new FileDialog(getShell(), SWT.MULTI);
	dialog.setText(Messages.getString("dialog.RTFCleanerDialog.dialogTitle"));
	String[] extensions = { "*.rtf", "*" };
	String[] filters = { Messages.getString("dialog.RTFCleanerDialog.filters1"),
			Messages.getString("dialog.RTFCleanerDialog.filters2") };
	dialog.setFilterExtensions(extensions);
	dialog.setFilterNames(filters);
	dialog.setFilterPath(System.getProperty("user.home"));
	dialog.open();
	String[] arrSource = dialog.getFileNames();
	if (arrSource == null || arrSource.length == 0) {
		return;
	}
	int errors = 0;
	for (int i = 0; i < arrSource.length; i++) {
		File f = new File(dialog.getFilterPath() + System.getProperty("file.separator") + arrSource[i]); //$NON-NLS-1$
		Hashtable<String, String> params = new Hashtable<String, String>();
		params.put("source", f.getAbsolutePath()); //$NON-NLS-1$
		params.put("output", f.getAbsolutePath()); //$NON-NLS-1$

		Vector<String> result = RTFCleaner.run(params);

		if (!"0".equals(result.get(0))) { //$NON-NLS-1$
			String msg = MessageFormat.format(Messages.getString("dialog.RTFCleanerDialog.msg1"), arrSource[i])
					+ (String) result.get(1);
			MessageDialog.openInformation(getShell(), Messages.getString("dialog.RTFCleanerDialog.msgTitle"), msg);
			errors++;
		}
	}
	if (errors < arrSource.length) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.RTFCleanerDialog.msgTitle"),
				Messages.getString("dialog.RTFCleanerDialog.msg2"));
	}
}
 
Example 13
Source File: BluemixUtil.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public static String launchChooseFileDialog(String file, String[] filterExts, String[] filterNames) {
    FileDialog dlg = new FileDialog(Display.getCurrent().getActiveShell());
    dlg.setFileName(file);
    dlg.setText("Choose file"); // $NLX-BluemixUtil.Choosefile-1$
    dlg.setFilterExtensions(filterExts);
    dlg.setFilterNames(filterNames);
    return dlg.open();
}
 
Example 14
Source File: LoadStopWordsAction.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run(IAction action) {
	FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
	dialog.setText("Select a stopword file, containing one word per line...");
	String sourceFile = dialog.open();
	if (sourceFile == null)
		return;
	TypeCollector.setStopwords(sourceFile);
}
 
Example 15
Source File: TableEditor.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
protected File openExternalFile(String title) {
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
			.getShell();
	FileDialog fileDialog = new FileDialog(shell);
	fileDialog.setText(title);
	String file = fileDialog.open();
	if (file != null) {
		return new File(file);
	}
	return null;
}
 
Example 16
Source File: FileChooser.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
public String openFile()
{
	FileDialog dlg = new FileDialog(button.getShell(), SWT.OPEN);
	dlg.setFileName(text.getText());
	dlg.setFilterExtensions(new String[] { "*.gif; *.jpg; *.png; *.ico; *.bmp" });

	dlg.setText(OPEN);
	String path = dlg.open();

	return path;
}
 
Example 17
Source File: LongMethod.java    From JDeodorant with MIT License 5 votes vote down vote up
private void saveResults() {
	FileDialog fd = new FileDialog(getSite().getWorkbenchWindow().getShell(), SWT.SAVE);
	fd.setText("Save Results");
       String[] filterExt = { "*.txt" };
       fd.setFilterExtensions(filterExt);
       String selected = fd.open();
       if(selected != null) {
       	try {
       		BufferedWriter out = new BufferedWriter(new FileWriter(selected));
       		Tree tree = treeViewer.getTree();
       		/*TreeColumn[] columns = tree.getColumns();
       		for(int i=0; i<columns.length; i++) {
       			if(i == columns.length-1)
       				out.write(columns[i].getText());
       			else
       				out.write(columns[i].getText() + "\t");
       		}
       		out.newLine();*/
       		for(int i=0; i<tree.getItemCount(); i++) {
				TreeItem treeItem = tree.getItem(i);
				ASTSliceGroup group = (ASTSliceGroup)treeItem.getData();
				for(ASTSlice candidate : group.getCandidates()) {
					out.write(candidate.toString());
					out.newLine();
				}
			}
       		out.close();
       	} catch (IOException e) {
       		e.printStackTrace();
       	}
       }
}
 
Example 18
Source File: ScriptMainTab.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private File chooseReportDesign( )
{
	if ( lastUsedPath == null )
	{
		lastUsedPath = ""; //$NON-NLS-1$
	}
	FileDialog dialog = new FileDialog( getShell( ), SWT.SINGLE );
	dialog.setText( Messages.getString( "ScriptMainTab.msg.select.report.file" ) ); //$NON-NLS-1$

	if ( bRender.getSelection( ) )
	{
		dialog.setFilterExtensions( new String[]{
			"*." + DOCUMENT_FILE_EXT} ); //$NON-NLS-1$
	}
	else
	{
		dialog.setFilterExtensions( new String[]{
			"*." + IReportElementConstants.DESIGN_FILE_EXTENSION} ); //$NON-NLS-1$
	}

	dialog.setFilterPath( lastUsedPath );
	String res = dialog.open( );
	if ( res == null )
	{
		return null;
	}
	String[] fileNames = dialog.getFileNames( );

	IPath filterPath = new Path( dialog.getFilterPath( ) );
	lastUsedPath = dialog.getFilterPath( );

	IPath path = null;
	for ( int i = 0; i < 1; i++ )
	{
		path = filterPath.append( fileNames[i] ).makeAbsolute( );
		return path.toFile( );
	}
	return null;
}
 
Example 19
Source File: AbstractExportAction.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected Optional<String> getPath(Shell shell, IRepositoryFileStore fStore) {
    final FileDialog fd = new FileDialog(shell, SWT.SAVE | SWT.SHEET);
    fd.setFileName(fStore.getName());
    fd.setFilterExtensions(new String[] { "*.xml" });
    fd.setText(getExportTitle());
    return Optional.ofNullable(fd.open());
}
 
Example 20
Source File: FilterFilesTab.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void configureDialog(FileDialog dialog) {
    dialog.setFilterExtensions(new String[] { "*.xml" });
    dialog.setText(FindbugsPlugin.getDefault().getMessage(kind.propertyName) + ": select xml file(s) containing filters");
}