Search in sources :

Example 1 with DBVObject

use of org.jkiss.dbeaver.model.virtual.DBVObject in project dbeaver by serge-rider.

the class ERDEditorEmbedded method loadFromDatabase.

private EntityDiagram loadFromDatabase(DBRProgressMonitor monitor) throws DBException {
    DBSObject dbObject = getRootObject();
    if (dbObject == null) {
        log.error("Database object must be entity container to render ERD diagram");
        return null;
    }
    EntityDiagram diagram;
    if (!dbObject.isPersisted()) {
        diagram = new EntityDiagram(dbObject, "New Object", getContentProvider(), getDecorator());
    } else {
        diagram = new EntityDiagram(dbObject, dbObject.getName(), getContentProvider(), getDecorator());
        // Fill from database even if we loaded from state (something could change since last view)
        diagram.fillEntities(monitor, ERDUtils.collectDatabaseTables(monitor, dbObject, diagram, ERDUIActivator.getDefault().getPreferenceStore().getBoolean(ERDUIConstants.PREF_DIAGRAM_SHOW_VIEWS), ERDUIActivator.getDefault().getPreferenceStore().getBoolean(ERDUIConstants.PREF_DIAGRAM_SHOW_PARTITIONS)), dbObject);
        boolean hasPersistedState = false;
        try {
            // Load persisted state
            DBVObject vObject = this.getVirtualObject();
            if (vObject != null) {
                Map<String, Object> diagramState = vObject.getProperty(PROP_DIAGRAM_STATE);
                if (diagramState != null) {
                    String serializedDiagram = (String) diagramState.get(PROPS_DIAGRAM_SERIALIZED);
                    if (!CommonUtils.isEmpty(serializedDiagram)) {
                        Document xmlDocument = XMLUtils.parseDocument(new StringReader(serializedDiagram));
                        DiagramLoader.loadDiagram(monitor, xmlDocument, dbObject.getDataSource().getContainer().getProject(), diagram);
                        hasPersistedState = true;
                    }
                }
            }
        } catch (Exception e) {
            log.error("Error loading ER diagram from saved state", e);
        }
        diagram.setLayoutManualAllowed(true);
        diagram.setNeedsAutoLayout(!hasPersistedState);
    }
    return diagram;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) StringReader(java.io.StringReader) DBVObject(org.jkiss.dbeaver.model.virtual.DBVObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Document(org.w3c.dom.Document) DBException(org.jkiss.dbeaver.DBException) DBVObject(org.jkiss.dbeaver.model.virtual.DBVObject)

Example 2 with DBVObject

use of org.jkiss.dbeaver.model.virtual.DBVObject in project dbeaver by serge-rider.

the class ERDEditorEmbedded method resetSavedState.

public void resetSavedState(boolean refreshDiagram) {
    try {
        DBVObject vObject = this.getVirtualObject();
        if (vObject != null && vObject.getProperty(PROP_DIAGRAM_STATE) != null) {
            vObject.setProperty(PROP_DIAGRAM_STATE, null);
            vObject.persistConfiguration();
        }
    } catch (Exception e) {
        log.error("Error resetting diagram state", e);
    }
    if (refreshDiagram) {
        refreshDiagram(true, true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBVObject(org.jkiss.dbeaver.model.virtual.DBVObject)

Example 3 with DBVObject

use of org.jkiss.dbeaver.model.virtual.DBVObject in project dbeaver by dbeaver.

the class ERDEditorEmbedded method doSave.

@Override
public void doSave(IProgressMonitor monitor) {
    try {
        // Save in virtual model as entity property.
        DBVObject vObject = this.getVirtualObject();
        if (vObject == null) {
            return;
        }
        Map<String, Object> diagramStateMap = new LinkedHashMap<>();
        vObject.setProperty(PROP_DIAGRAM_STATE, diagramStateMap);
        String diagramState = DiagramLoader.serializeDiagram(RuntimeUtils.makeMonitor(monitor), getDiagramPart(), getDiagram(), false, true);
        diagramStateMap.put(PROPS_DIAGRAM_SERIALIZED, diagramState);
        vObject.persistConfiguration();
        getCommandStack().markSaveLocation();
    } catch (Exception e) {
        log.error("Error saving diagram", e);
    }
    updateToolbarActions();
}
Also used : DBVObject(org.jkiss.dbeaver.model.virtual.DBVObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBVObject(org.jkiss.dbeaver.model.virtual.DBVObject) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with DBVObject

use of org.jkiss.dbeaver.model.virtual.DBVObject in project dbeaver by dbeaver.

the class ERDEditorEmbedded method resetSavedState.

public void resetSavedState(boolean refreshDiagram) {
    try {
        DBVObject vObject = this.getVirtualObject();
        if (vObject != null && vObject.getProperty(PROP_DIAGRAM_STATE) != null) {
            vObject.setProperty(PROP_DIAGRAM_STATE, null);
            vObject.persistConfiguration();
        }
    } catch (Exception e) {
        log.error("Error resetting diagram state", e);
    }
    if (refreshDiagram) {
        refreshDiagram(true, true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBVObject(org.jkiss.dbeaver.model.virtual.DBVObject)

Example 5 with DBVObject

use of org.jkiss.dbeaver.model.virtual.DBVObject in project dbeaver by dbeaver.

the class ERDEditorEmbedded method loadFromDatabase.

private EntityDiagram loadFromDatabase(DBRProgressMonitor monitor) throws DBException {
    DBSObject dbObject = getRootObject();
    if (dbObject == null) {
        log.error("Database object must be entity container to render ERD diagram");
        return null;
    }
    EntityDiagram diagram;
    if (!dbObject.isPersisted()) {
        diagram = new EntityDiagram(dbObject, "New Object", getContentProvider(), getDecorator());
    } else {
        diagram = new EntityDiagram(dbObject, dbObject.getName(), getContentProvider(), getDecorator());
        // Fill from database even if we loaded from state (something could change since last view)
        diagram.fillEntities(monitor, ERDUtils.collectDatabaseTables(monitor, dbObject, diagram, ERDUIActivator.getDefault().getPreferenceStore().getBoolean(ERDUIConstants.PREF_DIAGRAM_SHOW_VIEWS), ERDUIActivator.getDefault().getPreferenceStore().getBoolean(ERDUIConstants.PREF_DIAGRAM_SHOW_PARTITIONS)), dbObject);
        boolean hasPersistedState = false;
        try {
            // Load persisted state
            DBVObject vObject = this.getVirtualObject();
            if (vObject != null) {
                Map<String, Object> diagramState = vObject.getProperty(PROP_DIAGRAM_STATE);
                if (diagramState != null) {
                    String serializedDiagram = (String) diagramState.get(PROPS_DIAGRAM_SERIALIZED);
                    if (!CommonUtils.isEmpty(serializedDiagram)) {
                        Document xmlDocument = XMLUtils.parseDocument(new StringReader(serializedDiagram));
                        DiagramLoader.loadDiagram(monitor, xmlDocument, dbObject.getDataSource().getContainer().getProject(), diagram);
                        hasPersistedState = true;
                    }
                }
            }
        } catch (Exception e) {
            log.error("Error loading ER diagram from saved state", e);
        }
        diagram.setLayoutManualAllowed(true);
        diagram.setNeedsAutoLayout(!hasPersistedState);
    }
    return diagram;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) StringReader(java.io.StringReader) DBVObject(org.jkiss.dbeaver.model.virtual.DBVObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Document(org.w3c.dom.Document) DBException(org.jkiss.dbeaver.DBException) DBVObject(org.jkiss.dbeaver.model.virtual.DBVObject)

Aggregations

DBException (org.jkiss.dbeaver.DBException)6 DBVObject (org.jkiss.dbeaver.model.virtual.DBVObject)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 StringReader (java.io.StringReader)2 LinkedHashMap (java.util.LinkedHashMap)2 EntityDiagram (org.jkiss.dbeaver.erd.ui.model.EntityDiagram)2 Document (org.w3c.dom.Document)2