use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class RemoveRelationshipAction method removeObjRelationships.
public void removeObjRelationships(ObjEntity entity, ObjRelationship[] rels) {
ProjectController mediator = getProjectController();
for (ObjRelationship rel : rels) {
entity.removeRelationship(rel.getName());
RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
mediator.fireObjRelationshipEvent(e);
}
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class ResolveDbRelationshipDialog method save.
private void save() {
stopEditing();
DbJoinTableModel model = (DbJoinTableModel) table.getModel();
boolean updatingReverse = model.getObjectList().size() > 0;
// handle name update
handleNameUpdate(relationship, name.getText().trim());
model.commit();
// maybe this is no longer valid
if (relationship.isToDependentPK() && !relationship.isValidForDepPk()) {
relationship.setToDependentPK(false);
}
// Don't create reverse with no joins - makes no sense...
if (updatingReverse) {
// If didn't find anything, create reverseDbRel
if (reverseRelationship == null) {
reverseRelationship = new DbRelationship();
reverseRelationship.setName(NameBuilder.builder(reverseRelationship, relationship.getTargetEntity()).baseName(reverseName.getText().trim()).name());
reverseRelationship.setSourceEntity(relationship.getTargetEntity());
reverseRelationship.setTargetEntityName(relationship.getSourceEntity());
reverseRelationship.setToMany(!relationship.isToMany());
relationship.getTargetEntity().addRelationship(reverseRelationship);
// this is needed to update entity view...
if (relationship.getSourceEntity() == relationship.getTargetEntity()) {
getMediator().fireDbRelationshipEvent(new RelationshipEvent(this, reverseRelationship, reverseRelationship.getSourceEntity(), MapEvent.ADD));
}
} else {
handleNameUpdate(reverseRelationship, reverseName.getText().trim());
}
Collection<DbJoin> reverseJoins = getReverseJoins();
reverseRelationship.setJoins(reverseJoins);
// check if joins map to a primary key of this entity
if (!relationship.isToDependentPK() && reverseRelationship.isValidForDepPk()) {
reverseRelationship.setToDependentPK(true);
}
}
Application.getInstance().getUndoManager().addEdit(undo);
getMediator().fireDbRelationshipEvent(new RelationshipEvent(this, relationship, relationship.getSourceEntity()));
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class InferRelationshipsController method generateAction.
public void generateAction() {
ProjectController mediator = application.getFrameController().getProjectController();
InferRelationshipsUndoableEdit undoableEdit = new InferRelationshipsUndoableEdit();
for (InferredRelationship temp : selectedEntities) {
DbRelationship rel = new DbRelationship(uniqueRelName(temp.getSource(), temp.getName()));
RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, temp.getSource(), MapEvent.ADD);
mediator.fireDbRelationshipEvent(e);
rel.setSourceEntity(temp.getSource());
rel.setTargetEntityName(temp.getTarget());
DbJoin join = new DbJoin(rel, temp.getJoinSource().getName(), temp.getJoinTarget().getName());
rel.addJoin(join);
rel.setToMany(temp.isToMany());
temp.getSource().addRelationship(rel);
undoableEdit.addEdit(new CreateRelationshipUndoableEdit(temp.getSource(), new DbRelationship[] { rel }));
}
JOptionPane.showMessageDialog(this.getView(), getSelectedEntitiesSize() + " relationships generated");
view.dispose();
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class CreateRelationshipAction method fireDbRelationshipEvent.
/**
* Fires events when a db rel was added
*/
static void fireDbRelationshipEvent(Object src, ProjectController mediator, DbEntity dbEntity, DbRelationship rel) {
mediator.fireDbRelationshipEvent(new RelationshipEvent(src, rel, dbEntity, MapEvent.ADD));
RelationshipDisplayEvent rde = new RelationshipDisplayEvent(src, rel, dbEntity, mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
mediator.fireDbRelationshipDisplayEvent(rde);
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class RelationshipEventTest method testRelationship.
@Test
public void testRelationship() throws Exception {
Object src = new Object();
Relationship r = new DbRelationship();
r.setName("xyz");
RelationshipEvent e = new RelationshipEvent(src, null, null);
e.setRelationship(r);
assertSame(r, e.getRelationship());
}
Aggregations