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

The following examples show how to use org.eclipse.swt.widgets.FileDialog#setFilterNames() . 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: FilterView.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        FileDialog dlg = TmfFileDialogFactory.create(new Shell(), SWT.SAVE);
        dlg.setFilterNames(new String[] { Messages.FilterView_FileDialogFilterName + " (*.xml)" }); //$NON-NLS-1$
        dlg.setFilterExtensions(new String[] { "*.xml" }); //$NON-NLS-1$

        String fn = dlg.open();
        if (fn != null) {
            TmfFilterXMLWriter writerXML = new TmfFilterXMLWriter(fRoot);
            writerXML.saveTree(fn);
        }

    } catch (ParserConfigurationException e) {
        Activator.getDefault().logError("Error parsing filter xml file", e); //$NON-NLS-1$
    }
}
 
Example 2
Source File: PluginHelpDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private void openFile() {
	FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
	String[] extensions = { "*.xml", "*.*" };
	String[] filterNames = { Messages.getString("dialog.PluginHelpDialog.filterNames0"),
			Messages.getString("dialog.PluginHelpDialog.filterNames1") };
	fileDialog.setFilterExtensions(extensions);
	fileDialog.setFilterNames(filterNames);
	fileDialog.setFilterPath(System.getProperty("user.home"));
	String name = fileDialog.open();
	if (name == null) {
		return;
	}
	File file = new File(name);
	getShell().setText(file.getName());
	loadTree(file.getAbsolutePath());
}
 
Example 3
Source File: XSLTransformationDialog.java    From tmxeditor8 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: RestoreDatabaseDialog.java    From Rel with Apache License 2.0 6 votes vote down vote up
/**
 * Create the dialog.
 * @param parent
 * @param style
 */
public RestoreDatabaseDialog(Shell parent) {
	super(parent, SWT.DIALOG_TRIM | SWT.RESIZE);
	setText("Create and Restore Database");
	
	newDatabaseDialog = new DirectoryDialog(parent);
	newDatabaseDialog.setText("Create Database");
	newDatabaseDialog.setMessage("Select a folder to hold a new database.");
	newDatabaseDialog.setFilterPath(System.getProperty("user.home"));

	restoreFileDialog = new FileDialog(Core.getShell(), SWT.OPEN);
	restoreFileDialog.setFilterPath(System.getProperty("user.home"));
	restoreFileDialog.setFilterExtensions(new String[] {"*.rel", "*.*"});
	restoreFileDialog.setFilterNames(new String[] {"Rel script", "All Files"});
	restoreFileDialog.setText("Load Backup");
}
 
Example 5
Source File: FileChooser.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
private static String openFileDialog(Shell shell, String extension,
		String defaultName, String filterPath, int swtFlag) {
	FileDialog dialog = new FileDialog(shell, swtFlag);
	dialog.setText(getDialogText(swtFlag));
	String ext = null;
	if (extension != null) {
		ext = extension.trim();
		if (ext.contains("|"))
			ext = ext.substring(0, ext.indexOf("|")).trim();
		dialog.setFilterExtensions(new String[] { ext });
	}
	dialog.setFileName(defaultName);
	if (filterPath != null)
		dialog.setFilterPath(filterPath);
	if (extension != null) {
		if (extension.contains("|")) {
			String label = extension.substring(extension.indexOf("|") + 1);
			label += " (" + ext + ")";
			dialog.setFilterNames(new String[] { label });
		}
	}
	return dialog.open();
}
 
