Search in sources :

Example 21 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class PackageUpdateController method updatePackage.

protected void updatePackage() {
    boolean doAll = isAllEntities();
    Map<String, String> oldNameEmbeddableToNewName = new HashMap<>();
    // Create local copy to escape ConcurrentModificationException
    Collection<Embeddable> embeddables = new ArrayList<>(dataMap.getEmbeddables());
    for (Embeddable embeddable : embeddables) {
        String oldName = embeddable.getClassName();
        Pattern p = Pattern.compile("[.]");
        String[] tokens = p.split(oldName);
        String className = tokens[tokens.length - 1];
        if (doAll || Util.isEmptyString(oldName) || oldName.indexOf('.') < 0) {
            EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName());
            String newClassName = getNameWithDefaultPackage(className);
            oldNameEmbeddableToNewName.put(oldName, newClassName);
            embeddable.setClassName(newClassName);
            mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());
        }
    }
    for (ObjEntity entity : dataMap.getObjEntities()) {
        String oldName = getClassName(entity);
        if (doAll || Util.isEmptyString(oldName) || oldName.indexOf('.') < 0) {
            String className = extractClassName(Util.isEmptyString(oldName) ? entity.getName() : oldName);
            setClassName(entity, getNameWithDefaultPackage(className));
        }
        for (ObjAttribute attribute : entity.getAttributes()) {
            if (attribute instanceof EmbeddedAttribute) {
                if (oldNameEmbeddableToNewName.size() > 0 && oldNameEmbeddableToNewName.containsKey(attribute.getType())) {
                    attribute.setType(oldNameEmbeddableToNewName.get(attribute.getType()));
                    AttributeEvent ev = new AttributeEvent(this, attribute, entity);
                    mediator.fireObjAttributeEvent(ev);
                }
            }
        }
    }
    view.dispose();
}
Also used : Pattern(java.util.regex.Pattern) EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) ObjAttribute(org.apache.cayenne.map.ObjAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) Embeddable(org.apache.cayenne.map.Embeddable) ObjEntity(org.apache.cayenne.map.ObjEntity)

Example 22 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class ObjAttributeInfoDialog method getCurrentOverrideAttribute.

public Map<String, String> getCurrentOverrideAttribute() {
    Map<String, String> currentEmbeddableOverrite = new HashMap<>();
    Collection<EmbeddableAttribute> embList = embeddableModel.getEmbeddableList();
    Embeddable emb = stringToEmbeddables.get(attributeSaved.getType());
    for (EmbeddableAttribute e : embList) {
        if ((emb.getAttribute(e.getName()).getDbAttributeName() == null && e.getDbAttributeName() != null) || (emb.getAttribute(e.getName()).getDbAttributeName() != null && !emb.getAttribute(e.getName()).getDbAttributeName().equals(e.getDbAttributeName()))) {
            currentEmbeddableOverrite.put(e.getName(), e.getDbAttributeName());
        }
    }
    return currentEmbeddableOverrite;
}
Also used : HashMap(java.util.HashMap) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Embeddable(org.apache.cayenne.map.Embeddable)

Example 23 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class PasteUndoableEdit method undo.

