Search in sources :

Example 31 with ProjectController

use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.

the class RemoveRelationshipAction method performAction.

@Override
public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    ProjectController mediator = getProjectController();
    ObjRelationship[] rels = getProjectController().getCurrentObjRelationships();
    if (rels != null && rels.length > 0) {
        if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName())) || (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            removeObjRelationships(entity, rels);
            Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
        }
    } else {
        DbRelationship[] dbRels = getProjectController().getCurrentDbRelationships();
        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();
                removeDbRelationships(entity, dbRels);
                Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
            }
        }
    }
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) ProjectController(org.apache.cayenne.modeler.ProjectController) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)

Example 32 with ProjectController

use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.

the class AdapterEditor method setAdapterName.

public void setAdapterName(String name) {
    if (node == null) {
        return;
    }
    // ModelerDbAdapter adapter = new ModelerDbAdapter(name, node.getDataSource());
    // adapter.validate();
    node.setAdapterType(name);
    DataNodeEvent e = new DataNodeEvent(AdapterEditor.this, node);
    ((ProjectController) getParent()).fireDataNodeEvent(e);
}
Also used : DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 33 with ProjectController

use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.

the class JDBCDataSourceEditor method syncDataSourceAction.

/**
 * This action is called whenever the password location is changed
 * in the GUI pulldown.  It changes labels and editability of the
 * password fields depending on the option that was selected.
 */
public void syncDataSourceAction() {
    CayenneModelerController mainController = getApplication().getFrameController();
    if (getNode() == null || getNode().getDataSourceDescriptor() == null) {
        return;
    }
    DataSourceInfo projectDSI = getNode().getDataSourceDescriptor();
    ProjectController parent = (ProjectController) getParent();
    String key = parent.getDataNodePreferences().getLocalDataSource();
    if (key == null) {
        mainController.updateStatus("No Local DataSource selected for node...");
        return;
    }
    DBConnectionInfo dataSource = (DBConnectionInfo) getApplication().getCayenneProjectPreferences().getDetailObject(DBConnectionInfo.class).getObject(key);
    if (dataSource != null) {
        if (dataSource.copyTo(projectDSI)) {
            refreshView();
            super.nodeChangeProcessor.modelUpdated(null, null, null);
            mainController.updateStatus(null);
        } else {
            mainController.updateStatus("DataNode is up to date...");
        }
    } else {
        mainController.updateStatus("Invalid Local DataSource selected for node...");
    }
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) CayenneModelerController(org.apache.cayenne.modeler.CayenneModelerController) ProjectController(org.apache.cayenne.modeler.ProjectController) DBConnectionInfo(org.apache.cayenne.modeler.pref.DBConnectionInfo)

Example 34 with ProjectController

use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.

the class MainDataNodeEditor method setNodeName.

public void setNodeName(String newName) {
    if (node == null) {
        return;
    }
    // validate...
    if (newName == null) {
        throw new ValidationException("Empty DataNode Name");
    }
    ProjectController parent = (ProjectController) getParent();
    DataNodeDefaults oldPref = parent.getDataNodePreferences();
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) getApplication().getProject().getRootNode();
    Collection<DataNodeDescriptor> matchingNode = dataChannelDescriptor.getNodeDescriptors();
    Iterator<DataNodeDescriptor> it = matchingNode.iterator();
    while (it.hasNext()) {
        DataNodeDescriptor node = it.next();
        if (node.getName().equals(newName)) {
            // there is an entity with the same name
            throw new ValidationException("There is another DataNode named '" + newName + "'. Use a different name.");
        }
    }
    // passed validation, set value...
    // TODO: fixme....there is a slight chance that domain is different than
    // the one
    // cached node belongs to
    ProjectUtil.setDataNodeName((DataChannelDescriptor) parent.getProject().getRootNode(), node, newName);
    oldPref.copyPreferences(newName);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataNodeDefaults(org.apache.cayenne.modeler.pref.DataNodeDefaults) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 35 with ProjectController

use of org.apache.cayenne.modeler.ProjectController 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)

Aggregations

ProjectController (org.apache.cayenne.modeler.ProjectController)59 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)12 ObjEntity (org.apache.cayenne.map.ObjEntity)10 DbEntity (org.apache.cayenne.map.DbEntity)8 DataMap (org.apache.cayenne.map.DataMap)7 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)6 EntityEvent (org.apache.cayenne.map.event.EntityEvent)6 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)5 ArrayList (java.util.ArrayList)4 DbAttribute (org.apache.cayenne.map.DbAttribute)4 DbRelationship (org.apache.cayenne.map.DbRelationship)4 Embeddable (org.apache.cayenne.map.Embeddable)4 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 RelationshipEvent (org.apache.cayenne.map.event.RelationshipEvent)4 ComponentAdapter (java.awt.event.ComponentAdapter)3 ComponentEvent (java.awt.event.ComponentEvent)3 EntityMergeSupport (org.apache.cayenne.dbsync.merge.context.EntityMergeSupport)3