org.eclipse.swt.widgets.FileDialog Java Examples

The following examples show how to use org.eclipse.swt.widgets.FileDialog. 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 Project: hop   Author: project-hop   File: SasInputDialog.java    License: Apache License 2.0 6 votes vote down vote up
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 );
  }
}
 
Example #2
Source Project: translationstudio8   Author: heartsome   File: XSLTransformationDialog.java    License: 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 #3
Source Project: tmxeditor8   Author: heartsome   File: XSLTransformationDialog.java    License: 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 Project: astor   Author: SpoonLabs   File: ChartComposite.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart
 * in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
public void doSaveAs() throws IOException {
    FileDialog fileDialog = new FileDialog(this.canvas.getShell(), 
            SWT.SAVE);
    String[] extensions = { "*.png" };
    fileDialog.setFilterExtensions(extensions);
    String filename = fileDialog.open();
    if (filename != null) {
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        //TODO replace getSize by getBounds ?
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart, 
                this.canvas.getSize().x, this.canvas.getSize().y);
    }
}
 
Example #5
Source Project: tracecompass   Author: tracecompass   File: FilterView.java    License: 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 #6
Source Project: pmTrans   Author: juanerasmoe   File: PmTrans.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void importText() {
	if (!textEditor.isDisposed()) {
		FileDialog fd = new FileDialog(shell, SWT.OPEN);
		fd.setText("Open");
		String[] filterExt = { "*.txt;*.TXT" };
		String[] filterNames = { "TXT files" };
		fd.setFilterExtensions(filterExt);
		fd.setFilterNames(filterNames);
		String lastPath = Config.getInstance().getString(Config.LAST_OPEN_TEXT_PATH);
		if (lastPath != null && !lastPath.isEmpty())
			fd.setFileName(lastPath);
		String selected = fd.open();
		if (selected != null) {
			importTextFile(new File(selected));
			Config.getInstance().putValue(Config.LAST_OPEN_TEXT_PATH, selected);
			try {
				Config.getInstance().save();
			} catch (IOException e) {
				// The user do not NEED to know about this...
			}
		}
	}
}
 
Example #7
Source Project: birt   Author: eclipse   File: ClassPathBlock.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static IPath configureExternalJAREntry( Shell shell,
		IPath initialEntry )
{
	if ( initialEntry == null )
	{
		throw new IllegalArgumentException( );
	}

	String lastUsedPath = initialEntry.removeLastSegments( 1 ).toOSString( );

	FileDialog dialog = new FileDialog( shell, SWT.SINGLE );
	dialog.setText( Messages.getString( "ClassPathBlock_FileDialog.edit.text" ) ); //$NON-NLS-1$
	dialog.setFilterExtensions( JAR_ZIP_FILTER_EXTENSIONS );
	dialog.setFilterPath( lastUsedPath );
	dialog.setFileName( initialEntry.lastSegment( ) );

	String res = dialog.open( );
	if ( res == null )
	{
		return null;
	}
	//lastUsedPath = dialog.getFilterPath( );

	return Path.fromOSString( res ).makeAbsolute( );
}
 
Example #8
Source Project: neoscada   Author: eclipse   File: HiveTab.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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 ();
    }
}
 
Example #9
Source Project: ECG-Viewer   Author: CBLRIT   File: ChartComposite.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart
 * in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
public void doSaveAs() throws IOException {
    FileDialog fileDialog = new FileDialog(this.canvas.getShell(),
            SWT.SAVE);
    String[] extensions = {"*.png"};
    fileDialog.setFilterExtensions(extensions);
    String filename = fileDialog.open();
    if (filename != null) {
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        //TODO replace getSize by getBounds ?
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
                this.canvas.getSize().x, this.canvas.getSize().y);
    }
}
 
