Search in sources :

Example 1 with EntityDisplayEvent

use of org.apache.cayenne.modeler.event.EntityDisplayEvent 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 EntityDisplayEvent

use of org.apache.cayenne.modeler.event.EntityDisplayEvent in project cayenne by apache.

the class ObjEntityCallbackMethodsTab method initController.

/**
 * listeners initialization
 */
protected void initController() {
    super.initController();
    addComponentListener(new ComponentAdapter() {

        public void componentShown(ComponentEvent e) {
            rebuildTables();
        }
    });
    mediator.addObjEntityDisplayListener(new ObjEntityDisplayListener() {

        public void currentObjEntityChanged(EntityDisplayEvent e) {
            if (ObjEntityCallbackMethodsTab.this.isVisible()) {
                rebuildTables();
            }
        }
    });
}
Also used : EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter) ObjEntityDisplayListener(org.apache.cayenne.modeler.event.ObjEntityDisplayListener)

Example 3 with EntityDisplayEvent

use of org.apache.cayenne.modeler.event.EntityDisplayEvent 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 4 with EntityDisplayEvent

use of org.apache.cayenne.modeler.event.EntityDisplayEvent in project cayenne by apache.

the class DataDomainGraphTab method currentDomainChanged.

public void currentDomainChanged(DomainDisplayEvent e) {
    if (e instanceof EntityDisplayEvent) {
        // selecting an event
        // choose type of diagram
        Entity entity = ((EntityDisplayEvent) e).getEntity();
        diagramCombo.setSelectedIndex(entity instanceof ObjEntity ? 1 : 0);
        refresh();
        GraphBuilder builder = getGraphRegistry().getGraphMap(domain).get(getSelectedType());
        Object cell = builder.getEntityCell(entity.getName());
        if (cell != null) {
            graph.setSelectionCell(cell);
            graph.scrollCellToVisible(cell);
        }
    } else if (domain != e.getDomain()) {
        needRebuild = true;
        domain = e.getDomain();
        if (isVisible()) {
            refresh();
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) ObjEntity(org.apache.cayenne.map.ObjEntity) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent)

Example 5 with EntityDisplayEvent

use of org.apache.cayenne.modeler.event.EntityDisplayEvent in project cayenne by apache.

the class ShowGraphEntityAction method showEntity.

void showEntity(Entity entity) {
    // we're always in same domain
    EditorView editor = ((CayenneModelerFrame) Application.getInstance().getFrameController().getView()).getView();
    editor.getProjectTreeView().getSelectionModel().setSelectionPath(editor.getProjectTreeView().getSelectionPath().getParentPath().getParentPath());
    DomainDisplayEvent event = new EntityDisplayEvent(editor.getProjectTreeView(), entity, entity.getDataMap(), (DataChannelDescriptor) getProjectController().getProject().getRootNode());
    getProjectController().fireDomainDisplayEvent(event);
}
Also used : DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EditorView(org.apache.cayenne.modeler.editor.EditorView) CayenneModelerFrame(org.apache.cayenne.modeler.CayenneModelerFrame)

Aggregations

EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)20 ObjEntity (org.apache.cayenne.map.ObjEntity)10 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)8 DbEntity (org.apache.cayenne.map.DbEntity)7 EntityEvent (org.apache.cayenne.map.event.EntityEvent)7 DataMap (org.apache.cayenne.map.DataMap)6 Entity (org.apache.cayenne.map.Entity)5 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 AttributeDisplayEvent (org.apache.cayenne.modeler.event.AttributeDisplayEvent)3 EmbeddedAttribute (org.apache.cayenne.map.EmbeddedAttribute)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)2 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)2 DomainDisplayEvent (org.apache.cayenne.modeler.event.DomainDisplayEvent)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 LinkedList (java.util.LinkedList)1