use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class CreateRelationshipAction method fireObjRelationshipEvent.
/**
* Fires events when a obj rel was added
*/
static void fireObjRelationshipEvent(Object src, ProjectController mediator, ObjEntity objEntity, ObjRelationship rel) {
mediator.fireObjRelationshipEvent(new RelationshipEvent(src, rel, objEntity, MapEvent.ADD));
RelationshipDisplayEvent rde = new RelationshipDisplayEvent(src, rel, objEntity, mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
mediator.fireObjRelationshipDisplayEvent(rde);
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class RemoveRelationshipAction method removeDbRelationships.
public void removeDbRelationships(DbEntity entity, DbRelationship[] rels) {
ProjectController mediator = getProjectController();
for (DbRelationship rel : rels) {
entity.removeRelationship(rel.getName());
RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
mediator.fireDbRelationshipEvent(e);
}
ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class ResolveDbRelationshipDialog method handleNameUpdate.
private void handleNameUpdate(DbRelationship relationship, String userInputName) {
if (Util.nullSafeEquals(relationship.getName(), userInputName)) {
return;
}
String sourceEntityName = NameBuilder.builder(relationship, relationship.getSourceEntity()).baseName(userInputName).name();
if (Util.nullSafeEquals(sourceEntityName, relationship.getName())) {
return;
}
String oldName = relationship.getName();
relationship.setName(sourceEntityName);
undo.addNameUndo(relationship, oldName, sourceEntityName);
getMediator().fireDbRelationshipEvent(new RelationshipEvent(this, relationship, relationship.getSourceEntity(), oldName));
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class ObjRelationshipInfo method saveMapping.
protected void saveMapping() {
if (!getDbRelationships().equals(getSavedDbRelationships())) {
if (JOptionPane.showConfirmDialog((Component) getView(), "You have changed Db Relationship path. Do you want it to be saved?", "Save ObjRelationship", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
selectPath();
}
}
if (savePath()) {
mediator.fireObjRelationshipEvent(new RelationshipEvent(Application.getFrame(), getRelationship(), getRelationship().getSourceEntity()));
}
view.sourceEntityLabel.setText(relationship.getSourceEntity().getName());
view.dispose();
}
use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.
the class ObjRelationshipTableModel method setUpdatedValueAt.
@Override
public void setUpdatedValueAt(Object value, int row, int column) {
ObjRelationship relationship = getRelationship(row);
RelationshipEvent event = new RelationshipEvent(eventSource, relationship, entity);
switch(column) {
case REL_NAME:
String text = (String) value;
event.setOldName(relationship.getName());
ProjectUtil.setRelationshipName(entity, relationship, text);
fireTableCellUpdated(row, column);
break;
case REL_TARGET:
ObjEntity target = (ObjEntity) value;
relationship.setTargetEntityName(target);
// Clear existing relationships, otherwise addDbRelationship() might fail
relationship.clearDbRelationships();
// now try to connect DbEntities if we can do it in one step
if (target != null) {
DbEntity srcDB = relationship.getSourceEntity().getDbEntity();
DbEntity targetDB = target.getDbEntity();
if (srcDB != null && targetDB != null) {
Relationship anyConnector = srcDB.getAnyRelationship(targetDB);
if (anyConnector != null) {
relationship.addDbRelationship((DbRelationship) anyConnector);
}
}
}
fireTableRowsUpdated(row, row);
break;
case REL_DELETE_RULE:
relationship.setDeleteRule(DeleteRule.deleteRuleForName((String) value));
fireTableCellUpdated(row, column);
break;
case REL_LOCKING:
relationship.setUsedForLocking((value instanceof Boolean) && (Boolean) value);
fireTableCellUpdated(row, column);
break;
case REL_TARGET_PATH:
relationship.setDbRelationshipPath((String) value);
fireTableCellUpdated(row, column);
case REL_COMMENT:
setComment((String) value, relationship);
fireTableRowsUpdated(row, row);
break;
}
mediator.fireObjRelationshipEvent(event);
}
Aggregations