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