Search in sources :

Example 1 with ISupportOnRenderCallback

use of com.servoy.j2db.ui.ISupportOnRenderCallback in project servoy-client by Servoy.

the class WebBaseLabel method fireOnRender.

public void fireOnRender(boolean force) {
    if (scriptable instanceof ISupportOnRenderCallback) {
        boolean isFocused = false;
        IMainContainer currentContainer = ((FormManager) application.getFormManager()).getCurrentContainer();
        if (currentContainer instanceof MainPage) {
            isFocused = this.equals(((MainPage) currentContainer).getFocusedComponent());
        }
        if (force)
            ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor().setRenderStateChanged();
        ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor().fireOnRender(isFocused);
    }
}
Also used : FormManager(com.servoy.j2db.FormManager) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IMainContainer(com.servoy.j2db.IMainContainer) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 2 with ISupportOnRenderCallback

use of com.servoy.j2db.ui.ISupportOnRenderCallback in project servoy-client by Servoy.

the class WebCellAdapter method valueChanged.

public void valueChanged(ModificationEvent e) {
    MainPage mp = view.findParent(MainPage.class);
    if (mp != null)
        mp.touch();
    IRecord record = e.getRecord();
    Iterator iterator = ((MarkupContainer) view.getTable()).iterator();
    while (iterator.hasNext()) {
        Object next = iterator.next();
        if (next instanceof ListItem) {
            ListItem li = (ListItem) next;
            Object modelObject = li.getModelObject();
            if (record == null || modelObject == record) {
                boolean hasOnRender = false;
                Iterator iterator2 = li.iterator();
                while (iterator2.hasNext()) {
                    ArrayList<Object> cellDisplays = new ArrayList<Object>();
                    Object cell = iterator2.next();
                    cell = CellContainer.getContentsForCell((Component) cell);
                    if (cell instanceof WebCellBasedViewListViewItem) {
                        Iterator listItemIte = ((WebCellBasedViewListViewItem) cell).iterator();
                        while (listItemIte.hasNext()) {
                            Object listItemDisplay = listItemIte.next();
                            if (listItemDisplay instanceof WrapperContainer) {
                                listItemDisplay = ((WrapperContainer) listItemDisplay).getDelegate();
                            }
                            cellDisplays.add(listItemDisplay);
                        }
                    } else {
                        cellDisplays.add(cell);
                    }
                    for (Object cellDisplay : cellDisplays) {
                        if (cellDisplay instanceof IProviderStylePropertyChanges && cellDisplay instanceof IDisplayData && ((IDisplayData) cellDisplay).getDataProviderID() == dataprovider) {
                            // only test if it is not already changed
                            view.checkForValueChanges(cellDisplay);
                            // do fire on render on all components for record change
                            if (cellDisplay instanceof ISupportOnRender && cellDisplay instanceof IScriptableProvider) {
                                IScriptable so = ((IScriptableProvider) cellDisplay).getScriptObject();
                                if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
                                    String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
                                    if (record != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
                                        ((ISupportOnRender) cellDisplay).fireOnRender(true);
                                        hasOnRender = true;
                                    }
                                }
                            }
                        }
                    }
                }
                if (record != null || (!hasOnRender && !canChangeValue(e)))
                    break;
            }
        }
    }
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) ISupportOnRender(com.servoy.j2db.ui.ISupportOnRender) IRecord(com.servoy.j2db.dataprocessing.IRecord) ArrayList(java.util.ArrayList) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) WebCellBasedViewListViewItem(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.WebCellBasedViewListViewItem) IScriptable(com.servoy.j2db.scripting.IScriptable) WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) Iterator(java.util.Iterator) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) ListItem(org.apache.wicket.markup.html.list.ListItem) Component(org.apache.wicket.Component) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 3 with ISupportOnRenderCallback

use of com.servoy.j2db.ui.ISupportOnRenderCallback in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method createComponents.

