Search in sources :

Example 1 with IAjaxCallListener

use of org.apache.wicket.ajax.attributes.IAjaxCallListener in project webanno by webanno.

the class AnnotationFeatureForm method createForwardAnnotationTextField.

private TextField<String> createForwardAnnotationTextField() {
    TextField<String> textfield = new TextField<>("forwardAnno");
    textfield.setOutputMarkupId(true);
    textfield.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        private static final long serialVersionUID = 4554834769861958396L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            IAjaxCallListener listener = new AjaxCallListener() {

                private static final long serialVersionUID = -7968540662654079601L;

                @Override
                public CharSequence getPrecondition(Component component) {
                    return "var keycode = Wicket.Event.keyCode(attrs.event);    return true;";
                }
            };
            attributes.getAjaxCallListeners().add(listener);
            attributes.getDynamicExtraParameters().add("var eventKeycode = Wicket.Event" + ".keyCode(attrs.event);return {keycode: eventKeycode};");
            attributes.setPreventDefault(false);
        }

        @Override
        protected void onUpdate(AjaxRequestTarget aTarget) {
            final Request request = RequestCycle.get().getRequest();
            final String jsKeycode = request.getRequestParameters().getParameterValue("keycode").toString("");
            if (jsKeycode.equals("32")) {
                try {
                    JCas jCas = editorPanel.getEditorCas();
                    editorPanel.actionCreateForward(aTarget, jCas);
                    selectedTag = "";
                } catch (Exception e) {
                    handleException(textfield, aTarget, e);
                }
                return;
            }
            if (jsKeycode.equals("13")) {
                selectedTag = "";
                return;
            }
            selectedTag = (textfield.getModelObject() == null ? "" : textfield.getModelObject().charAt(0)) + selectedTag;
            Map<String, String> bindTags = getBindTags();
            if (!bindTags.isEmpty()) {
                List<FeatureState> featureStates = getModelObject().getFeatureStates();
                featureStates.get(0).value = getKeyBindValue(selectedTag, bindTags);
            }
            aTarget.add(textfield);
            aTarget.add(featureEditorPanelContent.get(0));
        }
    });
    textfield.add(new AttributeAppender("style", "opacity:0", ";"));
    // forwardAnno.add(new AttributeAppender("style", "filter:alpha(opacity=0)", ";"));
    return textfield;
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener) Request(org.apache.wicket.request.Request) JCas(org.apache.uima.jcas.JCas) AnnotationDetailEditorPanel.handleException(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.handleException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) IOException(java.io.IOException) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) TextField(com.googlecode.wicket.kendo.ui.form.TextField) List(java.util.List) ArrayList(java.util.ArrayList) Component(org.apache.wicket.Component) IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 2 with IAjaxCallListener

use of org.apache.wicket.ajax.attributes.IAjaxCallListener in project the-app by devops-dojo.

the class KeyPressBehavior method updateAjaxAttributes.

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    IAjaxCallListener listener = new AjaxCallListener() {

        @Override
        public CharSequence getPrecondition(Component component) {
            // Here only by keyocdes for F9 and F10
            return "var keycode = Wicket.Event.keyCode(attrs.event);" + "if ((keycode == 112) || (keycode == 113) || (keycode == 114) || (keycode == 115))" + "    return true;" + "else" + "    return false;";
        }
    };
    attributes.getAjaxCallListeners().add(listener);
    // Append the pressed keycode to the ajaxrequest
    attributes.getDynamicExtraParameters().add("var eventKeycode = Wicket.Event.keyCode(attrs.event);" + "return {keycode: eventKeycode};");
    // whithout setting, no keyboard events will reach any inputfield
    attributes.setPreventDefault(true);
}
Also used : IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener) Component(org.apache.wicket.Component) IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 3 with IAjaxCallListener

use of org.apache.wicket.ajax.attributes.IAjaxCallListener in project wicket by apache.

the class AbstractDefaultAjaxBehavior method renderExtraHeaderContributors.

/**
 * Renders header contribution by IAjaxCallListener instances which additionally implement
 * IComponentAwareHeaderContributor interface.
 *
 * @param component
 *            the component assigned to this behavior
 * @param response
 *            the current header response
 */
private void renderExtraHeaderContributors(final Component component, final IHeaderResponse response) {
    AjaxRequestAttributes attributes = getAttributes();
    List<IAjaxCallListener> ajaxCallListeners = attributes.getAjaxCallListeners();
    for (IAjaxCallListener ajaxCallListener : ajaxCallListeners) {
        if (ajaxCallListener instanceof IComponentAwareHeaderContributor) {
            IComponentAwareHeaderContributor contributor = (IComponentAwareHeaderContributor) ajaxCallListener;
            contributor.renderHead(component, response);
        }
    }
}
Also used : AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) IComponentAwareHeaderContributor(org.apache.wicket.markup.html.IComponentAwareHeaderContributor) IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener)

