Search in sources :

Example 1 with AjaxPreventSubmitBehavior

use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project webanno by webanno.

the class DynamicTextAreaFeatureEditor method createInputField.

@Override
protected AbstractTextComponent createInputField() {
    textarea = new TextArea<>("value");
    textarea.setOutputMarkupId(true);
    textarea.add(new AjaxPreventSubmitBehavior());
    return textarea;
}
Also used : AjaxPreventSubmitBehavior(org.apache.wicket.ajax.AjaxPreventSubmitBehavior)

Example 2 with AjaxPreventSubmitBehavior

use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project wicket by apache.

the class FormPage method addPreventEnterSubmitForm.

private void addPreventEnterSubmitForm() {
    Bean bean = new Bean();
    Form<Bean> form = new Form<Bean>("preventEnterForm", new CompoundPropertyModel<>(bean)) {

        @Override
        protected void onSubmit() {
            super.onSubmit();
            info("Form successfully submitted!");
        }
    };
    add(form);
    form.setOutputMarkupId(true);
    addFormComponents(form);
    form.add(new AjaxPreventSubmitBehavior());
}
Also used : Form(org.apache.wicket.markup.html.form.Form) AjaxPreventSubmitBehavior(org.apache.wicket.ajax.AjaxPreventSubmitBehavior)

Example 3 with AjaxPreventSubmitBehavior

use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project webanno by webanno.

the class TextAreaFeatureEditor method createInputField.

@Override
protected AbstractTextComponent createInputField() {
    TextArea<String> textarea = new TextArea<>("value");
    textarea.add(new AjaxPreventSubmitBehavior());
    try {
        String traitsString = getModelObject().feature.getTraits();
        StringFeatureTraits traits = JSONUtil.fromJsonString(StringFeatureTraits.class, traitsString);
        textarea.add(new AttributeModifier("rows", traits.getCollapsedRows()));
        textarea.add(new AttributeAppender("onfocus", "this.rows=" + traits.getExpandedRows() + ";"));
        textarea.add(new AttributeAppender("onblur", "this.rows=" + traits.getCollapsedRows() + ";"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return textarea;
}
Also used : TextArea(org.apache.wicket.markup.html.form.TextArea) IOException(java.io.IOException) AttributeModifier(org.apache.wicket.AttributeModifier) AjaxPreventSubmitBehavior(org.apache.wicket.ajax.AjaxPreventSubmitBehavior) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 4 with AjaxPreventSubmitBehavior

use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project webanno by webanno.

the class InputFieldTextFeatureEditor method createInputField.

@Override
protected AbstractTextComponent createInputField() {
    TextField<String> textfield = new TextField<>("value");
    textfield.add(new AjaxPreventSubmitBehavior());
    return textfield;
}
Also used : TextField(com.googlecode.wicket.kendo.ui.form.TextField) AjaxPreventSubmitBehavior(org.apache.wicket.ajax.AjaxPreventSubmitBehavior)

Example 5 with AjaxPreventSubmitBehavior

use of org.apache.wicket.ajax.AjaxPreventSubmitBehavior in project webanno by webanno.

the class AnnotationDetailEditorPanel method createForwardAnnotationKeySequenceCapturingForm.

private Component createForwardAnnotationKeySequenceCapturingForm() {
    Form<Void> form = new Form<>("forwardForm");
    TextField<String> textfield = new TextField<>("forwardAnno");
    textfield.setModel(Model.of());
    textfield.setOutputMarkupId(true);
    // We don't want the form to be submitted when the user pressed ENTER. Instead, we want to
    // capture the key event and send it as part of the AJAX request. Note that the
    // AjaxPreventSubmitBehavior triggers on "keydown" while our
    // AjaxFormComponentUpdatingBehavior has to trigger on "keyup", otherwise the pressed key
    // does not end up in the TextField's model.
    textfield.add(new AjaxPreventSubmitBehavior());
    textfield.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        private static final long serialVersionUID = 4554834769861958396L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getDynamicExtraParameters().add("return { 'keycode': Wicket.Event.keyCode(attrs.event) };");
        }

        @Override
        protected void onUpdate(AjaxRequestTarget aTarget) {
            AnnotatorState state = getModelObject();
            // Forward annotation mode only works on span layers
            if (!state.getSelection().isSpan()) {
                return;
            }
            // If the user has selected an annotation of a different type or no annotation at
            // all, then the forward-annotation key bindings must not be considered.
            AnnotationLayer layer = state.getSelectedAnnotationLayer();
            if (layer == null || !layer.equals(state.getDefaultAnnotationLayer())) {
                return;
            }
            try {
                final Request request = RequestCycle.get().getRequest();
                final String jsKeycode = request.getRequestParameters().getParameterValue("keycode").toString("");
                if (KEY_ENTER.equals(jsKeycode)) {
                    CAS cas = getEditorCas();
                    actionCreateForward(aTarget, cas);
                    setForwardAnnotationKeySequence(null, "complete annotation (space)");
                    return;
                } else if (KEY_BACKSPACE.equals(jsKeycode)) {
                    FeatureState featureState = getModelObject().getFeatureStates().get(0);
                    featureState.value = null;
                    setForwardAnnotationKeySequence(null, "delete annotation (backspace)");
                    CAS cas = getEditorCas();
                    actionCreateForward(aTarget, cas);
                } else {
                    String newTag = (textfield.getModelObject() == null ? "" : textfield.getModelObject().charAt(0)) + getForwardAnnotationKeySequence();
                    setForwardAnnotationKeySequence(newTag, "cycle tags");
                    Map<String, String> bindTags = buildKeySequenceToTagMap();
                    if (!bindTags.isEmpty()) {
                        FeatureState featureState = getModelObject().getFeatureStates().get(0);
                        featureState.value = getTagForKeySequence(getForwardAnnotationKeySequence(), bindTags);
                    }
                }
                aTarget.add(textfield);
                getFeatureEditorListPanel().getFirstFeatureEditor().ifPresent(aTarget::add);
            } catch (Exception e) {
                handleException(textfield, aTarget, e);
            }
        }
    });
    form.add(textfield);
    forwardAnnotationTextField = textfield;
    return form;
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) Form(org.apache.wicket.markup.html.form.Form) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) Request(org.apache.wicket.request.Request) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AjaxPreventSubmitBehavior(org.apache.wicket.ajax.AjaxPreventSubmitBehavior) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) NoResultException(javax.persistence.NoResultException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) IllegalPlacementException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalPlacementException) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CAS(org.apache.uima.cas.CAS) TextField(com.googlecode.wicket.kendo.ui.form.TextField)

Aggregations

AjaxPreventSubmitBehavior (org.apache.wicket.ajax.AjaxPreventSubmitBehavior)5 TextField (com.googlecode.wicket.kendo.ui.form.TextField)2 IOException (java.io.IOException)2 Form (org.apache.wicket.markup.html.form.Form)2 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1 IllegalPlacementException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalPlacementException)1 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)1 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 NoResultException (javax.persistence.NoResultException)1 UIMAException (org.apache.uima.UIMAException)1 CAS (org.apache.uima.cas.CAS)1 AttributeModifier (org.apache.wicket.AttributeModifier)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)1 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)1 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)1 TextArea (org.apache.wicket.markup.html.form.TextArea)1 Request (org.apache.wicket.request.Request)1