Search in sources :

Example 1 with PrototypeState

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

the class FormController method refreshAllPartRenderers.

@Override
protected void refreshAllPartRenderers(IRecordInternal[] records) {
    if (!isFormVisible || application.isShutDown())
        return;
    // don't do anything yet when there are records but the selection is invalid
    if (formModel.getSize() > 0 && (formModel.getSelectedIndex() < 0 || formModel.getSelectedIndex() >= formModel.getSize()))
        return;
    // let the ui know that it will be touched, so that locks can be taken if needed.
    getFormUI().touch();
    boolean executeOnRecordSelect = false;
    IRecordInternal[] state = records;
    if (state == null) {
        if (formModel != null) {
            state = new IRecordInternal[] { formModel.getPrototypeState() };
        } else {
            state = new IRecordInternal[] { new PrototypeState(null) };
        }
    }
    if (dataRenderers[FORM_EDITOR] != null && !(records == null && formModel != null && formModel.getRawSize() > 0) && isStateChanged(state)) {
        lastState = state;
        executeOnRecordSelect = true;
    }
    for (int i = FORM_RENDERER + 1; i < dataRenderers.length; i++) {
        IDataRenderer dataRenderer = dataRenderers[i];
        if (dataRenderer != null) {
            for (IRecordInternal r : state) dataRenderer.refreshRecord(r);
        }
    }
    if (executeOnRecordSelect) {
        // do this at the end because dataRenderer.refreshRecord(state) will update selection
        // for related tabs - and we should execute js code after they have been updated
        executeOnRecordSelect();
    }
}
Also used : IDataRenderer(com.servoy.j2db.ui.IDataRenderer) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Example 2 with PrototypeState

use of com.servoy.j2db.dataprocessing.PrototypeState 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 3 with PrototypeState

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

the class J2DBClient method setTitle.

public void setTitle(String name) {
    // $NON-NLS-1$
    String title = "";
    String solutionTitle = getSolution().getTitleText();
    if (solutionTitle == null) {
        title = getSolution().getName();
    } else if (// $NON-NLS-1$
    !solutionTitle.equals("<empty>")) {
        title = solutionTitle;
    }
    title = getI18NMessageIfPrefixed(title);
    if (// $NON-NLS-1$ //$NON-NLS-2$
    name != null && !name.trim().equals("") && !"<empty>".equals(name)) {
        String i18nName = getI18NMessageIfPrefixed(name);
        FormController formController = (FormController) getFormManager().getCurrentForm();
        if (formController != null) {
            String name2 = Text.processTags(i18nName, formController.getTagResolver());
            if (name2 != null)
                i18nName = name2;
        } else {
            String name2 = Text.processTags(i18nName, TagResolver.createResolver(new PrototypeState(null)));
            if (name2 != null)
                i18nName = name2;
        }
        if (// $NON-NLS-1$
        !i18nName.trim().equals("")) {
            if (// $NON-NLS-1$
            "".equals(title)) {
                title += i18nName;
            } else {
                // $NON-NLS-1$
                title += " - " + i18nName;
            }
        }
    }
    String appName = getDisplayApplicationName();
    if (// $NON-NLS-1$
    appName.endsWith("Developer")) {
        // $NON-NLS-1$
        title = appName + " - " + title;
    } else {
        if (// $NON-NLS-1$
        title.equals("")) {
            title = appName;
        } else {
            // $NON-NLS-1$
            title += " - " + appName;
        }
    }
    frame.setTitle(title);
}
Also used : FormController(com.servoy.j2db.FormController) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Example 4 with PrototypeState

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

the class SwingForm method initView.

