Example usage for org.apache.wicket.ajax.markup.html AjaxLink add

List of usage examples for org.apache.wicket.ajax.markup.html AjaxLink add

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.markup.html AjaxLink add.

Prototype

public MarkupContainer add(final Component... children) 

Source Link

Document

Adds the child component(s) to this container.

Usage

From source file:org.obiba.onyx.webapp.action.panel.ActionsPanel.java

License:Open Source License

public ActionsPanel(String id, IModel<Stage> stageModel, final ActionWindow modal) {
    super(id, stageModel);
    setOutputMarkupId(true);/* ww  w  . j a v  a  2s  .  c o m*/

    RepeatingView repeating = new RepeatingView("link");
    add(repeating);
    SeparatorMarkupComponentBorder border = new SeparatorMarkupComponentBorder();
    for (ActionDefinition actionDef : getStageExecution().getActionDefinitions()) {

        AjaxLink<String> link = new AjaxLink<String>(repeating.newChildId(),
                new Model<String>(actionDef.getCode())) {

            private static final long serialVersionUID = 1L;

            @SuppressWarnings("unchecked")
            @Override
            public void onClick(AjaxRequestTarget target) {
                // Before allowing the action, make sure our actionDefinition is sill available
                // in the IStageExecution. This protects concurrent interview administration.
                // See ONYX-154
                IStageExecution stageExec = getStageExecution();
                String code = getModelObject();
                ActionDefinition actionDefinition = null;
                for (ActionDefinition definition : stageExec.getActionDefinitions()) {
                    if (code.equals(definition.getCode())) {
                        actionDefinition = definition;
                        break;
                    }
                }
                if (actionDefinition != null) {
                    modal.show(target, (IModel<Stage>) ActionsPanel.this.getDefaultModel(), actionDefinition);
                } else {
                    log.warn(
                            "Concurrent interview administration. Session {} tried to execute ActionDefinition {} on stage {}, yet that ActionDefinition is not available for the current stage's state.",
                            new Object[] { Session.get().getId(), getModelObject(), getStage() });
                    setResponsePage(InterviewPage.class);
                }
            }

        };
        link.add(new Label("action", new MessageSourceResolvableStringModel(actionDef.getLabel()))
                .setRenderBodyOnly(true));
        link.setComponentBorder(border);
        repeating.add(link);
    }
}

From source file:org.obiba.onyx.webapp.administration.page.AdministrationPage.java

License:Open Source License

public AdministrationPage() {

    AjaxLink<?> userTab = new AdminTab("userTab") {

        @Override//from  w  w w  . j  a  va 2 s  .  c o m
        public Component getTabComponent() {
            return new UserSearchPanel(getContentId());
        }

    };
    add(userTab.setOutputMarkupId(true));
    links.add(userTab);

    AjaxLink<?> dataTab = new AdminTab("dataTab") {

        @Override
        public Component getTabComponent() {
            return new DataManagementPanel(getContentId());
        }

    };
    add(dataTab.setOutputMarkupId(true));
    links.add(dataTab);

    AjaxLink<?> editorTab = new EditorTab("editorTab") {

        @Override
        public Component getTabComponent() {
            for (Module module : moduleRegistry.getModules()) {
                Component editorComponent = module.getEditorPanel(getContentId());
                if (editorComponent != null)
                    return editorComponent;
            }
            return null;
        }

    };
    add(editorTab.setOutputMarkupId(true));
    links.add(editorTab);

    AjaxLink<?> devTab = new AdminTab("devTab") {

        @Override
        public Component getTabComponent() {
            return new DevelopersPanel(getContentId());
        }

        @Override
        public boolean isVisible() {
            return ((OnyxApplication) WebApplication.get()).isDevelopmentMode();
        }
    };
    add(devTab.setOutputMarkupId(true));
    links.add(devTab);

    // Display first permitted tab
    for (AjaxLink<?> link : links) {
        if (link.isActionAuthorized(new Action(Action.RENDER))) {
            Component tabComponent = ((Link) link).getTabComponent();
            add(tabComponent.setOutputMarkupId(true));
            link.add(new AttributeModifier("class", true,
                    new Model<String>("obiba-button ui-corner-all selected")));
            break;
        }
    }

}

From source file:org.obiba.onyx.webapp.administration.page.AdministrationPage.java

License:Open Source License

private void activateLink(AjaxLink<?> selectedLink, AjaxRequestTarget target) {
    for (AjaxLink<?> link : links) {
        link.add(new AttributeModifier("class", true,
                new Model<String>("obiba-button ui-corner-all" + (link == selectedLink ? " selected" : ""))));
        target.addComponent(link);//ww w  . ja va 2  s .com
    }
}

From source file:org.obiba.onyx.webapp.stage.panel.StageMenuBar.java

License:Open Source License

