Search in sources :

Example 21 with IDisplayData

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

the class WebDataRenderer method createDataAdapter.

void createDataAdapter(IApplication app, IDataProviderLookup dataProviderLookup, IScriptExecuter el, ControllerUndoManager undoManager) throws Exception {
    dataAdapterList = new DataAdapterList(app, dataProviderLookup, fieldComponents, el.getFormController(), null, undoManager);
    // make it really fields only
    HashMap<IPersist, IDisplay> f = new HashMap<IPersist, IDisplay>();
    Iterator<Map.Entry<IPersist, IDisplay>> it = fieldComponents.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<IPersist, IDisplay> element = it.next();
        if (element.getValue() instanceof IDisplayData) {
            // String id = ((IDisplayData)element.getValue()).getDataProviderID();
            // if (dataProviderLookup.getDataProvider(id) instanceof ScriptVariable)
            // {
            // globalFields.add(element.getValue());
            // }
            f.put(element.getKey(), element.getValue());
        }
    }
    fieldComponents = f;
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) HashMap(java.util.HashMap) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with IDisplayData

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

the class WebEventExecutor method generateResponse.

@SuppressWarnings("nls")
public static void generateResponse(final AjaxRequestTarget target, Page page) {
    WebClientSession webClientSession = WebClientSession.get();
    if (target != null && page instanceof MainPage && webClientSession != null && webClientSession.getWebClient() != null && webClientSession.getWebClient().getSolution() != null) {
        if (target instanceof CloseableAjaxRequestTarget && ((CloseableAjaxRequestTarget) target).isClosed()) {
            return;
        }
        // do executed the events for before generating the response.
        webClientSession.getWebClient().executeEvents();
        if (webClientSession.getWebClient() == null || webClientSession.getWebClient().getSolution() == null) {
            // how can web client be null here ?
            return;
        }
        final MainPage mainPage = ((MainPage) page);
        if (mainPage.getPageMap() instanceof ModifiedAccessStackPageMap) {
            // at every request mark the pagemap as dirty so lru eviction really works
            ((ModifiedAccessStackPageMap) mainPage.getPageMap()).flagDirty();
        }
        // If the main form is switched then do a normal redirect.
        if (mainPage.isMainFormSwitched()) {
            mainPage.versionPush();
            RequestCycle.get().setResponsePage(page);
        } else {
            page.visitChildren(WebTabPanel.class, new Component.IVisitor<WebTabPanel>() {

                public Object component(WebTabPanel component) {
                    component.initalizeFirstTab();
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            mainPage.addWebAnchoringInfoIfNeeded();
            final Set<WebCellBasedView> tableViewsToRender = new HashSet<WebCellBasedView>();
            final List<String> valueChangedIds = new ArrayList<String>();
            final List<String> invalidValueIds = new ArrayList<String>();
            final Map<WebCellBasedView, List<Integer>> tableViewsWithChangedRowIds = new HashMap<WebCellBasedView, List<Integer>>();
            // first, get all invalidValue & valueChanged components
            page.visitChildren(IProviderStylePropertyChanges.class, new Component.IVisitor<Component>() {

                public Object component(Component component) {
                    if (component instanceof IDisplayData && !((IDisplayData) component).isValueValid()) {
                        invalidValueIds.add(component.getMarkupId());
                    }
                    if (((IProviderStylePropertyChanges) component).getStylePropertyChanges().isValueChanged()) {
                        if (component.getParent().isVisibleInHierarchy()) {
                            // the component will get added to the target & rendered only if it's parent is visible in hierarchy because changed flag is also set (see the visitor below)
                            // so we will only list these components if they are visible otherwise ajax timer could end up sending hundreds of id's that don't actually render every 5 seconds
                            // because the valueChanged flag is cleared only by onRender
                            valueChangedIds.add(component.getMarkupId());
                            if (component instanceof MarkupContainer) {
                                ((MarkupContainer) component).visitChildren(IDisplayData.class, new IVisitor<Component>() {

                                    public Object component(Component comp) {
                                        // labels/buttons that don't display data are not changed
                                        if (!(comp instanceof ILabel)) {
                                            valueChangedIds.add(comp.getMarkupId());
                                        }
                                        return CONTINUE_TRAVERSAL;
                                    }
                                });
                            }
                        }
                    }
                    return CONTINUE_TRAVERSAL;
                }
            });
            // add changed components to target; if a component is changed, the change check won't go deeper in hierarchy
            page.visitChildren(IProviderStylePropertyChanges.class, new Component.IVisitor<Component>() {

                public Object component(Component component) {
                    if (((IProviderStylePropertyChanges) component).getStylePropertyChanges().isChanged()) {
                        if (component.getParent().isVisibleInHierarchy()) {
                            target.addComponent(component);
                            generateDragAttach(component, target.getHeaderResponse());
                            WebForm parentForm = component.findParent(WebForm.class);
                            boolean isDesignMode = parentForm != null && parentForm.isDesignMode();
                            if (!component.isVisible() || (component instanceof WrapperContainer && !((WrapperContainer) component).getDelegate().isVisible())) {
                                ((IProviderStylePropertyChanges) component).getStylePropertyChanges().setRendered();
                                if (isDesignMode) {
                                    target.appendJavascript("Servoy.ClientDesign.hideSelected('" + component.getMarkupId() + "')");
                                }
                            } else {
                                if (isDesignMode) {
                                    target.appendJavascript("Servoy.ClientDesign.refreshSelected('" + component.getMarkupId() + "')");
                                }
                                // some components need to perform js layout tasks when their markup is replaced when using anchored layout
                                mainPage.getPageContributor().markComponentForAnchorLayoutIfNeeded(component);
                            }
                            ListItem<IRecordInternal> row = component.findParent(ListItem.class);
                            if (row != null) {
                                WebCellBasedView wcbv = row.findParent(WebCellBasedView.class);
                                if (wcbv != null) {
                                    if (tableViewsWithChangedRowIds.get(wcbv) == null) {
                                        tableViewsWithChangedRowIds.put(wcbv, new ArrayList<Integer>());
                                    }
                                    List<Integer> ids = tableViewsWithChangedRowIds.get(wcbv);
                                    int changedRowIdx = wcbv.indexOf(row);
                                    if (changedRowIdx >= 0 && !ids.contains(changedRowIdx)) {
                                        ids.add(changedRowIdx);
                                    }
                                }
                            }
                        }
                        return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                    } else if (component instanceof WebCellBasedView)
                        tableViewsToRender.add((WebCellBasedView) component);
                    return component.isVisible() ? IVisitor.CONTINUE_TRAVERSAL : IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            });
            page.visitChildren(IComponentToRequestAttacher.class, new Component.IVisitor<Component>() {

                public Object component(Component component) {
                    ((IComponentToRequestAttacher) component).attachComponents(target);
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            final List<String> visibleEditors = new ArrayList<String>();
            page.visitChildren(WebDataHtmlArea.class, new Component.IVisitor<Component>() {

                public Object component(Component component) {
                    visibleEditors.add(((WebDataHtmlArea) component).getEditorID());
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            StringBuffer argument = new StringBuffer();
            for (String id : visibleEditors) {
                argument.append("\"");
                argument.append(id);
                argument.append("\"");
                if (visibleEditors.indexOf(id) != visibleEditors.size() - 1) {
                    argument.append(",");
                }
            }
            target.prependJavascript("Servoy.HTMLEdit.removeInvalidEditors(" + argument + ");");
            String rowSelectionScript, columnResizeScript;
            for (final WebCellBasedView wcbv : tableViewsToRender) {
                if (wcbv.isScrollMode())
                    wcbv.scrollViewPort(target);
                wcbv.updateRowSelection(target);
                List<Integer> changedIds = tableViewsWithChangedRowIds.get(wcbv);
                List<Integer> selectedIndexesChanged = wcbv.getIndexToUpdate(false);
                List<Integer> mergedIds = selectedIndexesChanged != null ? selectedIndexesChanged : new ArrayList<Integer>();
                if (changedIds != null) {
                    for (Integer id : changedIds) {
                        if (!mergedIds.contains(id)) {
                            mergedIds.add(id);
                        }
                    }
                }
                rowSelectionScript = wcbv.getRowSelectionScript(mergedIds);
                wcbv.clearSelectionByCellActionFlag();
                if (rowSelectionScript != null)
                    target.appendJavascript(rowSelectionScript);
                columnResizeScript = wcbv.getColumnResizeScript();
                if (columnResizeScript != null)
                    target.appendJavascript(columnResizeScript);
            }
            // double check if the page contributor is changed, because the above IStylePropertyChanges ischanged could have altered it.
            if (mainPage.getPageContributor().getStylePropertyChanges().isChanged()) {
                target.addComponent((Component) mainPage.getPageContributor());
            }
            if (invalidValueIds.size() == 0) {
                // $NON-NLS-1$
                target.appendJavascript("setValidationFailed(null);");
            } else {
                // $NON-NLS-1$
                target.appendJavascript("setValidationFailed('" + invalidValueIds.get(0) + "');");
            }
            Component comp = mainPage.getAndResetToFocusComponent();
            if (comp != null) {
                if (comp instanceof WebDataHtmlArea) {
                    target.appendJavascript("tinyMCE.activeEditor.focus()");
                } else {
                    target.focusComponent(comp);
                }
            } else if (mainPage.getAndResetMustFocusNull()) {
                // This is needed for example when showing a non-modal dialog in IE7 (or otherwise
                // the new window would be displayed in the background).
                target.focusComponent(null);
            }
            if (valueChangedIds.size() > 0) {
                argument = new StringBuffer();
                for (String id : valueChangedIds) {
                    argument.append("\"");
                    argument.append(id);
                    argument.append("\"");
                    if (valueChangedIds.indexOf(id) != valueChangedIds.size() - 1) {
                        argument.append(",");
                    }
                }
                target.prependJavascript("storeValueAndCursorBeforeUpdate(" + argument + ");");
                target.appendJavascript("restoreValueAndCursorAfterUpdate();");
            }
            // if we have admin info, show it
            String adminInfo = mainPage.getAdminInfo();
            if (adminInfo != null) {
                adminInfo = Utils.stringReplace(adminInfo, "\r", "");
                adminInfo = Utils.stringReplace(adminInfo, "\n", "\\n");
                target.appendJavascript("alert('" + adminInfo + "');");
            }
            // If we have a status text, set it.
            String statusText = mainPage.getStatusText();
            if (statusText != null) {
                target.appendJavascript("setStatusText('" + statusText + "');");
            }
            String show = mainPage.getShowUrlScript();
            if (show != null) {
                target.appendJavascript(show);
            }
            mainPage.renderJavascriptChanges(target);
            if (((WebClientInfo) webClientSession.getClientInfo()).getProperties().isBrowserInternetExplorer() && ((WebClientInfo) webClientSession.getClientInfo()).getProperties().getBrowserVersionMajor() < 9) {
                target.appendJavascript("Servoy.Utils.checkWebFormHeights();");
            }
            try {
                if (isStyleSheetLimitForIE(page.getSession())) {
                    target.appendJavascript("testStyleSheets();");
                }
            } catch (Exception e) {
                // cannot retrieve session/clientinfo/properties?
                Debug.error(e);
                target.appendJavascript("testStyleSheets();");
            }
        }
    }
}
Also used : WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) HashMap(java.util.HashMap) ILabel(com.servoy.j2db.ui.ILabel) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ArrayList(java.util.ArrayList) CloseableAjaxRequestTarget(com.servoy.j2db.server.headlessclient.CloseableAjaxRequestTarget) List(java.util.List) ArrayList(java.util.ArrayList) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) MainPage(com.servoy.j2db.server.headlessclient.MainPage) HashSet(java.util.HashSet) MarkupContainer(org.apache.wicket.MarkupContainer) ModifiedAccessStackPageMap(com.servoy.j2db.server.headlessclient.WebClientsApplication.ModifiedAccessStackPageMap) IVisitor(org.apache.wicket.Component.IVisitor) WebClientSession(com.servoy.j2db.server.headlessclient.WebClientSession) WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 23 with IDisplayData

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

the class ComponentValueComparator method compare.

/**
 * @see wicket.model.IModelComparator#compare(wicket.Component, java.lang.Object)
 */
public boolean compare(Component component, Object newObject) {
    // When value is not valid re-setting the original value should be accepted
    if (component instanceof IDisplayData && !((IDisplayData) component).isValueValid()) {
        return false;
    }
    Object previous = null;
    IModel model = component.getInnermostModel();
    if (model instanceof RecordItemModel) {
        previous = ((RecordItemModel) model).getLastRenderedValue(component);
    } else {
        previous = model.getObject();
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    if (previous == null && "".equals(newObject) || "".equals(previous) && newObject == null)
        return true;
    return Utils.equalObjects(previous, newObject);
}
Also used : IModel(org.apache.wicket.model.IModel) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData)

Example 24 with IDisplayData

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

the class RecordItemModel method setValue.

/**
 * @param obj
 * @param dataProviderID
 * @param prevValue
 */
public void setValue(Component component, String dataProviderID, Object value) {
    Object obj = value;
    String compDpid = getDataProviderID(component);
    boolean ownComponentsValue = compDpid != null && dataProviderID.endsWith(compDpid);
    Object prevValue = null;
    if (ownComponentsValue && component instanceof IResolveObject) {
        obj = ((IResolveObject) component).resolveRealValue(obj);
    }
    if (component instanceof IDisplayData) {
        obj = Utils.removeJavascripLinkFromDisplay((IDisplayData) component, new Object[] { obj });
    }
    WebForm webForm = component.findParent(WebForm.class);
    IRecordInternal record = (IRecordInternal) RecordItemModel.this.getObject();
    // use UI converter to convert from UI value to record value
    if (!(record instanceof FindState)) {
        obj = ComponentFormat.applyUIConverterFromObject(component, obj, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
    }
    FormScope fs = webForm.getController().getFormScope();
    try {
        Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
        if (scope.getLeft() != null) {
            if (record == null) {
                webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().getGlobalScope(scope.getLeft()).put(scope.getRight(), obj);
            } else {
                // does an additional fire in foundset!
                prevValue = record.getParentFoundSet().setDataProviderValue(dataProviderID, obj);
            }
        } else if (fs.has(dataProviderID, fs)) {
            prevValue = fs.get(dataProviderID);
            fs.put(dataProviderID, obj);
        } else {
            if (record != null && record.startEditing()) {
                try {
                    prevValue = record.getValue(dataProviderID);
                    record.setValue(dataProviderID, obj);
                } catch (IllegalArgumentException e) {
                    Debug.trace(e);
                    ((WebClientSession) Session.get()).getWebClient().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
                    Object stateValue = record.getValue(dataProviderID);
                    if (!Utils.equalObjects(prevValue, stateValue)) {
                        // reset display to changed value in validator method
                        obj = stateValue;
                    }
                    if (ownComponentsValue) {
                        ((IDisplayData) component).setValueValid(false, prevValue);
                    }
                    return;
                }
                if (ownComponentsValue && record instanceof FindState && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat() != null) {
                    ((FindState) record).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat().parsedFormat);
                }
            }
        }
        // then dont call notify
        if (ownComponentsValue) {
            ((IDisplayData) component).notifyLastNewValueWasChange(prevValue, obj);
        }
    } finally {
        // then touch the lastInvalidValue
        if (ownComponentsValue) {
            if (((IDisplayData) component).isValueValid()) {
                lastInvalidValue = NONE;
            } else {
                lastInvalidValue = obj;
            }
        }
    }
    return;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) FormScope(com.servoy.j2db.scripting.FormScope) FindState(com.servoy.j2db.dataprocessing.FindState) ApplicationException(com.servoy.j2db.ApplicationException) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Aggregations

IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)24 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)8 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)7 HashMap (java.util.HashMap)7 JComponent (javax.swing.JComponent)7 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)6 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)6 Point (java.awt.Point)6 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)5 IPersist (com.servoy.j2db.persistence.IPersist)5 IScriptable (com.servoy.j2db.scripting.IScriptable)5 IComponent (com.servoy.j2db.ui.IComponent)5 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)5 Component (java.awt.Component)5 EventObject (java.util.EventObject)5 Iterator (java.util.Iterator)5 Component (org.apache.wicket.Component)5 FindState (com.servoy.j2db.dataprocessing.FindState)4 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)4 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)4