Search in sources :

Example 6 with EntityDiagram

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;
}
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 7 with EntityDiagram

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;
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) DiagramPart(org.jkiss.dbeaver.erd.ui.part.DiagramPart) FileInputStream(java.io.FileInputStream) PartInitException(org.eclipse.ui.PartInitException) DBException(org.jkiss.dbeaver.DBException)

Example 8 with 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);
        }
    }
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram)

Example 9 with EntityDiagram

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);
    }
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) ERDEditorPart(org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart)

Example 10 with EntityDiagram

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

Aggregations

EntityDiagram (org.jkiss.dbeaver.erd.ui.model.EntityDiagram)20 DBException (org.jkiss.dbeaver.DBException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 ERDEditorPart (org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart)4 NotePart (org.jkiss.dbeaver.erd.ui.part.NotePart)4 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 StringReader (java.io.StringReader)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 StandardCharsets (java.nio.charset.StandardCharsets)2 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2 IFolder (org.eclipse.core.resources.IFolder)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 PartInitException (org.eclipse.ui.PartInitException)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2