Search in sources :

Example 91 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project knime-core by knime.

the class WorkflowImportSelectionPage method handleZipBrowseButtonPressed.

private void handleZipBrowseButtonPressed() {
    // open a FileSelection dialog
    FileDialog dialog = new FileDialog(getShell());
    // allow only archive files
    dialog.setFilterExtensions(ZIP_FILE_MASK);
    // set initial location (either an already selected one)
    String fileName = m_fromZipTextUI.getText().trim();
    if (fileName.isEmpty()) {
        // restore
        fileName = initialZipLocation;
    }
    // if still empty -> set to workspace root
    if (fileName.isEmpty()) {
        fileName = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
    }
    File initialPath = new File(fileName);
    if (initialPath.exists()) {
        String filterPath = new Path(initialPath.getParent()).toOSString();
        dialog.setFilterPath(filterPath);
        initialZipLocation = filterPath;
    }
    String selectedFile = dialog.open();
    // null if dialog was canceled/error occurred
    if (selectedFile != null) {
        clear();
        initialZipLocation = selectedFile;
        m_fromZipTextUI.setText(selectedFile);
        // do this in separate thread...
        collectWorkflowsFromZipFile(selectedFile);
    }
    validateWorkflows();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) FileDialog(org.eclipse.swt.widgets.FileDialog) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File)

Example 92 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project knime-core by knime.

the class WrappedNodeDialog method configureShell.

/**
 * Configure shell, create top level menu.
 *
 * {@inheritDoc}
 */
@Override
protected void configureShell(final Shell newShell) {
    super.configureShell(newShell);
    Menu menuBar = new Menu(newShell, SWT.BAR);
    newShell.setMenuBar(menuBar);
    Menu menu = new Menu(newShell, SWT.DROP_DOWN);
    MenuItem rootItem = new MenuItem(menuBar, SWT.CASCADE);
    rootItem.setText("File");
    rootItem.setAccelerator(SWT.MOD1 | 'F');
    rootItem.setMenu(menu);
    final FileDialog openDialog = new FileDialog(newShell, SWT.OPEN);
    final FileDialog saveDialog = new FileDialog(newShell, SWT.SAVE);
    MenuItem itemLoad = new MenuItem(menu, SWT.PUSH);
    itemLoad.setText("Load Settings");
    itemLoad.setAccelerator(SWT.MOD1 | 'L');
    itemLoad.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            String file = openDialog.open();
            if (file != null) {
                NodeContext.pushContext(m_nodeContainer);
                try {
                    m_dialogPane.loadSettingsFrom(new FileInputStream(file));
                } catch (IOException ioe) {
                    showErrorMessage(ioe.getMessage());
                } catch (NotConfigurableException ex) {
                    showErrorMessage(ex.getMessage());
                } finally {
                    NodeContext.removeLastContext();
                }
            }
        }
    });
    MenuItem itemSave = new MenuItem(menu, SWT.PUSH);
    itemSave.setText("Save Settings");
    itemSave.setAccelerator(SWT.MOD1 | 'S');
    itemSave.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            String file = saveDialog.open();
            if (file != null) {
                NodeContext.pushContext(m_nodeContainer);
                try {
                    m_dialogPane.saveSettingsTo(new FileOutputStream(file));
                } catch (IOException ioe) {
                    showErrorMessage(ioe.getMessage());
                    // SWT-AWT-Bridge doesn't properly
                    // repaint after dialog disappears
                    m_dialogPane.getPanel().repaint();
                } catch (InvalidSettingsException ise) {
                    showErrorMessage("Invalid Settings\n" + ise.getMessage());
                    // SWT-AWT-Bridge doesn't properly
                    // repaint after dialog disappears
                    m_dialogPane.getPanel().repaint();
                } finally {
                    NodeContext.removeLastContext();
                }
            }
        }
    });
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FileOutputStream(java.io.FileOutputStream) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) FileInputStream(java.io.FileInputStream)

Example 93 with FileDialog

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

the class ImageAnalyzer method menuSaveMaskAs.

