Search in sources :

Example 26 with IFoundSetInternal

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

the class SwingForm method print.

/**
 * @see com.servoy.j2db.IFormUIInternal#print(boolean, boolean, boolean, java.awt.print.PrinterJob)
 */
public void print(boolean showDialogs, boolean printCurrentRecordOnly, boolean showPrinterSelectDialog, PrinterJob printerJob) {
    IFoundSetInternal fs = formController.getFoundSet();
    if (!printCurrentRecordOnly) {
        if (showDialogs) {
            int option = willingToPrint(fs);
            if (option == 2) {
                printCurrentRecordOnly = true;
            } else if (option == 1) {
                // cancel
                return;
            }
        }
    }
    IApplication application = formController.getApplication();
    try {
        // $NON-NLS-1$
        application.blockGUI(Messages.getString("servoy.formPanel.status.printProgress"));
        if (printCurrentRecordOnly) {
            fs = fs.copyCurrentRecordFoundSet();
        }
        FormPreviewPanel fpp = new FormPreviewPanel(application, formController, fs);
        fpp.process();
        PrintPreview.startPrinting(application, fpp.getPageable(), printerJob, formController.getPreferredPrinterName(), showPrinterSelectDialog, false);
        fpp.destroy();
    } catch (Exception ex) {
        // $NON-NLS-1$
        application.reportError(Messages.getString("servoy.formPanel.error.printDocument"), ex);
    } finally {
        application.releaseGUI();
    }
}
Also used : IApplication(com.servoy.j2db.IApplication) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) FormPreviewPanel(com.servoy.j2db.printing.FormPreviewPanel) Point(java.awt.Point)

Example 27 with IFoundSetInternal

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

the class SwingForm method printXML.

/**
 * @see com.servoy.j2db.IFormUIInternal#printXML(boolean)
 */
public String printXML(boolean printCurrentRecordOnly) {
    IApplication application = formController.getApplication();
    IFoundSetInternal fs = formController.getFoundSet();
    try {
        // $NON-NLS-1$
        application.blockGUI(Messages.getString("servoy.formPanel.status.xmlPrinting"));
        if (printCurrentRecordOnly) {
            fs = fs.copyCurrentRecordFoundSet();
        }
        FormPreviewPanel fpp = new FormPreviewPanel(application, formController, fs);
        fpp.process();
        StringWriter w = new StringWriter();
        ((PageList) fpp.getPageable()).toXML(w);
        fpp.destroy();
        return w.toString();
    } catch (Throwable ex) {
        // $NON-NLS-1$
        application.reportError(Messages.getString("servoy.formPanel.error.printDocument"), ex);
    } finally {
        application.releaseGUI();
    }
    return null;
}
Also used : IApplication(com.servoy.j2db.IApplication) StringWriter(java.io.StringWriter) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) FormPreviewPanel(com.servoy.j2db.printing.FormPreviewPanel) PageList(com.servoy.j2db.printing.PageList)

Example 28 with IFoundSetInternal

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

the class JSUtils method js_stringReplaceTags.

/**
 * Returns the text with %%tags%% replaced, based on provided record or foundset or form.
 *
 * @sample
 * //Next line places a string in variable x, whereby the tag(%%TAG%%) is filled with the value of the database column 'company_name' of the selected record.
 * var x = utils.stringReplaceTags("The companyName of the selected record is %%company_name%% ", foundset)
 * //var otherExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails);
 * //var recordExample = utils.stringReplaceTags("The amount of the related order line %%amount%% ", order_to_orderdetails.getRecord(i);
 * //Next line places a string in variable y, whereby the tag(%%TAG%%) is filled with the value of the form variable 'x' of the form named 'main'.
 * //var y = utils.stringReplaceTags("The value of form variable is %%x%% ", forms.main);
 * //The next sample shows the use of a javascript object
 * //var obj = new Object();//create a javascript object
 * //obj['x'] = 'test';//assign an named value
 * //var y = utils.stringReplaceTags("The value of object variable is %%x%% ", obj);//use the named value in a tag
 * @param text the text tags to work with
 * @param scriptable the javascript object or foundset,record,form to be used to fill in the tags
 * @return the text with replaced tags
 */
