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;
}
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;
}
}
}
}
}
}
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;
}
Aggregations