Example #10
Source Project: tracecompass   Author: tracecompass   File: XMLAnalysesManagerPreferencePage.java    License: 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 #11
Source Project: http4e   Author: nextinterfaces   File: ParamsAttachManager.java    License: Apache License 2.0 6 votes vote down vote up
public void widgetSelected( SelectionEvent event){
   FileDialog fd = new FileDialog(st.getShell(), SWT.OPEN);
   fd.setText("Add File Parameter");
   fd.setFilterExtensions(CoreConstants.FILE_FILTER_EXT);
   String file = fd.open();

   if (file != null) {
      if (manager.isMultipart()) {
         st.setText(st.getText() + CoreConstants.FILE_PREFIX + file);
      } else {
         try {
            st.setText(readFileAsString(file));
         } catch (IOException e) {
            // ignore
         }
      }
      // 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 Project: astor   Author: SpoonLabs   File: ChartComposite.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart
 * in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
public void doSaveAs() throws IOException {
    FileDialog fileDialog = new FileDialog(this.canvas.getShell(),
            SWT.SAVE);
    String[] extensions = {"*.png"};
    fileDialog.setFilterExtensions(extensions);
    String filename = fileDialog.open();
    if (filename != null) {
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        //TODO replace getSize by getBounds ?
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
                this.canvas.getSize().x, this.canvas.getSize().y);
    }
}
 
Example #13
Source Project: http4e   Author: nextinterfaces   File: ExportHTTP4eAction.java    License: 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 #14
Source Project: tracecompass   Author: tracecompass   File: ExportToTextCommandHandler.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    List<TmfEventTableColumn> columns = getColumns(event.getApplicationContext());
    ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
    ITmfFilter filter = TmfTraceManager.getInstance().getCurrentTraceContext().getFilter();
    if (trace != null) {
        FileDialog fd = TmfFileDialogFactory.create(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
        fd.setFilterExtensions(new String[] { "*.csv", "*.*", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        fd.setOverwrite(true);
        final String s = fd.open();
        if (s != null) {
            Job j = new ExportToTextJob(trace, filter, columns, s);
            j.setUser(true);
            j.schedule();
        }
    }
    return null;
}
 
Example #15
Source Project: olca-app   Author: GreenDelta   File: FileChooser.java    License: 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 #16
Source Project: ermaster-b   Author: naoki-iwami   File: Activator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * �ۑ��_�C�A���O��\�����܂�
 *
 * @param filePath
 *            �f�t�H���g�̃t�@�C���p�X
 * @param filterExtensions
 *            �g���q
 * @return �ۑ��_�C�A���O�őI�����ꂽ�t�@�C���̃p�X
 */
public static String showSaveDialog(String filePath,
		String[] filterExtensions) {
	String dir = null;
	String fileName = null;

	if (filePath != null && !"".equals(filePath.trim())) {
		File file = new File(filePath.trim());

		dir = file.getParent();
		fileName = file.getName();
	}

	FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getShell(), SWT.SAVE);

	fileDialog.setFilterPath(dir);
	fileDialog.setFileName(fileName);

	fileDialog.setFilterExtensions(filterExtensions);

	return fileDialog.open();
}
 
Example #17
Source Project: SIMVA-SoS   Author: SESoS   File: ChartComposite.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Opens a file chooser and gives the user an opportunity to save the chart
 * in PNG format.
 *
 * @throws IOException if there is an I/O error.
 */
public void doSaveAs() throws IOException {
    FileDialog fileDialog = new FileDialog(this.canvas.getShell(),
            SWT.SAVE);
    String[] extensions = {"*.png"};
    fileDialog.setFilterExtensions(extensions);
    String filename = fileDialog.open();
    if (filename != null) {
        if (isEnforceFileExtensions()) {
            if (!filename.endsWith(".png")) {
                filename = filename + ".png";
            }
        }
        //TODO replace getSize by getBounds ?
        ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
                this.canvas.getSize().x, this.canvas.getSize().y);
    }
}
 
Example #18
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 #19
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: BuildPathDialogAccess.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Shows the UI to configure an external JAR or ZIP archive.
 * The dialog returns the configured or <code>null</code> if the dialog has
 * been canceled. The dialog does not apply any changes.
 *
 * @param shell The parent shell for the dialog.
 * @param initialEntry The path of the initial archive entry.
 * @return Returns the configured external JAR path or <code>null</code> if the dialog has
 * been canceled by the user.
 */
public static IPath configureExternalJAREntry(Shell shell, IPath initialEntry) {
	if (initialEntry == null) {
		throw new IllegalArgumentException();
	}

	String lastUsedPath= initialEntry.removeLastSegments(1).toOSString();

	FileDialog dialog= new FileDialog(shell, SWT.SINGLE);
	dialog.setText(NewWizardMessages.BuildPathDialogAccess_ExtJARArchiveDialog_edit_title);
	dialog.setFilterExtensions(ArchiveFileFilter.JAR_ZIP_FILTER_EXTENSIONS);
	dialog.setFilterPath(lastUsedPath);
	dialog.setFileName(initialEntry.lastSegment());

	String res= dialog.open();
	if (res == null) {
		return null;
	}
	JavaPlugin.getDefault().getDialogSettings().put(IUIConstants.DIALOGSTORE_LASTEXTJAR, dialog.getFilterPath());

	return Path.fromOSString(res).makeAbsolute();
}
 
Example #20
Source Project: birt   Author: eclipse   File: JdbcDriverManagerDialog.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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( );
	}
}
 
