Search in sources :

Example 16 with EntityDiagram

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

Example 17 with EntityDiagram

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

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)

Example 18 with 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;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) IFolder(org.eclipse.core.resources.IFolder) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ERDContentProviderDecorated(org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated) CoreException(org.eclipse.core.runtime.CoreException) NotNull(org.jkiss.code.NotNull) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IFile(org.eclipse.core.resources.IFile) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) ERDEditorStandalone(org.jkiss.dbeaver.erd.ui.editor.ERDEditorStandalone) DiagramLoader(org.jkiss.dbeaver.erd.ui.model.DiagramLoader) CommonUtils(org.jkiss.utils.CommonUtils) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ContentUtils(org.jkiss.dbeaver.utils.ContentUtils) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) StandardCharsets(java.nio.charset.StandardCharsets) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) AbstractResourceHandler(org.jkiss.dbeaver.ui.resources.AbstractResourceHandler) RuntimeUtils(org.jkiss.dbeaver.utils.RuntimeUtils) DBException(org.jkiss.dbeaver.DBException) IResource(org.eclipse.core.resources.IResource) ERDDecoratorDefault(org.jkiss.dbeaver.erd.ui.model.ERDDecoratorDefault) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) InputStream(java.io.InputStream) DBException(org.jkiss.dbeaver.DBException) EntityDiagram(org.jkiss.dbeaver.erd.ui.model.EntityDiagram) IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ERDContentProviderDecorated(org.jkiss.dbeaver.erd.ui.model.ERDContentProviderDecorated) ERDDecoratorDefault(org.jkiss.dbeaver.erd.ui.model.ERDDecoratorDefault) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)

Example 19 with EntityDiagram

use of org.jkiss.dbeaver.erd.ui.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.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 20 with EntityDiagram

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

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)

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