Search in sources :

Example 6 with ISwingFoundSet

use of com.servoy.j2db.dataprocessing.ISwingFoundSet in project servoy-client by Servoy.

the class DataproviderTypeSabloValue method getRelatedRecords.

private ArrayList<IRecordInternal> getRelatedRecords(IRecordInternal record, String relName) {
    // similar code as the loop below is also in class DisplaysAdapter - just in case future fixes need to apply to both places
    ArrayList<IRecordInternal> returnRelatedRecords = new ArrayList<IRecordInternal>();
    if (record != null) {
        // get the new records were are depending on
        IRecordInternal currRecord = record;
        // $NON-NLS-1$
        String[] parts = relName.split("\\.");
        for (int i = 0; currRecord != null && i < parts.length; i++) {
            Object v = currRecord.getValue(parts[i]);
            if (v instanceof ISwingFoundSet) {
                currRecord = ((ISwingFoundSet) v).getRecord(((ISwingFoundSet) v).getSelectedIndex());
                if (currRecord == null)
                    currRecord = ((ISwingFoundSet) v).getPrototypeState();
                returnRelatedRecords.add(currRecord);
            } else {
                currRecord = null;
            }
        }
    }
    return returnRelatedRecords;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ArrayList(java.util.ArrayList) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet)

Example 7 with ISwingFoundSet

use of com.servoy.j2db.dataprocessing.ISwingFoundSet in project servoy-client by Servoy.

the class BasicFormController method setFormModelInternal.

protected void setFormModelInternal(IFoundSetInternal newModel) {
    if (formModel == newModel)
        return;
    boolean isInFind = false;
    ISwingFoundSet mustUnpinSelectionMode = null;
    if (formModel != null) {
        formModel.removeFoundSetEventListener(this);
        isInFind = formModel.isInFindMode();
        if (formModel instanceof ISwingFoundSet) {
            mustUnpinSelectionMode = (ISwingFoundSet) formModel;
        }
    }
    formModel = newModel;
    if (mustUnpinSelectionMode != null) {
        mustUnpinSelectionMode.unpinMultiSelectIfNeeded(getName());
    }
    // form model change set it on -2 so that we know that we shouldnt update the selection before it is tested
    lastSelectedIndex = -2;
    if (formModel != null) {
        formModel.addFoundSetEventListener(this);
        if (isInFind != formModel.isInFindMode()) {
            propagateFindMode(formModel.isInFindMode());
        }
        pinSelectionModeIfNecessary();
    }
}
Also used : ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet)

Example 8 with ISwingFoundSet

use of com.servoy.j2db.dataprocessing.ISwingFoundSet in project servoy-client by Servoy.

the class BasicFormController method setModel.