public IView initView(IApplication application, FormController fp, int viewType) {
    view = null;
    IDataRenderer[] dataRenderers = fp.getDataRenderers();
    setTitleHeader((JComponent) dataRenderers[Part.TITLE_HEADER]);
    setHeader((JComponent) dataRenderers[Part.HEADER]);
    setLeadingGrandSummary((JComponent) dataRenderers[Part.LEADING_GRAND_SUMMARY]);
    setTrailingGrandSummary((JComponent) dataRenderers[Part.TRAILING_GRAND_SUMMARY]);
    setFooter((JComponent) dataRenderers[Part.FOOTER]);
    // remove any left slider
    setWest(null);
    switch(viewType) {
        case FormController.LOCKED_LIST_VIEW:
        case IForm.LIST_VIEW:
            view = new ListView();
            PrototypeState proto = null;
            if (fp.getFoundSet() != null) {
                proto = fp.getFoundSet().getPrototypeState();
            } else {
                proto = new PrototypeState(null);
            }
            // this call is extreemly inportant, it prevent all rows retrieval
            ((ListView) view).setPrototypeCellValue(proto);
            FormBodyEditor editor = null;
            if (dataRenderers[FormController.FORM_RENDERER] != null) {
                Component[] rendererComponents = ((Container) dataRenderers[FormController.FORM_RENDERER]).getComponents();
                for (Component rendererComponent : rendererComponents) {
                    if (rendererComponent instanceof ISupportAsyncLoading) {
                        // in listview it is impossible to get lazy loaded images displaying correctly, due to needed repaintfire, which we cannot initiate
                        ((ISupportAsyncLoading) rendererComponent).setAsyncLoadingEnabled(false);
                    }
                    rendererComponent.setFocusable(false);
                }
                ((Component) dataRenderers[FormController.FORM_RENDERER]).setFocusable(false);
            }
            editor = new FormBodyEditor((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
            if (dataRenderers[FormController.FORM_RENDERER] != null) {
                DataRenderer dr = (DataRenderer) dataRenderers[FormController.FORM_RENDERER];
                dr.setRenderer(true);
                String bgcolorCalc = fp.getForm().getRowBGColorCalculation();
                if (bgcolorCalc != null) {
                    // dr.setRowBGColorProvider(bgcolorCalc);
                    dr.setShowSelection(false);
                    // $NON-NLS-1$
                    ((ListView) view).setRowBGColorScript(bgcolorCalc, fp.getForm().getFlattenedMethodArguments("rowBGColorCalculation"));
                    ((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
                }
                ((ListView) view).setCellRenderer(dr);
            } else {
                // form with no body part - used only for printing probably
                ((ListView) view).setCellRenderer(new ListCellRenderer() {

                    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                        // $NON-NLS-1$
                        return new JLabel("");
                    }
                });
            }
            ((ListView) view).setCellEditor(editor);
            ((ListView) view).setRendererSameAsEditor(false);
            ((ListView) view).setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            break;
        case FormController.LOCKED_TABLE_VIEW:
        case FormController.TABLE_VIEW:
            view = new TableView(application, fp, fp.getForm(), fp.getForm(), fp.getScriptExecuter(), dataRenderers[Part.HEADER], dataRenderers[Part.LEADING_GRAND_SUMMARY], false);
            if (dataRenderers[FormController.FORM_EDITOR] != null)
                dataRenderers[FormController.FORM_EDITOR].destroy();
            dataRenderers[FormController.FORM_EDITOR] = (IDataRenderer) view;
            if (formController.getBodyStyle() != null) {
                Pair<IStyleSheet, IStyleRule> pairStyle = ComponentFactory.getCSSPairStyleForForm(application, fp.getForm());
                if (pairStyle != null && pairStyle.getLeft() != null) {
                    Border border = pairStyle.getLeft().getBorder(formController.getBodyStyle());
                    if (border != null) {
                        innerPanel.setBorder(border);
                    }
                }
            }
            break;
        case IForm.LOCKED_RECORD_VIEW:
        case IForm.RECORD_VIEW:
        default:
            view = new RecordView(formController);
            if (dataRenderers[FormController.FORM_EDITOR] != null) {
                ((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
                ((RecordView) view).setCellRenderer((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
            }
            int form_id = fp.getForm().getNavigatorID();
            if (form_id == 0) {
                StyledEnablePanel slider = ((RecordView) view).getSliderComponent();
                if (bgColor != null)
                    slider.setBackground(bgColor);
                setWest(slider);
            }
    }
    getVerticalScrollBar().setValue(1);
    getVerticalScrollBar().setValue(0);
    setViewportView((JComponent) view);
    if (view instanceof TableView) {
        // the table view needs it's orientation set correctly
        OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
    }
    if (view instanceof ListView) {
        view.requestFocus();
    }
    OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
    if ((bgColor != null) && (view instanceof ListView))
        ((ListView) view).setBackground(bgColor);
    // except if it's a table view, that is always transparent
    if (!(view instanceof TableView)) {
        setOpaque(isOpaque());
    } else {
        for (int i = FormController.FORM_RENDERER + 1; i < dataRenderers.length; i++) {
            if (dataRenderers[i] != null && !(dataRenderers[i] instanceof TableView)) {
                dataRenderers[i].setOpaque(isOpaque());
            }
        }
    }
    return view;
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) DataRenderer(com.servoy.j2db.smart.dataui.DataRenderer) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) StyledEnablePanel(com.servoy.j2db.smart.dataui.StyledEnablePanel) JLabel(javax.swing.JLabel) ISupportAsyncLoading(com.servoy.j2db.component.ISupportAsyncLoading) Point(java.awt.Point) Container(java.awt.Container) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) FormBodyEditor(com.servoy.j2db.smart.dataui.FormBodyEditor) ListCellRenderer(javax.swing.ListCellRenderer) IStyleRule(com.servoy.j2db.util.IStyleRule) TwoNativeJavaObject(com.servoy.j2db.smart.scripting.TwoNativeJavaObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) Border(javax.swing.border.Border) JList(javax.swing.JList)

Example 5 with PrototypeState

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

the class MainPage method setTitle.

public void setTitle(String name) {
    touch();
    Solution solution = this.client.getSolution();
    // $NON-NLS-1$
    String titleString = "";
    String solutionTitle = solution.getTitleText();
    if (solutionTitle == null) {
        titleString = solution.getName();
    } else if (// $NON-NLS-1$
    !solutionTitle.equals("<empty>")) {
        titleString = solutionTitle;
    }
    titleString = client.getI18NMessageIfPrefixed(titleString);
    if (// $NON-NLS-1$ //$NON-NLS-2$
    name != null && !name.trim().equals("") && !"<empty>".equals(name) && main != null) {
        String nameString = client.getI18NMessageIfPrefixed(name);
        FormController formController = main.getController();
        if (formController != null) {
            String name2 = Text.processTags(nameString, formController.getTagResolver());
            if (name2 != null)
                nameString = name2;
        } else {
            String name2 = Text.processTags(nameString, TagResolver.createResolver(new PrototypeState(null)));
            if (name2 != null)
                nameString = name2;
        }
        if (// $NON-NLS-1$
        !nameString.trim().equals("")) {
            if (// $NON-NLS-1$
            "".equals(titleString)) {
                titleString += nameString;
            } else {
                // $NON-NLS-1$
                titleString += " - " + nameString;
            }
        }
    }
    // $NON-NLS-1$
    String appName = "Servoy Web Client";
    // $NON-NLS-1$ //$NON-NLS-2$
    boolean branding = Utils.getAsBoolean(client.getSettings().getProperty("servoy.branding", "false"));
    // $NON-NLS-1$
    String appTitle = client.getSettings().getProperty("servoy.branding.windowtitle");
    if (branding && appTitle != null) {
        appName = appTitle;
    }
    if (// $NON-NLS-1$
    titleString.equals("")) {
        titleString = appName;
    } else {
        // $NON-NLS-1$
        titleString += " - " + appName;
    }
    this.title.setDefaultModelObject(titleString);
    addJSAction(new RenderComponentAction(title));
}
Also used : IFormController(com.servoy.j2db.IFormController) FormController(com.servoy.j2db.FormController) RenderComponentAction(com.servoy.j2db.server.headlessclient.PageJSActionBuffer.RenderComponentAction) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) Solution(com.servoy.j2db.persistence.Solution)

Aggregations

PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)14 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)7 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)5 FormController (com.servoy.j2db.FormController)4 FindState (com.servoy.j2db.dataprocessing.FindState)4 IStyleRule (com.servoy.j2db.util.IStyleRule)3 IStyleSheet (com.servoy.j2db.util.IStyleSheet)3 JSONObject (org.json.JSONObject)3 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 IDataProvider (com.servoy.j2db.persistence.IDataProvider)2 Relation (com.servoy.j2db.persistence.Relation)2 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 Solution (com.servoy.j2db.persistence.Solution)2 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)2 ISupportRowStyling (com.servoy.j2db.ui.ISupportRowStyling)2 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)2 ServoyException (com.servoy.j2db.util.ServoyException)2 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)2 Color (java.awt.Color)2 Container (java.awt.Container)2