use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class ObjRelationshipInfo method connectEnds.
// Connects last selected DbRelationship in the path to the
// last DbEntity, creating a dummy relationship if needed.
private void connectEnds() {
Relationship last = null;
int size = dbRelationships.size();
if (size > 0) {
last = dbRelationships.get(size - 1);
}
Entity target = getEndEntity();
if (target != null && (last == null || last.getTargetEntity() != target)) {
// try to connect automatically, if we can't use dummy connector
Entity source = (last == null) ? getStartEntity() : last.getTargetEntity();
if (source != null) {
Relationship anyConnector = source != null ? source.getAnyRelationship(target) : null;
if (anyConnector != null) {
dbRelationships.add((DbRelationship) anyConnector);
}
}
}
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class ObjRelationshipInfo method savePath.
/**
* Stores current state of the model in the internal ObjRelationship.
*/
public boolean savePath() {
boolean hasChanges = false;
boolean oldToMany = relationship.isToMany();
String relationshipName = getRelationshipName();
if (!Util.nullSafeEquals(relationship.getName(), relationshipName)) {
hasChanges = true;
relationship.setName(relationshipName);
}
if (savedDbRelationships.size() > 0) {
DbEntity lastEntity = (DbEntity) savedDbRelationships.get(savedDbRelationships.size() - 1).getTargetEntity();
if (objectTarget == null || objectTarget.getDbEntity() != lastEntity) {
/**
* Entities in combobox and path browser do not match. In this
* case, we rely on the browser and automatically select one of
* lastEntity's ObjEntities
*/
Collection<ObjEntity> objEntities = lastEntity.getDataMap().getMappedEntities(lastEntity);
objectTarget = objEntities.size() == 0 ? null : objEntities.iterator().next();
}
}
if (objectTarget == null || !Util.nullSafeEquals(objectTarget.getName(), relationship.getTargetEntityName())) {
hasChanges = true;
// note on events notification - this needs to be propagated
// via old modeler events, but we leave this to the controller
// since model knows nothing about Modeler mediator.
relationship.setTargetEntityName(objectTarget);
}
// check for path modifications
List<DbRelationship> oldPath = relationship.getDbRelationships();
if (oldPath.size() != savedDbRelationships.size()) {
hasChanges = true;
updatePath();
} else {
for (int i = 0; i < oldPath.size(); i++) {
DbRelationship next = savedDbRelationships.get(i);
if (oldPath.get(i) != next) {
hasChanges = true;
updatePath();
break;
}
}
}
String collectionType = ObjRelationship.DEFAULT_COLLECTION_TYPE.equals(targetCollection) || !relationship.isToMany() ? null : targetCollection;
if (!Util.nullSafeEquals(collectionType, relationship.getCollectionType())) {
hasChanges = true;
relationship.setCollectionType(collectionType);
}
// map key only makes sense for Map relationships
String mapKey = COLLECTION_TYPE_MAP.equals(collectionType) && !DEFAULT_MAP_KEY.equals(this.mapKey) ? this.mapKey : null;
if (!Util.nullSafeEquals(mapKey, relationship.getMapKey())) {
hasChanges = true;
relationship.setMapKey(mapKey);
}
/**
* As of CAY-436 here we check if to-many property has changed during
* the editing, and if so, delete rule must be reset to default value
*/
if (hasChanges && relationship.isToMany() != oldToMany) {
DeleteRuleUpdater.updateObjRelationship(relationship);
}
return hasChanges;
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class DbEntityRelationshipPanel method tableChanged.
public void tableChanged(TableModelEvent e) {
if (table.getSelectedRow() >= 0) {
DbRelationshipTableModel model = (DbRelationshipTableModel) table.getModel();
DbRelationship rel = model.getRelationship(table.getSelectedRow());
enabledResolve = (rel.getTargetEntity() != null);
resolveMenu.setEnabled(enabledResolve);
}
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class DbEntityRelationshipPanel method initController.
private void initController() {
this.mediator.addDbEntityDisplayListener(this);
this.mediator.addDbEntityListener(this);
this.mediator.addDbRelationshipListener(this);
resolver = new ActionListener() {
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();
if (row < 0) {
return;
}
// Get DbRelationship
DbRelationshipTableModel model = (DbRelationshipTableModel) table.getModel();
DbRelationship rel = model.getRelationship(row);
ResolveDbRelationshipDialog dialog = new ResolveDbRelationshipDialog(rel);
dialog.setVisible(true);
dialog.dispose();
}
};
resolveMenu.addActionListener(resolver);
table.getSelectionModel().addListSelectionListener(new DbRelationshipListSelectionListener());
mediator.getApplication().getActionManager().setupCutCopyPaste(table, CutAttributeRelationshipAction.class, CopyAttributeRelationshipAction.class);
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class DbEntityRelationshipPanel method dbRelationshipRemoved.
public void dbRelationshipRemoved(RelationshipEvent e) {
DbRelationshipTableModel model = (DbRelationshipTableModel) table.getModel();
DbRelationship relationship = (DbRelationship) e.getRelationship();
int ind = model.getObjectList().indexOf(relationship);
model.removeRelationship(relationship);
table.select(ind);
}
Aggregations