use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class ObjRelationshipTableModel method removeRow.
public void removeRow(int row) {
if (row < 0) {
return;
}
Relationship rel = getRelationship(row);
RelationshipEvent e;
e = new RelationshipEvent(eventSource, rel, entity, RelationshipEvent.REMOVE);
mediator.fireObjRelationshipEvent(e);
objectList.remove(row);
entity.removeRelationship(rel.getName());
fireTableRowsDeleted(row, row);
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class LockingUpdateController method updateAction.
public void updateAction() {
int defaultLockType = dataMap.getDefaultLockType();
boolean on = defaultLockType == ObjEntity.LOCK_TYPE_OPTIMISTIC;
boolean updateEntities = view.getEntities().isSelected();
boolean updateAttributes = view.getAttributes().isSelected();
boolean updateRelationships = view.getRelationships().isSelected();
ProjectController parent = (ProjectController) getParent();
for (ObjEntity entity : dataMap.getObjEntities()) {
if (updateEntities && defaultLockType != entity.getDeclaredLockType()) {
entity.setDeclaredLockType(defaultLockType);
parent.fireObjEntityEvent(new EntityEvent(this, entity));
}
if (updateAttributes) {
for (ObjAttribute a : entity.getAttributes()) {
if (a.isUsedForLocking() != on) {
a.setUsedForLocking(on);
parent.fireObjAttributeEvent(new AttributeEvent(this, a, entity));
}
}
}
if (updateRelationships) {
for (ObjRelationship r : entity.getRelationships()) {
if (r.isUsedForLocking() != on) {
r.setUsedForLocking(on);
parent.fireObjRelationshipEvent(new RelationshipEvent(this, r, entity));
}
}
}
}
if (view != null) {
view.dispose();
}
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class DbRelationshipTableModel method setUpdatedValueAt.
public void setUpdatedValueAt(Object aValue, int row, int column) {
DbRelationship rel = getRelationship(row);
// If name column
if (column == NAME) {
RelationshipEvent e = new RelationshipEvent(eventSource, rel, entity, rel.getName());
rel.setName((String) aValue);
mediator.fireDbRelationshipEvent(e);
fireTableCellUpdated(row, column);
} else if (column == TARGET) {
// If target column
DbEntity target = (DbEntity) aValue;
if (WarningDialogByDbTargetChange.showWarningDialog(mediator, rel)) {
// clear joins...
rel.removeAllJoins();
rel.setTargetEntityName(target);
}
mediator.fireDbRelationshipEvent(new RelationshipEvent(eventSource, rel, entity));
} else if (column == TO_DEPENDENT_KEY) {
boolean flag = (Boolean) aValue;
// make sure reverse relationship "to-dep-pk" is unset.
if (flag) {
DbRelationship reverse = rel.getReverseRelationship();
if (reverse != null && reverse.isToDependentPK()) {
String message = "Unset reverse relationship's \"To Dep PK\" setting?";
int answer = JOptionPane.showConfirmDialog(Application.getFrame(), message);
if (answer != JOptionPane.YES_OPTION) {
// no action needed
return;
}
// unset reverse
reverse.setToDependentPK(false);
}
}
rel.setToDependentPK(flag);
mediator.fireDbRelationshipEvent(new RelationshipEvent(eventSource, rel, entity));
} else if (column == CARDINALITY) {
rel.setToMany((Boolean) aValue);
mediator.fireDbRelationshipEvent(new RelationshipEvent(eventSource, rel, entity));
updateDependentObjRelationships(rel);
} else if (column == COMMENTS) {
setComment((String) aValue, rel);
mediator.fireDbRelationshipEvent(new RelationshipEvent(eventSource, rel, entity));
}
fireTableRowsUpdated(row, row);
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class RemoveAction method removeObjRelationships.
private void removeObjRelationships(ProjectController mediator, ConfirmRemoveDialog dialog, ObjRelationship[] rels) {
if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName())) || (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
ObjEntity entity = mediator.getCurrentObjEntity();
for (ObjRelationship rel : rels) {
entity.removeRelationship(rel.getName());
RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
mediator.fireObjRelationshipEvent(e);
}
Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
}
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class RemoveAction method removeDBRelationships.
private void removeDBRelationships(ProjectController mediator, ConfirmRemoveDialog dialog, DbRelationship[] dbRels) {
if (dbRels != null && dbRels.length > 0) {
if ((dbRels.length == 1 && dialog.shouldDelete("DbRelationship", dbRels[0].getName())) || (dbRels.length > 1 && dialog.shouldDelete("selected DbRelationships"))) {
DbEntity entity = mediator.getCurrentDbEntity();
for (DbRelationship rel : dbRels) {
entity.removeRelationship(rel.getName());
RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
mediator.fireDbRelationshipEvent(e);
}
ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
}
}
}
Aggregations