use of org.jkiss.dbeaver.ext.erd.export.ERDExportFormatHandler 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);
}
}
Aggregations