private void createComponents(final IApplication app, final Form form, final AbstractBase view, final IDataProviderLookup dataProviderLookup, final IScriptExecuter el, final int viewStartY, final int viewEndY, final ItemAdd output) {
    List<IPersist> elements = ComponentFactory.sortElementsOnPositionAndGroup(view.getAllObjectsAsList());
    int startX = 0;
    for (int i = 0; i < elements.size(); i++) {
        IPersist element = elements.get(i);
        if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
            if (!isListViewMode()) {
                if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                    if (isInView(cellview, ((GraphicalComponent) element).getLabelFor())) {
                        labelsFor.put(((GraphicalComponent) element).getLabelFor(), element);
                    }
                    continue;
                }
            }
            Point l = ((IFormElement) element).getLocation();
            if (l == null) {
                // unknown where to add
                continue;
            }
            if (l.y >= viewStartY && l.y < viewEndY) {
                IComponent c = ComponentFactory.createComponent(app, form, element, dataProviderLookup, el, false);
                if (cellview instanceof Portal && c instanceof IScriptableProvider) {
                    IScriptable s = ((IScriptableProvider) c).getScriptObject();
                    if (s instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) s).getRenderEventExecutor() != null)
                        ComponentFactoryHelper.addPortalOnRenderCallback((Portal) cellview, ((ISupportOnRenderCallback) s).getRenderEventExecutor(), element, fc != null ? fc.getScriptExecuter() : null);
                }
                initializeComponent((Component) c, view, element);
                output.add(element, (Component) c);
                if (!isListViewMode()) {
                    // reset location.x as defined in this order, elements are ordered by location.x which is modified in drag-n-drop
                    Point loc = c.getLocation();
                    if (loc != null) {
                        c.setLocation(new Point(startX, loc.y));
                    }
                    Dimension csize = c.getSize();
                    startX += (csize != null) ? csize.width : ((IFormElement) element).getSize().width;
                }
            }
        }
    }
}
Also used : IComponent(com.servoy.j2db.ui.IComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) IScriptable(com.servoy.j2db.scripting.IScriptable) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Bean(com.servoy.j2db.persistence.Bean) Field(com.servoy.j2db.persistence.Field) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 4 with ISupportOnRenderCallback

use of com.servoy.j2db.ui.ISupportOnRenderCallback in project servoy-client by Servoy.

the class WebEventExecutor method handleEvent.

/**
 * @param type
 * @param target
 * @param comp
 * @param webModifiers
 * @param mouseLocation
 * @param page
 */