Example 4 with IAjaxCallListener

use of org.apache.wicket.ajax.attributes.IAjaxCallListener in project wicket by apache.

the class AbstractDefaultAjaxBehavior method renderAjaxAttributes.

/**
 * @param component
 * @param attributes
 * @return the attributes as string in JSON format
 */
protected final CharSequence renderAjaxAttributes(final Component component, AjaxRequestAttributes attributes) {
    JSONObject attributesJson = new JSONObject();
    try {
        attributesJson.put(AjaxAttributeName.URL.jsonName(), getCallbackUrl());
        Method method = attributes.getMethod();
        if (Method.POST == method) {
            attributesJson.put(AjaxAttributeName.METHOD.jsonName(), method);
        }
        if (component instanceof Page == false) {
            String componentId = component.getMarkupId();
            attributesJson.put(AjaxAttributeName.MARKUP_ID.jsonName(), componentId);
        }
        String formId = attributes.getFormId();
        if (Strings.isEmpty(formId) == false) {
            attributesJson.put(AjaxAttributeName.FORM_ID.jsonName(), formId);
        }
        if (attributes.isMultipart()) {
            attributesJson.put(AjaxAttributeName.IS_MULTIPART.jsonName(), true);
        }
        String submittingComponentId = attributes.getSubmittingComponentName();
        if (Strings.isEmpty(submittingComponentId) == false) {
            attributesJson.put(AjaxAttributeName.SUBMITTING_COMPONENT_NAME.jsonName(), submittingComponentId);
        }
        CharSequence childSelector = attributes.getChildSelector();
        if (Strings.isEmpty(childSelector) == false) {
            attributesJson.put(AjaxAttributeName.CHILD_SELECTOR.jsonName(), childSelector);
        }
        if (attributes.isSerializeRecursively()) {
            attributesJson.put(AjaxAttributeName.SERIALIZE_RECURSIVELY.jsonName(), true);
        }
        String indicatorId = findIndicatorId();
        if (Strings.isEmpty(indicatorId) == false) {
            attributesJson.put(AjaxAttributeName.INDICATOR_ID.jsonName(), indicatorId);
        }
        for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners()) {
            if (ajaxCallListener != null) {
                CharSequence initHandler = ajaxCallListener.getInitHandler(component);
                appendListenerHandler(initHandler, attributesJson, AjaxAttributeName.INIT_HANDLER.jsonName(), INIT_HANDLER_FUNCTION_TEMPLATE);
                CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component);
                appendListenerHandler(beforeHandler, attributesJson, AjaxAttributeName.BEFORE_HANDLER.jsonName(), BEFORE_HANDLER_FUNCTION_TEMPLATE);
                CharSequence beforeSendHandler = ajaxCallListener.getBeforeSendHandler(component);
                appendListenerHandler(beforeSendHandler, attributesJson, AjaxAttributeName.BEFORE_SEND_HANDLER.jsonName(), BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE);
                CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
                appendListenerHandler(afterHandler, attributesJson, AjaxAttributeName.AFTER_HANDLER.jsonName(), AFTER_HANDLER_FUNCTION_TEMPLATE);
                CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
                appendListenerHandler(successHandler, attributesJson, AjaxAttributeName.SUCCESS_HANDLER.jsonName(), SUCCESS_HANDLER_FUNCTION_TEMPLATE);
                CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
                appendListenerHandler(failureHandler, attributesJson, AjaxAttributeName.FAILURE_HANDLER.jsonName(), FAILURE_HANDLER_FUNCTION_TEMPLATE);
                CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
                appendListenerHandler(completeHandler, attributesJson, AjaxAttributeName.COMPLETE_HANDLER.jsonName(), COMPLETE_HANDLER_FUNCTION_TEMPLATE);
                CharSequence precondition = ajaxCallListener.getPrecondition(component);
                appendListenerHandler(precondition, attributesJson, AjaxAttributeName.PRECONDITION.jsonName(), PRECONDITION_FUNCTION_TEMPLATE);
                CharSequence doneHandler = ajaxCallListener.getDoneHandler(component);
                appendListenerHandler(doneHandler, attributesJson, AjaxAttributeName.DONE_HANDLER.jsonName(), DONE_HANDLER_FUNCTION_TEMPLATE);
            }
        }
        JSONArray extraParameters = JsonUtils.asArray(attributes.getExtraParameters());
        if (extraParameters.length() > 0) {
            attributesJson.put(AjaxAttributeName.EXTRA_PARAMETERS.jsonName(), extraParameters);
        }
        List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters();
        if (dynamicExtraParameters != null) {
            for (CharSequence dynamicExtraParameter : dynamicExtraParameters) {
                String func = String.format(DYNAMIC_PARAMETER_FUNCTION_TEMPLATE, dynamicExtraParameter);
                JSONFunction function = new JSONFunction(func);
                attributesJson.append(AjaxAttributeName.DYNAMIC_PARAMETER_FUNCTION.jsonName(), function);
            }
        }
        if (attributes.isAsynchronous() == false) {
            attributesJson.put(AjaxAttributeName.IS_ASYNC.jsonName(), false);
        }
        String[] eventNames = attributes.getEventNames();
        if (eventNames.length == 1) {
            attributesJson.put(AjaxAttributeName.EVENT_NAME.jsonName(), eventNames[0]);
        } else {
            for (String eventName : eventNames) {
                attributesJson.append(AjaxAttributeName.EVENT_NAME.jsonName(), eventName);
            }
        }
        AjaxChannel channel = attributes.getChannel();
        if (channel != null && channel.equals(AjaxChannel.DEFAULT) == false) {
            attributesJson.put(AjaxAttributeName.CHANNEL.jsonName(), channel);
        }
        if (attributes.isPreventDefault()) {
            attributesJson.put(AjaxAttributeName.IS_PREVENT_DEFAULT.jsonName(), true);
        }
        if (AjaxRequestAttributes.EventPropagation.STOP.equals(attributes.getEventPropagation())) {
            attributesJson.put(AjaxAttributeName.EVENT_PROPAGATION.jsonName(), "stop");
        } else if (AjaxRequestAttributes.EventPropagation.STOP_IMMEDIATE.equals(attributes.getEventPropagation())) {
            attributesJson.put(AjaxAttributeName.EVENT_PROPAGATION.jsonName(), "stopImmediate");
        }
        Duration requestTimeout = attributes.getRequestTimeout();
        if (requestTimeout != null) {
            attributesJson.put(AjaxAttributeName.REQUEST_TIMEOUT.jsonName(), requestTimeout.getMilliseconds());
        }
        boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
        if (wicketAjaxResponse == false) {
            attributesJson.put(AjaxAttributeName.IS_WICKET_AJAX_RESPONSE.jsonName(), false);
        }
        String dataType = attributes.getDataType();
        if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false) {
            attributesJson.put(AjaxAttributeName.DATATYPE.jsonName(), dataType);
        }
        ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
        if (throttlingSettings != null) {
            JSONObject throttlingSettingsJson = new JSONObject();
            String throttleId = throttlingSettings.getId();
            if (throttleId == null) {
                throttleId = component.getMarkupId();
            }
            throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_ID.jsonName(), throttleId);
            throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_DELAY.jsonName(), throttlingSettings.getDelay().getMilliseconds());
            if (throttlingSettings.getPostponeTimerOnUpdate()) {
                throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_POSTPONE_ON_UPDATE.jsonName(), true);
            }
            attributesJson.put(AjaxAttributeName.THROTTLING.jsonName(), throttlingSettingsJson);
        }
        postprocessConfiguration(attributesJson, component);
    } catch (JSONException e) {
        throw new WicketRuntimeException(e);
    }
    String attributesAsJson = attributesJson.toString();
    return attributesAsJson;
}
Also used : ThrottlingSettings(org.apache.wicket.ajax.attributes.ThrottlingSettings) IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) JSONArray(com.github.openjson.JSONArray) JSONException(com.github.openjson.JSONException) Page(org.apache.wicket.Page) Duration(org.apache.wicket.util.time.Duration) Method(org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method) JSONFunction(org.apache.wicket.ajax.json.JSONFunction) JSONObject(com.github.openjson.JSONObject)

Aggregations

IAjaxCallListener (org.apache.wicket.ajax.attributes.IAjaxCallListener)4 Component (org.apache.wicket.Component)2 AjaxCallListener (org.apache.wicket.ajax.attributes.AjaxCallListener)2 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)2 JSONArray (com.github.openjson.JSONArray)1 JSONException (com.github.openjson.JSONException)1 JSONObject (com.github.openjson.JSONObject)1 TextField (com.googlecode.wicket.kendo.ui.form.TextField)1 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1 AnnotationDetailEditorPanel.handleException (de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.handleException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 JCas (org.apache.uima.jcas.JCas)1 Page (org.apache.wicket.Page)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 Method (org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method)1