public StageMenuBar(String id, IModel<Stage> stageModel) {
    super(id);// w  ww.ja va 2  s . c  om

    participantDetailsModalWindow = new Dialog("participantDetailsModalWindow");
    participantDetailsModalWindow.setTitle(new StringResourceModel("Participant", this, null));
    participantDetailsModalWindow.setHeightUnit("em");
    participantDetailsModalWindow.setWidthUnit("em");
    participantDetailsModalWindow.setInitialHeight(45);
    participantDetailsModalWindow.setInitialWidth(34);
    participantDetailsModalWindow.setType(Dialog.Type.PLAIN);
    participantDetailsModalWindow.setOptions(Dialog.Option.CLOSE_OPTION);
    add(participantDetailsModalWindow);

    Participant participant = activeInterviewService.getParticipant();

    add(new Label("stageLabel",
            new MessageSourceResolvableStringModel(new PropertyModel(stageModel, "description"))));

    // add(new Label("participantLabel", participant.getBarcode()));

    AjaxLink link = new AjaxLink("link") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            ParticipantPanel component = new ParticipantPanel("content",
                    new Model(activeInterviewService.getParticipant()));
            component.add(
                    new AttributeModifier("class", true, new Model("obiba-content participant-panel-content")));
            participantDetailsModalWindow.setContent(component);
            participantDetailsModalWindow.show(target);
        }
    };
    link.add(new Label("label", participant.getBarcode()));
    add(link);
}

From source file:org.obiba.onyx.webapp.stage.panel.ViewCommentsActionPanel.java

License:Open Source License

public ViewCommentsActionPanel(String id) {
    super(id);/*from w  w w.j a  v a2s  . c o m*/

    AjaxLink viewLogs = new AjaxLink("viewLogs") {

        private static final long serialVersionUID = 1L;

        public void onClick(AjaxRequestTarget target) {
            ViewCommentsActionPanel.this.onViewLogs(target);
        }
    };
    viewLogs.add(new ContextImage("viewLogsImg", new Model("icons/loupe_button.png")));
    add(viewLogs);
    viewLogs.setVisible(logEntryExists());

    AjaxLink viewComments = new AjaxLink("viewComments") {

        private static final long serialVersionUID = 1L;

        public void onClick(AjaxRequestTarget target) {
            ViewCommentsActionPanel.this.onViewComments(target);
        }
    };
    viewComments.add(new ContextImage("viewCommentsImg", new Model("icons/note.png")));
    add(viewComments);
    viewComments.setVisible(commentEntryExists());

}

From source file:org.obiba.onyx.wicket.reusable.Dialog.java

License:Open Source License

public Dialog(String id) {
    super(id);/* w w w  .j  a v a 2s .  c  o  m*/

    setCssClassName("onyx");
    setResizable(false);

    form = new Form<Object>("form");
    form.setOutputMarkupId(true);
    form.add(new WebMarkupContainer(getContentId()));

    AjaxButton okButton = new AjaxButton("ok", form) {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form1) {
            Dialog.this.setStatus(Status.SUCCESS);
            if (closeButtonCallback == null
                    || closeButtonCallback.onCloseButtonClicked(target, Dialog.this.getStatus())) {
                // ModalWindow.closeCurrent(target);
                close(target);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form1) {
            Dialog.this.setStatus(Status.ERROR);
            if (closeButtonCallback == null
                    || closeButtonCallback.onCloseButtonClicked(target, Dialog.this.getStatus())) {
                // ModalWindow.closeCurrent(target);
                close(target);
            }
        }

    };
    okButton.add(new AttributeModifier("value", true, new StringResourceModel("Dialog.Ok", this, null)));
    form.add(okButton);

    @SuppressWarnings("rawtypes")
    AjaxLink<?> cancelButton = new AjaxLink("cancel") {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            Dialog.this.setStatus(Status.CANCELLED);
            if (closeButtonCallback == null
                    || closeButtonCallback.onCloseButtonClicked(target, Dialog.this.getStatus())) {
                // ModalWindow.closeCurrent(target);
                close(target);
            }
        }

    };
    cancelButton
            .add(new AttributeModifier("value", true, new StringResourceModel("Dialog.Cancel", this, null)));
    form.add(cancelButton);

    @SuppressWarnings("rawtypes")
    AjaxLink<?> yesButton = new AjaxLink("yes") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            Dialog.this.setStatus(Status.YES);
            if (closeButtonCallback == null
                    || closeButtonCallback.onCloseButtonClicked(target, Dialog.this.getStatus())) {
                // ModalWindow.closeCurrent(target);
                close(target);
            }
        }

    };
    yesButton.add(new AttributeModifier("value", true, new StringResourceModel("Dialog.Yes", this, null)));
    form.add(yesButton);

    @SuppressWarnings("rawtypes")
    AjaxLink<?> noButton = new AjaxLink("no") {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            Dialog.this.setStatus(Status.NO);
            if (closeButtonCallback == null
                    || closeButtonCallback.onCloseButtonClicked(target, Dialog.this.getStatus())) {
                // ModalWindow.closeCurrent(target);
                close(target);
            }
        }

    };
    noButton.add(new AttributeModifier("value", true, new StringResourceModel("Dialog.No", this, null)));
    form.add(noButton);

    @SuppressWarnings("rawtypes")
    AjaxLink<?> closeButton = new AjaxLink("close") {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            // Don't overwrite SUCCESS or ERROR status when closing the dialog.
            if (!Status.SUCCESS.equals(Dialog.this.getStatus())
                    && !Status.ERROR.equals(Dialog.this.getStatus())) {
                Dialog.this.setStatus(Status.CLOSED);
            }
            if (closeButtonCallback == null
                    || closeButtonCallback.onCloseButtonClicked(target, Dialog.this.getStatus())) {
                // ModalWindow.closeCurrent(target);
                close(target);
            }
        }

    };
    closeButton.add(new AttributeModifier("value", true, new StringResourceModel("Dialog.Close", this, null)));
    closeButton.add(new FocusBehavior());
    form.add(closeButton);

    this.setWindowClosedCallback(new WindowClosedCallback() {
        private static final long serialVersionUID = 1L;

        public void onClose(AjaxRequestTarget target, @SuppressWarnings("hiding") Status status) {
        }
    });

    WebMarkupContainer modalContent = new WebMarkupContainer(getContentId());
    modalContent.setOutputMarkupId(true);
    modalContent.add(form);
    super.setContent(modalContent);
}

