use of com.servoy.j2db.dataprocessing.SortColumn in project servoy-client by Servoy.
the class SortModel method setValue.
void setValue(IApplication app, String notused) {
application = app;
try {
FormManager fm = (FormManager) application.getFormManager();
FormController fc = fm.getCurrentMainShowingFormController();
if (fc != null) {
Form form = fc.getForm();
ITable t = application.getFoundSetManager().getTable(form.getDataSource());
if (t != null) {
List<SortColumn> list = application.getFoundSetManager().getSortColumns(t, form.getInitialSort());
init(app, t, list);
}
}
} catch (RepositoryException e) {
Debug.error(e);
}
}
use of com.servoy.j2db.dataprocessing.SortColumn in project servoy-client by Servoy.
the class PartNode method process.
public List<DataRendererDefinition> process(FormPreviewPanel fpp, FoundSet fs, Table table, QuerySelect sqlString) throws Exception {
// Selection model must be in print mode to be able to set the selection to -1 . Otherwise is not allowed by the selectionModel
((ISwingFoundSet) fs).getSelectionModel().hideSelectionForPrinting();
// this is needed because we must keep sql the same in foundset during printing
FoundSet rootSet = (FoundSet) fs.copy(false);
foundSets.add(rootSet);
IApplication app = fpp.getApplication();
// retval
List<DataRendererDefinition> list = new ArrayList<DataRendererDefinition>();
if (part != null && (part.getPartType() == Part.LEADING_SUBSUMMARY || part.getPartType() == Part.TRAILING_SUBSUMMARY || isLeadingAndTrailingSubsummary)) {
QuerySelect newSQLString = AbstractBaseQuery.deepClone(sqlString);
IDataServer server = app.getDataServer();
// build the sql parts based on sort columns
ArrayList<IQuerySelectValue> selectCols = new ArrayList<IQuerySelectValue>();
ArrayList<QueryColumn> groupbyCols = new ArrayList<QueryColumn>();
ArrayList<QuerySort> sortbyCols = new ArrayList<QuerySort>();
for (SortColumn element : sortColumns) {
BaseQueryTable queryTable = sqlString.getTable();
Relation[] relations = element.getRelations();
if (relations != null) {
for (Relation relation : relations) {
ISQLTableJoin join = (ISQLTableJoin) sqlString.getJoin(queryTable, relation.getName());
if (join == null) {
// $NON-NLS-1$ //$NON-NLS-2$
Debug.log("Missing relation " + relation.getName() + " in join condition for form on table " + table.getName());
} else {
queryTable = join.getForeignTable();
}
}
}
Column column = (Column) element.getColumn();
QueryColumn queryColumn = column.queryColumn(queryTable);
selectCols.add(queryColumn);
groupbyCols.add(queryColumn);
sortbyCols.add(new QuerySort(queryColumn, element.getSortOrder() == SortColumn.ASCENDING, fs.getFoundSetManager().getSortOptions(column)));
}
// make sql
for (AggregateVariable ag : allAggregates) {
selectCols.add(new QueryAggregate(ag.getType(), new QueryColumn(newSQLString.getTable(), -1, ag.getColumnNameToAggregate(), ag.getDataProviderType(), ag.getLength(), 0, null, ag.getFlags()), ag.getName()));
}
newSQLString.setColumns(selectCols);
newSQLString.setGroupBy(groupbyCols);
ArrayList<IQuerySort> oldSort = newSQLString.getSorts();
// fix the sort (if columns not are selected of used in groupby they cannot be used in sort)
newSQLString.setSorts(sortbyCols);
FoundSetManager foundSetManager = ((FoundSetManager) app.getFoundSetManager());
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
IDataSet data = server.performQuery(app.getClientID(), table.getServerName(), transaction_id, newSQLString, null, foundSetManager.getTableFilterParams(table.getServerName(), newSQLString), false, 0, foundSetManager.config.pkChunkSize() * 4, IDataServer.PRINT_QUERY);
// create a new FoundSet with 'data' and with right 'table', 'where','whereArgs'
SubSummaryFoundSet newSet = new SubSummaryFoundSet(app.getFoundSetManager(), rootSet, sortColumns, allAggregates, data, table);
// restore the sort for child body parts
newSQLString.setSorts(oldSort);
// make new where for use in sub queries
for (QuerySort sortbyCol : sortbyCols) {
QueryColumn sc = (QueryColumn) (sortbyCol).getColumn();
newSQLString.addCondition(SQLGenerator.CONDITION_SEARCH, new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, sc, new Placeholder(new TablePlaceholderKey(sc.getTable(), '#' + sc.getName()))));
}
int count = newSet.getSize();
for (int ii = 0; ii < count; ii++) {
// make copy for setting sort column
QuerySelect newSQLStringCopy = AbstractBaseQuery.deepClone(newSQLString);
// handle the child first, this puts the rootset in the right state! for use of related(!) fields in the subsums
// THIS is EXTREMELY important for correct printing, see also SubSummaryFoundSet.queryForRelatedFoundSet
List<DataRendererDefinition> childRetval = null;
IFoundSetInternal curLeafFoundSet = null;
if (child != null) {
for (int i = 0; i < sortbyCols.size(); i++) {
QueryColumn sc = (QueryColumn) (sortbyCols.get(i)).getColumn();
TablePlaceholderKey placeholderKey = new TablePlaceholderKey(sc.getTable(), '#' + sc.getName());
if (!newSQLStringCopy.setPlaceholderValue(placeholderKey, data.getRow(ii)[i])) {
Debug.error(// $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
new RuntimeException("Could not set placeholder " + placeholderKey + " in query " + newSQLStringCopy + "-- continuing"));
}
}
childRetval = child.process(fpp, rootSet, table, newSQLStringCopy);
curLeafFoundSet = child.getCurrentLeafFoundSet();
}
SubSummaryFoundSet.PrintState state = (SubSummaryFoundSet.PrintState) newSet.getRecord(ii);
state.setDelegate(curLeafFoundSet);
if (part.getPartType() == Part.LEADING_SUBSUMMARY) {
state.doAggregatesLookup();
list.add(new DataRendererDefinition(fpp, renderParent, part, renderer, state));
}
if (childRetval != null) {
list.addAll(childRetval);
}
if (isLeadingAndTrailingSubsummary) {
state.doAggregatesLookup();
list.add(new DataRendererDefinition(fpp, renderParent, second_part, second_renderer, state));
} else if (part.getPartType() == Part.TRAILING_SUBSUMMARY) {
state.doAggregatesLookup();
list.add(new DataRendererDefinition(fpp, renderParent, part, renderer, state));
}
}
} else // for handeling (virtual) body part
{
rootSet.browseAll(sqlString);
int count = app.getFoundSetManager().getFoundSetCount(rootSet);
for (int ii = 0; ii < count; ii++) {
currentLeafFoundSet = rootSet;
list.add(new DataRendererDefinition(fpp, renderParent, part, renderer, rootSet, ii));
}
}
return list;
}
use of com.servoy.j2db.dataprocessing.SortColumn in project servoy-client by Servoy.
the class TableView method setSortStatus.
public boolean setSortStatus(IFoundSetInternal foundset) {
if (foundset != null) {
List<SortColumn> sortCols = foundset.getSortColumns();
if (sortCols != null && sortCols.size() > 0) {
boolean found = false;
for (SortColumn sc : sortCols) {
for (int i = 0; (i < getColumnModel().getColumnCount()); i++) {
TableColumn tc = getColumnModel().getColumn(i);
if (tc instanceof CellAdapter) {
CellAdapter ca = (CellAdapter) tc;
if (ca.getDataProviderID() != null) {
List<String> sortingProviders = null;
Component renderer = ca.getRenderer();
if (renderer instanceof ISupportValueList && ((ISupportValueList) renderer).getValueList() != null) {
try {
sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) renderer).getValueList().getValueList(), (Table) foundset.getTable(), ca.getDataProviderID(), application.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(ca.getDataProviderID());
}
for (String sortingProvider : sortingProviders) {
SortColumn existingSc;
try {
FoundSetManager fsm = (FoundSetManager) foundset.getFoundSetManager();
existingSc = fsm.getSortColumn(foundset.getTable(), sortingProvider, false);
} catch (Exception e) {
Debug.error(e);
continue;
}
if (sc.equalsIgnoreSortorder(existingSc)) {
if (!found) {
// clear old sort
updateSortStatus(-1, true);
}
found = true;
updateSortStatus(ca.getModelIndex(), sc.getSortOrder() == SortColumn.ASCENDING);
}
}
}
}
}
}
return found;
}
}
return false;
}
use of com.servoy.j2db.dataprocessing.SortColumn in project servoy-client by Servoy.
the class SortModel method up.
public void up(int index) {
if (index > 0) {
SortColumn obj = rows.get(index - 1);
rows.remove(index - 1);
rows.add(index, obj);
}
fireTableDataChanged();
}
use of com.servoy.j2db.dataprocessing.SortColumn in project servoy-client by Servoy.
the class SortModel method getValueAt.
public Object getValueAt(int row, int col) {
SortColumn v = rows.get(row);
switch(col) {
case -1:
return v;
// return new Boolean(v.getInUse());
case 0:
String title = null;
IColumn c = v.getColumn();
if (c instanceof Column) {
title = ((Column) c).getTitle();
}
return (title == null ? v.getName() : title);
case 1:
return new Integer(v.getSortOrder());
default:
return null;
}
}
Aggregations