Search in sources :

Example 1 with DomainEvent

use of org.apache.cayenne.configuration.event.DomainEvent 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 2 with DomainEvent

use of org.apache.cayenne.configuration.event.DomainEvent 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 3 with DomainEvent

use of org.apache.cayenne.configuration.event.DomainEvent in project cayenne by apache.

the class ProjectController method removeFromHistory.

private void removeFromHistory(EventObject e) {
    int count = controllerStateHistory.size();
    List<ControllerState> removeList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        ControllerState cs = controllerStateHistory.get(i);
        if (cs == null || cs.event == null) {
            continue;
        }
        EventObject csEvent = cs.event;
        if (e instanceof EntityEvent && csEvent instanceof EntityDisplayEvent) {
            if (((EntityEvent) e).getEntity() == ((EntityDisplayEvent) csEvent).getEntity()) {
                removeList.add(cs);
            }
        } else if (e instanceof EmbeddableEvent && csEvent instanceof EmbeddableDisplayEvent) {
            if (((EmbeddableEvent) e).getEmbeddable() == ((EmbeddableDisplayEvent) csEvent).getEmbeddable()) {
                removeList.add(cs);
            }
        } else if (e instanceof ProcedureEvent && csEvent instanceof ProcedureDisplayEvent) {
            if (((ProcedureEvent) e).getProcedure() == ((ProcedureDisplayEvent) csEvent).getProcedure()) {
                removeList.add(cs);
            }
        } else if (e instanceof QueryEvent && csEvent instanceof QueryDisplayEvent) {
            if (((QueryEvent) e).getQuery() == ((QueryDisplayEvent) csEvent).getQuery()) {
                removeList.add(cs);
            }
        } else if (e instanceof DataMapEvent && csEvent instanceof DataMapDisplayEvent) {
            if (((DataMapEvent) e).getDataMap() == ((DataMapDisplayEvent) csEvent).getDataMap()) {
                removeList.add(cs);
            }
        } else if (e instanceof DataNodeEvent && csEvent instanceof DataNodeDisplayEvent) {
            if (((DataNodeEvent) e).getDataNode() == ((DataNodeDisplayEvent) csEvent).getDataNode()) {
                removeList.add(cs);
            }
        } else if (e instanceof DomainEvent && csEvent instanceof DomainDisplayEvent) {
            if (((DomainEvent) e).getDomain() == ((DomainDisplayEvent) csEvent).getDomain()) {
                removeList.add(cs);
            }
        }
    }
    for (ControllerState o : removeList) {
        controllerStateHistory.remove(o);
    }
}
Also used : EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent) ArrayList(java.util.ArrayList) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) EventObject(java.util.EventObject) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 4 with DomainEvent

use of org.apache.cayenne.configuration.event.DomainEvent in project cayenne by apache.

the class DomainEventTest method testConstructor2.

@Test
public void testConstructor2() throws Exception {
    Object src = new Object();
    DataChannelDescriptor d = new DataChannelDescriptor();
    DomainEvent e = new DomainEvent(src, d, "oldname");
    assertSame(src, e.getSource());
    assertSame(d, e.getDomain());
    assertEquals("oldname", e.getOldName());
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) Test(org.junit.Test)

Example 5 with DomainEvent

use of org.apache.cayenne.configuration.event.DomainEvent in project cayenne by apache.

the class DomainEventTest method testDomain.

@Test
public void testDomain() throws Exception {
    Object src = new Object();
    DataChannelDescriptor d = new DataChannelDescriptor();
    DomainEvent e = new DomainEvent(src, null);
    e.setDomain(d);
    assertSame(d, e.getDomain());
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) Test(org.junit.Test)

Aggregations

DomainEvent (org.apache.cayenne.configuration.event.DomainEvent)6 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)5 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 EventObject (java.util.EventObject)1 Map (java.util.Map)1 Preferences (java.util.prefs.Preferences)1 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)1 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)1 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)1 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)1 EmbeddableEvent (org.apache.cayenne.map.event.EmbeddableEvent)1 EntityEvent (org.apache.cayenne.map.event.EntityEvent)1 RenamedPreferences (org.apache.cayenne.pref.RenamedPreferences)1 ValidationException (org.apache.cayenne.validation.ValidationException)1