From source file:org.obiba.onyx.wicket.reusable.Dialog.java

License:Open Source License

public void addOption(String label, OptionSide side, AjaxLink<?> link, String... name) {
    link.add(new AttributeModifier("value", true, new SpringStringResourceModel("Dialog." + label)));
    if (name.length > 0)
        link.add(new AttributeModifier("name", true, new Model<String>(name[0])));

    if (side.equals(OptionSide.LEFT)) {
        link.add(new AttributeAppender("class", new Model<String>("left"), " "));
        customOptionsLeft.add(link);//www  . j a  va  2  s  .  c  o m
    } else {
        link.add(new AttributeAppender("class", new Model<String>("right"), " "));
        customOptionsRight.add(link);
    }
}

From source file:org.obiba.onyx.wicket.toggle.ToggleLink.java

License:Open Source License

/**
 * Constructor./*from   w w  w . j av a2  s.  co  m*/
 * @param id
 * @param showModel
 * @param hideModel
 * @param toggle
 */
@SuppressWarnings("serial")
public ToggleLink(String id, final IModel showModel, final IModel hideModel, final Component toggle) {
    super(id);
    setOutputMarkupId(true);
    toggle.getParent().setOutputMarkupId(true);

    AjaxLink link = new AjaxLink("link") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            toggle.setVisible(!toggle.isVisible());
            if (toggle.isVisible()) {
                toggleLabel.setDefaultModel(hideModel);
            } else {
                toggleLabel.setDefaultModel(showModel);
            }
            target.addComponent(toggle.getParent());
        }

    };
    add(link);

    link.add(toggleLabel = new Label("label", showModel));
    toggle.setVisible(false);
}

From source file:org.obiba.onyx.wicket.wizard.WizardForm.java

License:Open Source License

public WizardForm(String id, IModel model) {
    super(id, model);

    setOutputMarkupId(true);/*from ww w . j  a  v a2s . c  om*/

    IBehavior buttonStyleBehavior = new AttributeAppender("class", new Model("ui-corner-all"), " ");

    // finish button
    AjaxButton finish = createFinish();
    finish.add(buttonStyleBehavior);
    finish.setVisible(false);
    finish.setOutputMarkupId(true);
    finish.setOutputMarkupPlaceholderTag(true);
    add(finish);

    // previous button
    AjaxLink link = createPrevious();
    link.setVisible(false);
    link.setOutputMarkupId(true);
    link.setOutputMarkupPlaceholderTag(true);
    link.add(buttonStyleBehavior);
    add(link);

    // next button
    AjaxButton button = createNext();
    button.setOutputMarkupId(true);
    button.setOutputMarkupPlaceholderTag(true);
    button.add(buttonStyleBehavior);
    add(button);

    // cancel button
    AjaxLink cancelLink = createCancel();
    cancelLink.add(buttonStyleBehavior);
    add(cancelLink);

    add(new LanguageStyleBehavior());
}

From source file:org.obiba.onyx.wicket.wizard.WizardForm.java

License:Open Source License

private AjaxLink createPrevious() {
    AjaxLink link = new AjaxLink("previousLink") {
        private static final long serialVersionUID = 0L;

        @Override// w  w w.j  a v a  2s  . co  m
        public void onClick(AjaxRequestTarget target) {
            onPreviousClick(target);
        }

    };
    link.add(new AttributeModifier("value", true, getLabelModel("Previous")));

    return link;
}