Search in sources :

Example 6 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.model.EntityDiagram in project dbeaver by serge-rider.

the class ERDEditorStandalone method loadContentFromFile.

private EntityDiagram loadContentFromFile(DBRProgressMonitor progressMonitor) throws DBException {
    final IFile file = getEditorFile();
    final DiagramPart diagramPart = getDiagramPart();
    EntityDiagram entityDiagram = new EntityDiagram(null, file.getName());
    entityDiagram.clear();
    entityDiagram.setLayoutManualAllowed(true);
    entityDiagram.setLayoutManualDesired(true);
    diagramPart.setModel(entityDiagram);
    try (final InputStream fileContent = file.getContents()) {
        DiagramLoader.load(progressMonitor, file.getProject(), diagramPart, fileContent);
    } catch (Exception e) {
        log.error("Error loading ER diagram from '" + file.getName() + "'", e);
    }
    return entityDiagram;
}
Also used : EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DiagramPart(org.jkiss.dbeaver.ext.erd.part.DiagramPart) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Example 7 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.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");
    } else {
        diagram = new EntityDiagram(dbObject, dbObject.getName());
        diagram.fillTables(monitor, collectDatabaseTables(monitor, dbObject), dbObject);
    }
    return diagram;
}
Also used : EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram)

Example 8 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.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);
        }
    }
}
Also used : EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram)

Example 9 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.model.EntityDiagram in project dbeaver by serge-rider.

the class NoteEditPolicy method createDeleteCommand.

@Override
protected Command createDeleteCommand(GroupRequest request) {
    NotePart notePart = (NotePart) getHost();
    Rectangle bounds = notePart.getFigure().getBounds().getCopy();
    EntityDiagram parent = (EntityDiagram) (notePart.getParent().getModel());
    return new NoteDeleteCommand(parent, notePart, bounds);
}
Also used : NoteDeleteCommand(org.jkiss.dbeaver.ext.erd.command.NoteDeleteCommand) EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram) NotePart(org.jkiss.dbeaver.ext.erd.part.NotePart) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 10 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.model.EntityDiagram in project dbeaver by serge-rider.

the class EntityEditPolicy method createDeleteCommand.

@Override
protected Command createDeleteCommand(GroupRequest request) {
    EntityPart entityPart = (EntityPart) getHost();
    Rectangle bounds = entityPart.getFigure().getBounds().getCopy();
    EntityDiagram parent = (EntityDiagram) (entityPart.getParent().getModel());
    return new EntityDeleteCommand(parent, entityPart, bounds);
}
Also used : EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram) EntityDeleteCommand(org.jkiss.dbeaver.ext.erd.command.EntityDeleteCommand) Rectangle(org.eclipse.draw2d.geometry.Rectangle) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart)

Aggregations

EntityDiagram (org.jkiss.dbeaver.ext.erd.model.EntityDiagram)10 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 DBException (org.jkiss.dbeaver.DBException)2 ERDEditorPart (org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 PartInitException (org.eclipse.ui.PartInitException)1 EntityDeleteCommand (org.jkiss.dbeaver.ext.erd.command.EntityDeleteCommand)1 NoteDeleteCommand (org.jkiss.dbeaver.ext.erd.command.NoteDeleteCommand)1 EntityFigure (org.jkiss.dbeaver.ext.erd.figures.EntityFigure)1 DiagramPart (org.jkiss.dbeaver.ext.erd.part.DiagramPart)1 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)1 NotePart (org.jkiss.dbeaver.ext.erd.part.NotePart)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)1