Search in sources :

Example 11 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class QueryErrorMsg method displayField.

public void displayField(ProjectController mediator, JFrame frame) {
    Object object = super.validationFailure.getSource();
    DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
    QueryDescriptor query = (QueryDescriptor) object;
    DataMap map = query.getDataMap();
    QueryDisplayEvent event = new QueryDisplayEvent(frame, query, map, domain);
    mediator.fireQueryDisplayEvent(event);
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 12 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class DataDomainView method setDomainProperty.

/**
 * Helper method that updates domain properties. If a value equals to default, null
 * value is used instead.
 */
protected void setDomainProperty(String property, String value, String defaultValue) {
    DataChannelDescriptor domain = (DataChannelDescriptor) projectController.getProject().getRootNode();
    if (domain == null) {
        return;
    }
    // no empty strings
    if ("".equals(value)) {
        value = null;
    }
    // use NULL for defaults
    if (value != null && value.equals(defaultValue)) {
        value = null;
    }
    Map properties = domain.getProperties();
    Object oldValue = properties.get(property);
    if (!Util.nullSafeEquals(value, oldValue)) {
        properties.put(property, value);
        DomainEvent e = new DomainEvent(this, domain);
        projectController.fireDomainEvent(e);
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) Map(java.util.Map)

Example 13 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class DataDomainView method setDomainName.

void setDomainName(String newName) {
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) Application.getInstance().getProject().getRootNode();
    if (Util.nullSafeEquals(dataChannelDescriptor.getName(), newName)) {
        return;
    }
    if (newName == null || newName.trim().length() == 0) {
        throw new ValidationException("Enter name for DataDomain");
    }
    Preferences prefs = projectController.getPreferenceForDataDomain();
    DomainEvent e = new DomainEvent(this, dataChannelDescriptor, dataChannelDescriptor.getName());
    dataChannelDescriptor.setName(newName);
    RenamedPreferences.copyPreferences(newName, prefs);
    projectController.fireDomainEvent(e);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) Preferences(java.util.prefs.Preferences) RenamedPreferences(org.apache.cayenne.pref.RenamedPreferences)

Example 14 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class DataMapView method setDataMapName.

void setDataMapName(String newName) {
    if (newName == null || newName.trim().length() == 0) {
        throw new ValidationException("Enter name for DataMap");
    }
    DataMap map = eventController.getCurrentDataMap();
    // search for matching map name across domains, as currently they have to be
    // unique globally
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) Application.getInstance().getProject().getRootNode();
    DataMap matchingMap = dataChannelDescriptor.getDataMap(newName);
    if (matchingMap != null && !matchingMap.equals(map)) {
        // there is an entity with the same name
        throw new ValidationException("There is another DataMap named '" + newName + "'. Use a different name.");
    }
    String oldName = map.getName();
    if (Util.nullSafeEquals(newName, oldName)) {
        return;
    }
    // completely new name, set new name for domain
    DataMapDefaults pref = eventController.getDataMapPreferences("");
    DataMapEvent e = new DataMapEvent(this, map, map.getName());
    ProjectUtil.setDataMapName((DataChannelDescriptor) eventController.getProject().getRootNode(), map, newName);
    pref.copyPreferences(newName);
    eventController.fireDataMapEvent(e);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 15 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.

the class Application method getMainPreferenceForProject.

public Preferences getMainPreferenceForProject() {
    DataChannelDescriptor descriptor = (DataChannelDescriptor) getFrameController().getProjectController().getProject().getRootNode();
    // if new project
    if (descriptor.getConfigurationSource() == null) {
        return getPreferencesNode(getProject().getClass(), getNewProjectTemporaryName());
    }
    String path = CayennePreference.filePathToPrefereceNodePath(descriptor.getConfigurationSource().getURL().getPath());
    Preferences pref = getPreferencesNode(getProject().getClass(), "");
    return pref.node(pref.absolutePath() + path);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) Preferences(java.util.prefs.Preferences) CayenneProjectPreferences(org.apache.cayenne.pref.CayenneProjectPreferences) ClasspathPreferences(org.apache.cayenne.modeler.dialog.pref.ClasspathPreferences)

Aggregations

DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)100 DataMap (org.apache.cayenne.map.DataMap)50 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)28 Test (org.junit.Test)20 ObjEntity (org.apache.cayenne.map.ObjEntity)18 DbEntity (org.apache.cayenne.map.DbEntity)12 ProjectController (org.apache.cayenne.modeler.ProjectController)12 URL (java.net.URL)11 Embeddable (org.apache.cayenne.map.Embeddable)11 ArrayList (java.util.ArrayList)10 URLResource (org.apache.cayenne.resource.URLResource)10 ObjAttribute (org.apache.cayenne.map.ObjAttribute)8 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)8 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)6 Injector (org.apache.cayenne.di.Injector)6 Procedure (org.apache.cayenne.map.Procedure)6 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)6 Resource (org.apache.cayenne.resource.Resource)6