use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram 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.erd.ui.model.EntityDiagram in project dbeaver by serge-rider.
the class ERDEditorStandalone method loadContentFromFile.
private EntityDiagram loadContentFromFile(DBRProgressMonitor progressMonitor) throws DBException {
IFile resFile = getEditorFile();
IProject project = resFile == null ? DBWorkbench.getPlatform().getWorkspace().getActiveProject().getEclipseProject() : resFile.getProject();
final File localFile = EditorUtils.getLocalFileFromInput(getEditorInput());
final DiagramPart diagramPart = getDiagramPart();
EntityDiagram entityDiagram = new EntityDiagram(null, localFile.getName(), getContentProvider(), getDecorator());
entityDiagram.clear();
entityDiagram.setLayoutManualAllowed(true);
entityDiagram.setLayoutManualDesired(true);
diagramPart.setModel(entityDiagram);
try (final InputStream fileContent = new FileInputStream(localFile)) {
DiagramLoader.load(progressMonitor, project, diagramPart, fileContent);
} catch (Exception e) {
log.error("Error loading ER diagram from '" + localFile.getName() + "'", e);
}
return entityDiagram;
}
use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by serge-rider.
the class DelegatingLayoutManager method layout.
@Override
public void layout(IFigure container) {
EntityDiagram entityDiagram = diagram.getDiagram();
try {
if (entityDiagram.isLayoutManualDesired()) {
if (activeLayoutManager != xyLayoutManager) {
if (entityDiagram.isLayoutManualAllowed() && !entityDiagram.isNeedsAutoLayout()) {
// yes we are okay to start populating the table bounds
setLayoutManager(container, xyLayoutManager);
activeLayoutManager.layout(container);
} else {
// we first have to set the constraint data
if (diagram.setTableFigureBounds(true)) {
// we successfully set bounds for all the existing
// tables so we can start using xyLayout immediately
setLayoutManager(container, xyLayoutManager);
activeLayoutManager.layout(container);
} else {
// we did not - we still need to run autolayout once
// before we can set xyLayout
activeLayoutManager.layout(container);
// run this again so that it will work again next time
setLayoutManager(container, xyLayoutManager);
}
}
} else {
setLayoutManager(container, xyLayoutManager);
activeLayoutManager.layout(container);
}
} else {
setLayoutManager(container, graphLayoutManager);
activeLayoutManager.layout(container);
}
} finally {
if (!diagram.getChildren().isEmpty()) {
entityDiagram.setNeedsAutoLayout(false);
}
}
}
use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by dbeaver.
the class FlyoutChangeLayoutAction method run.
@Override
public void run() {
if (editor instanceof ERDEditorPart) {
ERDEditorPart erdEditor = (ERDEditorPart) editor;
EntityDiagram entityDiagram = erdEditor.getDiagram();
boolean isManual = entityDiagram.isLayoutManualDesired();
entityDiagram.setLayoutManualDesired(!isManual);
erdEditor.getDiagramPart().changeLayout();
checked = !isManual;
setChecked(checked);
}
}
use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by dbeaver.
the class ERDEditorPart method createGraphicalViewer.
/**
* Creates a new <code>GraphicalViewer</code>, configures, registers and
* initializes it.
*
* @param parent the parent composite
*/
@Override
protected void createGraphicalViewer(Composite parent) {
GraphicalViewer viewer = createViewer(parent);
// hook the viewer into the EditDomain
setGraphicalViewer(viewer);
configureGraphicalViewer();
hookGraphicalViewer();
initializeGraphicalViewer();
// Set initial (empty) contents
viewer.setContents(new EntityDiagram(null, "empty", getContentProvider(), getDecorator()));
// Set context menu
ContextMenuProvider provider = new ERDEditorContextMenuProvider(this);
viewer.setContextMenu(provider);
IWorkbenchPartSite site = getSite();
if (site instanceof IEditorSite) {
((IEditorSite) site).registerContextMenu(ERDEditorPart.class.getName() + ".EditorContext", provider, viewer, false);
} else {
site.registerContextMenu(ERDEditorPart.class.getName() + ".EditorContext", provider, viewer);
}
}
Aggregations