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 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 ERDResourceHandler method createDiagram.
public static IFile createDiagram(final EntityDiagram copyFrom, final String title, IFolder folder, DBRProgressMonitor monitor) throws DBException {
if (folder == null) {
try {
folder = getDiagramsFolder(DBWorkbench.getPlatform().getWorkspace().getActiveProject(), true);
} catch (CoreException e) {
throw new DBException("Can't obtain folder for diagram", e);
}
}
if (folder == null) {
throw new DBException("Can't detect folder for diagram");
}
ContentUtils.checkFolderExists(folder, monitor);
final IFile file = ContentUtils.getUniqueFile(folder, CommonUtils.escapeFileName(title), ERD_EXT);
try {
DBRRunnableWithProgress runnable = monitor1 -> {
try {
EntityDiagram newDiagram = copyFrom == null ? new EntityDiagram(null, "<Diagram>", new ERDContentProviderDecorated(), new ERDDecoratorDefault()) : copyFrom.copy();
newDiagram.setName(title);
newDiagram.setLayoutManualAllowed(true);
newDiagram.setLayoutManualDesired(true);
String diagramState = DiagramLoader.serializeDiagram(monitor1, null, newDiagram, false, false);
InputStream data = new ByteArrayInputStream(diagramState.getBytes(StandardCharsets.UTF_8));
file.create(data, true, RuntimeUtils.getNestedMonitor(monitor1));
} catch (Exception e) {
throw new InvocationTargetException(e);
}
};
if (monitor == null) {
UIUtils.runInProgressService(runnable);
} else {
runnable.run(monitor);
}
} catch (InvocationTargetException e) {
throw new DBException("Error creating diagram", e.getTargetException());
} catch (InterruptedException e) {
// interrupted
}
return file;
}
use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by serge-rider.
the class ERDEditorPart method restoreVisualSettings.
private boolean restoreVisualSettings(DiagramPart oldDiagram, EntityDiagram newDiagram) {
boolean hasChanges = false;
// Collect visual settings from old diagram and apply them to the new one
for (ERDEntity newEntity : newDiagram.getEntities()) {
NodePart oldEntity = oldDiagram.getChildByObject(newEntity.getObject());
if (oldEntity instanceof EntityPart) {
EntityDiagram.NodeVisualInfo vi = new EntityDiagram.NodeVisualInfo(oldEntity);
newDiagram.addVisualInfo(newEntity.getObject(), vi);
hasChanges = true;
}
}
for (ERDNote newNote : newDiagram.getNotes()) {
NodePart oldNotePart = oldDiagram.getChildByObject(newNote.getObject());
if (oldNotePart instanceof NotePart) {
EntityDiagram.NodeVisualInfo vi = new EntityDiagram.NodeVisualInfo(oldNotePart);
vi.initBounds = oldNotePart.getBounds();
newDiagram.addVisualInfo(newNote, vi);
hasChanges = true;
}
}
return hasChanges;
}
Aggregations