Search in sources :

Example 1 with RelationshipEvent

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);
}
Also used : RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent) RelationshipDisplayEvent(org.apache.cayenne.modeler.event.RelationshipDisplayEvent)

Example 2 with RelationshipEvent

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());
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) ProjectController(org.apache.cayenne.modeler.ProjectController) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 3 with RelationshipEvent

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));
}
Also used : RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 4 with RelationshipEvent

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();
}
Also used : RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 5 with RelationshipEvent

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);
}
Also used : RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Aggregations

RelationshipEvent (org.apache.cayenne.map.event.RelationshipEvent)15 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ProjectController (org.apache.cayenne.modeler.ProjectController)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)3 DbEntity (org.apache.cayenne.map.DbEntity)2 DbJoin (org.apache.cayenne.map.DbJoin)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 RelationshipDisplayEvent (org.apache.cayenne.modeler.event.RelationshipDisplayEvent)2 RemoveRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 Relationship (org.apache.cayenne.map.Relationship)1 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)1 EntityEvent (org.apache.cayenne.map.event.EntityEvent)1 CreateRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.CreateRelationshipUndoableEdit)1 InferRelationshipsUndoableEdit (org.apache.cayenne.modeler.undo.InferRelationshipsUndoableEdit)1 Test (org.junit.Test)1