Search in sources :

Example 6 with EntityPart

use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.

the class ERDGraphicalViewer method setContents.

@Override
public void setContents(EditPart editpart) {
    loadContents = true;
    try {
        super.setContents(editpart);
        // Reset palette contents
        if (editpart instanceof DiagramPart) {
            List<DBSEntity> tables = new ArrayList<>();
            for (Object child : editpart.getChildren()) {
                if (child instanceof EntityPart) {
                    tables.add(((EntityPart) child).getTable().getObject());
                }
            }
            Collections.sort(tables, DBUtils.<DBSEntity>nameComparator());
            Map<PaletteDrawer, List<ToolEntryTable>> toolMap = new LinkedHashMap<>();
            for (DBSEntity table : tables) {
                DBPDataSourceContainer container = table.getDataSource().getContainer();
                PaletteDrawer drawer = getContainerPaletteDrawer(container);
                if (drawer != null) {
                    List<ToolEntryTable> tools = toolMap.get(drawer);
                    if (tools == null) {
                        tools = new ArrayList<>(tables.size());
                        toolMap.put(drawer, tools);
                    }
                    tools.add(new ToolEntryTable(table));
                }
            }
            for (Map.Entry<PaletteDrawer, List<ToolEntryTable>> entry : toolMap.entrySet()) {
                entry.getKey().setChildren(entry.getValue());
            }
        //editor.getPaletteContents().setChildren(tools);
        }
    } finally {
        loadContents = false;
    }
}
Also used : PaletteDrawer(org.eclipse.gef.palette.PaletteDrawer) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart) DiagramPart(org.jkiss.dbeaver.ext.erd.part.DiagramPart)

Example 7 with EntityPart

use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.

the class EntityAddCommand method execute.

@Override
public void execute() {
    Point curLocation = location == null ? null : new Point(location);
    for (ERDEntity entity : entities) {
        diagramPart.getDiagram().addTable(entity, true);
        if (curLocation != null) {
            // Put new entities in specified location
            for (Object diagramChild : diagramPart.getChildren()) {
                if (diagramChild instanceof EntityPart) {
                    EntityPart entityPart = (EntityPart) diagramChild;
                    if (entityPart.getTable() == entity) {
                        final Rectangle newBounds = new Rectangle();
                        final Dimension size = entityPart.getFigure().getPreferredSize();
                        newBounds.x = curLocation.x;
                        newBounds.y = curLocation.y;
                        newBounds.width = size.width;
                        newBounds.height = size.height;
                        entityPart.modifyBounds(newBounds);
                        curLocation.x += size.width + 20;
                        break;
                    }
                }
            }
        }
    }
}
Also used : ERDEntity(org.jkiss.dbeaver.ext.erd.model.ERDEntity) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart)

Example 8 with EntityPart

use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.

the class DirectedGraphLayoutVisitor method addEntityNode.

/**
     * Adds nodes to the graph object for use by the GraphLayoutAuto
     */
protected void addEntityNode(NodeEditPart nodeEditPart) {
    Node entityNode;
    if (nodeEditPart instanceof EntityPart && ((EntityPart) nodeEditPart).getTable().hasSelfLinks()) {
        entityNode = new Subgraph(nodeEditPart);
    } else {
        entityNode = new Node(nodeEditPart);
    }
    Dimension preferredSize = nodeEditPart.getFigure().getPreferredSize(400, 300);
    entityNode.width = preferredSize.width;
    entityNode.height = preferredSize.height;
    entityNode.setPadding(new Insets(20, 20, 10, 20));
    partToNodesMap.put(nodeEditPart, entityNode);
    graph.nodes.add(entityNode);
    if (entityNode instanceof Subgraph) {
        Node sourceAnchor = new Node("Fake node for source links", (Subgraph) entityNode);
        sourceAnchor.width = 0;
        sourceAnchor.height = 0;
        Node targetAnchor = new Node("Fake node for target links", (Subgraph) entityNode);
        targetAnchor.width = 0;
        targetAnchor.height = 0;
    }
/*
*/
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) Dimension(org.eclipse.draw2d.geometry.Dimension) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart)

Example 9 with EntityPart

use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.

the class EntityNodeEditPolicy method getConnectionCompleteCommand.

/**
	 * @see GraphicalNodeEditPolicy#getConnectionCompleteCommand(CreateConnectionRequest)
	 */
@Override
protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
    AssociationCreateCommand cmd = (AssociationCreateCommand) request.getStartCommand();
    EntityPart part = (EntityPart) request.getTargetEditPart();
    cmd.setPrimaryEntity(part.getTable());
    return cmd;
}
Also used : AssociationCreateCommand(org.jkiss.dbeaver.ext.erd.command.AssociationCreateCommand) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart)

Example 10 with EntityPart

use of org.jkiss.dbeaver.ext.erd.part.EntityPart in project dbeaver by serge-rider.

the class DiagramXYLayoutPolicy method createChangeConstraintCommand.

/**
	 * Creates command to move table. Does not allow table to be resized
	 */
@Override
protected Command createChangeConstraintCommand(EditPart child, Object constraint) {
    if (!(child instanceof NodePart))
        return null;
    if (!(constraint instanceof Rectangle))
        return null;
    NodePart nodePart = (NodePart) child;
    Figure figure = (Figure) nodePart.getFigure();
    Rectangle oldBounds = figure.getBounds();
    Rectangle newBounds = (Rectangle) constraint;
    // Restrict resize for entities
    if (nodePart instanceof EntityPart) {
        if (oldBounds.width != newBounds.width && newBounds.width != -1)
            return null;
        if (oldBounds.height != newBounds.height && newBounds.height != -1)
            return null;
    }
    return new NodeMoveCommand(nodePart, oldBounds.getCopy(), newBounds.getCopy());
}
Also used : NodeMoveCommand(org.jkiss.dbeaver.ext.erd.command.NodeMoveCommand) Rectangle(org.eclipse.draw2d.geometry.Rectangle) NodePart(org.jkiss.dbeaver.ext.erd.part.NodePart) EntityPart(org.jkiss.dbeaver.ext.erd.part.EntityPart) Figure(org.eclipse.draw2d.Figure) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)13 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 Bendpoint (org.eclipse.draw2d.Bendpoint)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Point (org.eclipse.draw2d.geometry.Point)2 AssociationCreateCommand (org.jkiss.dbeaver.ext.erd.command.AssociationCreateCommand)2 ERDEntity (org.jkiss.dbeaver.ext.erd.model.ERDEntity)2 AssociationPart (org.jkiss.dbeaver.ext.erd.part.AssociationPart)2 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)2 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)1 Figure (org.eclipse.draw2d.Figure)1 IFigure (org.eclipse.draw2d.IFigure)1 RelativeBendpoint (org.eclipse.draw2d.RelativeBendpoint)1 Insets (org.eclipse.draw2d.geometry.Insets)1 PaletteDrawer (org.eclipse.gef.palette.PaletteDrawer)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 DBException (org.jkiss.dbeaver.DBException)1 AssociationReconnectSourceCommand (org.jkiss.dbeaver.ext.erd.command.AssociationReconnectSourceCommand)1