Example usage for org.apache.wicket.ajax.attributes ThrottlingSettings ThrottlingSettings

List of usage examples for org.apache.wicket.ajax.attributes ThrottlingSettings ThrottlingSettings

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.attributes ThrottlingSettings ThrottlingSettings.

Prototype

public ThrottlingSettings(final String id, final Duration delay, final boolean postponeTimerOnUpdate) 

Source Link

Document

Construct.

Usage

From source file:com.evolveum.midpoint.web.component.search.SearchPanel.java

License:Apache License

private void initLayout() {
    moreDialogModel = new LoadableModel<MoreDialogDto>(false) {

        @Override/*from  w  ww  .j  a v  a  2  s. c  o m*/
        protected MoreDialogDto load() {
            MoreDialogDto dto = new MoreDialogDto();
            dto.setProperties(createPropertiesList());

            return dto;
        }
    };

    Form form = new Form(ID_FORM);
    add(form);

    ListView items = new ListView<SearchItem>(ID_ITEMS,
            new PropertyModel<List<SearchItem>>(getModel(), Search.F_ITEMS)) {

        @Override
        protected void populateItem(ListItem<SearchItem> item) {
            SearchItemPanel searchItem = new SearchItemPanel(ID_ITEM, item.getModel());
            item.add(searchItem);
        }
    };
    items.add(createAdvancedVisibleBehaviour(false));
    form.add(items);

    WebMarkupContainer moreGroup = new WebMarkupContainer(ID_MORE_GROUP);
    moreGroup.add(createAdvancedVisibleBehaviour(false));
    form.add(moreGroup);

    AjaxLink more = new AjaxLink(ID_MORE) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            Component button = SearchPanel.this.get(createComponentPath(ID_FORM, ID_MORE_GROUP, ID_MORE));
            Component popover = SearchPanel.this.get(createComponentPath(ID_POPOVER));
            togglePopover(target, button, popover, 14);
        }
    };
    more.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            Search search = getModelObject();
            return !search.getAvailableDefinitions().isEmpty();
        }
    });
    more.setOutputMarkupId(true);
    moreGroup.add(more);

    WebMarkupContainer searchContainer = new WebMarkupContainer(ID_SEARCH_CONTAINER);
    searchContainer.setOutputMarkupId(true);
    form.add(searchContainer);

    AjaxSubmitButton searchSimple = new AjaxSubmitButton(ID_SEARCH_SIMPLE) {

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(form);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            searchPerformed(target);
        }
    };
    searchSimple.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isEnabled() {
            Search search = getModelObject();
            if (!search.isShowAdvanced()) {
                return true;
            }

            PrismContext ctx = getPageBase().getPrismContext();
            return search.isAdvancedQueryValid(ctx);
        }

        @Override
        public boolean isVisible() {
            return !getModelObject().isShowAdvanced() || !queryPlagroundAccessible;
        }
    });
    searchSimple.setOutputMarkupId(true);
    searchContainer.add(searchSimple);

    WebMarkupContainer searchDropdown = new WebMarkupContainer(ID_SEARCH_DROPDOWN);
    searchDropdown.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return getModelObject().isShowAdvanced() && queryPlagroundAccessible;
        }
    });
    searchContainer.add(searchDropdown);

    AjaxSubmitButton searchButtonBeforeDropdown = new AjaxSubmitButton(ID_SEARCH_BUTTON_BEFORE_DROPDOWN) {
        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(form);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            searchPerformed(target);
        }
    };
    searchButtonBeforeDropdown.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isEnabled() {
            Search search = getModelObject();
            if (!search.isShowAdvanced()) {
                return true;
            }
            PrismContext ctx = getPageBase().getPrismContext();
            return search.isAdvancedQueryValid(ctx);
        }
    });
    searchDropdown.add(searchButtonBeforeDropdown);

    List<InlineMenuItem> searchItems = new ArrayList<>();

    InlineMenuItem searchItem = new InlineMenuItem(createStringResource("SearchPanel.search"),
            new InlineMenuItemAction() {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    PrismContext ctx = getPageBase().getPrismContext();
                    if (getModelObject().isAdvancedQueryValid(ctx)) {
                        searchPerformed(target);
                    }
                }
            });
    searchItems.add(searchItem);

    searchItem = new InlineMenuItem(createStringResource("SearchPanel.debug"), new InlineMenuItemAction() {
        @Override
        public void onClick(AjaxRequestTarget target) {
            debugPerformed();
        }
    });
    searchItems.add(searchItem);

    ListView<InlineMenuItem> li = new ListView<InlineMenuItem>(ID_MENU_ITEM, Model.ofList(searchItems)) {
        @Override
        protected void populateItem(ListItem<InlineMenuItem> item) {
            WebMarkupContainer menuItemBody = new MenuLinkPanel(ID_MENU_ITEM_BODY, item.getModel());
            menuItemBody.setRenderBodyOnly(true);
            item.add(menuItemBody);
        }
    };
    searchDropdown.add(li);

    AjaxButton advanced = new AjaxButton(ID_ADVANCED, createAdvancedModel()) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            advancedPerformed(target);
        }
    };
    advanced.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return advancedSearch;
        }
    });
    form.add(advanced);

    initPopover();

    WebMarkupContainer advancedGroup = new WebMarkupContainer(ID_ADVANCED_GROUP);
    advancedGroup.add(createAdvancedVisibleBehaviour(true));
    advancedGroup.add(AttributeAppender.append("class", createAdvancedGroupStyle()));
    advancedGroup.setOutputMarkupId(true);
    form.add(advancedGroup);

    Label advancedCheck = new Label(ID_ADVANCED_CHECK);
    advancedCheck.add(AttributeAppender.append("class", createAdvancedGroupLabelStyle()));
    advancedGroup.add(advancedCheck);

    final TextArea advancedArea = new TextArea(ID_ADVANCED_AREA,
            new PropertyModel(getModel(), Search.F_ADVANCED_QUERY));
    advancedArea.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateAdvancedArea(advancedArea, target);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);

            attributes.setThrottlingSettings(
                    new ThrottlingSettings(ID_ADVANCED_AREA, Duration.milliseconds(500), true));
        }
    });
    advancedGroup.add(advancedArea);

    Label advancedError = new Label(ID_ADVANCED_ERROR,
            new PropertyModel<String>(getModel(), Search.F_ADVANCED_ERROR));
    advancedError.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            Search search = getModelObject();

            if (!search.isShowAdvanced()) {
                return false;
            }

            return StringUtils.isNotEmpty(search.getAdvancedError());
        }
    });
    advancedGroup.add(advancedError);
}