@Override
public void undo() throws CannotUndoException {
    RemoveAttributeAction rAttributeAction = actionManager.getAction(RemoveAttributeAction.class);
    RemoveAction rAction = actionManager.getAction(RemoveAction.class);
    RemoveRelationshipAction rRelationShipAction = actionManager.getAction(RemoveRelationshipAction.class);
    RemoveCallbackMethodAction rCallbackMethodAction = actionManager.getAction(RemoveCallbackMethodAction.class);
    RemoveProcedureParameterAction rProcedureParamAction = actionManager.getAction(RemoveProcedureParameterAction.class);
    if (content instanceof DataMap) {
        if (where instanceof DataChannelDescriptor) {
            rAction.removeDataMap((DataMap) content);
        } else if (where instanceof DataNodeDescriptor) {
            rAction.removeDataMapFromDataNode((DataNodeDescriptor) where, (DataMap) content);
        }
    } else if (where instanceof DataMap) {
        if (content instanceof DbEntity) {
            rAction.removeDbEntity(map, (DbEntity) content);
        } else if (content instanceof ObjEntity) {
            rAction.removeObjEntity(map, (ObjEntity) content);
        } else if (content instanceof Embeddable) {
            rAction.removeEmbeddable(map, (Embeddable) content);
        } else if (content instanceof QueryDescriptor) {
            rAction.removeQuery(map, (QueryDescriptor) content);
        } else if (content instanceof Procedure) {
            rAction.removeProcedure(map, (Procedure) content);
        }
    } else if (where instanceof DbEntity) {
        if (content instanceof DbEntity) {
            rAction.removeDbEntity(map, (DbEntity) content);
        } else if (content instanceof DbAttribute) {
            rAttributeAction.removeDbAttributes(map, (DbEntity) where, new DbAttribute[] { (DbAttribute) content });
        } else if (content instanceof DbRelationship) {
            rRelationShipAction.removeDbRelationships((DbEntity) where, new DbRelationship[] { (DbRelationship) content });
        }
    } else if (where instanceof ObjEntity) {
        if (content instanceof ObjEntity) {
            rAction.removeObjEntity(map, (ObjEntity) content);
        } else if (content instanceof ObjAttribute) {
            rAttributeAction.removeObjAttributes((ObjEntity) where, new ObjAttribute[] { (ObjAttribute) content });
        } else if (content instanceof ObjRelationship) {
            rRelationShipAction.removeObjRelationships((ObjEntity) where, new ObjRelationship[] { (ObjRelationship) content });
        } else if (content instanceof ObjCallbackMethod) {
            ObjCallbackMethod[] methods = new ObjCallbackMethod[] { (ObjCallbackMethod) content };
            for (ObjCallbackMethod callbackMethod : methods) {
                rCallbackMethodAction.removeCallbackMethod(methods[0].getCallbackType(), callbackMethod.getName());
            }
        }
    } else if (where instanceof Procedure) {
        final Procedure procedure = (Procedure) where;
        if (content instanceof ProcedureParameter) {
            rProcedureParamAction.removeProcedureParameters(procedure, new ProcedureParameter[] { (ProcedureParameter) content });
        }
    } else if (where instanceof Embeddable) {
        if (content instanceof Embeddable) {
            rAction.removeEmbeddable(map, (Embeddable) content);
        } else if (content instanceof EmbeddableAttribute) {
            rAttributeAction.removeEmbeddableAttributes((Embeddable) where, new EmbeddableAttribute[] { (EmbeddableAttribute) content });
        }
    }
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbAttribute(org.apache.cayenne.map.DbAttribute) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable) RemoveProcedureParameterAction(org.apache.cayenne.modeler.action.RemoveProcedureParameterAction) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) RemoveCallbackMethodAction(org.apache.cayenne.modeler.action.RemoveCallbackMethodAction) Procedure(org.apache.cayenne.map.Procedure) RemoveRelationshipAction(org.apache.cayenne.modeler.action.RemoveRelationshipAction) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) RemoveAction(org.apache.cayenne.modeler.action.RemoveAction) ObjCallbackMethod(org.apache.cayenne.modeler.editor.ObjCallbackMethod) RemoveAttributeAction(org.apache.cayenne.modeler.action.RemoveAttributeAction)

Example 24 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class EmbeddableTab method currentEmbeddableChanged.

public void currentEmbeddableChanged(EmbeddableDisplayEvent e) {
    Embeddable embeddable = e.getEmbeddable();
    if (embeddable == null || !e.isEmbeddableChanged()) {
        return;
    }
    initFromModel(embeddable);
}
Also used : Embeddable(org.apache.cayenne.map.Embeddable)

Example 25 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class EmbeddableTabbedView method currentEmbeddableChanged.

public void currentEmbeddableChanged(EmbeddableDisplayEvent e) {
    Embeddable emb = e.getEmbeddable();
    if (e.isMainTabFocus() && emb instanceof Embeddable) {
        if (getSelectedComponent() != embeddablePanel) {
            setSelectedComponent(embeddablePanel);
            embeddablePanel.setVisible(true);
        }
    }
    resetRemoveButtons();
    setVisible(e.getEmbeddable() != null);
}
Also used : Embeddable(org.apache.cayenne.map.Embeddable)

Aggregations

Embeddable (org.apache.cayenne.map.Embeddable)33 DataMap (org.apache.cayenne.map.DataMap)14 ObjEntity (org.apache.cayenne.map.ObjEntity)14 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)11 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)11 DbEntity (org.apache.cayenne.map.DbEntity)8 ArrayList (java.util.ArrayList)7 ObjAttribute (org.apache.cayenne.map.ObjAttribute)7 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)6 DbAttribute (org.apache.cayenne.map.DbAttribute)5 Procedure (org.apache.cayenne.map.Procedure)5 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 ProjectController (org.apache.cayenne.modeler.ProjectController)4 HashMap (java.util.HashMap)3 DbRelationship (org.apache.cayenne.map.DbRelationship)3 EmbeddableDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)3 RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)3 File (java.io.File)2 LinkedList (java.util.LinkedList)2