Search in sources :

Example 1 with WebEventExecutor

use of com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor in project servoy-client by Servoy.

the class MainPage method respond.

/**
 * Respond to focus/blur events.
 */
@SuppressWarnings("nls")
public void respond(AjaxRequestTarget target, final String event, final String markupId) {
    Component component = (Component) visitChildren(IComponent.class, new IVisitor<Component>() {

        public Object component(Component c) {
            Component targetComponent = c;
            if (c instanceof WebBaseSelectBox && ("blur".equals(event) || "focus".equals(event))) {
                Component[] cs = ((WebBaseSelectBox) c).getFocusChildren();
                if (cs != null && cs.length == 1)
                    targetComponent = cs[0];
            }
            if (targetComponent.getMarkupId().equals(markupId)) {
                return c;
            }
            return IVisitor.CONTINUE_TRAVERSAL;
        }
    });
    if (component == null) {
        // $NON-NLS-1$
        Debug.log("Component not found markupId " + markupId);
        return;
    }
    IFormUIInternal<?> formui = component.findParent(IFormUIInternal.class);
    if (formui != null && formui.isDesignMode()) {
        // $NON-NLS-1$
        Debug.log("Event ignored because of design mode");
        return;
    }
    if (component instanceof IFieldComponent) {
        WebEventExecutor eventExecutor = (WebEventExecutor) ((IFieldComponent) component).getEventExecutor();
        if (eventExecutor != null) {
            if ("focus".equals(event)) {
                int webModifier = Utils.getAsInteger(RequestCycle.get().getRequest().getParameter(IEventExecutor.MODIFIERS_PARAMETER));
                StartEditOnFocusGainedEventBehavior.startEditing(component, WebEventExecutor.convertModifiers(webModifier), target);
                eventExecutor.onEvent(JSEvent.EventType.focusGained, target, component, webModifier);
            } else if ("blur".equals(event)) {
                // test if the data is really posted by looking up the key.
                if (component instanceof FormComponent<?> && RequestCycle.get().getRequest().getParameter("nopostdata") == null) {
                    // changed data is posted
                    ((FormComponent<?>) component).processInput();
                }
                eventExecutor.onEvent(JSEvent.EventType.focusLost, target, component, IEventExecutor.MODIFIERS_UNSPECIFIED);
            } else {
                Debug.trace("Ignored event " + event);
            }
        } else {
            Debug.trace("Ignored event, no eventExecutor");
        }
    } else {
        // other non-field components like WebLabel
        ServoyForm form = component.findParent(ServoyForm.class);
        if (form != null) {
            // JS might change the page this form belongs to... so remember it now
            Page page = form.getPage();
            int webModifier = Utils.getAsInteger(RequestCycle.get().getRequest().getParameter(IEventExecutor.MODIFIERS_PARAMETER));
            WebEventExecutor.setSelectedIndex(component, target, WebEventExecutor.convertModifiers(webModifier), true);
            WebEventExecutor.generateResponse(target, page);
        }
    }
}
Also used : WebEventExecutor(com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IComponent(com.servoy.j2db.ui.IComponent) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page) WebBaseSelectBox(com.servoy.j2db.server.headlessclient.dataui.WebBaseSelectBox) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) 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) Point(java.awt.Point)

Aggregations

WebBaseSelectBox (com.servoy.j2db.server.headlessclient.dataui.WebBaseSelectBox)1 WebEventExecutor (com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 Point (java.awt.Point)1 Component (org.apache.wicket.Component)1 Page (org.apache.wicket.Page)1 WebPage (org.apache.wicket.markup.html.WebPage)1 FormComponent (org.apache.wicket.markup.html.form.FormComponent)1