Search in sources :

Example 21 with IFoundSetInternal

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

the class FoundsetLinkedTypeSabloValue method updatePropertyValueForRecord.

protected void updatePropertyValueForRecord(FoundsetTypeSabloValue foundsetPropertyValue, String rowIDValue, Object value, PropertyDescription wrappedPropertyDescription, IBrowserConverterContext dataConverterContext) {
    IFoundSetInternal foundset = foundsetPropertyValue.getFoundset();
    Pair<String, Integer> splitHashAndIndex = FoundsetTypeSabloValue.splitPKHashAndIndex(rowIDValue);
    if (foundset != null) {
        int recordIndex = foundset.getRecordIndex(splitHashAndIndex.getLeft(), splitHashAndIndex.getRight().intValue());
        if (recordIndex != -1) {
            foundsetPropertyValue.getDataAdapterList().setRecordQuietly(foundset.getRecord(recordIndex));
            try {
                ValueReference<Boolean> returnValueAdjustedIncommingValueForRow = new ValueReference<Boolean>(Boolean.FALSE);
                YT newWrappedValue = (YT) JSONUtils.fromJSONUnwrapped(wrappedSabloValue, value, wrappedPropertyDescription, dataConverterContext, returnValueAdjustedIncommingValueForRow);
                if (newWrappedValue != wrappedSabloValue) {
                    // TODO should we make current method return a completely new instance instead and leave component code do the rest?
                    if (wrappedSabloValue instanceof IDataLinkedPropertyValue)
                        ((IDataLinkedPropertyValue) wrappedSabloValue).detach();
                    setWrappedSabloValue(newWrappedValue);
                    if (wrappedSabloValue instanceof IDataLinkedPropertyValue)
                        ((IDataLinkedPropertyValue) wrappedSabloValue).attachToBaseObject(changeMonitor, wrappedComponentContext);
                    // the full value has changed; the whole viewport might be affected
                    viewPortChangeMonitor.viewPortCompletelyChanged();
                } else if (returnValueAdjustedIncommingValueForRow.value.booleanValue()) {
                    FoundsetTypeViewport viewPort = foundsetPropertyValue.getViewPort();
                    int firstViewPortIndex = Math.max(viewPort.getStartIndex(), recordIndex);
                    int lastViewPortIndex = Math.min(viewPort.getStartIndex() + viewPort.getSize() - 1, recordIndex);
                    if (firstViewPortIndex <= lastViewPortIndex) {
                        viewPortChangeMonitor.queueOperation(firstViewPortIndex - viewPort.getStartIndex(), lastViewPortIndex - viewPort.getStartIndex(), viewPort.getSize(), ArrayOperation.CHANGE);
                    }
                }
            } catch (JSONException e) {
                Debug.error("Setting value for record dependent property '" + wrappedPropertyDescription + "' in foundset linked component to value: " + value + " failed.", e);
            } finally {
                foundsetPropertyValue.setDataAdapterListToSelectedRecord();
            }
        } else {
            Debug.error("Cannot set foundset linked record dependent property for (" + rowIDValue + ") property '" + wrappedPropertyDescription + "' to value '" + value + "' of component: " + webObjectContext + ". Record not found.", new RuntimeException());
        }
    } else {
        Debug.error("Cannot set foundset linked record dependent property for (" + rowIDValue + ") property '" + wrappedPropertyDescription + "' to value '" + value + "' of component: " + webObjectContext + ". Foundset is null.", new RuntimeException());
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) JSONException(org.json.JSONException) ValueReference(org.sablo.util.ValueReference)

Example 22 with IFoundSetInternal

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

the class FoundsetPropertyType method toSabloComponentValue.

@Override
public FoundsetTypeSabloValue toSabloComponentValue(Object rhinoValue, FoundsetTypeSabloValue previousComponentValue, PropertyDescription pd, IWebObjectContext componentOrService) {
    FoundsetTypeSabloValue newSabloValue = null;
    IFoundSetInternal newFoundset = null;
    JSONObject dataproviders = null;
    boolean sendDefaultFormats = FoundsetPropertyTypeConfig.DEFAULT_SEND_DEFAULT_FORMATS;
    int initialPreferredViewPortSize = FoundsetPropertyTypeConfig.DEFAULT_INITIALL_PREFERRED_VIEWPORT_SIZE;
    boolean sendSelectionViewportInitially = FoundsetPropertyTypeConfig.DEFAULT_SEND_SELECTION_VIEWPORT_INITIALLY;
    boolean foundsetDefinitionListener = FoundsetPropertyTypeConfig.DEFAULT_FOUNDSET_DEFINITION_LISTENER;
    if (rhinoValue instanceof Wrapper)
        rhinoValue = ((Wrapper) rhinoValue).unwrap();
    if (rhinoValue instanceof FoundsetTypeSableValueWrapper) {
        return ((FoundsetTypeSableValueWrapper) rhinoValue).webComponentValue;
    }
    if (rhinoValue instanceof NativeObject) {
        NativeObject obj = (NativeObject) rhinoValue;
        Object foundset = obj.get(FOUNDSET_KEY_FOR_RHINO, obj);
        if (foundset instanceof Wrapper)
            foundset = ((Wrapper) foundset).unwrap();
        if (foundset instanceof IFoundSetInternal) {
            newFoundset = (IFoundSetInternal) foundset;
            if (obj.has(FoundsetPropertyTypeConfig.DATAPROVIDERS, obj)) {
                Object dpsValue = obj.get(FoundsetPropertyTypeConfig.DATAPROVIDERS, obj);
                if (dpsValue instanceof Scriptable) {
                    dataproviders = new JSONObject();
                    Object[] ids = ((Scriptable) dpsValue).getIds();
                    for (Object id : ids) {
                        dataproviders.put((String) id, (String) ((Scriptable) dpsValue).get((String) id, ((Scriptable) dpsValue)));
                    }
                }
            }
            if (obj.has(FoundsetPropertyTypeConfig.SEND_DEFAULT_FORMATS, obj))
                sendDefaultFormats = Utils.getAsBoolean(obj.get(FoundsetPropertyTypeConfig.SEND_DEFAULT_FORMATS, obj));
            if (obj.has(FoundsetPropertyTypeConfig.INITIAL_PREFERRED_VIEWPORT_SIZE, obj))
                initialPreferredViewPortSize = Utils.getAsInteger(obj.get(FoundsetPropertyTypeConfig.INITIAL_PREFERRED_VIEWPORT_SIZE, obj));
            if (obj.has(FoundsetPropertyTypeConfig.SEND_SELECTION_VIEWPORT_INITIALLY, obj))
                sendSelectionViewportInitially = Utils.getAsBoolean(obj.get(FoundsetPropertyTypeConfig.SEND_SELECTION_VIEWPORT_INITIALLY, obj));
            if (obj.has(FoundsetPropertyTypeConfig.FOUNDSET_DEFINITION_LISTENER, obj))
                foundsetDefinitionListener = Utils.getAsBoolean(obj.get(FoundsetPropertyTypeConfig.FOUNDSET_DEFINITION_LISTENER, obj));
        }
    } else if (rhinoValue instanceof IFoundSetInternal) {
        newFoundset = (IFoundSetInternal) rhinoValue;
    }
    if (newFoundset != null) {
        if (previousComponentValue != null && previousComponentValue.getFoundset() == newFoundset)
            newSabloValue = previousComponentValue;
        else {
            JSONObject designJSON = new JSONObject();
            // tell the FoundsetTypeSabloValue that it shouldn't try to automatically get a foundset
            designJSON.put(FOUNDSET_SELECTOR, (String) null);
            if (dataproviders != null)
                designJSON.put(DATAPROVIDERS_KEY_FOR_DESIGN, dataproviders);
            newSabloValue = new FoundsetTypeSabloValue(designJSON, null, null, new FoundsetPropertyTypeConfig(sendDefaultFormats, true, null, sendSelectionViewportInitially, initialPreferredViewPortSize, foundsetDefinitionListener));
            newSabloValue.updateFoundset(newFoundset);
        }
    } else if (rhinoValue != null && !RhinoConversion.isUndefinedOrNotFound(rhinoValue)) {
        throw new RuntimeException("Cannot set " + rhinoValue + " into a foundset property type; for existing foundset properties you can set the myProp.foundset or myProp.dataproviders directly. If you want to set a complete new value you have to give here something like { foundset : ...someFoundset..., dataproviders : { dp1: 'userNickname', dp2: 'userReviewRating', ... } } instead.");
    }
    return newSabloValue;
}
Also used : Wrapper(org.mozilla.javascript.Wrapper) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Scriptable(org.mozilla.javascript.Scriptable) NativeObject(org.mozilla.javascript.NativeObject) JSONObject(org.json.JSONObject) NativeObject(org.mozilla.javascript.NativeObject) JSONObject(org.json.JSONObject)

Example 23 with IFoundSetInternal

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

the class WebTabPanel method showFoundSet.

protected void showFoundSet(WebTabFormLookup flp, IRecordInternal parentState, List<SortColumn> sort) {
    deregisterSelectionListeners();
    if (!flp.isReady())
        return;
    FormController fp = flp.getWebForm().getController();
    if (fp != null && flp.getRelationName() != null) {
        IFoundSetInternal relatedFoundset = parentState == null ? null : parentState.getRelatedFoundSet(flp.getRelationName(), sort);
        registerSelectionListeners(parentState, flp.getRelationName());
        fp.loadData(relatedFoundset, null);
    }
    ITagResolver resolver = getTagResolver(parentState);
    // refresh tab text
    for (int i = 0; i < allTabs.size(); i++) {
        WebTabHolder element = allTabs.get(i);
        if (element.getPanel() == flp) {
            element.refreshTagStrings(resolver);
            break;
        }
    }
}
Also used : FormController(com.servoy.j2db.FormController) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ITagResolver(com.servoy.base.util.ITagResolver) Point(java.awt.Point)

Example 24 with IFoundSetInternal

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

the class UsedDataProviderTracker method usedFromRecord.

/**
 * Used name from Record,
 * @param record may be null (for global relations)
 * @param name
 */
protected void usedFromRecord(IRecordInternal record, String name) {
    IRecordInternal currentRecord = record;
    try {
        // $NON-NLS-1$
        String[] parts = name.split("\\.");
        for (String part : parts) {
            Relation relation = flattenedSolution.getRelation(part);
            if (relation != null) {
                // calc depends on the relation, add a dependency for the primary data providers for the relation
                IDataProvider[] primaryDataProviders = relation.getPrimaryDataProviders(flattenedSolution);
                for (IDataProvider prim : primaryDataProviders) {
                    if (prim instanceof LiteralDataprovider)
                        continue;
                    String primdp = prim.getDataProviderID();
                    if (ScopesUtils.isVariableScope(primdp)) {
                        // global
                        usedGlobal(primdp);
                    } else {
                        // column
                        if (currentRecord != null) {
                            if (currentRecord.getRawData() == null) {
                                if (currentRecord instanceof PrototypeState) {
                                    Debug.trace("Calculation '" + name + "' depends on field '" + part + "' from PrototypeState " + currentRecord);
                                } else {
                                    // should not happen
                                    Debug.error("Unexpected state: calculation '" + name + "' depends on column '" + part + "' from record without pk: " + currentRecord, new IllegalStateException());
                                }
                            } else {
                                usedColumn(currentRecord.getParentFoundSet().getDataSource(), currentRecord.getRawData().getPKHashKey(), primdp);
                            }
                        }
                    }
                }
                IFoundSetInternal foundSet = null;
                if (currentRecord != null)
                    foundSet = currentRecord.getRelatedFoundSet(relation.getName());
                currentRecord = null;
                if (foundSet instanceof RelatedFoundSet) {
                    usedRelatedFoundSet(relation.getName(), (RelatedFoundSet) foundSet);
                    currentRecord = foundSet.getRecord(foundSet.getSelectedIndex());
                }
            } else {
                if (currentRecord != null) {
                    IFoundSetInternal foundSet = currentRecord.getParentFoundSet();
                    if (foundSet.getSQLSheet().containsAggregate(part)) {
                        // aggregate
                        usedAggregate(foundSet, part);
                    } else {
                        // field or calc
                        if (currentRecord.has(part)) {
                            if (currentRecord.getRawData() == null) {
                                if (currentRecord instanceof PrototypeState) {
                                    Debug.trace("Calculation '" + name + "' depends on field '" + part + "' from PrototypeState " + currentRecord);
                                } else {
                                    // should not happen
                                    Debug.error("Unexpected state: calculation '" + name + "' depends on field '" + part + "' from record without pk: " + currentRecord, new IllegalStateException());
                                }
                            } else {
                                usedColumn(foundSet.getDataSource(), currentRecord.getRawData().getPKHashKey(), part);
                            }
                        }
                    }
                }
                return;
            }
            if (currentRecord == null) {
                return;
            }
        }
    } catch (RepositoryException e) {
        Debug.error(e);
    }
}
Also used : Relation(com.servoy.j2db.persistence.Relation) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider) LiteralDataprovider(com.servoy.j2db.persistence.LiteralDataprovider) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Example 25 with IFoundSetInternal

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

