Search in sources :

Example 6 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener 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 7 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project syncope by apache.

the class SearchClausePanel method enableSearch.

public void enableSearch(final IEventSink resultContainer) {
    this.resultContainer = resultContainer;
    this.searchButton.setEnabled(true);
    this.searchButton.setVisible(true);
    field.add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
    field.add(new AjaxEventBehavior("onkeydown") {

        private static final long serialVersionUID = -7133385027739964990L;

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            if (resultContainer == null) {
                send(SearchClausePanel.this, Broadcast.BUBBLE, new SearchEvent(target));
            } else {
                send(resultContainer, Broadcast.EXACT, new SearchEvent(target));
            }
        }

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().add(new AjaxCallListener() {

                private static final long serialVersionUID = 7160235486520935153L;

                @Override
                public CharSequence getPrecondition(final Component component) {
                    return "if (Wicket.Event.keyCode(attrs.event)  == 13) { return true; } else { return false; }";
                }
            });
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) IndicatorAjaxEventBehavior(org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxEventBehavior) AjaxEventBehavior(org.apache.wicket.ajax.AjaxEventBehavior) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 8 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project syncope by apache.

the class SearchClausePanel method settingsDependingComponents.

@Override
public FieldPanel<SearchClause> settingsDependingComponents() {
    final SearchClause searchClause = this.clause.getObject();
    final WebMarkupContainer operatorContainer = new WebMarkupContainer("operatorContainer");
    operatorContainer.setOutputMarkupId(true);
    field.add(operatorContainer);
    final BootstrapToggleConfig config = new BootstrapToggleConfig().withOnStyle(BootstrapToggleConfig.Style.info).withOffStyle(BootstrapToggleConfig.Style.warning).withSize(BootstrapToggleConfig.Size.mini);
    operatorFragment.add(new BootstrapToggle("operator", new Model<Boolean>() {

        private static final long serialVersionUID = -7157802546272668001L;

        @Override
        public Boolean getObject() {
            return searchClause.getOperator() == Operator.AND;
        }

        @Override
        public void setObject(final Boolean object) {
            searchClause.setOperator(object ? Operator.AND : Operator.OR);
        }
    }, config) {

        private static final long serialVersionUID = 2969634208049189343L;

        @Override
        protected IModel<String> getOffLabel() {
            return Model.of("OR");
        }

        @Override
        protected IModel<String> getOnLabel() {
            return Model.of("AND");
        }

        @Override
        protected CheckBox newCheckBox(final String id, final IModel<Boolean> model) {
            final CheckBox checkBox = super.newCheckBox(id, model);
            checkBox.add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(final AjaxRequestTarget target) {
                }
            });
            return checkBox;
        }
    }.setOutputMarkupPlaceholderTag(true));
    if (getIndex() > 0) {
        operatorContainer.add(operatorFragment);
    } else {
        operatorContainer.add(searchButtonFragment);
    }
    final AjaxTextFieldPanel property = new AjaxTextFieldPanel("property", "property", new PropertyModel<String>(searchClause, "property"), false);
    property.hideLabel().setOutputMarkupId(true).setEnabled(true);
    property.setChoices(properties.getObject());
    field.add(property);
    property.getField().add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) { event.preventDefault(); }")));
    property.getField().add(new IndicatorAjaxEventBehavior("onkeyup") {

        private static final long serialVersionUID = -7866120562087857309L;

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            if (field.getModel().getObject() == null || field.getModel().getObject().getType() == null) {
                return;
            }
            if (field.getModel().getObject().getType() == Type.GROUP_MEMBERSHIP) {
                String[] inputAsArray = property.getField().getInputAsArray();
                if (StringUtils.isBlank(property.getField().getInput()) || inputAsArray.length == 0) {
                    property.setChoices(properties.getObject());
                } else {
                    String inputValue = (inputAsArray.length > 1 && inputAsArray[1] != null) ? inputAsArray[1] : property.getField().getInput();
                    inputValue = (inputValue.startsWith("*") && !inputValue.endsWith("*")) ? inputValue + "*" : (!inputValue.startsWith("*") && inputValue.endsWith("*")) ? "*" + inputValue : (inputValue.startsWith("*") && inputValue.endsWith("*") ? inputValue : "*" + inputValue + "*");
                    if (groupInfo.getRight() > AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY) {
                        List<GroupTO> filteredGroups = groupRestClient.search("/", SyncopeClient.getGroupSearchConditionBuilder().is("name").equalToIgnoreCase(inputValue).query(), 1, AnyObjectSearchPanel.MAX_GROUP_LIST_CARDINALITY, new SortParam<>("name", true), null);
                        Collection<String> newList = CollectionUtils.collect(filteredGroups, new Transformer<GroupTO, String>() {

                            @Override
                            public String transform(final GroupTO input) {
                                return input.getName();
                            }
                        });
                        final List<String> names = new ArrayList<>(newList);
                        Collections.sort(names);
                        property.setChoices(names);
                    }
                }
            }
        }

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().clear();
        }
    }, new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
        }
    });
    final AjaxDropDownChoicePanel<SearchClause.Comparator> comparator = new AjaxDropDownChoicePanel<>("comparator", "comparator", new PropertyModel<>(searchClause, "comparator"));
    comparator.setChoices(comparators);
    comparator.setNullValid(false).hideLabel().setOutputMarkupId(true);
    comparator.setRequired(required);
    comparator.setChoiceRenderer(getComparatorRender(field.getModel()));
    field.add(comparator);
    final AjaxTextFieldPanel value = new AjaxTextFieldPanel("value", "value", new PropertyModel<>(searchClause, "value"), false);
    value.hideLabel().setOutputMarkupId(true);
    field.add(value);
    value.getField().add(AttributeModifier.replace("onkeydown", Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
    value.getField().add(new IndicatorAjaxEventBehavior("onkeydown") {

        private static final long serialVersionUID = -7133385027739964990L;

        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            target.focusComponent(null);
            value.getField().inputChanged();
            value.getField().validate();
            if (value.getField().isValid()) {
                value.getField().valid();
                value.getField().updateModel();
            }
        }

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().add(new AjaxCallListener() {

                private static final long serialVersionUID = 7160235486520935153L;

                @Override
                public CharSequence getPrecondition(final Component component) {
                    return "if (Wicket.Event.keyCode(attrs.event)  == 13) { return true; } else { return false; }";
                }
            });
        }
    });
    final AjaxDropDownChoicePanel<SearchClause.Type> type = new AjaxDropDownChoicePanel<>("type", "type", new PropertyModel<>(searchClause, "type"));
    type.setChoices(types).hideLabel().setRequired(required).setOutputMarkupId(true);
    type.setNullValid(false);
    type.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            final SearchClause searchClause = new SearchClause();
            if (StringUtils.isNotEmpty(type.getDefaultModelObjectAsString())) {
                searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
            }
            SearchClausePanel.this.clause.setObject(searchClause);
            setFieldAccess(searchClause.getType(), property, comparator, value);
            // reset property value in case and just in case of change of type
            property.setModelObject(StringUtils.EMPTY);
            target.add(property);
            target.add(comparator);
            target.add(value);
        }
    });
    field.add(type);
    comparator.getField().add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            if (type.getModelObject() == SearchClause.Type.ATTRIBUTE || type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
                if (comparator.getModelObject() == SearchClause.Comparator.IS_NULL || comparator.getModelObject() == SearchClause.Comparator.IS_NOT_NULL) {
                    value.setModelObject(StringUtils.EMPTY);
                    value.setEnabled(false);
                } else {
                    value.setEnabled(true);
                }
                target.add(value);
            }
            if (type.getModelObject() == SearchClause.Type.RELATIONSHIP) {
                property.setEnabled(true);
                final SearchClause searchClause = new SearchClause();
                searchClause.setType(Type.valueOf(type.getDefaultModelObjectAsString()));
                searchClause.setComparator(comparator.getModelObject());
                SearchClausePanel.this.clause.setObject(searchClause);
                target.add(property);
            }
        }
    });
    setFieldAccess(searchClause.getType(), property, comparator, value);
    return this;
}
Also used : Transformer(org.apache.commons.collections4.Transformer) IndicatorAjaxFormComponentUpdatingBehavior(org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) SortParam(org.apache.wicket.extensions.markup.html.repeater.util.SortParam) Comparator(org.apache.syncope.client.console.panels.search.SearchClause.Comparator) IndicatorAjaxEventBehavior(org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxEventBehavior) List(java.util.List) ArrayList(java.util.ArrayList) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IModel(org.apache.wicket.model.IModel) AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) Type(org.apache.syncope.client.console.panels.search.SearchClause.Type) BootstrapToggleConfig(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig) BootstrapToggle(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle) CheckBox(org.apache.wicket.markup.html.form.CheckBox) Collection(java.util.Collection) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 9 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener 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 10 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project oc-explorer by devgateway.

the class BootstrapDeleteButton method updateAjaxAttributes.

@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    AjaxCallListener ajaxCallListener = new AjaxCallListener();
    ajaxCallListener.onPrecondition("return confirm('Confirm Delete?');");
    attributes.getAjaxCallListeners().add(ajaxCallListener);
}
Also used : AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Aggregations

AjaxCallListener (org.apache.wicket.ajax.attributes.AjaxCallListener)14 Component (org.apache.wicket.Component)9 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)7 List (java.util.List)3 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)3 FormComponent (org.apache.wicket.markup.html.form.FormComponent)3 IModel (org.apache.wicket.model.IModel)3 ArrayList (java.util.ArrayList)2 IndicatorAjaxEventBehavior (org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxEventBehavior)2 IAjaxCallListener (org.apache.wicket.ajax.attributes.IAjaxCallListener)2 TextField (com.googlecode.wicket.kendo.ui.form.TextField)1 BootstrapToggle (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle)1 BootstrapToggleConfig (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig)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 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Transformer (org.apache.commons.collections4.Transformer)1