Example usage for org.apache.wicket.ajax AjaxEventBehavior AjaxEventBehavior

List of usage examples for org.apache.wicket.ajax AjaxEventBehavior AjaxEventBehavior

Introduction

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

Prototype

public AjaxEventBehavior(String event) 

Source Link

Document

Construct.

Usage

From source file:eu.uqasar.web.components.navigation.notification.thresholdReached.ThresholdReachedNotificationLink.java

License:Apache License

public ThresholdReachedNotificationLink(String id, PageParameters parameters,
        final IModel<ThresholdReachedNotification> model) {

    super(id, ProjectViewPage.class, BaseTreePage.forProject(model.getObject().getProject()), model);

    add(new Label("projectName", model.getObject().getProject().getAbbreviatedName()));

    add(new ListView<TreeNode>("treeNodeNames", model.getObject().getTreeNodes()) {
        @Override/*from   ww  w .ja va2  s  . c  om*/
        protected void populateItem(ListItem<TreeNode> item) {
            TreeNode node = item.getModelObject();
            item.add(new BookmarkablePageLink<QualityObjectiveViewPage>("QOlink",
                    QualityObjectiveViewPage.class, new PageParameters().set("id", node.getId()))
                            .add(new Label("name", node.getName())));
        }
    });

    //set containers 
    setIcon(new IconType("exclamation-sign"));
    get("notification.container").add(new AttributeModifier("style", "width:95%;"));
    get("notification.container").add(new AttributeModifier("class", "notification project red"));

    //trash
    final WebMarkupContainer deleteContainer = new WebMarkupContainer("delete");
    final String deleteMessage = new StringResourceModel("delete.message", this, null).getString();
    deleteContainer.add(new AjaxEventBehavior("onclick") {
        private static final long serialVersionUID = -4295786924073241665L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            UQasarUtil.getNotifications().remove(model.getObject());
            setResponsePage(AboutPage.class, BasePage.appendSuccessMessage(getPageParameters(), deleteMessage));
        }
    });
    deleteContainer.setOutputMarkupId(true);
    add(deleteContainer);

    // tooltip
    TooltipConfig confConfig = new TooltipConfig().withPlacement(TooltipConfig.Placement.right);
    deleteContainer.add(new TooltipBehavior(new StringResourceModel("delete.title", this, null), confConfig));
}

From source file:eu.uqasar.web.pages.qmtree.metric.panels.MetricEditPanel.java

License:Apache License

private <T extends MetaData> Select2MultiChoice<T> newSelect2(final String id, Class<T> clazz,
        PropertyModel<Collection<T>> model, final Form<?> form) {

    metaDataProvider = new MetaDataChoiceProvider<>(metaDataService.getAll(clazz), clazz);

    Select2MultiChoice<T> select2MultiChoice = new Select2MultiChoice<>(id, model, metaDataProvider);

    select2MultiChoice.add(new AjaxEventBehavior("onchange") { //oninput doesntwork
        @Override// w  w w  .ja va 2s .c o  m
        protected void onEvent(AjaxRequestTarget target) {
            String input = getWebRequest().getRequestParameters().getParameterValue("qModelTagData").toString();
            try {
                if (input != null && !input.equals("")) {
                    metaDataProvider.toChoices((Arrays.asList(input.split(","))));
                }
            } catch (EntityNotFoundException ex) {
                //SelectionModal
                tagsModal.setInputSelection(input);
                tagsModal.setTagName(ex.getMessage());
                tagsModal.setVisible(true);
                tagsModal.add(new CssClassNameAppender(""));
                tagsModal.setFadeIn(false);
                tagsModal.show(true);
                target.add(tagsModal);
            }
        }
    });

    final IModel<String> placeHolder = new StringResourceModelPlaceholderDelegate("placeholder.meta.input",
            this, null, MetaData.getLabelModel(clazz));
    select2MultiChoice.getSettings().setCloseOnSelect(false);
    select2MultiChoice.getSettings().setPlaceholder(placeHolder);
    select2MultiChoice.getSettings().setTokenSeparators(new String[] { "," });
    select2MultiChoice.getSettings().setCreateSearchChoice(
            "function(term) { if (term.length > 1) { return { id: term, text: term }; } }");
    form.add(new Label("label." + id,
            new StringResourceModel("label.meta.known", this, null, MetaData.getLabelModel(clazz))));
    form.add(new Label("help." + id,
            new StringResourceModel("help.meta.input", this, null, MetaData.getLabelModel(clazz))));
    return select2MultiChoice;
}

