use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.
the class SQLTemplateMainTab method initFromModel.
/**
* Updates the view from the current model state. Invoked when a currently displayed
* query is changed.
*/
void initFromModel() {
QueryDescriptor query = mediator.getCurrentQuery();
if (query == null || !QueryDescriptor.SQL_TEMPLATE.equals(query.getType())) {
setVisible(false);
return;
}
name.setText(query.getName());
properties.initFromModel(query);
comment.setText(getQueryComment(query));
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);
setVisible(true);
}
use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.
the class SQLTemplatePrefetchTab method initFromModel.
protected void initFromModel() {
QueryDescriptor query = mediator.getCurrentQuery();
if (query == null || !QueryDescriptor.SQL_TEMPLATE.equals(query.getType())) {
processInvalidModel("Unknown query.");
return;
}
if (!(query.getRoot() instanceof Entity)) {
processInvalidModel("SQLTemplate has no root set.");
return;
}
this.sqlTemplate = (SQLTemplateDescriptor) query;
browser.setModel(createBrowserModel((Entity) sqlTemplate.getRoot()));
table.setModel(createTableModel());
setUpPrefetchBox(table.getColumnModel().getColumn(2));
// init column sizes
table.getColumnModel().getColumn(0).setPreferredWidth(250);
cardLayout.show(this, REAL_PANEL);
}
use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.
the class SQLTemplateScriptsTab method initFromModel.
void initFromModel() {
QueryDescriptor query = mediator.getCurrentQuery();
if (query == null || !QueryDescriptor.SQL_TEMPLATE.equals(query.getType())) {
setVisible(false);
return;
}
// select default script.. display it bypassing the listener...
scripts.removeListSelectionListener(scriptRefreshHandler);
scripts.setSelectedIndex(0);
displayScript();
scripts.addListSelectionListener(scriptRefreshHandler);
setVisible(true);
}
use of org.apache.cayenne.map.QueryDescriptor in project cayenne by apache.
the class SelectQueryMainTab method setQueryComment.
private void setQueryComment(String text) {
QueryDescriptor query = getQuery();
if (query == null) {
return;
}
ObjectInfo.putToMetaData(mediator.getApplication().getMetaData(), query, ObjectInfo.COMMENT, text);
mediator.fireQueryEvent(new QueryEvent(this, query));
}
use of org.apache.cayenne.map.QueryDescriptor 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