the class SwingForm method printPreview.

/**
 * @see com.servoy.j2db.IFormUIInternal#printPreview(boolean, boolean, java.awt.print.PrinterJob)
 */
public void printPreview(boolean showDialogs, boolean printCurrentRecordOnly, int zoomFactor, PrinterJob printerJob) {
    ISmartClientApplication application = (ISmartClientApplication) formController.getApplication();
    try {
        // TODO do a print preview even if records are not saved?
        if (application.getFoundSetManager().getEditRecordList().stopEditing(false) != ISaveConstants.STOPPED)
            return;
        IFoundSetInternal set = formController.getFormModel();
        if (set == null) {
            if (showDialogs) {
                // $NON-NLS-1$
                JOptionPane.showMessageDialog(// $NON-NLS-1$
                application.getMainApplicationFrame(), // $NON-NLS-1$
                Messages.getString("servoy.formPanel.error.noRecordsToPrint"), Messages.getString("servoy.general.warning"), // $NON-NLS-1$
                JOptionPane.INFORMATION_MESSAGE);
            }
            return;
        }
        if (showDialogs) {
            if (// test if foundset is zero. if so ask if really want to print/preview
            set.getSize() == 0) {
                int val = JOptionPane.showConfirmDialog(application.getMainApplicationFrame(), // $NON-NLS-1$//$NON-NLS-2$
                Messages.getString("servoy.formPanel.error.noRecordsToPrint"), // $NON-NLS-1$//$NON-NLS-2$
                Messages.getString("servoy.general.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
                if (val != JOptionPane.OK_OPTION) {
                    return;
                }
            } else if (!printCurrentRecordOnly) {
                int option = willingToPrint(set);
                if (option == 2) {
                    printCurrentRecordOnly = true;
                } else if (option == 1) {
                    // cancel
                    return;
                }
            }
        }
        if (printCurrentRecordOnly) {
            set = set.copyCurrentRecordFoundSet();
        }
        ((FormManager) application.getFormManager()).showPreview(formController, set, zoomFactor, printerJob);
    } catch (Exception ex) {
        // $NON-NLS-1$
        application.reportError(Messages.getString("servoy.formPanel.error.printPreview"), ex);
    }
}
Also used : ISmartClientApplication(com.servoy.j2db.ISmartClientApplication) FormManager(com.servoy.j2db.FormManager) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Point(java.awt.Point)

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