org.eclipse.swt.widgets.FileDialog#setFilterNames ( )源码实例Demo

下面列出了org.eclipse.swt.widgets.FileDialog#setFilterNames ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tracecompass   文件: FilterView.java
@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$
    }
}
 
源代码2 项目: tmxeditor8   文件: XSLTransformationDialog.java
/**
 * 打开文件对话框
 * @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);
	}
}
 
源代码3 项目: Rel   文件: RestoreDatabaseDialog.java
/**
 * 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");
}
 
源代码4 项目: olca-app   文件: FileChooser.java
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();
}
 
/**
 * 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);
        }
    }
}
 
源代码6 项目: translationstudio8   文件: PluginHelpDialog.java
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());
}
 
源代码7 项目: tmxeditor8   文件: TMXValidatorDialog.java
/**
 * 打开文件
 */
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);
	}
}
 
源代码8 项目: tmxeditor8   文件: TMXValidatorDialog.java
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);
	}
}
 
源代码9 项目: Universal-FE-Randomizer   文件: OpenFileFlow.java
@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());
}
 
源代码10 项目: n4js   文件: DashboardComposite.java
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;
}
 
源代码11 项目: pentaho-kettle   文件: ImportRulesDialog.java
/**
 * 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 );
    }

  }
}
 
@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);
        }
    }
}
 
源代码13 项目: elexis-3-core   文件: ExportTemplateCommand.java
@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;
}
 
源代码14 项目: translationstudio8   文件: TMXValidatorDialog.java
/**
 * 打开文件
 */
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);
	}
}
 
源代码15 项目: translationstudio8   文件: TMXValidatorDialog.java
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);
	}
}
 
源代码16 项目: gama   文件: FileOpen.java
@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;
}
 
源代码17 项目: tmxeditor8   文件: TmxValidatorDialog.java
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);
}
 
源代码18 项目: http4e   文件: ImportLiveHttpHeadersAction.java
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);
      }
   }
 
源代码19 项目: tmxeditor8   文件: ExportAsHtmlHandler.java
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;
}
 
@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;
}