From source file:guru.mmp.application.web.template.components.ExtensibleFormDialogImplementation.java

License:Apache License

/**
 * Returns the buttons associated with the extensible dialog.
 *
 * @return the buttons associated with the extensible dialog
 *//*from   ww w .j a  v  a  2 s  .  c o  m*/
@Override
protected List<ExtensibleDialogButton> getButtons() {
    ExtensibleDialogButton cancelButton = new ExtensibleDialogButton(cancelText);

    cancelButton.add(new AjaxEventBehavior("click") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            System.out.println("[DEBUG][cancelButton][onSubmit] HERE!!!!");

            ExtensibleFormDialogImplementation.this.onCancel(target, form);

            // resetExtensibleFormDialogImplementation(target);

            getDialog().hide(target);
        }
    });

    ExtensibleDialogButton submitButton = new ExtensibleDialogButton(submitText, true);

    submitButton.add(new AjaxFormSubmitBehavior(form, "click") {
        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            if (target != null) {
                resetFeedbackMessages(target);
            }

            if (ExtensibleFormDialogImplementation.this.onSubmit(target,
                    ExtensibleFormDialogImplementation.this.form)) {
                getDialog().hide(target);
            } else {
                target.add(ExtensibleFormDialogImplementation.this.alerts);
            }
        }

        @Override
        protected void onAfterSubmit(AjaxRequestTarget target) {
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            if (target != null) {
                // Visit each form component and if it is visible re-render it.
                // NOTE: We have to re-render every component to remove stale validation error messages.
                form.visitFormComponents((formComponent, iVisit) -> {
                    if ((formComponent.getParent() != null) && formComponent.getParent().isVisible()
                            && formComponent.isVisible()) {
                        target.add(formComponent);
                    }
                });
            }

            ExtensibleFormDialogImplementation.this.onError(target, form);
        }

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

            // Do not allow normal form submit to happen
            attributes.setPreventDefault(true);
        }

        @Override
        public boolean getDefaultProcessing() {
            return submitButton.getDefaultFormProcessing();
        }

        @Override
        public boolean getStatelessHint(Component component) {
            return false;
        }
    });
    submitButton.setDefaultFormProcessing(true);

    List<ExtensibleDialogButton> buttons = new ArrayList<>();
    buttons.add(submitButton);
    buttons.add(cancelButton);

    return buttons;
}

From source file:name.martingeisse.webeco.SimulatorPage.java

License:Open Source License

/**
 * Constructor.//from   w  w  w  .j  a v  a 2s  . co  m
 */