Example 6
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 7
Source File: ExportTemplateCommand.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	// get selection
	ISelection selection =
		HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
	if (selection != null) {
		Object firstElement = ((IStructuredSelection) selection).getFirstElement();
		
		if (firstElement != null && firstElement instanceof TextTemplate) {
			TextTemplate textTemplate = (TextTemplate) firstElement;
			if (textTemplate.getTemplate() != null) {
				try {
					FileDialog fdl = new FileDialog(UiDesk.getTopShell(), SWT.SAVE);
					fdl.setFilterExtensions(new String[] {
						MimeTypeUtil.getExtensions(textTemplate.getMimeType()), "*.*"
					});
					fdl.setFilterNames(new String[] {
						textTemplate.getMimeTypePrintname(), "All files"
					});
					
					String filename = fdl.open();
					if (filename != null) {
						File file = new File(filename);
						byte[] contents = textTemplate.getTemplate().loadBinary();
						ByteArrayInputStream bais = new ByteArrayInputStream(contents);
						FileOutputStream fos = new FileOutputStream(file);
						FileTool.copyStreams(bais, fos);
						fos.close();
						bais.close();
					}
				} catch (IOException e) {
					logger.error("Error executing file dialog for text template export", e);
				}
			}
		}
	}
	return null;
}
 
Example 8
Source File: ImportLiveHttpHeadersAction.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("*.*");
         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 9
Source File: TmxValidatorDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void openFile() {
	FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
	String[] extensions = { "*.tmx" }; //$NON-NLS-1$ //$NON-NLS-2$
	fd.setFilterExtensions(extensions);
	String[] names = { Messages.getString("dialog.TmxValidatorDialog.label.tmxex") };
	/* Messages.getString("dialog.TmxValidatorDialog.label.allex" */
	fd.setFilterNames(names);
	String path = fd.open();
	txtTmxFilePath.setText(path == null ? "" : path);
}
 
Example 10
Source File: FileOpen.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {

	final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
	final FileDialog dialog = new FileDialog(shell, SWT.OPEN);
	dialog.setFilterExtensions(new String[] { "*.gaml", "*.experiment", "*.*" });
	dialog.setFilterNames(new String[] { "GAML model files", "GAML experiment files", "All Files" });
	final String fileSelected = dialog.open();

	if (fileSelected != null && GamlFileExtension.isAny(fileSelected)) {
		// Perform Action, like open the file.
		WorkspaceModelsManager.instance.openModelPassedAsArgument(fileSelected);
	}
	return null;
}
 
