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