Search in sources :

Example 6 with SelectQueryDescriptor

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);
}
Also used : SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) SelectQueryDescriptor(org.apache.cayenne.map.SelectQueryDescriptor) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)6 DataMap (org.apache.cayenne.map.DataMap)3 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)3 Entity (org.apache.cayenne.map.Entity)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 Expression (org.apache.cayenne.exp.Expression)1 ExpressionConvertor (org.apache.cayenne.modeler.util.ExpressionConvertor)1 Ordering (org.apache.cayenne.query.Ordering)1 ValidationException (org.apache.cayenne.validation.ValidationException)1 Test (org.junit.Test)1