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();
}
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();
}
}
}
});
}
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);
}
}
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);
}
}
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);
}
}
Aggregations