Search in sources :

Example 1 with Relationship

use of com.cubrid.common.ui.er.model.Relationship in project cubrid-manager by CUBRID.

the class DeleteTableCommand method deleteRelationships.

private void deleteRelationships(ERTable t) {
    this.foreignKeyRelationships.addAll(t.getForeignKeyRelationships());
    // for all relationships where current table is foreign key
    for (int i = 0; i < foreignKeyRelationships.size(); i++) {
        Relationship r = (Relationship) foreignKeyRelationships.get(i);
        t.deleteForeignKeyShipAndFire(r);
    }
    // for all relationships where current table is primary key
    this.primaryKeyRelationships.addAll(t.getTargetedRelationships());
    for (int i = 0; i < primaryKeyRelationships.size(); i++) {
        Relationship r = (Relationship) primaryKeyRelationships.get(i);
        r.getForeignKeyTable().deleteForeignKeyShipAndFire(r);
    }
}
Also used : Relationship(com.cubrid.common.ui.er.model.Relationship)

Example 2 with Relationship

use of com.cubrid.common.ui.er.model.Relationship in project cubrid-manager by CUBRID.

the class ReconnectForeignKeyCommand method canExecute.

/**
	 * Makes sure that primary key doesn't reconnect to itself or try to create
	 * a relationship which already exists
	 */
@Override
public boolean canExecute() {
    boolean returnVal = true;
    ERTable primaryKeyTable = relationship.getPrimaryKeyTable();
    // cannot connect to itself
    if (primaryKeyTable.equals(sourceForeignTable)) {
        returnVal = false;
    } else {
        List relationships = sourceForeignTable.getForeignKeyRelationships();
        for (int i = 0; i < relationships.size(); i++) {
            Relationship relationship = ((Relationship) (relationships.get(i)));
            if (relationship.getPrimaryKeyTable().equals(targetPrimaryTable) && relationship.getForeignKeyTable().equals(sourceForeignTable)) {
                returnVal = false;
                break;
            }
        }
    }
    return returnVal;
}
Also used : Relationship(com.cubrid.common.ui.er.model.Relationship) ERTable(com.cubrid.common.ui.er.model.ERTable) List(java.util.List)

Example 3 with Relationship

use of com.cubrid.common.ui.er.model.Relationship in project cubrid-manager by CUBRID.

the class RelationshipEditPolicy method createDeleteCommand.

protected Command createDeleteCommand(GroupRequest request) {
    Relationship relationship = (Relationship) getHost().getModel();
    ERTable primaryKeyTarget = relationship.getPrimaryKeyTable();
    ERTable foreignKeySource = relationship.getForeignKeyTable();
    DeleteRelationshipCommand deleteCmd = new DeleteRelationshipCommand(foreignKeySource, primaryKeyTarget, relationship);
    return deleteCmd;
}
Also used : DeleteRelationshipCommand(com.cubrid.common.ui.er.commands.DeleteRelationshipCommand) Relationship(com.cubrid.common.ui.er.model.Relationship) ERTable(com.cubrid.common.ui.er.model.ERTable)

Example 4 with Relationship

use of com.cubrid.common.ui.er.model.Relationship in project cubrid-manager by CUBRID.

the class PartFactory method createEditPart.

public EditPart createEditPart(EditPart context, Object model) {
    EditPart part = null;
    if (model instanceof ERSchema) {
        part = new SchemaDiagramPart();
    } else if (model instanceof ERTable) {
        part = new TablePart();
    } else if (model instanceof Relationship) {
        part = new RelationshipPart();
    } else if (model instanceof ERTableColumn) {
        part = new ColumnPart();
    }
    if (null == part) {
        LOGGER.error("Part is null :" + context + "," + model);
    }
    part.setModel(model);
    return part;
}
Also used : Relationship(com.cubrid.common.ui.er.model.Relationship) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) EditPart(org.eclipse.gef.EditPart) ERSchema(com.cubrid.common.ui.er.model.ERSchema) ERTable(com.cubrid.common.ui.er.model.ERTable)

Example 5 with Relationship

use of com.cubrid.common.ui.er.model.Relationship in project cubrid-manager by CUBRID.

the class RelationshipPart method setRelationColumnProtrude.

/**
	 * Set foreign columns relation with the line to be protruded.
	 * 
	 * @param focus
	 */
@SuppressWarnings("unchecked")
public void setRelationColumnProtrude(boolean focus) {
    Relationship relations = (Relationship) this.getModel();
    TablePart sourceTablePart = (TablePart) this.getSource();
    TablePart targetTablePart = (TablePart) this.getTarget();
    if (sourceTablePart == null || targetTablePart == null) {
        return;
    }
    // set source and target columns
    List<EditPart> children = sourceTablePart.getChildren();
    for (EditPart child : children) {
        if (!(child instanceof ColumnPart)) {
            continue;
        }
        ColumnPart columnPart = (ColumnPart) child;
        ERTableColumn column = (ERTableColumn) columnPart.getModel();
        if (relations.getReferenceColumns().contains(column.getName())) {
            EditableLabel columnLable = (EditableLabel) columnPart.getFigure();
            if (this.isSelected() || sourceTablePart.isSelected() || targetTablePart.isSelected()) {
                columnLable.setFontProtrude(true);
            } else {
                columnLable.setFontProtrude(focus);
            }
        }
    }
    // target
    children = targetTablePart.getChildren();
    for (EditPart child : children) {
        if (!(child instanceof ColumnPart)) {
            continue;
        }
        ColumnPart columnPart = (ColumnPart) child;
        ERTableColumn column = (ERTableColumn) columnPart.getModel();
        if (relations.getReferencedPKs().contains(column.getName())) {
            EditableLabel columnLable = (EditableLabel) columnPart.getFigure();
            if (this.isSelected() || sourceTablePart.isSelected() || targetTablePart.isSelected()) {
                columnLable.setFontProtrude(true);
            } else {
                columnLable.setFontProtrude(focus);
            }
        }
    }
}
Also used : EditableLabel(com.cubrid.common.ui.er.figures.EditableLabel) Relationship(com.cubrid.common.ui.er.model.Relationship) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) EditPart(org.eclipse.gef.EditPart)

Aggregations

Relationship (com.cubrid.common.ui.er.model.Relationship)8 ERTable (com.cubrid.common.ui.er.model.ERTable)4 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)3 EditPart (org.eclipse.gef.EditPart)3 EditableLabel (com.cubrid.common.ui.er.figures.EditableLabel)2 List (java.util.List)2 DeleteRelationshipCommand (com.cubrid.common.ui.er.commands.DeleteRelationshipCommand)1 ERSchema (com.cubrid.common.ui.er.model.ERSchema)1