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();
}
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;
}
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);
}
}
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);
}
Aggregations