void menuSaveMaskAs() {
    if (image == null || !showMask)
        return;
    if (imageData.getTransparencyType() == SWT.TRANSPARENCY_NONE)
        return;
    // stop any animation in progress
    animate = false;
    // Get the user to choose a file name and type to save.
    FileDialog fileChooser = new FileDialog(shell, SWT.SAVE);
    fileChooser.setFilterPath(lastPath);
    if (fileName != null)
        fileChooser.setFileName(fileName);
    fileChooser.setFilterExtensions(SAVE_FILTER_EXTENSIONS);
    fileChooser.setFilterNames(SAVE_FILTER_NAMES);
    String filename = fileChooser.open();
    lastPath = fileChooser.getFilterPath();
    if (filename == null)
        return;
    // Figure out what file type the user wants saved.
    int filetype = fileChooser.getFilterIndex();
    if (filetype == -1) {
        /* The platform file dialog does not support user-selectable file filters.
			 * Determine the desired type by looking at the file extension.
			 */
        filetype = determineFileType(filename);
        if (filetype == SWT.IMAGE_UNDEFINED) {
            MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);
            box.setMessage(createMsg(bundle.getString("Unknown_extension"), filename.substring(filename.lastIndexOf('.') + 1)));
            box.open();
            return;
        }
    }
    if (new java.io.File(filename).exists()) {
        MessageBox box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
        box.setMessage(createMsg(bundle.getString("Overwrite"), filename));
        if (box.open() == SWT.CANCEL)
            return;
    }
    Cursor waitCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);
    imageCanvas.setCursor(waitCursor);
    try {
        // Save the mask of the current image to the specified file.
        ImageData maskImageData = imageData.getTransparencyMask();
        loader.data = new ImageData[] { maskImageData };
        loader.save(filename, filetype);
    } catch (SWTException e) {
        showErrorDialog(bundle.getString("Saving_lc"), filename, e);
    } catch (SWTError e) {
        showErrorDialog(bundle.getString("Saving_lc"), filename, e);
    } finally {
        shell.setCursor(null);
        imageCanvas.setCursor(crossCursor);
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) SWTException(org.eclipse.swt.SWTException) ImageData(org.eclipse.swt.graphics.ImageData) Cursor(org.eclipse.swt.graphics.Cursor) FileDialog(org.eclipse.swt.widgets.FileDialog) Point(org.eclipse.swt.graphics.Point) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 94 with FileDialog

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

the class ImageAnalyzer method menuOpenFile.

void menuOpenFile() {
    // 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;
    showFileType(filename);
    Cursor waitCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);
    imageCanvas.setCursor(waitCursor);
    ImageLoader oldLoader = loader;
    try {
        loader = new ImageLoader();
        if (incremental) {
            // Prepare to handle incremental events.
            loader.addImageLoaderListener(event -> incrementalDataLoaded(event));
            incrementalThreadStart();
        }
        // Read the new image(s) from the chosen file.
        long startTime = System.currentTimeMillis();
        imageDataArray = loader.load(filename);
        loadTime = System.currentTimeMillis() - startTime;
        if (imageDataArray.length > 0) {
            // Cache the filename.
            currentName = filename;
            fileName = filename;
            // If there are multiple images in the file (typically GIF)
            // then enable the Previous, Next and Animate buttons.
            previousButton.setEnabled(imageDataArray.length > 1);
            nextButton.setEnabled(imageDataArray.length > 1);
            animateButton.setEnabled(imageDataArray.length > 1 && loader.logicalScreenWidth > 0 && loader.logicalScreenHeight > 0);
            // Display the first image in the file.
            imageDataIndex = 0;
            displayImage(imageDataArray[imageDataIndex]);
        }
    } catch (SWTException e) {
        showErrorDialog(bundle.getString("Loading_lc"), filename, e);
        loader = oldLoader;
    } catch (SWTError e) {
        showErrorDialog(bundle.getString("Loading_lc"), filename, e);
        loader = oldLoader;
    } catch (OutOfMemoryError e) {
        showErrorDialog(bundle.getString("Loading_lc"), filename, e);
        loader = oldLoader;
    } 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) ImageLoader(org.eclipse.swt.graphics.ImageLoader) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 95 with FileDialog

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

the class ImageAnalyzer method menuSaveAs.