From source file:net.rrm.ehour.ui.common.component.ValidatingFormComponentAjaxBehavior.java

License:Open Source License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    attributes.setThrottlingSettings(new ThrottlingSettings("1", Duration.ONE_SECOND, true));
}

From source file:org.lbogdanov.poker.web.page.MySessionsPage.java

License:Apache License

/**
 * Creates a new instance of <code>MySessionsPage</code> page.
 *///from w  w  w  .  java2s  .co m
@SuppressWarnings("unchecked")
public MySessionsPage() {
    final SessionsProvider dataProvider = new SessionsProvider();
    dataProvider.setSort("created", SortOrder.DESCENDING); // default sort: created, desc
    List<AbstractColumn<Session, String>> columns = Arrays.asList(new Column("session.name", "name", "name") {

        @Override
        public void populateItem(Item<ICellPopulator<Session>> item, String compId, IModel<Session> model) {
            Session session = model.getObject();
            PageParameters params = new PageParameters().add("code", session.getCode());
            Link<?> go = new BookmarkablePageLink<Void>("goto", SessionPage.class, params);
            go.add(new BodylessLabel("name", session.getName()));
            item.add(new Fragment(compId, "nameLink", MySessionsPage.this).add(go));
        }

    }, new Column("session.description", null, "description"),
            new Column("session.created", "created", "created") {

                @Override
                @SuppressWarnings("rawtypes")
                public IModel<Object> getDataModel(IModel<Session> rowModel) {
                    Date created = (Date) super.getDataModel(rowModel).getObject();
                    String formatted = DateFormat
                            .getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale())
                            .format(created);
                    return new Model(formatted);
                }

            }, new Column("session.author", "author", "author"),
            new AbstractColumn<Session, String>(new ResourceModel("session.actions")) {

                @Override
                public void populateItem(Item<ICellPopulator<Session>> item, String compId,
                        IModel<Session> model) {
                    Link<?> delete = new AjaxFallbackLink<Session>("delete", model) {

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            sessionService.delete(getModelObject());
                            dataProvider.invalidate();
                            if (target != null) {
                                target.add(sessionsTable);
                            }
                        }

                        @Override
                        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                            super.updateAjaxAttributes(attributes);
                            AjaxCallListener listener = new AjaxCallListener();
                            listener.onPrecondition("return Poker.confirm(attrs.c);");
                            attributes.getAjaxCallListeners().add(listener);
                        }

                    };
                    item.add(new Fragment(compId, "actions", MySessionsPage.this).add(delete));
                }

                @Override
                public String getCssClass() {
                    return "actions";
                }

            });
    sessionsTable = new DataTable<Session, String>("sessions", columns, dataProvider, ITEMS_PER_PAGE.get(0));
    sessionsTable.addTopToolbar(new AjaxFallbackHeadersToolbar<String>(sessionsTable, dataProvider) {

        @Override
        protected WebMarkupContainer newSortableHeader(String borderId, String property,
                ISortStateLocator<String> locator) {
            return new AjaxFallbackOrderByBorder<String>(borderId, property, locator, getAjaxCallListener()) {

                @Override
                protected void onAjaxClick(AjaxRequestTarget target) {
                    target.add(getTable());
                }

                @Override
                protected void onSortChanged() {
                    dataProvider.invalidate();
                    getTable().setCurrentPage(0);
                }

            };
        }

    });
    sessionsTable.addBottomToolbar(new AjaxNavigationToolbar(sessionsTable) {

        @Override
        protected PagingNavigator newPagingNavigator(String navigatorId, final DataTable<?, ?> table) {
            return new BootstrapPagingNavigator(navigatorId, table) {

                @Override
                protected void onAjaxEvent(AjaxRequestTarget target) {
                    target.add(table);
                }

            };
        }

    });
    sessionsTable.addBottomToolbar(new NoRecordsToolbar(sessionsTable));

    TextField<?> sessionName = new TextField<String>("sessionName",
            PropertyModel.<String>of(dataProvider, "sessionName"));
    sessionName.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dataProvider.invalidate();
            target.add(sessionsTable);
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            ThrottlingSettings throttling = new ThrottlingSettings("sessionName", Duration.milliseconds(300),
                    true);
            attributes.setThrottlingSettings(throttling);
        }

    });
    DropDownChoice<?> pageSize = new DropDownChoice<Long>("pageSize",
            PropertyModel.<Long>of(sessionsTable, "itemsPerPage"), ITEMS_PER_PAGE);
    pageSize.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dataProvider.invalidate();
            target.add(sessionsTable);
        }

    });
    add(sessionsTable.setOutputMarkupId(true), sessionName, pageSize);
}

