Search in sources :

Example 1 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.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 EntityFigure figure = new EntityFigure(getTable());
    final EntityDiagram diagram = ((DiagramPart) getParent()).getDiagram();
    Rectangle bounds = diagram.getInitBounds(getTable());
    if (bounds != null) {
        figure.setLocation(bounds.getLocation());
    }
    return figure;
}
Also used : EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram) EntityFigure(org.jkiss.dbeaver.ext.erd.figures.EntityFigure) Rectangle(org.eclipse.draw2d.geometry.Rectangle)

Example 2 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.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"));
    // Set context menu
    ContextMenuProvider provider = new ERDEditorContextMenuProvider(this);
    viewer.setContextMenu(provider);
    getSite().registerContextMenu(ERDEditorPart.class.getName() + ".EditorContext", provider, viewer);
}
Also used : EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram)

Example 3 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.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.ext.erd.model.EntityDiagram) ERDEditorPart(org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart)

Example 4 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.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.ext.erd.model.EntityDiagram) ERDEditorPart(org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart)

Example 5 with EntityDiagram

use of org.jkiss.dbeaver.ext.erd.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(DBeaverCore.getInstance().getProjectRegistry().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");
    }
    final IFile file = ContentUtils.getUniqueFile(folder, CommonUtils.escapeFileName(title), ERD_EXT);
    try {
        DBRRunnableWithProgress runnable = new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    EntityDiagram newDiagram = copyFrom == null ? new EntityDiagram(null, "<Diagram>") : copyFrom.copy();
                    newDiagram.setName(title);
                    newDiagram.setLayoutManualAllowed(true);
                    newDiagram.setLayoutManualDesired(true);
                    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                    DiagramLoader.save(monitor, null, newDiagram, false, buffer);
                    InputStream data = new ByteArrayInputStream(buffer.toByteArray());
                    file.create(data, true, RuntimeUtils.getNestedMonitor(monitor));
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        if (monitor == null) {
            DBeaverUI.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 : DBException(org.jkiss.dbeaver.DBException) EntityDiagram(org.jkiss.dbeaver.ext.erd.model.EntityDiagram) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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