private void handleEvent(EventType type, AjaxRequestTarget target, Component comp, int webModifiers, Point mouseLocation, Point absoluteMouseLocation, Page page) {
    // process model changes from web components
    WebClientSession.get().getWebClient().executeEvents();
    Component renderScriptProvider = comp;
    ISupplyFocusChildren<?> componentWithChildren = renderScriptProvider.findParent(ISupplyFocusChildren.class);
    if (componentWithChildren != null)
        renderScriptProvider = (Component) componentWithChildren;
    if (renderScriptProvider instanceof WrapperContainer)
        renderScriptProvider = ((WrapperContainer) renderScriptProvider).getDelegate();
    RenderEventExecutor renderEventExecutor = null;
    if (renderScriptProvider instanceof IScriptableProvider) {
        IScriptable s = ((IScriptableProvider) renderScriptProvider).getScriptObject();
        if (s instanceof ISupportOnRenderCallback) {
            renderEventExecutor = ((ISupportOnRenderCallback) s).getRenderEventExecutor();
            if (!renderEventExecutor.hasRenderCallback())
                renderEventExecutor = null;
        }
    }
    if (type == EventType.focusGained || type == EventType.action || type == EventType.focusLost) {
        if (type == EventType.focusGained || type == EventType.action) {
            ((MainPage) page).setFocusedComponent(comp);
        } else {
            ((MainPage) page).setFocusedComponent(null);
        }
        if (renderEventExecutor != null) {
            renderEventExecutor.setRenderStateChanged();
            // if component's onRender did not change any properties, don't add it to the target
            if (renderScriptProvider instanceof ISupportOnRender && WebOnRenderHelper.doRender((ISupportOnRender) renderScriptProvider)) {
                target.addComponent(renderScriptProvider);
            }
        }
    }
    if (type == EventType.focusLost || setSelectedIndex(comp, target, convertModifiers(webModifiers), type == EventType.focusGained || type == EventType.action)) {
        if (skipFireFocusGainedCommand && type.equals(JSEvent.EventType.focusGained)) {
            skipFireFocusGainedCommand = false;
        } else {
            switch(type) {
                case action:
                    fireActionCommand(false, comp, convertModifiers(webModifiers), mouseLocation);
                    break;
                case focusGained:
                    fireEnterCommands(false, comp, convertModifiers(webModifiers));
                    break;
                case focusLost:
                    fireLeaveCommands(comp, false, convertModifiers(webModifiers));
                    break;
                case doubleClick:
                    fireDoubleclickCommand(false, comp, convertModifiers(webModifiers), mouseLocation);
                    break;
                case rightClick:
                    // if right click, mark the meta flag as it is on the smart client
                    fireRightclickCommand(false, comp, convertModifiers(webModifiers | 8), null, mouseLocation, absoluteMouseLocation);
                    break;
                case none:
                case dataChange:
                case form:
                case onDrag:
                case onDragOver:
                case onDrop:
            }
        }
    }
}
Also used : WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) ISupportOnRender(com.servoy.j2db.ui.ISupportOnRender) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) 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) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 5 with ISupportOnRenderCallback

use of com.servoy.j2db.ui.ISupportOnRenderCallback in project servoy-client by Servoy.

the class DisplaysAdapter method valueChanged.

/*
	 * _____________________________________________________________ JavaScriptModificationlistener
	 */
public void valueChanged(ModificationEvent e) {
    if (!adjusting) {
        try {
            adjusting = true;
            Object obj = null;
            boolean formVariable = false;
            if (dataProviderID != null) {
                if (dal.getFormScope().has(dataProviderID, dal.getFormScope())) {
                    formVariable = true;
                    obj = dal.getFormScope().get(dataProviderID);
                } else if (record != null) {
                    obj = record.getValue(dataProviderID);
                    if (obj == Scriptable.NOT_FOUND) {
                        obj = null;
                    }
                    // have to do this because for calcs in calcs. Better was to had a check for previous value.
                    fireModificationEvent(obj);
                }
            }
            // do not set value for form variable except when really changed
            if (!formVariable || dataProviderID == null || dataProviderID.equals(e.getName())) {
                setValueToDisplays(obj);
            }
        } finally {
            adjusting = false;
        }
    }
    // do fire on render on all components for record change
    for (IDisplayData displayData : displays) {
        if (displayData instanceof ISupportOnRender && displayData instanceof IScriptableProvider) {
            IScriptable so = ((IScriptableProvider) displayData).getScriptObject();
            if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
                String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
                if (e.getRecord() != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
                    ((ISupportOnRender) displayData).fireOnRender(true);
                }
            }
        }
    }
}
Also used : ISupportOnRender(com.servoy.j2db.ui.ISupportOnRender) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable)

Aggregations

ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)15 IScriptable (com.servoy.j2db.scripting.IScriptable)11 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)11 RenderEventExecutor (com.servoy.j2db.ui.RenderEventExecutor)6 IComponent (com.servoy.j2db.ui.IComponent)5 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)5 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)4 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)4 MainPage (com.servoy.j2db.server.headlessclient.MainPage)4 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)4 JComponent (javax.swing.JComponent)4 Component (org.apache.wicket.Component)4 ServoyBeanState (com.servoy.j2db.component.ServoyBeanState)3 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)3 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)3 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)3 ISupportOnRender (com.servoy.j2db.ui.ISupportOnRender)3 EventObject (java.util.EventObject)3 Iterator (java.util.Iterator)3 FormManager (com.servoy.j2db.FormManager)2