Search in sources :

Example 96 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project eclipse.platform.swt by eclipse.

the class ImageAnalyzer method menuLoad.

/* Just use Image(device, filename) to load an image file. */
void menuLoad() {
    // stop any animation in progress
    animate = false;
    // Get the user to choose an image file.
    FileDialog fileChooser = new FileDialog(shell, SWT.OPEN);
    if (lastPath != null)
        fileChooser.setFilterPath(lastPath);
    fileChooser.setFilterExtensions(OPEN_FILTER_EXTENSIONS);
    fileChooser.setFilterNames(OPEN_FILTER_NAMES);
    String filename = fileChooser.open();
    lastPath = fileChooser.getFilterPath();
    if (filename == null)
        return;
    Cursor waitCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);
    imageCanvas.setCursor(waitCursor);
    try {
        // Read the new image from the chosen file.
        long startTime = System.currentTimeMillis();
        Image newImage = new Image(display, filename);
        // don't include getImageData in load time
        loadTime = System.currentTimeMillis() - startTime;
        imageData = newImage.getImageData();
        // Cache the filename.
        currentName = filename;
        fileName = filename;
        // Fill in array and loader data.
        loader = new ImageLoader();
        imageDataArray = new ImageData[] { imageData };
        loader.data = imageDataArray;
        // Display the image.
        imageDataIndex = 0;
        displayImage(imageData);
    } catch (SWTException e) {
        showErrorDialog(bundle.getString("Loading_lc"), filename, e);
    } catch (SWTError e) {
        showErrorDialog(bundle.getString("Loading_lc"), filename, e);
    } catch (OutOfMemoryError e) {
        showErrorDialog(bundle.getString("Loading_lc"), filename, e);
    } finally {
        shell.setCursor(null);
        imageCanvas.setCursor(crossCursor);
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) SWTException(org.eclipse.swt.SWTException) Cursor(org.eclipse.swt.graphics.Cursor) Image(org.eclipse.swt.graphics.Image) ImageLoader(org.eclipse.swt.graphics.ImageLoader) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 97 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project eclipse.platform.swt by eclipse.

the class JavaViewer method openFile.

void openFile() {
    if (fileDialog == null) {
        fileDialog = new FileDialog(shell, SWT.OPEN);
    }
    fileDialog.setFilterExtensions(new String[] { "*.java", "*.*" });
    String name = fileDialog.open();
    open(name);
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 98 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project dbeaver by dbeaver.

the class ERDEditorPart method saveDiagramAs.

public void saveDiagramAs() {
    List<ERDExportFormatRegistry.FormatDescriptor> allFormats = ERDExportFormatRegistry.getInstance().getFormats();
    String[] extensions = new String[allFormats.size()];
    String[] filterNames = new String[allFormats.size()];
    for (int i = 0; i < allFormats.size(); i++) {
        extensions[i] = "*." + allFormats.get(i).getExtension();
        filterNames[i] = allFormats.get(i).getLabel() + " (" + extensions[i] + ")";
    }
    final Shell shell = getSite().getShell();
    FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
    saveDialog.setFilterExtensions(extensions);
    saveDialog.setFilterNames(filterNames);
    String filePath = DialogUtils.openFileDialog(saveDialog);
    if (filePath == null || filePath.trim().length() == 0) {
        return;
    }
    File outFile = new File(filePath);
    if (outFile.exists()) {
        if (!UIUtils.confirmAction(shell, "Overwrite file", "File '" + filePath + "' already exists.\nOverwrite?")) {
            return;
        }
    }
    int divPos = filePath.lastIndexOf('.');
    if (divPos == -1) {
        DBUserInterface.getInstance().showError("ERD export", "No file extension was specified");
        return;
    }
    String ext = filePath.substring(divPos + 1);
    ERDExportFormatRegistry.FormatDescriptor targetFormat = null;
    for (ERDExportFormatRegistry.FormatDescriptor format : allFormats) {
        if (format.getExtension().equals(ext)) {
            targetFormat = format;
            break;
        }
    }
    if (targetFormat == null) {
        DBUserInterface.getInstance().showError("ERD export", "No export format correspond to file extension '" + ext + "'");
        return;
    }
    try {
        ERDExportFormatHandler formatHandler = targetFormat.getInstance();
        IFigure figure = rootPart.getLayer(ScalableFreeformRootEditPart.PRINTABLE_LAYERS);
        formatHandler.exportDiagram(getDiagram(), figure, getDiagramPart(), outFile);
    } catch (DBException e) {
        DBUserInterface.getInstance().showError("ERD export failed", null, e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) ERDExportFormatHandler(org.jkiss.dbeaver.ext.erd.export.ERDExportFormatHandler) Shell(org.eclipse.swt.widgets.Shell) ERDExportFormatRegistry(org.jkiss.dbeaver.ext.erd.export.ERDExportFormatRegistry) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) IFigure(org.eclipse.draw2d.IFigure)

Example 99 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project yamcs-studio by yamcs.

the class ImportCommandStackHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);
    dialog.setFilterExtensions(new String[] { "*.xml" });
    String importFile = dialog.open();
    if (importFile == null) {
        // cancelled
        return null;
    }
    log.log(Level.INFO, "Importing command stack from file: " + importFile);
    // get command stack object
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IWorkbenchPart part = window.getActivePage().findView(CommandStackView.ID);
    CommandStackView commandStackView = (CommandStackView) part;
    // import new commands
    for (StackedCommand sc : parseCommandStack(importFile)) {
        commandStackView.addTelecommand(sc);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 100 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project yamcs-studio by yamcs.

the class FileUtil method saveFileDialog.

/**
 * Open a file save dialog.
 *
 * @param startingFolder
 *            the folder where the file dialog starts.
 * @return the full file path. Or null if it is cancelled.
 */
public static String saveFileDialog(String startingFolder) {
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
    dialog.setFilterPath(startingFolder);
    return dialog.open();
}
Also used : FileDialog(org.eclipse.swt.widgets.FileDialog)

Aggregations

FileDialog (org.eclipse.swt.widgets.FileDialog)512 File (java.io.File)198 SelectionEvent (org.eclipse.swt.events.SelectionEvent)181 Button (org.eclipse.swt.widgets.Button)181 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)160 Label (org.eclipse.swt.widgets.Label)153 Text (org.eclipse.swt.widgets.Text)151 Composite (org.eclipse.swt.widgets.Composite)136 Shell (org.eclipse.swt.widgets.Shell)120 GridData (org.eclipse.swt.layout.GridData)110 ModifyListener (org.eclipse.swt.events.ModifyListener)109 ModifyEvent (org.eclipse.swt.events.ModifyEvent)107 GridLayout (org.eclipse.swt.layout.GridLayout)105 Group (org.eclipse.swt.widgets.Group)90 Event (org.eclipse.swt.widgets.Event)76 Listener (org.eclipse.swt.widgets.Listener)76 Display (org.eclipse.swt.widgets.Display)72 FormAttachment (org.eclipse.swt.layout.FormAttachment)68 FormData (org.eclipse.swt.layout.FormData)68 FormLayout (org.eclipse.swt.layout.FormLayout)68