protected boolean setModel(IFoundSetInternal newModel) throws ServoyException {
    if (newModel == formModel || adjustingModel) {
        // same or adjusting do nothing
        return true;
    }
    ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
    if (newModel != null && ((formTable == null && newModel.getTable() != null) || (formTable != null && !formTable.equals(newModel.getTable())))) {
        throw new IllegalArgumentException(application.getI18NMessage("servoy.formPanel.error.wrongFoundsetTable", new Object[] { // $NON-NLS-1$
        newModel.getTable() == null ? "NONE" : newModel.getTable().getName(), // $NON-NLS-1$
        form.getTableName() }));
    }
    try {
        IView view = getViewComponent();
        if (view != null && view.isEditing()) {
            // TODO if save fails don't set the newModel??
            int stopped = application.getFoundSetManager().getEditRecordList().stopEditing(false);
            if (stopped != ISaveConstants.STOPPED && stopped != ISaveConstants.AUTO_SAVE_BLOCKED) {
                return false;
            }
        }
        adjustingModel = true;
        if (formModel != null) {
            try {
                ((ISwingFoundSet) formModel).getSelectionModel().removeListSelectionListener(this);
                ((ISwingFoundSet) formModel).getSelectionModel().removeFormController(this);
                ((ISwingFoundSet) formModel).removeTableModelListener(this);
                // to make sure all data is gc'ed
                if (formModel instanceof FoundSet)
                    ((FoundSet) formModel).flushAllCachedItems();
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
        setFormModelInternal(newModel == null ? ((FoundSetManager) application.getFoundSetManager()).getEmptyFoundSet(this) : newModel);
        if (formScope != null) {
            // $NON-NLS-1$
            formScope.putWithoutFireChange("foundset", formModel);
            if (formScope.getPrototype() == null) {
                formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
            }
        }
        if (isFormVisible) {
            ((ISwingFoundSet) formModel).getSelectionModel().addListSelectionListener(this);
            ((ISwingFoundSet) formModel).getSelectionModel().addFormController(this);
            ((ISwingFoundSet) formModel).addTableModelListener(this);
            if (// it may not yet exist
            view != null) {
                view.setModel(formModel);
            }
            // this was former a call to aggregateChange, but now does now unwanted parent traverse...
            int[] idx = null;
            if (getView() == RECORD_VIEW || getView() == LOCKED_RECORD_VIEW) {
                int selIdx = formModel.getSelectedIndex();
                if (selIdx != -1)
                    idx = new int[] { selIdx };
            } else {
                idx = formModel.getSelectedIndexes();
            }
            if (idx == null || idx.length == 0) {
                refreshAllPartRenderers(new IRecordInternal[] { formModel.getPrototypeState() });
            } else {
                IRecordInternal[] row = new IRecordInternal[idx.length];
                for (int i = 0; i < idx.length; i++) row[i] = formModel.getRecord(idx[i]);
                refreshAllPartRenderers(row);
            }
        }
    } finally {
        adjustingModel = false;
    }
    return true;
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) ViewFoundSet(com.servoy.j2db.dataprocessing.ViewFoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SelectedRecordScope(com.servoy.j2db.scripting.SelectedRecordScope) ITable(com.servoy.j2db.persistence.ITable) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ITwoNativeJavaObject(com.servoy.j2db.scripting.ITwoNativeJavaObject)

Example 9 with ISwingFoundSet

use of com.servoy.j2db.dataprocessing.ISwingFoundSet in project servoy-client by Servoy.

the class SpecialSplitPane method registerSelectionListeners.

private void registerSelectionListeners(IRecordInternal parentState, String relationName) {
    // $NON-NLS-1$
    String[] parts = relationName.split("\\.");
    IRecordInternal currentRecord = parentState;
    for (int i = 0; currentRecord != null && i < parts.length - 1; i++) {
        IFoundSetInternal fs = currentRecord.getRelatedFoundSet(parts[i]);
        if (fs instanceof ISwingFoundSet) {
            related.add((ISwingFoundSet) fs);
            ((ISwingFoundSet) fs).getSelectionModel().addListSelectionListener(this);
        }
        currentRecord = (fs == null) ? null : fs.getRecord(fs.getSelectedIndex());
    }
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet)

Example 10 with ISwingFoundSet

use of com.servoy.j2db.dataprocessing.ISwingFoundSet 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;
}
Also used : Placeholder(com.servoy.j2db.query.Placeholder) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ArrayList(java.util.ArrayList) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) IQuerySort(com.servoy.j2db.query.IQuerySort) Relation(com.servoy.j2db.persistence.Relation) ISQLTableJoin(com.servoy.j2db.query.ISQLTableJoin) QueryColumn(com.servoy.j2db.query.QueryColumn) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) Column(com.servoy.j2db.persistence.Column) IQuerySort(com.servoy.j2db.query.IQuerySort) QuerySort(com.servoy.j2db.query.QuerySort) CompareCondition(com.servoy.j2db.query.CompareCondition) QueryAggregate(com.servoy.j2db.query.QueryAggregate) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) TablePlaceholderKey(com.servoy.j2db.query.TablePlaceholderKey) IDataServer(com.servoy.j2db.dataprocessing.IDataServer) SubSummaryFoundSet(com.servoy.j2db.dataprocessing.SubSummaryFoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) QuerySelect(com.servoy.j2db.query.QuerySelect) AggregateVariable(com.servoy.j2db.persistence.AggregateVariable) IApplication(com.servoy.j2db.IApplication) BaseQueryTable(com.servoy.base.query.BaseQueryTable) QueryColumn(com.servoy.j2db.query.QueryColumn) SubSummaryFoundSet(com.servoy.j2db.dataprocessing.SubSummaryFoundSet) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) IQuerySelectValue(com.servoy.j2db.query.IQuerySelectValue)

Aggregations

ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)16 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)11 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)10 Point (java.awt.Point)6 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)3 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)3 ServoyException (com.servoy.j2db.util.ServoyException)3 EventObject (java.util.EventObject)3 IApplication (com.servoy.j2db.IApplication)2 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)2 IFoundSet (com.servoy.j2db.dataprocessing.IFoundSet)2 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)2 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)2 IComponent (com.servoy.j2db.ui.IComponent)2 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)2 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)2 Color (java.awt.Color)2 ArrayList (java.util.ArrayList)2 Component (org.apache.wicket.Component)2 BaseQueryTable (com.servoy.base.query.BaseQueryTable)1