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