Example 11
Source File: TMXValidatorDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private void cleanCharacters() {
	FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
	String[] extensions = { "*.tmx", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
	fd.setFilterExtensions(extensions);
	String[] names = { Messages.getString("dialog.TMXValidatorDialog.names1"),
			Messages.getString("dialog.TMXValidatorDialog.names2") };
	fd.setFilterNames(names);
	String name = fd.open();
	if (name != null) {
		red = Display.getDefault().getSystemColor(SWT.COLOR_RED);

		styledText.setText("");
		styledText.append(Messages.getString("dialog.TMXValidatorDialog.styledText1"));
		getShell().setCursor(cursorWait);
		try {

		} catch (Exception e) {
			LOGGER.error("", e);
			String errorTip = e.getMessage();
			if (errorTip == null) {
				errorTip = MessageFormat.format(Messages.getString("dialog.TMXValidatorDialog.msg1"), name);
			}
			StyleRange range = new StyleRange(styledText.getText().length(), errorTip.length(), red, null);
			styledText.append(errorTip);
			styledText.setStyleRange(range);
		}

		styledText.append(Messages.getString("dialog.TMXValidatorDialog.styledText2"));
		getShell().setCursor(cursorArrow);
	}
}
 
Example 12
Source File: TMXValidatorDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 打开文件
 */
private void openFile() {
	FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
	String[] extensions = { "*.tmx", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
	fd.setFilterExtensions(extensions);
	String[] names = { Messages.getString("dialog.TMXValidatorDialog.names1"),
			Messages.getString("dialog.TMXValidatorDialog.names2") };
	fd.setFilterNames(names);
	String name = fd.open();
	if (name != null) {
		validate(name);
	}
}
 
Example 13
Source File: TMXValidatorDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 打开文件
 */
private void openFile() {
	FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
	String[] extensions = { "*.tmx", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
	fd.setFilterExtensions(extensions);
	String[] names = { Messages.getString("dialog.TMXValidatorDialog.names1"),
			Messages.getString("dialog.TMXValidatorDialog.names2") };
	fd.setFilterNames(names);
	String name = fd.open();
	if (name != null) {
		validate(name);
	}
}
 
Example 14
Source File: ZipFileBluemixWizardPage.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent event) {
    if (event.widget == _zipBtn) {
        FileDialog dlg = new FileDialog(getShell());
        dlg.setFileName(StringUtil.getNonNullString(_zipText.getText()));
        dlg.setText("Choose the zip file containing the XPages starter code"); // $NLX-ZipFileBluemixWizardPage.ChoosetheZipfilecontainingtheXPag-1$
        dlg.setFilterExtensions(new String[]{"*.zip","*.*"}); // $NON-NLS-1$
        dlg.setFilterNames(new String[]{"ZIP files","All files"}); // $NLX-ZipFileBluemixWizardPage.Zipfiles-1$ $NLX-ZipFileBluemixWizardPage.Allfiles-2$
        String loc = dlg.open();
        if (StringUtil.isNotEmpty(loc)) {
            _zipText.setText(loc);
        }
    }
}
 
Example 15
Source File: ImportRulesDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Import the rules from an XML rules file...
 */
protected void importRules() {
  if ( !importRules.getRules().isEmpty() ) {
    MessageBox box =
      new MessageBox( shell, SWT.ICON_WARNING | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.YES | SWT.NO );
    box.setText( "Warning" );
    box.setMessage( "Are you sure you want to load a new set of rules, replacing the current list?" );
    int answer = box.open();
    if ( answer != SWT.YES ) {
      return;
    }
  }

  FileDialog dialog = new FileDialog( shell, SWT.OPEN );
  dialog.setFilterExtensions( new String[] { "*.xml;*.XML", "*" } );
  dialog.setFilterNames( new String[] {
    BaseMessages.getString( PKG, "System.FileType.XMLFiles" ),
    BaseMessages.getString( PKG, "System.FileType.AllFiles" ) } );
  if ( dialog.open() != null ) {
    String filename = dialog.getFilterPath() + System.getProperty( "file.separator" ) + dialog.getFileName();

    ImportRules newRules = new ImportRules();
    try {
      newRules.loadXML( XMLHandler.getSubNode( XMLHandler.loadXMLFile( filename ), ImportRules.XML_TAG ) );
      importRules = newRules;

      // Re-load the dialog.
      //
      getCompositesData();

    } catch ( Exception e ) {
      new ErrorDialog(
        shell, "Error",
        "There was an error during the import of the import rules file, verify the XML format.", e );
    }

  }
}
 
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: OpenFileFlow.java    From Universal-FE-Randomizer with MIT License 5 votes vote down vote up
@Override
public void handleEvent(Event event) {
	// TODO Auto-generated method stub
	FileDialog openDialog = new FileDialog(parent, SWT.OPEN);
	openDialog.setFilterExtensions(new String[] {"*.gba;*.smc;*.sfc;*.iso", "*"});
	openDialog.setFilterNames(new String[] {"*.gba, *.smc, *.sfc, *.iso", "All Files (*.*)"});
	delegate.onSelectedFile(openDialog.open());
}
 
Example 18
Source File: TMXValidatorDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private void cleanCharacters() {
	FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
	String[] extensions = { "*.tmx", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
	fd.setFilterExtensions(extensions);
	String[] names = { Messages.getString("dialog.TMXValidatorDialog.names1"),
			Messages.getString("dialog.TMXValidatorDialog.names2") };
	fd.setFilterNames(names);
	String name = fd.open();
	if (name != null) {
		red = Display.getDefault().getSystemColor(SWT.COLOR_RED);

		styledText.setText("");
		styledText.append(Messages.getString("dialog.TMXValidatorDialog.styledText1"));
		getShell().setCursor(cursorWait);
		try {

		} catch (Exception e) {
			LOGGER.error("", e);
			String errorTip = e.getMessage();
			if (errorTip == null) {
				errorTip = MessageFormat.format(Messages.getString("dialog.TMXValidatorDialog.msg1"), name);
			}
			StyleRange range = new StyleRange(styledText.getText().length(), errorTip.length(), red, null);
			styledText.append(errorTip);
			styledText.setStyleRange(range);
		}

		styledText.append(Messages.getString("dialog.TMXValidatorDialog.styledText2"));
		getShell().setCursor(cursorArrow);
	}
}
 
Example 19
Source File: ExportAsHtmlHandler.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 = { "HTML Files [*.html]", "All Files [*.*]" };
	String[] extensions = { "*.html", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
	fd.setFilterExtensions(extensions);
	fd.setFilterNames(names);

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

	XLFHandler handler = xliffEditor.getXLFHandler();
	boolean result = handler.saveAsHtml(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: ImportSelectedTemplateCommand.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	IWorkbenchPage activePage =
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	TextTemplateView textTemplateView =
		(TextTemplateView) activePage.findView(TextTemplateView.ID);
	
	TextTemplate textTemplate = getSelectedTextTemplate(event);
	if (textTemplate == null) {
		logger.warn("No TextTemplate selected - skipping template import");
		return null;
	}
	
	ITextPlugin plugin = textTemplateView.getActiveTextPlugin();
	if (plugin == null) {
		logger.warn("No TextPlugin found - skipping text template import");
		return null;
	}
	
	try {
		String mimeType = plugin.getMimeType();
		FileDialog fdl = new FileDialog(UiDesk.getTopShell());
		fdl.setFilterExtensions(new String[] {
			MimeTypeUtil.getExtensions(mimeType)
		});
		fdl.setFilterNames(new String[] {
			MimeTypeUtil.getPrettyPrintName(mimeType)
		});
		
		String filename = fdl.open();
		if (filename != null) {
			File file = new File(filename);
			if (file.exists()) {
				FileInputStream fis = new FileInputStream(file);
				byte[] contentToStore = new byte[(int) file.length()];
				fis.read(contentToStore);
				fis.close();
				
				List<Brief> existing = TextTemplate.findExistingTemplates(
					textTemplate.isSystemTemplate(),
					textTemplate.getName(), (String) null,
					textTemplate.getMandant() != null ? textTemplate.getMandant().getId() : "");
				if(!existing.isEmpty()) {
					if (MessageDialog.openQuestion(HandlerUtil.getActiveShell(event),
						"Vorlagen existieren",
						String.format(
							"Sollen die (%d) existierenden %s Vorlagen überschrieben werden?",
							existing.size(), textTemplate.getName()))) {
						for (Brief brief : existing) {
							brief.delete();
						}
					}
				}
				
				Brief bTemplate = new Brief(textTemplate.getName(), null, CoreHub.getLoggedInContact(),
					textTemplate.getMandant(), null, Brief.TEMPLATE);
				if (textTemplate.isSystemTemplate()) {
					bTemplate.set(Brief.FLD_KONSULTATION_ID, Brief.SYS_TEMPLATE);
					textTemplate.addSystemTemplateReference(bTemplate);
				} else {
					textTemplate.addFormTemplateReference(bTemplate);
				}
				bTemplate.save(contentToStore, plugin.getMimeType());
				textTemplateView.update(textTemplate);
			}
		}
	} catch (Throwable ex) {
		ExHandler.handle(ex);
	}
	ElexisEventDispatcher.getInstance().fire(new ElexisEvent(Brief.class, null,
		ElexisEvent.EVENT_RELOAD, ElexisEvent.PRIORITY_NORMAL));
	return null;
}