Search in sources :

Example 16 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class SelectQueryOrderingTab method getSelectedPath.

protected String getSelectedPath() {
    Object[] path = browser.getSelectionPath().getPath();
    // at least two elements to constitute a valid ordering path
    if (path.length < 2) {
        return null;
    }
    StringBuilder buffer = new StringBuilder();
    // attribute or relationships
    CayenneMapEntry first = (CayenneMapEntry) path[1];
    buffer.append(first.getName());
    for (int i = 2; i < path.length; i++) {
        CayenneMapEntry pathEntry = (CayenneMapEntry) path[i];
        buffer.append(".").append(pathEntry.getName());
    }
    return buffer.toString();
}
Also used : CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry)

Example 17 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class ObjAttributeInfoDialog method getFirstEntity.

private Entity getFirstEntity() {
    Iterator<CayenneMapEntry> it = attribute.getDbPathIterator();
    Entity firstEnt = attribute.getDbAttribute().getEntity();
    boolean setEnt = false;
    while (it.hasNext()) {
        Object ob = it.next();
        if (ob instanceof DbRelationship) {
            if (!setEnt) {
                firstEnt = ((DbRelationship) ob).getSourceEntity();
                setEnt = true;
            }
        } else if (ob instanceof DbAttribute) {
            if (!setEnt) {
                firstEnt = ((DbAttribute) ob).getEntity();
            }
        }
    }
    return firstEnt;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 18 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class ObjAttributeInfoDialog method setSelectionPath.

/**
 * Selects path in browser
 */
public void setSelectionPath() {
    List<CayenneMapEntry> list = new ArrayList<>();
    boolean isAttributeLast = false;
    Iterator<CayenneMapEntry> it = attribute.getDbPathIterator();
    while (it.hasNext()) {
        CayenneMapEntry obj = it.next();
        list.add(obj);
        if (obj instanceof DbAttribute && !it.hasNext()) {
            isAttributeLast = true;
        }
    }
    if (isAttributeLast) {
        Object[] path = new Object[list.size() + 1];
        path[0] = getFirstEntity();
        System.arraycopy(list.toArray(), 0, path, 1, list.size());
        view.getPathBrowser().setSelectionPath(new TreePath(path));
        view.getSaveButton().setEnabled(true);
    }
}
Also used : CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry) TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 19 with CayenneMapEntry

use of org.apache.cayenne.util.CayenneMapEntry in project cayenne by apache.

the class CellRenderers method asString.

/**
 * Converts non-String Object used in renderers (currently CayenneMapEntry
 * instances only) to String
 *
 * @param obj Object to be converted
 * @param namespace the current namespace
 */
public static String asString(Object obj, MappingNamespace namespace) {
    if (obj instanceof CayenneMapEntry) {
        CayenneMapEntry mapObject = (CayenneMapEntry) obj;
        String label = mapObject.getName();
        if (mapObject instanceof Entity) {
            Entity entity = (Entity) mapObject;
            // for different namespace display its name
            DataMap dataMap = entity.getDataMap();
            if (dataMap != null && dataMap != namespace) {
                label += " (" + dataMap.getName() + ")";
            }
        }
        return label;
    } else if (obj instanceof DataMap) {
        return ((DataMap) obj).getName();
    }
    return obj == null ? null : String.valueOf(obj);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) CayenneMapEntry(org.apache.cayenne.util.CayenneMapEntry) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

CayenneMapEntry (org.apache.cayenne.util.CayenneMapEntry)19 DbEntity (org.apache.cayenne.map.DbEntity)6 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ObjEntity (org.apache.cayenne.map.ObjEntity)6 Expression (org.apache.cayenne.exp.Expression)5 DbAttribute (org.apache.cayenne.map.DbAttribute)5 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)4 ASTDbPath (org.apache.cayenne.exp.parser.ASTDbPath)3 Entity (org.apache.cayenne.map.Entity)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)3 ObjRelationship (org.apache.cayenne.map.ObjRelationship)3 HashSet (java.util.HashSet)2 ExpressionException (org.apache.cayenne.exp.ExpressionException)2 DbJoin (org.apache.cayenne.map.DbJoin)2 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)2 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)2 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)2 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)2 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)2 Test (org.junit.Test)2