下面列出了org.eclipse.swt.widgets.FileDialog#getFilterPath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void get() {
try {
// As the user for a file to use as a reference
//
FileDialog dialog = new FileDialog( shell, SWT.OPEN );
dialog.setFilterExtensions( new String[] { "*.sas7bdat;*.SAS7BDAT", "*.*" } );
dialog.setFilterNames( new String[] {
BaseMessages.getString( PKG, "SASInputDialog.FileType.SAS7BAT" ) + ", "
+ BaseMessages.getString( PKG, "System.FileType.TextFiles" ),
BaseMessages.getString( PKG, "System.FileType.CSVFiles" ),
BaseMessages.getString( PKG, "System.FileType.TextFiles" ),
BaseMessages.getString( PKG, "System.FileType.AllFiles" ) } );
if ( dialog.open() != null ) {
String filename = dialog.getFilterPath() + System.getProperty( "file.separator" ) + dialog.getFileName();
SasInputHelper helper = new SasInputHelper( filename );
BaseTransformDialog.getFieldsFromPrevious(
helper.getRowMeta(), wFields, 1, new int[] { 1 }, new int[] { 3 }, 4, 5, null );
}
} catch ( Exception e ) {
new ErrorDialog( shell, "Error", "Error reading information from file", e );
}
}
protected void chooseFile ()
{
final FileDialog dlg = new FileDialog ( getShell (), SWT.OPEN | SWT.MULTI );
dlg.setFilterExtensions ( new String[] { "*.xml", "*.*" } );
dlg.setFilterNames ( new String[] { "Eclipse NeoSCADA Exporter Files", "All files" } );
final String result = dlg.open ();
if ( result != null )
{
final File base = new File ( dlg.getFilterPath () );
for ( final String name : dlg.getFileNames () )
{
this.fileText.setText ( new File ( base, name ).getAbsolutePath () );
}
makeDirty ();
}
}
public void exportAll( RepositoryDirectoryInterface dir ) {
FileDialog dialog = Spoon.getInstance().getExportFileDialog(); // new FileDialog( shell, SWT.SAVE | SWT.SINGLE );
if ( dialog.open() == null ) {
return;
}
String filename = dialog.getFilterPath() + Const.FILE_SEPARATOR + dialog.getFileName();
// check if file is exists
MessageBox box = RepositoryExportProgressDialog.checkIsFileIsAcceptable( shell, log, filename );
int answer = ( box == null ) ? SWT.OK : box.open();
if ( answer != SWT.OK ) {
// seems user don't want to overwrite file...
return;
}
if ( log.isBasic() ) {
log.logBasic( "Exporting All", "Export objects to file [" + filename + "]" ); //$NON-NLS-3$
}
// check file is not empty
RepositoryExportProgressDialog repd = new RepositoryExportProgressDialog( shell, rep, dir, filename );
repd.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);
}
}
}
public void get() {
try {
// As the user for a file to use as a reference
//
FileDialog dialog = new FileDialog( shell, SWT.OPEN );
dialog.setFilterExtensions( new String[] { "*.sas7bdat;*.SAS7BDAT", "*.*" } );
dialog.setFilterNames( new String[] {
BaseMessages.getString( PKG, "SASInputDialog.FileType.SAS7BAT" ) + ", "
+ BaseMessages.getString( PKG, "System.FileType.TextFiles" ),
BaseMessages.getString( PKG, "System.FileType.CSVFiles" ),
BaseMessages.getString( PKG, "System.FileType.TextFiles" ),
BaseMessages.getString( PKG, "System.FileType.AllFiles" ) } );
if ( dialog.open() != null ) {
String filename = dialog.getFilterPath() + System.getProperty( "file.separator" ) + dialog.getFileName();
SasInputHelper helper = new SasInputHelper( filename );
BaseStepDialog.getFieldsFromPrevious(
helper.getRowMeta(), wFields, 1, new int[] { 1 }, new int[] { 3 }, 4, 5, null );
}
} catch ( Exception e ) {
new ErrorDialog( shell, "Error", "Error reading information from file", e );
}
}
/**
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog fDialog = new FileDialog(getShell(), SWT.MULTI);
fDialog.setFilterExtensions(new String[] { "*.tmx" });
fDialog.open();
String filterPath = fDialog.getFilterPath();
String[] fileNames = fDialog.getFileNames();
if (fileNames == null || fileNames.length == 0) {
return;
}
String absolutePath = null;
for (String fileName : fileNames) {
absolutePath = new File(filterPath + File.separator + fileName).getAbsolutePath();
if (Arrays.asList(tmxList.getItems()).contains(absolutePath)) {
continue;
}
tmxList.add(absolutePath);
}
setOkState();
}
/**
* actions after add button is click in jarPage
*/
private void addJars( )
{
jarChanged=true;
FileDialog dlg = new FileDialog( getShell( ), SWT.MULTI );
dlg.setFilterExtensions( new String[]{
"*.jar", "*.zip" //$NON-NLS-1$, $NON-NLS-2$
} );
if ( dlg.open( ) != null )
{
String jarNames[] = dlg.getFileNames( );
String folder = dlg.getFilterPath( ) + File.separator;
for( int i = 0; i < jarNames.length; i++ )
{
addSingleJar( folder + jarNames[i], jarNames[i] );
}
refreshJarViewer( );
updateJarButtons( );
}
}
public static String browseFile(Shell shell, boolean browseForSave, String text, String[] filterExt, String preferredPath) {
FileDialog fd = new FileDialog(shell, browseForSave ? SWT.SAVE : SWT.OPEN);
fd.setText(text);
fd.setFilterPath(mkPrefPath(preferredPath));
fd.setFilterExtensions(filterExt);
String res = fd.open();
lastBrowsePath = fd.getFilterPath();
return res; // null => cancel
}
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;
}
/**
* 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 );
}
}
}
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"));
}
}
}
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final FileDialog fd = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN | SWT.MULTI);
fd.setFilterExtensions(new String[] { "*.jar;*.zip" });
if (filenames != null) {
fd.setFilterNames(filenames);
}
if (fd.open() != null) {
final DependencyRepositoryStore libStore = RepositoryManager.getInstance().getRepositoryStore(DependencyRepositoryStore.class);
final String[] jars = fd.getFileNames();
final IProgressService progressManager = PlatformUI.getWorkbench().getProgressService();
final IRunnableWithProgress runnable = new ImportLibsOperation(libStore, jars, fd.getFilterPath());
try {
progressManager.run(true, false, runnable);
progressManager.run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
RepositoryManager.getInstance().getCurrentRepository().build(monitor);
}
});
} catch (final InvocationTargetException e1) {
BonitaStudioLog.error(e1);
if (e1.getCause() != null && e1.getCause().getMessage() != null) {
MessageDialog.openError(Display.getDefault().getActiveShell(), org.bonitasoft.studio.dependencies.i18n.Messages.importJar, e1.getCause()
.getMessage());
}
} catch (final InterruptedException e2) {
BonitaStudioLog.error(e2);
}
}
return fd.getFileNames();
}
public static IPath[] chooseExternalJAREntries( Shell shell )
{
if ( lastUsedPath == null )
{
lastUsedPath = ""; //$NON-NLS-1$
}
FileDialog dialog = new FileDialog( shell, SWT.MULTI );
dialog.setText( Messages.getString( "ClassPathBlock_FileDialog.jar.text" ) ); //$NON-NLS-1$
dialog.setFilterExtensions( ALL_ARCHIVES_FILTER_EXTENSIONS );
dialog.setFilterPath( lastUsedPath );
String res = dialog.open( );
if ( res == null )
{
return null;
}
String[] fileNames = dialog.getFileNames( );
int nChosen = fileNames.length;
IPath filterPath = Path.fromOSString( dialog.getFilterPath( ) );
IPath[] elems = new IPath[nChosen];
for ( int i = 0; i < nChosen; i++ )
{
elems[i] = filterPath.append( fileNames[i] ).makeAbsolute( );
}
lastUsedPath = dialog.getFilterPath( );
return elems;
}
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;
}
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;
}
/**
*
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
/*
* Open dialog for asking the user to enter some file names.
*/
FileDialog dialog = new FileDialog(this.window.getShell(), SWT.MULTI);
String[] individualFilters = Extensions
.getFiltersFromExtensions(Extensions.getMMPMDomainFileExtensions());
String[] unifiedFilter = new String[] { Extensions
.getUnifiedFilterFromExtensions(Extensions
.getMMPMDomainFileExtensions()) };
String[] filtersToUse = Extensions.joinArrays(individualFilters,
unifiedFilter);
dialog.setFilterExtensions(filtersToUse);
dialog.setText("Open BT");
if (dialog.open() != null) {
/* Get the name of the files (NOT absolute path). */
String[] singleNames = dialog.getFileNames();
/*
* This vector will store the absolute path of every single selected
* file.
*/
Vector<String> absolutePath = new Vector<String>();
for (int i = 0, n = singleNames.length; i < n; i++) {
StringBuffer buffer = new StringBuffer(dialog.getFilterPath());
if (buffer.charAt(buffer.length() - 1) != File.separatorChar)
buffer.append(File.separatorChar);
buffer.append(singleNames[i]);
absolutePath.add(buffer.toString());
}
new LoadMMPMDomainAction(absolutePath).run();
}
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
Mandant mandant = ElexisEventDispatcher.getSelectedMandator();
if (mandant == null) {
return null;
}
mandantId = mandant.getId();
IWorkbenchPage activePage =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
TextTemplateView ttView = (TextTemplateView) activePage.findView(TextTemplateView.ID);
ITextPlugin plugin = ttView.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(), SWT.MULTI);
fdl.setFilterExtensions(new String[] {
MimeTypeUtil.getExtensions(mimeType)
});
fdl.setFilterNames(new String[] {
MimeTypeUtil.getPrettyPrintName(mimeType)
});
fdl.open();
String[] fileNames = fdl.getFileNames();
String filterPath = fdl.getFilterPath() + File.separator;
if (fileNames.length > 0) {
for (String filename : fileNames) {
File file = new File(filterPath + filename);
if (file.exists()) {
String name = filename.substring(0, filename.lastIndexOf('.'));
TextTemplate sysTemplate = matchesRequiredSystemTemplate(
ttView.getRequiredTextTemplates(), name, mimeType);
// check existence of same template
List<Brief> equivalentTemplates =
TextTemplate.findExistingTemplates(sysTemplate != null, name, mimeType,
mandantId);
boolean replaceExisting = false;
if (equivalentTemplates != null && !equivalentTemplates.isEmpty()) {
TextTemplateImportConflictDialog ttiConflictDialog =
new TextTemplateImportConflictDialog(UiDesk.getTopShell(), name);
ttiConflictDialog.open();
if (ttiConflictDialog.doSkipTemplate()) {
continue;
} else if (ttiConflictDialog.doChangeTemplateName()) {
name = ttiConflictDialog.getNewName();
} else {
replaceExisting = true;
}
}
// perform the actual import
FileInputStream fis = new FileInputStream(file);
byte[] contentToStore = new byte[(int) file.length()];
fis.read(contentToStore);
fis.close();
if (replaceExisting) {
// only switch template content
if (equivalentTemplates instanceof List) {
equivalentTemplates.get(0).save(contentToStore, mimeType);
} else {
logger.error(
"Invalid state: equivalentTemplates is " + equivalentTemplates);
}
} else {
Brief template =
new Brief(name, null, CoreHub.getLoggedInContact(), null, null, Brief.TEMPLATE);
template.save(contentToStore, mimeType);
// add general form tempalte
if (sysTemplate == null) {
template.setAdressat(mandant.getId());
TextTemplate tt = new TextTemplate(name, "", mimeType);
tt.addFormTemplateReference(template);
ttView.update(tt);
} else {
// add system template
sysTemplate.addSystemTemplateReference(template);
ttView.update(sysTemplate);
}
}
}
}
}
} catch (Throwable ex) {
ExHandler.handle(ex);
logger.error("Error during import of text templates", ex);
}
ElexisEventDispatcher.getInstance()
.fire(new ElexisEvent(Brief.class, null, ElexisEvent.EVENT_RELOAD,
ElexisEvent.PRIORITY_NORMAL));
return null;
}
public void importAll() {
FileDialog dialog = new FileDialog( shell, SWT.OPEN | SWT.MULTI );
if ( dialog.open() != null ) {
// Ask for a destination in the repository...
//
SelectDirectoryDialog sdd = new SelectDirectoryDialog( shell, SWT.NONE, rep );
RepositoryDirectoryInterface baseDirectory = sdd.open();
if ( baseDirectory != null ) {
// Finally before importing, ask for a version comment (if applicable)
//
String versionComment = null;
boolean versionOk = false;
while ( !versionOk ) {
versionComment =
RepositorySecurityUI.getVersionComment( shell, rep, "Import of files into ["
+ baseDirectory.getPath() + "]", "", true );
// if the version comment is null, the user hit cancel, exit.
if ( rep != null
&& rep.getSecurityProvider() != null && versionComment == null ) {
return;
}
if ( Utils.isEmpty( versionComment ) && rep.getSecurityProvider().isVersionCommentMandatory() ) {
if ( !RepositorySecurityUI.showVersionCommentMandatoryDialog( shell ) ) {
versionOk = true;
}
} else {
versionOk = true;
}
}
String[] filenames = dialog.getFileNames();
if ( filenames.length > 0 ) {
RepositoryImportProgressDialog ripd =
new RepositoryImportProgressDialog(
shell, SWT.NONE, rep, dialog.getFilterPath(), filenames, baseDirectory, versionComment );
ripd.open();
refreshTree();
}
}
}
}
/**
* Opens a new {@link FileDialog} and imports any selected files into the
* ICE project space.
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Get the window and the shell.
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
Shell shell = window.getShell();
// Get the IProject instance if we can
IProject project = null;
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof IResource) {
project = ((IResource) element).getProject();
}
}
// Get the Client
IClient client = null;
try {
client = IClient.getClient();
} catch (CoreException e) {
logger.error("Could not get a valid IClient reference.", e);
}
// Make sure we got a valid IClient
if (client != null) {
// Create the dialog and get the files
FileDialog fileDialog = new FileDialog(shell, SWT.MULTI);
fileDialog.setText("Select a file to import into ICE");
fileDialog.open();
// Import the files
String filterPath = fileDialog.getFilterPath();
for (String name : fileDialog.getFileNames()) {
File importedFile = new File(filterPath, name);
if (project == null) {
client.importFile(importedFile.toURI());
} else {
client.importFile(importedFile.toURI(), project);
}
}
} else {
logger.error("Could not find a valid IClient.");
}
return null;
}
/**
*
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
/*
* Open dialog for asking the user to enter some file names.
*/
FileDialog dialog = new FileDialog(this.window.getShell(), SWT.MULTI);
String[] individualFilters = Extensions
.getFiltersFromExtensions(Extensions.getBTFileExtensions());
String[] unifiedFilter = new String[] { Extensions
.getUnifiedFilterFromExtensions(Extensions
.getBTFileExtensions()) };
String[] filtersToUse = Extensions.joinArrays(individualFilters,
unifiedFilter);
dialog.setFilterExtensions(filtersToUse);
dialog.setText("Open BT");
/*
* If the user has selected at least one file name, we must open it.
* Note that the user may select several files.
*/
if (dialog.open() != null) {
/* Get the name of the files (NOT absolute path). */
String[] singleNames = dialog.getFileNames();
/*
* This vector will store the absolute path of every single selected
* file.
*/
Vector<String> absolutePath = new Vector<String>();
for (int i = 0, n = singleNames.length; i < n; i++) {
StringBuffer buffer = new StringBuffer(dialog.getFilterPath());
if (buffer.charAt(buffer.length() - 1) != File.separatorChar)
buffer.append(File.separatorChar);
buffer.append(singleNames[i]);
absolutePath.add(buffer.toString());
}
new OpenBTAction(absolutePath).run();
}
}