Search in sources :

Example 1 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.

the class ObjAttributeTableModel method setObjAttributeType.

private void setObjAttributeType(ObjAttributeWrapper attribute, Object value) {
    String oldType = attribute.getType();
    String newType = value != null ? value.toString() : null;
    attribute.setType(newType);
    if (oldType == null || newType == null) {
        return;
    }
    String[] registeredTypes = ModelerUtil.getRegisteredTypeNames();
    Collection<String> registeredTypesList = Arrays.asList(registeredTypes);
    if (registeredTypesList.contains(oldType) == registeredTypesList.contains(newType)) {
        return;
    }
    ObjEntity entity = attribute.getEntity();
    ObjAttribute attributeNew;
    if (registeredTypesList.contains(newType) || !mediator.getEmbeddableNamesInCurrentDataDomain().contains(newType)) {
        attributeNew = new ObjAttribute();
        attributeNew.setDbAttributePath(attribute.getDbAttributePath());
    } else {
        attributeNew = new EmbeddedAttribute();
        attributeNew.setDbAttributePath(null);
    }
    attributeNew.setName(attribute.getName());
    attributeNew.setEntity(entity);
    attributeNew.setParent(attribute.getParent());
    attributeNew.setType(attribute.getType());
    attributeNew.setUsedForLocking(attribute.isUsedForLocking());
    entity.updateAttribute(attributeNew);
    mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
    mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
    mediator.fireObjAttributeEvent(new AttributeEvent(this, attributeNew, entity, MapEvent.CHANGE));
    mediator.fireObjAttributeDisplayEvent(new AttributeDisplayEvent(this, attributeNew, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) ObjAttribute(org.apache.cayenne.map.ObjAttribute) EntityEvent(org.apache.cayenne.map.event.EntityEvent) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 2 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.

the class ObjEntityTab method setClientSuperClassName.

void setClientSuperClassName(String text) {
    if (text != null && text.trim().length() == 0) {
        text = null;
    }
    ObjEntity ent = mediator.getCurrentObjEntity();
    if (ent != null && !Util.nullSafeEquals(ent.getClientSuperClassName(), text)) {
        ent.setClientSuperClassName(text);
        mediator.fireObjEntityEvent(new EntityEvent(this, ent));
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 3 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.

the class ObjEntityTab method setComment.

private void setComment(String value) {
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity == null) {
        return;
    }
    ObjectInfo.putToMetaData(mediator.getApplication().getMetaData(), entity, ObjectInfo.COMMENT, value);
    mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 4 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.

the class ObjEntityTab method initController.

private void initController() {
    // initialize events processing and tracking of UI updates...
    mediator.addObjEntityDisplayListener(this);
    dbEntityCombo.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // Change DbEntity for current ObjEntity
            ObjEntity entity = mediator.getCurrentObjEntity();
            DbEntity dbEntity = (DbEntity) dbEntityCombo.getSelectedItem();
            if (dbEntity != entity.getDbEntity()) {
                entity.setDbEntity(dbEntity);
                mediator.fireObjEntityEvent(new EntityEvent(this, entity));
            }
        }
    });
    superEntityCombo.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // Change super-entity
            ObjEntity superEntity = (ObjEntity) superEntityCombo.getSelectedItem();
            String name = (superEntity == null || superEntity == NO_INHERITANCE) ? null : superEntity.getName();
            ObjEntity entity = mediator.getCurrentObjEntity();
            if (!Util.nullSafeEquals(name, entity.getSuperEntityName())) {
                List<ObjAttribute> duplicateAttributes = null;
                if (name != null) {
                    duplicateAttributes = getDuplicatedAttributes(superEntity);
                }
                if (duplicateAttributes != null && duplicateAttributes.size() > 0) {
                    DuplicatedAttributesDialog.showDialog(Application.getFrame(), duplicateAttributes, superEntity, entity);
                    if (DuplicatedAttributesDialog.getResult().equals(DuplicatedAttributesDialog.CANCEL_RESULT)) {
                        superEntityCombo.setSelectedItem(entity.getSuperEntity());
                        superClassName.setText(entity.getSuperClassName());
                        return;
                    }
                }
                entity.setSuperEntityName(name);
                // drop not valid dbAttributePath
                if (name == null) {
                    for (ObjAttribute objAttribute : entity.getAttributes()) {
                        if (objAttribute.getDbAttribute() == null) {
                            objAttribute.setDbAttributePath(null);
                        }
                    }
                }
                if (name == null) {
                    dbEntityCombo.setEnabled(true);
                } else {
                    dbEntityCombo.setEnabled(false);
                    dbEntityCombo.getModel().setSelectedItem(null);
                }
                // if a super-entity selected, disable table selection
                // and also update parent DbEntity selection...
                toggleEnabled(name == null, !serverOnly.isSelected());
                dbEntityCombo.getModel().setSelectedItem(entity.getDbEntity());
                superClassName.setText(entity.getSuperClassName());
                // fire both EntityEvent and EntityDisplayEvent;
                // the later is to update attribute and relationship display
                DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
                DataMap map = mediator.getCurrentDataMap();
                mediator.fireObjEntityEvent(new EntityEvent(this, entity));
                mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, entity, map, domain));
            }
        }
    });
    tableLabel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // Jump to DbEntity of the current ObjEntity
            DbEntity entity = mediator.getCurrentObjEntity().getDbEntity();
            if (entity != null) {
                DataChannelDescriptor dom = (DataChannelDescriptor) mediator.getProject().getRootNode();
                mediator.fireDbEntityDisplayEvent(new EntityDisplayEvent(this, entity, entity.getDataMap(), dom));
            }
        }
    });
    readOnly.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            if (entity != null) {
                entity.setReadOnly(readOnly.isSelected());
                mediator.fireObjEntityEvent(new EntityEvent(this, entity));
            }
        }
    });
    optimisticLocking.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            if (entity != null) {
                entity.setDeclaredLockType(optimisticLocking.isSelected() ? ObjEntity.LOCK_TYPE_OPTIMISTIC : ObjEntity.LOCK_TYPE_NONE);
                mediator.fireObjEntityEvent(new EntityEvent(this, entity));
            }
        }
    });
    serverOnly.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            if (entity != null) {
                entity.setServerOnly(serverOnly.isSelected());
                toggleEnabled(dbEntityCombo.isEnabled(), !serverOnly.isSelected());
                mediator.fireObjEntityEvent(new EntityEvent(this, entity));
            }
        }
    });
    isAbstract.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            if (entity != null) {
                entity.setAbstract(isAbstract.isSelected());
                mediator.fireObjEntityEvent(new EntityEvent(this, entity));
            }
        }
    });
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ItemEvent(java.awt.event.ItemEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) ObjAttribute(org.apache.cayenne.map.ObjAttribute) ActionEvent(java.awt.event.ActionEvent) DataMap(org.apache.cayenne.map.DataMap) ObjEntity(org.apache.cayenne.map.ObjEntity) ActionListener(java.awt.event.ActionListener) DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) List(java.util.List) LinkedList(java.util.LinkedList) ItemListener(java.awt.event.ItemListener)

Example 5 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent 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)

Aggregations

EntityEvent (org.apache.cayenne.map.event.EntityEvent)36 DbEntity (org.apache.cayenne.map.DbEntity)14 ObjEntity (org.apache.cayenne.map.ObjEntity)13 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)7 ProjectController (org.apache.cayenne.modeler.ProjectController)6 Entity (org.apache.cayenne.map.Entity)5 Test (org.junit.Test)5 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)4 ArrayList (java.util.ArrayList)3 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)3 DbAttribute (org.apache.cayenne.map.DbAttribute)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)3 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)3 ValidationException (org.apache.cayenne.validation.ValidationException)3 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)2 EntityMergeSupport (org.apache.cayenne.dbsync.merge.context.EntityMergeSupport)2 Expression (org.apache.cayenne.exp.Expression)2 DbKeyGenerator (org.apache.cayenne.map.DbKeyGenerator)2