Search in sources :

Example 6 with ERDEntity

use of org.jkiss.dbeaver.ext.erd.model.ERDEntity in project dbeaver by serge-rider.

the class AssociationReconnectTargetCommand method canExecute.

/**
	 * Makes sure that foreign key doesn't reconnect to itself or try to create
	 * a relationship which already exists
	 */
@Override
public boolean canExecute() {
    boolean returnVal = true;
    ERDEntity foreignKeyEntity = relationship.getForeignKeyEntity();
    if (foreignKeyEntity.equals(targetPrimaryKey)) {
        returnVal = false;
    } else {
        List<?> relationships = targetPrimaryKey.getPrimaryKeyRelationships();
        for (int i = 0; i < relationships.size(); i++) {
            ERDAssociation relationship = ((ERDAssociation) (relationships.get(i)));
            if (relationship.getForeignKeyEntity().equals(sourceForeignKey) && relationship.getPrimaryKeyEntity().equals(targetPrimaryKey)) {
                returnVal = false;
                break;
            }
        }
    }
    return returnVal;
}
Also used : ERDEntity(org.jkiss.dbeaver.ext.erd.model.ERDEntity) ERDAssociation(org.jkiss.dbeaver.ext.erd.model.ERDAssociation)

Example 7 with ERDEntity

use of org.jkiss.dbeaver.ext.erd.model.ERDEntity 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 ERDEntity

use of org.jkiss.dbeaver.ext.erd.model.ERDEntity in project dbeaver by serge-rider.

the class ERDHandlerPaste method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
    if (control != null) {
        ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
        if (editor != null && !editor.isReadOnly()) {
            final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
            if (!CommonUtils.isEmpty(objects)) {
                final List<ERDEntity> erdEntities = DiagramObjectCollector.generateEntityList(editor.getDiagram(), objects);
                if (!CommonUtils.isEmpty(erdEntities)) {
                    EntityAddCommand command = new EntityAddCommand(editor.getDiagramPart(), erdEntities, new Point(10, 10));
                    editor.getCommandStack().execute(command);
                }
            }
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) ERDEditorPart(org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart) ERDEntity(org.jkiss.dbeaver.ext.erd.model.ERDEntity) Point(org.eclipse.draw2d.geometry.Point) EntityAddCommand(org.jkiss.dbeaver.ext.erd.command.EntityAddCommand)

Aggregations

ERDEntity (org.jkiss.dbeaver.ext.erd.model.ERDEntity)8 ERDAssociation (org.jkiss.dbeaver.ext.erd.model.ERDAssociation)4 Point (org.eclipse.draw2d.geometry.Point)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 EntityAddCommand (org.jkiss.dbeaver.ext.erd.command.EntityAddCommand)2 EntityFigure (org.jkiss.dbeaver.ext.erd.figures.EntityFigure)2 EntityPart (org.jkiss.dbeaver.ext.erd.part.EntityPart)2 FileOutputStream (java.io.FileOutputStream)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Bendpoint (org.eclipse.draw2d.Bendpoint)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Control (org.eclipse.swt.widgets.Control)1 AssociationDeleteCommand (org.jkiss.dbeaver.ext.erd.command.AssociationDeleteCommand)1 NoteCreateCommand (org.jkiss.dbeaver.ext.erd.command.NoteCreateCommand)1 ERDEditorPart (org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart)1 AttributeListFigure (org.jkiss.dbeaver.ext.erd.figures.AttributeListFigure)1 EditableLabel (org.jkiss.dbeaver.ext.erd.figures.EditableLabel)1 ERDEntityAttribute (org.jkiss.dbeaver.ext.erd.model.ERDEntityAttribute)1 ERDNote (org.jkiss.dbeaver.ext.erd.model.ERDNote)1