Example #21
Source Project: tmxeditor8   Author: heartsome   File: PluginConfigManageDialog.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 选择文件
 * @param title
 * @param extensions
 * @param names
 * @return ;
 */
private String browseFile(String title, String[] extensions, String[] names) {
	FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
	fd.setText(title);
	if (extensions != null) {
		fd.setFilterExtensions(extensions);
	}
	if (names != null) {
		fd.setFilterNames(names);
	}
	return fd.open();
}
 
Example #22
Source Project: gama   Author: gama-platform   File: ImportProjectWizardPage.java    License: 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 #23
Source Project: birt   Author: eclipse   File: ScriptMainTab.java    License: 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 #24
Source Project: nebula   Author: eclipse   File: AbstractPictureControl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Configure the {@link FileDialog} to set the file extension, the text,
 * etc. This method can be override to custome the configuration.
 *
 * @param fd
 */
protected void configure(FileDialog fd) {
	fd.setText(resources.getString(PICTURE_CONTROL_FILEDIALOG_TEXT));
	if (extensions != null) {
		fd.setFilterExtensions(extensions);
	}
}
 
Example #25
Source Project: APICloud-Studio   Author: apicloudcom   File: FormatterModifyDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void saveButtonPressed()
{
	// IProfileStore store = formatterFactory.getProfileStore();
	IProfileStore store = ProfileManager.getInstance().getProfileStore();
	IProfile selected = manager.create(dialogOwner.getProject(), ProfileKind.TEMPORARY,
			fProfileNameField.getText(), getPreferences(), profile.getVersion());

	final FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
	dialog.setText(FormatterMessages.FormatterModifyDialog_exportProfile);
	dialog.setFilterExtensions(new String[] { "*.xml" }); //$NON-NLS-1$

	final String path = dialog.open();
	if (path == null)
		return;

	final File file = new File(path);
	String message = NLS.bind(FormatterMessages.FormatterModifyDialog_replaceFileQuestion, file.getAbsolutePath());
	if (file.exists()
			&& !MessageDialog.openQuestion(getShell(), FormatterMessages.FormatterModifyDialog_exportProfile,
					message))
	{
		return;
	}

	final Collection<IProfile> profiles = new ArrayList<IProfile>();
	profiles.add(selected);
	try
	{
		// TODO - WRITE ALL PROFILES
		store.writeProfilesToFile(profiles, file);
	}
	catch (CoreException e)
	{
		final String title = FormatterMessages.FormatterModifyDialog_exportProfile;
		message = FormatterMessages.FormatterModifyDialog_exportProblem;
		ExceptionHandler.handle(e, getShell(), title, message);
	}
}
 
Example #26
Source Project: elexis-3-core   Author: elexis   File: PerspektiveExportHandler.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
	FileDialog dialog = new FileDialog(UiDesk.getTopShell(), SWT.SAVE);
	dialog.setFilterNames(new String[] {
		"XMI"
	});
	dialog.setFilterExtensions(new String[] {
		"*.xmi"
	});
	
	dialog.setFilterPath(CoreHub.getWritableUserDir().getAbsolutePath());
	dialog.setFileName("perspective_export.xmi");
	
	String path = dialog.open();
	if (path != null) {
		try {
			perspectiveExportService.exportPerspective(path, null, null);
			MessageDialog.openInformation(UiDesk.getDisplay().getActiveShell(), "Export",
				"Die aktuelle Perspektive wurde erfolgreich exportiert.");
		} catch (IOException e) {
			MessageDialog.openError(UiDesk.getDisplay().getActiveShell(), "Export",
				"Die aktuelle Perspektive kann nicht exportiert werden.");
			LoggerFactory.getLogger(PerspektiveExportHandler.class).error("export error", e);
		}
	}
	return null;
}
 
