Search in sources :

Example 1 with DataNodeDefaults

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

Aggregations

DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 DataNodeDefaults (org.apache.cayenne.modeler.pref.DataNodeDefaults)1 ValidationException (org.apache.cayenne.validation.ValidationException)1