Search in sources :

Example 11 with EntityDiagram

use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram 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;
}
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 12 with EntityDiagram

use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by dbeaver.

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.erd.ui.command.NoteDeleteCommand) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) NotePart(org.jkiss.dbeaver.erd.ui.part.NotePart) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 13 with EntityDiagram

use of org.jkiss.dbeaver.erd.ui.model.EntityDiagram in project dbeaver by dbeaver.

the class EntityPart method createFigure.

// ******************* Layout related methods *********************/
/**
 * Creates a figure which represents the table
 */
@Override
protected EntityFigure createFigure() {
    final EntityDiagram diagram = getDiagram();
    final EntityFigure figure = createFigureImpl();
    EntityDiagram.NodeVisualInfo visualInfo = diagram.getVisualInfo(getEntity().getObject());
    if (visualInfo != null) {
        if (visualInfo.initBounds != null) {
            figure.setLocation(visualInfo.initBounds.getLocation());
        }
        if (visualInfo.bgColor != null) {
            figure.setBackgroundColor(visualInfo.bgColor);
        }
        if (getEntity().getAttributeVisibility() == null && visualInfo.attributeVisibility != null) {
            getEntity().setAttributeVisibility(visualInfo.attributeVisibility);
        }
    }
    return figure;
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) EntityFigure(org.jkiss.dbeaver.erd.ui.figures.EntityFigure)

Example 14 with EntityDiagram

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

the class FlyoutChangeLayoutAction method isChecked.

/**
 * @see org.eclipse.jface.action.IAction#isChecked()
 */
public boolean isChecked(IEditorPart editor) {
    if (editor instanceof ERDEditorPart) {
        ERDEditorPart schemaEditor = (ERDEditorPart) editor;
        EntityDiagram entityDiagram = schemaEditor.getDiagram();
        boolean checkTrue = entityDiagram.isLayoutManualDesired();
        return (!checkTrue);
    } else {
        return false;
    }
}
Also used : EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) ERDEditorPart(org.jkiss.dbeaver.erd.ui.editor.ERDEditorPart)

Example 15 with EntityDiagram

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

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)

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