Search in sources :

Example 1 with RenderEventExecutor

use of com.servoy.j2db.ui.RenderEventExecutor 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 2 with RenderEventExecutor

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

the class ComponentFactory method createGraphicalComponent.

private static IComponent createGraphicalComponent(IApplication application, Form form, GraphicalComponent label, IScriptExecuter el, IDataProviderLookup dataProviderLookup) {
    int style_halign = -1;
    int style_valign = -1;
    int textTransform = 0;
    int mediaid = 0;
    Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, label, form);
    if (styleInfo != null) {
        IStyleSheet ss = styleInfo.getLeft();
        IStyleRule s = styleInfo.getRight();
        if (ss != null && s != null) {
            style_valign = ss.getVAlign(s);
            style_halign = ss.getHAlign(s);
            boolean parseMedia = true;
            // anything else then then the css through the templategenerator is used. (See TemplateGenerator.createGraphicalComponentHTML)
            if (application.getApplicationType() == IApplication.WEB_CLIENT) {
                parseMedia = s.getValue(CSS.Attribute.BACKGROUND_REPEAT.toString()) == null && s.getValue(CSS.Attribute.BACKGROUND_POSITION.toString()) == null;
            }
            if (parseMedia) {
                Object mediaUrl = s.getValue(CSS.Attribute.BACKGROUND_IMAGE.toString());
                if (mediaUrl != null && mediaUrl.toString() != null) {
                    String mediaUrlString = mediaUrl.toString();
                    int start = mediaUrlString.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
                    if (start != -1) {
                        String name = mediaUrlString.substring(start + MediaURLStreamHandler.MEDIA_URL_DEF.length());
                        if (name.endsWith("')") || name.endsWith("\")"))
                            name = name.substring(0, name.length() - 2);
                        if (name.endsWith(")"))
                            name = name.substring(0, name.length() - 1);
                        Media media = application.getFlattenedSolution().getMedia(name);
                        if (media != null) {
                            mediaid = media.getID();
                        }
                    }
                }
            }
            String transform = s.getValue(CSS.Attribute.TEXT_TRANSFORM.toString());
            if (transform != null) {
                if ("uppercase".equals(transform)) {
                    textTransform = ILabel.UPPERCASE;
                } else if ("lowercase".equals(transform)) {
                    textTransform = ILabel.LOWERCASE;
                } else if ("capitalize".equals(transform)) {
                    textTransform = ILabel.CAPITALIZE;
                }
            }
        }
    }
    ILabel l;
    AbstractRuntimeLabel<? extends ILabel> scriptable;
    IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
    if (ComponentFactory.isButton(label)) {
        IButton button;
        if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
            scriptable = new RuntimeScriptButton(jsChangeRecorder, application);
            button = application.getItemFactory().createScriptButton((RuntimeScriptButton) scriptable, getWebID(form, label));
        } else {
            scriptable = new RuntimeDataButton(jsChangeRecorder, application);
            button = application.getItemFactory().createDataButton((RuntimeDataButton) scriptable, getWebID(form, label));
            IDataProvider dp = null;
            try {
                dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
            } catch (RepositoryException e) {
                Debug.error(e);
            }
            ((IDisplayData) button).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
            ((IDisplayTagText) button).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
            ((IDisplayData) button).setNeedEntireState(label.getDisplaysTags());
        }
        ((AbstractRuntimeButton<IButton>) scriptable).setComponent(button, label);
        button.setMediaOption(label.getMediaOptions());
        if (label.getRolloverImageMediaID() > 0) {
            try {
                button.setRolloverIcon(label.getRolloverImageMediaID());
                button.setRolloverEnabled(true);
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
        l = button;
    } else {
        if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
            scriptable = new RuntimeScriptLabel(jsChangeRecorder, application);
            l = application.getItemFactory().createScriptLabel((RuntimeScriptLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
        } else {
            scriptable = new RuntimeDataLabel(jsChangeRecorder, application);
            l = application.getItemFactory().createDataLabel((RuntimeDataLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
            IDataProvider dp = null;
            try {
                dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
            } catch (RepositoryException e) {
                Debug.error(e);
            }
            ((IDisplayData) l).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
            ((IDisplayTagText) l).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
            ((IDisplayData) l).setNeedEntireState(label.getDisplaysTags());
        }
        ((AbstractHTMLSubmitRuntimeLabel<ILabel>) scriptable).setComponent(l, label);
        l.setMediaOption(label.getMediaOptions());
        if (label.getRolloverImageMediaID() > 0) {
            try {
                l.setRolloverIcon(label.getRolloverImageMediaID());
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
    }
    String mnemonic = application.getI18NMessageIfPrefixed(label.getMnemonic());
    if (mnemonic != null && mnemonic.length() > 0) {
        l.setDisplayedMnemonic(mnemonic.charAt(0));
    }
    l.setTextTransform(textTransform);
    if (el != null && (label.getOnActionMethodID() > 0 || label.getOnDoubleClickMethodID() > 0 || label.getOnRightClickMethodID() > 0)) {
        l.addScriptExecuter(el);
        if (label.getOnActionMethodID() > 0)
            l.setActionCommand(Integer.toString(label.getOnActionMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onActionMethodID")));
        if (label.getOnDoubleClickMethodID() > 0)
            l.setDoubleClickCommand(Integer.toString(label.getOnDoubleClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onDoubleClickMethodID")));
        if (label.getOnRightClickMethodID() > 0)
            l.setRightClickCommand(Integer.toString(label.getOnRightClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onRightClickMethodID")));
    }
    if (label.getLabelFor() == null || (form.getView() != FormController.TABLE_VIEW && form.getView() != FormController.LOCKED_TABLE_VIEW)) {
        int onRenderMethodID = label.getOnRenderMethodID();
        AbstractBase onRenderPersist = label;
        if (onRenderMethodID <= 0) {
            onRenderMethodID = form.getOnRenderMethodID();
            onRenderPersist = form;
        }
        if (onRenderMethodID > 0) {
            RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
            renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
            IForm rendererForm = application.getFormManager().getForm(form.getName());
            IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
            renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
        }
    }
    l.setRotation(label.getRotation());
    l.setFocusPainted(label.getShowFocus());
    l.setCursor(Cursor.getPredefinedCursor(label.getRolloverCursor()));
    try {
        int halign = label.getHorizontalAlignment();
        if (halign != -1) {
            l.setHorizontalAlignment(halign);
        } else if (style_halign != -1) {
            l.setHorizontalAlignment(style_halign);
        }
    } catch (RuntimeException e) {
    // just ignore...Debug.error(e);
    }
    int valign = label.getVerticalAlignment();
    if (valign != -1) {
        l.setVerticalAlignment(valign);
    } else if (style_valign != -1) {
        l.setVerticalAlignment(style_valign);
    }
    try {
        if (!label.getDisplaysTags()) {
            l.setText(application.getI18NMessageIfPrefixed(label.getText()));
        }
    } catch (RuntimeException e1) {
    // ignore
    }
    l.setToolTipText(application.getI18NMessageIfPrefixed(label.getToolTipText()));
    if (label.getImageMediaID() > 0) {
        try {
            l.setMediaIcon(label.getImageMediaID());
        } catch (Exception e) {
            Debug.error(e);
        }
    } else if (mediaid > 0) {
        try {
            l.setMediaIcon(mediaid);
        } catch (Exception e) {
            Debug.error(e);
        }
    }
    if (label.getDataProviderID() != null) {
        scriptable.setComponentFormat(ComponentFormat.getComponentFormat(label.getFormat(), label.getDataProviderID(), dataProviderLookup, application));
    }
    applyBasicComponentProperties(application, l, label, styleInfo);
    Border border = null;
    Insets insets = null;
    if (label.getBorderType() != null) {
        border = ComponentFactoryHelper.createBorder(label.getBorderType());
    }
    if (label.getMargin() != null) {
        insets = label.getMargin();
    }
    if (styleInfo != null && (border == null || insets == null)) {
        IStyleSheet ss = styleInfo.getLeft();
        IStyleRule s = styleInfo.getRight();
        if (ss != null && s != null) {
            if (border == null && ss.hasBorder(s)) {
                border = ss.getBorder(s);
            }
            if (insets == null && ss.hasMargin(s)) {
                insets = ss.getMargin(s);
            }
        }
    }
    if (border != null && insets != null) {
        l.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)));
    } else if (border == null && insets != null && l instanceof IButton) {
        ((IButton) l).setMargin(insets);
    } else // supports setMargin, then fake the margins through empty border. (issue 166391)
    if (border == null && insets != null) {
        l.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
    }
    if (l instanceof IAnchoredComponent) {
        ((IAnchoredComponent) l).setAnchors(label.getAnchors());
    }
    return l;
}
Also used : Insets(java.awt.Insets) ILabel(com.servoy.j2db.ui.ILabel) RuntimeDataLabel(com.servoy.j2db.ui.scripting.RuntimeDataLabel) IForm(com.servoy.j2db.IForm) IDataProvider(com.servoy.j2db.persistence.IDataProvider) RuntimeScriptButton(com.servoy.j2db.ui.scripting.RuntimeScriptButton) FormController(com.servoy.j2db.FormController) IStyleSheet(com.servoy.j2db.util.IStyleSheet) IScriptExecuter(com.servoy.j2db.IScriptExecuter) AbstractHTMLSubmitRuntimeLabel(com.servoy.j2db.ui.scripting.AbstractHTMLSubmitRuntimeLabel) RuntimeDataButton(com.servoy.j2db.ui.scripting.RuntimeDataButton) Media(com.servoy.j2db.persistence.Media) AbstractBase(com.servoy.j2db.persistence.AbstractBase) RuntimeScriptLabel(com.servoy.j2db.ui.scripting.RuntimeScriptLabel) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IAnchoredComponent(com.servoy.j2db.ui.IAnchoredComponent) IButton(com.servoy.j2db.ui.IButton) IStyleRule(com.servoy.j2db.util.IStyleRule) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) AbstractRuntimeButton(com.servoy.j2db.ui.scripting.AbstractRuntimeButton) IStylePropertyChangesRecorder(com.servoy.j2db.ui.IStylePropertyChangesRecorder) Border(javax.swing.border.Border) TitledBorder(javax.swing.border.TitledBorder) IDisplayTagText(com.servoy.j2db.ui.IDisplayTagText)

Example 3 with RenderEventExecutor

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

the class DataAdapterList method setDataRendererComponentsRenderState.

public static void setDataRendererComponentsRenderState(IDataRenderer dataRenderer, IRecordInternal rec) {
    if (rec != null) {
        Object[] recordStatus = null;
        if (dataRenderer.getOnRenderComponent().getRenderEventExecutor().hasRenderCallback()) {
            recordStatus = getRecordIndexAndSelectStatus(rec);
            dataRenderer.getOnRenderComponent().getRenderEventExecutor().setRenderState(rec, ((Integer) recordStatus[0]).intValue(), ((Boolean) recordStatus[1]).booleanValue(), true);
        }
        @SuppressWarnings("rawtypes") Iterator compIte = dataRenderer.getComponentIterator();
        Object comp;
        while (compIte.hasNext()) {
            comp = compIte.next();
            if (comp instanceof IScriptableProvider) {
                IScriptable scriptable = ((IScriptableProvider) comp).getScriptObject();
                if (scriptable instanceof ISupportOnRenderCallback) {
                    RenderEventExecutor rendererEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
                    if (rendererEventExecutor != null && rendererEventExecutor.hasRenderCallback()) {
                        if (recordStatus == null)
                            recordStatus = getRecordIndexAndSelectStatus(rec);
                        rendererEventExecutor.setRenderState(rec, ((Integer) recordStatus[0]).intValue(), ((Boolean) recordStatus[1]).booleanValue(), true);
                    }
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 4 with RenderEventExecutor

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

the class AbstractRuntimeRendersupportComponent method clearRenderableWrapperProperty.

public void clearRenderableWrapperProperty(String property) {
    RenderEventExecutor renderEventExecutor = getRenderEventExecutor();
    IScriptRenderMethods renderable = getRenderable();
    if (renderEventExecutor != null && !renderEventExecutor.isOnRenderExecuting() && renderable instanceof RenderableWrapper) {
        ((RenderableWrapper) renderable).clearProperty(property);
    }
}
Also used : IScriptRenderMethods(com.servoy.j2db.ui.IScriptRenderMethods) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) RenderableWrapper(com.servoy.j2db.ui.RenderableWrapper)

Example 5 with RenderEventExecutor

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

the class DataRenderer method fireDataRendererOnRender.

private void fireDataRendererOnRender() {
    dataRendererOnRenderWrapper.getRenderEventExecutor().fireOnRender(hasFocus());
    @SuppressWarnings("rawtypes") Iterator compIte = getComponentIterator();
    Object comp;
    while (compIte.hasNext()) {
        comp = compIte.next();
        if (comp instanceof IScriptableProvider && !(comp instanceof IDisplayData) && !(comp instanceof IDisplayRelatedData)) {
            IScriptable scriptable = ((IScriptableProvider) comp).getScriptObject();
            if (scriptable instanceof ISupportOnRenderCallback) {
                RenderEventExecutor rendererEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
                boolean hasFocus = (comp instanceof Component) ? ((Component) comp).hasFocus() : false;
                rendererEventExecutor.fireOnRender(hasFocus);
            }
        }
    }
}
Also used : IDisplayRelatedData(com.servoy.j2db.dataprocessing.IDisplayRelatedData) Iterator(java.util.Iterator) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptable(com.servoy.j2db.scripting.IScriptable)

Aggregations

RenderEventExecutor (com.servoy.j2db.ui.RenderEventExecutor)10 IScriptable (com.servoy.j2db.scripting.IScriptable)6 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)6 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)6 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)4 JComponent (javax.swing.JComponent)4 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)3 IComponent (com.servoy.j2db.ui.IComponent)3 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)3 IScriptRenderMethods (com.servoy.j2db.ui.IScriptRenderMethods)3 RenderableWrapper (com.servoy.j2db.ui.RenderableWrapper)3 EventObject (java.util.EventObject)3 FormController (com.servoy.j2db.FormController)2 IForm (com.servoy.j2db.IForm)2 IScriptExecuter (com.servoy.j2db.IScriptExecuter)2 ServoyBeanState (com.servoy.j2db.component.ServoyBeanState)2 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 DbIdentValue (com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue)2 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)2