Search in sources :

Example 6 with RelationshipEvent

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

Example 7 with RelationshipEvent

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

Example 8 with RelationshipEvent

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

Example 9 with RelationshipEvent

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

Example 10 with RelationshipEvent

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));
        }
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) 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