public SimulatorPage() {

    final GuiMessageHub guiMessageHub = Simulator.getGuiMessageHub();

    final CharacterDisplayPanel characterDisplayPanel = new CharacterDisplayPanel("characterDisplayPanel",
            guiMessageHub.getCharacterDisplayQueue());
    add(characterDisplayPanel);

    final QueueTextFeeder feeder = new QueueTextFeeder("text", guiMessageHub.getTerminalOutputQueue());
    add(feeder);

    add(new AbstractAjaxTimerBehavior(Duration.seconds(1)) {
        @Override
        protected void onTimer(final AjaxRequestTarget target) {
            characterDisplayPanel.feed(target);
            feeder.feed(target);
        }
    });

    final Form<Void> inputForm = new Form<Void>("inputForm");
    add(inputForm);

    final TextField<String> inputLineTextField = new TextField<String>("text",
            new PropertyModel<String>(this, "inputLine"));
    inputLineTextField.setOutputMarkupId(true);
    inputForm.add(inputLineTextField);

    inputForm.add(new AjaxButton("submit", inputForm) {
        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            inputLine = (inputLine == null) ? "" : inputLine;
            guiMessageHub.getTerminalInputQueue().add(inputLine + "\r\n");
            notifyTerminalInputAvailable();
            inputLine = null;
            target.add(inputLineTextField);
        }

        @Override
        protected void onError(AjaxRequestTarget arg0, Form<?> arg1) {
        }
    });

    final WebMarkupContainer backspaceButton = new WebMarkupContainer("backspaceButton");
    add(backspaceButton);
    backspaceButton.add(new AjaxEventBehavior("onclick") {
        @Override
        protected void onEvent(final AjaxRequestTarget target) {
            guiMessageHub.getTerminalInputQueue().add("\b");
            notifyTerminalInputAvailable();
        }
    });

    add(new AjaxLink<Void>("resetLink") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            guiMessageHub.getActions().add(new ISimulatorAction() {
                @Override
                public void execute(SimulationModel model) {
                    model.getCpu().reset();
                }
            });
        }
    });

}

From source file:net.dontdrinkandroot.extensions.wicket.component.jqueryui.JQueryUiAjaxRadioChoice.java

License:Apache License

public JQueryUiAjaxRadioChoice(String id, IModel<T> model, IModel<? extends List<T>> choices,
        IChoiceRenderer<? super T> renderer) {
    super(id, model);

    this.setOutputMarkupId(true);

    this.choices = choices;
    this.setChoiceRenderer(renderer);

    final RadioGroup<T> radioGroup = new RadioGroup<T>("radioGroup", model);
    this.add(radioGroup);

    final ListView<T> radioItemView = new ListView<T>("radioItem", choices) {

        private static final long serialVersionUID = 1L;

        @Override//from ww  w . j a v a  2  s.  co m
        protected void populateItem(final ListItem<T> item) {

            final Radio<T> radio = new Radio<T>("input", item.getModel(), radioGroup);
            radio.setOutputMarkupId(true);
            radio.add(new AjaxEventBehavior("onclick") {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    JQueryUiAjaxRadioChoice.this.onSelectionChanged(item.getModelObject(), target);
                }
            });
            item.add(radio);

            final Label label = new Label("label", JQueryUiAjaxRadioChoice.this.getChoiceRenderer()
                    .getDisplayValue(item.getModel().getObject()).toString());
            label.add(new AttributeAppender("for", new Model<String>(radio.getMarkupId())));
            item.add(label);

            item.setRenderBodyOnly(true);
        }
    };
    radioGroup.add(radioItemView);
}

From source file:net.dontdrinkandroot.wicket.bootstrap.component.button.AjaxButtonLink.java

License:Apache License

/**
 * @param event//from   w w w. ja  v  a2s  .  co  m
 *            the name of the default event on which this link will listen to
 * @return the ajax behavior which will be executed when the user clicks the link
 */
