use of org.apache.cayenne.map.SelectQueryDescriptor in project cayenne by apache.
the class SelectQueryMainTab method initFromModel.
/**
* Updates the view from the current model state. Invoked when a currently displayed
* query is changed.
*/
void initFromModel() {
QueryDescriptor descriptor = mediator.getCurrentQuery();
if (descriptor == null || !QueryDescriptor.SELECT_QUERY.equals(descriptor.getType())) {
setVisible(false);
return;
}
SelectQueryDescriptor query = (SelectQueryDescriptor) descriptor;
name.setText(query.getName());
distinct.setSelected(Boolean.valueOf(query.getProperties().get(SelectQuery.DISTINCT_PROPERTY)));
qualifier.setText(query.getQualifier() != null ? query.getQualifier().toString() : null);
comment.setText(getQueryComment(query));
// init root choices and title label..
// - SelectQuery supports ObjEntity roots
// TODO: now we only allow roots from the current map,
// since query root is fully resolved during map loading,
// making it impossible to reference other DataMaps.
DataMap map = mediator.getCurrentDataMap();
ObjEntity[] roots = map.getObjEntities().toArray(new ObjEntity[0]);
if (roots.length > 1) {
Arrays.sort(roots, Comparators.getDataMapChildrenComparator());
}
DefaultComboBoxModel<ObjEntity> model = new DefaultComboBoxModel<>(roots);
model.setSelectedItem(query.getRoot());
queryRoot.setModel(model);
properties.initFromModel(query);
setVisible(true);
}
Aggregations