From source file:org.ujorm.wicket.component.form.fields.Field.java

License:Apache License

/** Create new AjaxFormComponentUpdatingBehavior with delay 300 ms. */
protected AjaxEventBehavior createChangeBehaviour(final String action, final String jsEvent) {
    return new AjaxFormComponentUpdatingBehavior(jsEvent) {
        @Override//from  w w  w.j ava 2  s .  c o m
        protected void onUpdate(AjaxRequestTarget target) {
            send(Field.this, Broadcast.BUBBLE, new FieldEvent(action, key, target));
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setThrottlingSettings(new ThrottlingSettings("thr2Id", DEFAULT_DELAY, true));
        }
    };
}

From source file:org.ujorm.wicket.component.toolbar.AbstractToolbar.java

License:Apache License

/** Create an Updating Behavior with "keyup" event
 * @param field Field is not used by default, however it can be a switch for different results for example.
 * @return/*  www .  ja  v a 2 s .com*/
 */
protected AjaxEventBehavior createChangeBehavior(final FormComponent field) {
    return new AjaxFormComponentUpdatingBehavior("keyup") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            buildCriterion();
            send(getPage(), Broadcast.BREADTH, new UjoEvent(getDefaultActionName(), target));
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setThrottlingSettings(new ThrottlingSettings("thrId", DEFAULT_DELAY, true));
        }
    };
}