protected AjaxEventBehavior newAjaxEventBehavior(String event) {

    return new AjaxEventBehavior(event) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {

            AjaxButtonLink.this.onClick(target);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {

            // add the onclick handler only if link is enabled
            if (AjaxButtonLink.this.isLinkEnabled()) {
                super.onComponentTag(tag);
            }
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {

            super.updateAjaxAttributes(attributes);
            AjaxButtonLink.this.updateAjaxAttributes(attributes);
        }
    };
}

From source file:net.dontdrinkandroot.wicket.component.jqueryui.JQueryUiAjaxRadioChoice.java

License:Apache License

public JQueryUiAjaxRadioChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices,
        IChoiceRenderer<? super T> renderer) {

    super(id, model);

    this.setOutputMarkupId(true);

    this.choices = choices;
    this.setChoiceRenderer(renderer);

    final RadioGroup<T> radioGroup = new RadioGroup<T>("radioGroup", model);
    this.add(radioGroup);

    ListView<T> radioItemView = new ListView<T>("radioItem", choices) {

        private static final long serialVersionUID = 1L;

        @Override//from   w ww.j av a  2  s . com
        protected void populateItem(final ListItem<T> item) {

            Radio<T> radio = new Radio<T>("input", item.getModel(), radioGroup);
            radio.setOutputMarkupId(true);
            radio.add(new AjaxEventBehavior("onclick") {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {

                    JQueryUiAjaxRadioChoice.this.onSelectionChanged(item.getModelObject(), target);
                }
            });
            item.add(radio);

            Label label = new Label("label", JQueryUiAjaxRadioChoice.this.getChoiceRenderer()
                    .getDisplayValue(item.getModel().getObject()).toString());
            label.add(new AttributeAppender("for", new Model<String>(radio.getMarkupId())));
            item.add(label);

            item.setRenderBodyOnly(true);
        }

    };
    radioGroup.add(radioItemView);
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelAbstract.java

License:Apache License

protected void addFeedbackTo(MarkupContainer markupContainer, Component component) {
    markupContainer.addOrReplace(//w  w  w.  j  ava  2 s  .c  o  m
            new NotificationPanel(ID_FEEDBACK, component, new ComponentFeedbackMessageFilter(component)));

    final String disableReasonIfAny = scalarModel.disable(getRendering().getWhere());
    if (disableReasonIfAny == null && scalarModel.isViewMode()) {
        final WebMarkupContainer editProperty = new WebMarkupContainer(ID_EDIT_PROPERTY);

        editProperty.setOutputMarkupId(true);

        editProperty.add(new AjaxEventBehavior("click") {
            protected void onEvent(AjaxRequestTarget target) {

                final ActionPrompt prompt = ActionPromptProvider.Util.getFrom(ScalarPanelAbstract.this)
                        .getActionPrompt();

                PropertyEditPromptHeaderPanel titlePanel = new PropertyEditPromptHeaderPanel(
                        prompt.getTitleId(), scalarModel);

                final PropertyEditPanel propertyEditPanel = (PropertyEditPanel) getComponentFactoryRegistry()
                        .createComponent(ComponentType.PROPERTY_EDIT_PROMPT, prompt.getContentId(),
                                scalarModel);

                propertyEditPanel.setShowHeader(false);

                prompt.setTitle(titlePanel, target);
                prompt.setPanel(propertyEditPanel, target);
                prompt.showPrompt(target);

            }
        });

        markupContainer.addOrReplace(editProperty);
    } else {
        Components.permanentlyHide(markupContainer, ID_EDIT_PROPERTY);
    }

}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelAbstract2.java

License:Apache License

private void configureInlinePromptLinkCallback(final WebMarkupContainer inlinePromptLink) {

    inlinePromptLink.add(new AjaxEventBehavior("click") {
        @Override//from  ww w  .  j av a2 s.c  o m
        protected void onEvent(final AjaxRequestTarget target) {

            scalarModel.toEditMode();

            switchFormForInlinePrompt(target);

            getComponentForRegular().setVisible(false);
            scalarIfRegularInlinePromptForm.setVisible(true);

            target.add(scalarTypeContainer);
        }

        @Override
        public boolean isEnabled(final Component component) {
            return true;
        }
    });
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.ScalarPanelAbstract2.java

License:Apache License

private void configureInlinePromptLinkCallback(final WebMarkupContainer inlinePromptLink,
        final ActionLink actionLink) {

    inlinePromptLink.add(new AjaxEventBehavior("click") {
        @Override// w  ww.  j a  v a  2 s.  c om
        protected void onEvent(final AjaxRequestTarget target) {
            actionLink.onClick(target);
        }

        @Override
        public boolean isEnabled(final Component component) {
            return true;
        }
    });
}