public String js_stringReplaceTags(String text, Object scriptable) {
    if (text != null) {
        ITagResolver tagResolver = null;
        Properties settings = null;
        if (scriptable instanceof FoundSet) {
            IRecordInternal record = ((FoundSet) scriptable).getRecord(((FoundSet) scriptable).getSelectedIndex());
            if (record != null) {
                settings = record.getParentFoundSet().getFoundSetManager().getApplication().getSettings();
                tagResolver = TagResolver.createResolver(record);
            }
        } else if (scriptable instanceof IRecordInternal) {
            IRecordInternal record = (IRecordInternal) scriptable;
            settings = record.getParentFoundSet().getFoundSetManager().getApplication().getSettings();
            tagResolver = TagResolver.createResolver(record);
        } else if (scriptable instanceof BasicFormController) {
            final BasicFormController fc = (BasicFormController) scriptable;
            IFoundSetInternal fs = fc.getFoundSet();
            final ITagResolver defaultTagResolver = (fs != null) ? TagResolver.createResolver(fs.getRecord(fs.getSelectedIndex())) : null;
            settings = fc.getApplication().getSettings();
            tagResolver = new ITagResolver() {

                public String getStringValue(String name) {
                    Object value = fc.getFormScope().get(name);
                    if (value == null || value == Scriptable.NOT_FOUND) {
                        value = defaultTagResolver != null ? defaultTagResolver.getStringValue(name) : null;
                    }
                    // $NON-NLS-1$
                    return value != null ? value.toString() : "";
                }
            };
        } else if (scriptable instanceof Scriptable) {
            Scriptable scriptObject = (Scriptable) scriptable;
            settings = Settings.getInstance();
            tagResolver = TagResolver.createResolver(scriptObject, application);
        }
        if (tagResolver != null && settings != null) {
            return Text.processTags(TagResolver.formatObject(text, application), tagResolver);
        }
        // $NON-NLS-1$
        return "";
    } else {
        // $NON-NLS-1$
        return "";
    }
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ITagResolver(com.servoy.base.util.ITagResolver) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) IJSFoundSet(com.servoy.base.scripting.api.IJSFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) Properties(java.util.Properties) Scriptable(org.mozilla.javascript.Scriptable) BasicFormController(com.servoy.j2db.BasicFormController)

Example 29 with IFoundSetInternal

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

the class ComboModelListModelWrapper method fill.

public void fill(IRecordInternal ps) {
    this.parentState = ps;
    if (relatedRecord != null) {
        relatedRecord.removeModificationListener(this);
        relatedRecord = null;
    }
    boolean fireSelectionChange = false;
    if (selectedSet != null && selectedSet.size() > 0) {
        selectedSet.clear();
        fireSelectionChange = true;
    }
    Object obj = getSelectedItem();
    if (relatedFoundsetLookup == null || ps == null) {
        listModel.fill(ps);
    } else {
        IFoundSetInternal relatedFoundSet = ps.getRelatedFoundSet(relatedFoundsetLookup);
        if (relatedFoundSet == null || relatedFoundSet.getSize() == 0) {
            listModel.fill(null);
        } else {
            relatedRecord = relatedFoundSet.getRecord(relatedFoundSet.getSelectedIndex());
            if (relatedRecord != null)
                relatedRecord.addModificationListener(this);
            listModel.fill(relatedRecord);
        }
    }
    if (obj != null) {
        if (listModel.indexOf(obj) == -1 && hasRealValues()) {
            selectedObject = null;
            realSelectedObject = null;
            fireSelectionChange = true;
        } else {
            selectedObject = null;
            realSelectedObject = null;
            setSelectedItem(obj);
        }
    }
    // fire selection change after state is changed
    if (fireSelectionChange) {
        fireContentsChanged(this, -1, -1);
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal)

Example 30 with IFoundSetInternal

use of com.servoy.j2db.dataprocessing.IFoundSetInternal 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

IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)55 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)26 Point (java.awt.Point)13 FormController (com.servoy.j2db.FormController)12 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)11 ServoyException (com.servoy.j2db.util.ServoyException)8 ArrayList (java.util.ArrayList)8 IApplication (com.servoy.j2db.IApplication)6 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)6 EventObject (java.util.EventObject)6 ITagResolver (com.servoy.base.util.ITagResolver)5 FindState (com.servoy.j2db.dataprocessing.FindState)5 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)5 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)5 RepositoryException (com.servoy.j2db.persistence.RepositoryException)5 JSONObject (org.json.JSONObject)5 FormManager (com.servoy.j2db.FormManager)4 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)4 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)4 Color (java.awt.Color)4