Search in sources :

Example 1 with CreateRelationshipUndoableEdit

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

Example 2 with CreateRelationshipUndoableEdit

use of org.apache.cayenne.modeler.undo.CreateRelationshipUndoableEdit in project cayenne by apache.

the class CreateRelationshipAction method performAction.

/**
 * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
 */
@Override
public void performAction(ActionEvent e) {
    ObjEntity objEnt = getProjectController().getCurrentObjEntity();
    if (objEnt != null) {
        ObjRelationship rel = new ObjRelationship();
        rel.setName(NameBuilder.builder(rel, objEnt).name());
        createObjRelationship(objEnt, rel);
        application.getUndoManager().addEdit(new CreateRelationshipUndoableEdit(objEnt, new ObjRelationship[] { rel }));
    } else {
        DbEntity dbEnt = getProjectController().getCurrentDbEntity();
        if (dbEnt != null) {
            DbRelationship rel = new DbRelationship();
            rel.setName(NameBuilder.builder(rel, dbEnt).name());
            createDbRelationship(dbEnt, rel);
            application.getUndoManager().addEdit(new CreateRelationshipUndoableEdit(dbEnt, new DbRelationship[] { rel }));
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) CreateRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.CreateRelationshipUndoableEdit)

Aggregations

DbRelationship (org.apache.cayenne.map.DbRelationship)2 CreateRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.CreateRelationshipUndoableEdit)2 DbEntity (org.apache.cayenne.map.DbEntity)1 DbJoin (org.apache.cayenne.map.DbJoin)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1 RelationshipEvent (org.apache.cayenne.map.event.RelationshipEvent)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 InferRelationshipsUndoableEdit (org.apache.cayenne.modeler.undo.InferRelationshipsUndoableEdit)1