Search in sources :

Example 1 with ERDExportFormatHandler

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

Aggregations

File (java.io.File)1 IFigure (org.eclipse.draw2d.IFigure)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Shell (org.eclipse.swt.widgets.Shell)1 DBException (org.jkiss.dbeaver.DBException)1 ERDExportFormatHandler (org.jkiss.dbeaver.ext.erd.export.ERDExportFormatHandler)1 ERDExportFormatRegistry (org.jkiss.dbeaver.ext.erd.export.ERDExportFormatRegistry)1