Example #27
Source Project: tmxeditor8   Author: heartsome   File: ExportToExcelCommandHandler.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Override this to plugin custom OutputStream.
 */
protected OutputStream getOutputStream(ExportToExcelCommand command) throws IOException {
	FileDialog dialog = new FileDialog (command.getShell(), SWT.SAVE);
	dialog.setFilterPath ("/");
	dialog.setOverwrite(true);

	dialog.setFileName ("table_export.xls");
	dialog.setFilterExtensions(new String [] {"Microsoft Office Excel Workbook(.xls)"});
	String fileName = dialog.open();
	if(fileName == null){
		return null;
	}
	return new PrintStream(fileName);
}
 
Example #28
Source Project: birt   Author: eclipse   File: ImageDialog.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void createLocalBrowseButton( Composite innerComp )
{
	browseButton = new Button( innerComp, SWT.PUSH );
	browseButton.setText( Messages.getString( "ImageDialog.label.Browse" ) ); //$NON-NLS-1$
	browseButton.setLayoutData( new GridData( GridData.HORIZONTAL_ALIGN_END ) );
	browseButton.addSelectionListener( new SelectionAdapter( ) {

		@Override
		public void widgetSelected( SelectionEvent event )
		{
			FileDialog fileChooser = new FileDialog( getShell( ),
					SWT.OPEN );
			fileChooser.setText( Messages.getString( "ImageDialog.label.SelectFile" ) ); //$NON-NLS-1$
			fileChooser.setFilterExtensions( new String[]{
					"*.gif", "*.jpg", "*.png" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
			} );
			try
			{
				String fullPath = fileChooser.open( );
				if ( fullPath != null )
				{
					String fileName = fileChooser.getFileName( );
					if ( fileName != null )
					{
						imageData = null;
						fullPath = new StringBuffer( "file:///" ).append( fullPath ).toString( ); //$NON-NLS-1$
						uriEditor.setText( fullPath );
					}
				}
			}
			catch ( Throwable e )
			{
				e.printStackTrace( );
			}
		}
	} );
}
 
Example #29
Source Project: Eclipse-Postfix-Code-Completion   Author: trylimits   File: ModifyDialog.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void saveButtonPressed() {
	Profile selected= new CustomProfile(fProfileNameField.getText(), new HashMap<String, String>(fWorkingValues), fProfile.getVersion(), fProfileManager.getProfileVersioner().getProfileKind());

	final FileDialog dialog= new FileDialog(getShell(), SWT.SAVE);
	dialog.setText(FormatterMessages.CodingStyleConfigurationBlock_save_profile_dialog_title);
	dialog.setFilterExtensions(new String [] {"*.xml"}); //$NON-NLS-1$

	final String lastPath= JavaPlugin.getDefault().getDialogSettings().get(fLastSaveLoadPathKey + ".savepath"); //$NON-NLS-1$
	if (lastPath != null) {
		dialog.setFilterPath(lastPath);
	}
	final String path= dialog.open();
	if (path == null)
		return;

	JavaPlugin.getDefault().getDialogSettings().put(fLastSaveLoadPathKey + ".savepath", dialog.getFilterPath()); //$NON-NLS-1$

	final File file= new File(path);
	if (file.exists() && !MessageDialog.openQuestion(getShell(), FormatterMessages.CodingStyleConfigurationBlock_save_profile_overwrite_title, Messages.format(FormatterMessages.CodingStyleConfigurationBlock_save_profile_overwrite_message, BasicElementLabels.getPathLabel(file)))) {
		return;
	}
	String encoding= ProfileStore.ENCODING;
	final IContentType type= Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.xml"); //$NON-NLS-1$
	if (type != null)
		encoding= type.getDefaultCharset();
	final Collection<Profile> profiles= new ArrayList<Profile>();
	profiles.add(selected);
	try {
		fProfileStore.writeProfilesToFile(profiles, file, encoding);
	} catch (CoreException e) {
		final String title= FormatterMessages.CodingStyleConfigurationBlock_save_profile_error_title;
		final String message= FormatterMessages.CodingStyleConfigurationBlock_save_profile_error_message;
		ExceptionHandler.handle(e, getShell(), title, message);
	}
}
 
Example #30
Source Project: tmxeditor8   Author: heartsome   File: TMXValidatorDialog.java    License: 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);
	}
}