void menuSaveAs() {
    if (image == null)
        return;
    // stop any animation in progress
    animate = false;
    // Get the user to choose a file name and type to save.
    FileDialog fileChooser = new FileDialog(shell, SWT.SAVE);
    fileChooser.setFilterPath(lastPath);
    if (fileName != null) {
        String name = fileName;
        int nameStart = name.lastIndexOf(java.io.File.separatorChar);
        if (nameStart > -1) {
            name = name.substring(nameStart + 1);
        }
        fileChooser.setFileName(name.substring(0, name.indexOf(".")) + "." + imageTypeCombo.getText().toLowerCase());
    }
    fileChooser.setFilterExtensions(SAVE_FILTER_EXTENSIONS);
    fileChooser.setFilterNames(SAVE_FILTER_NAMES);
    switch(imageTypeCombo.getSelectionIndex()) {
        case 0:
            fileChooser.setFilterIndex(4);
            break;
        case 1:
            fileChooser.setFilterIndex(5);
            break;
        case 2:
            fileChooser.setFilterIndex(2);
            break;
        case 3:
            fileChooser.setFilterIndex(3);
            break;
        case 4:
            fileChooser.setFilterIndex(6);
            break;
        case 5:
            fileChooser.setFilterIndex(0);
            break;
    }
    String filename = fileChooser.open();
    lastPath = fileChooser.getFilterPath();
    if (filename == null)
        return;
    // Figure out what file type the user wants saved.
    int filetype = fileChooser.getFilterIndex();
    if (filetype == -1) {
        /* The platform file dialog does not support user-selectable file filters.
			 * Determine the desired type by looking at the file extension.
			 */
        filetype = determineFileType(filename);
        if (filetype == SWT.IMAGE_UNDEFINED) {
            MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);
            box.setMessage(createMsg(bundle.getString("Unknown_extension"), filename.substring(filename.lastIndexOf('.') + 1)));
            box.open();
            return;
        }
    }
    if (new java.io.File(filename).exists()) {
        MessageBox box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
        box.setMessage(createMsg(bundle.getString("Overwrite"), filename));
        if (box.open() == SWT.CANCEL)
            return;
    }
    Cursor waitCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);
    imageCanvas.setCursor(waitCursor);
    try {
        // Save the current image to the specified file.
        boolean multi = false;
        if (loader.data.length > 1) {
            MessageBox box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.CANCEL);
            box.setMessage(createMsg(bundle.getString("Save_all"), Integer.valueOf(loader.data.length)));
            int result = box.open();
            if (result == SWT.CANCEL)
                return;
            if (result == SWT.YES)
                multi = true;
        }
        /* If the image has transparency but the user has transparency turned off,
			 * turn it off in the saved image. */
        int transparentPixel = imageData.transparentPixel;
        if (!multi && transparentPixel != -1 && !transparent) {
            imageData.transparentPixel = -1;
        }
        if (!multi)
            loader.data = new ImageData[] { imageData };
        loader.compression = compressionCombo.indexOf(compressionCombo.getText());
        loader.save(filename, filetype);
        /* Restore the previous transparency setting. */
        if (!multi && transparentPixel != -1 && !transparent) {
            imageData.transparentPixel = transparentPixel;
        }
        // Update the shell title and file type label,
        // and use the new file.
        fileName = filename;
        shell.setText(createMsg(bundle.getString("Analyzer_on"), filename));
        typeLabel.setText(createMsg(bundle.getString("Type_string"), fileTypeString(filetype)));
    } catch (SWTException e) {
        showErrorDialog(bundle.getString("Saving_lc"), filename, e);
    } catch (SWTError e) {
        showErrorDialog(bundle.getString("Saving_lc"), filename, e);
    } finally {
        shell.setCursor(null);
        imageCanvas.setCursor(crossCursor);
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) SWTException(org.eclipse.swt.SWTException) ImageData(org.eclipse.swt.graphics.ImageData) Cursor(org.eclipse.swt.graphics.Cursor) FileDialog(org.eclipse.swt.widgets.FileDialog) Point(org.eclipse.swt.graphics.Point) MessageBox(org.eclipse.swt.widgets.MessageBox)

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