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:com.evolveum.midpoint.web.page.admin.resources.CapabilitiesPanel.java

License:Apache License

private void createCapabilityButton(String id) {
    AjaxLink<Boolean> button = new AjaxLink<Boolean>(id, new PropertyModel<Boolean>(getModel(), id)) {

        @Override//from w w w  . j  a v  a  2s . c o  m
        public void onClick(AjaxRequestTarget target) {
            // TODO:
        }

    };

    button.add(new AttributeModifier("class",
            button.getModelObject() ? "btn btn-app btn-resource-capability bg-light-blue"
                    : "btn btn-app btn-resource-capability bg-gray text-light-blue"));

    button.add(new Label("label", new ResourceModel("CapabilitiesType." + id)));

    add(button);
}

From source file:com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoicePanel.java

License:Apache License

private void initLayout(final IModel<PrismContainerValue<ShadowAssociationType>> value,
        final List<PrismPropertyValue> values, final boolean required, Class<C> type) {

    WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);

    textWrapper.setOutputMarkupId(true);

    TextField<String> text = new TextField<>(ID_TEXT, createTextModel(value));
    text.add(new AjaxFormComponentUpdatingBehavior("blur") {
        private static final long serialVersionUID = 1L;

        @Override/* www .j ava 2  s.c  o  m*/
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
        }
    });
    text.setRequired(required);
    text.setEnabled(false);
    textWrapper.add(text);

    FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text));
    feedback.setFilter(new ComponentFeedbackMessageFilter(text));
    textWrapper.add(feedback);

    AjaxLink edit = new AjaxLink(ID_EDIT) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            editValuePerformed(target);
        }
    };
    edit.add(new VisibleEnableBehaviour() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return model.getObject().isEmpty();
        }
    });
    textWrapper.add(edit);
    add(textWrapper);

    initDialog(type, values);

}

From source file:com.evolveum.midpoint.web.page.admin.users.component.AssociationValueChoosePanel.java

License:Apache License

private void initLayout(final IModel<PrismContainerValue<ShadowAssociationType>> value,
        final List<PrismPropertyValue> values, final boolean required, Class<C> type) {

    WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);

    textWrapper.setOutputMarkupId(true);

    TextField text = new TextField<>(ID_TEXT, createTextModel(value));
    text.add(new AjaxFormComponentUpdatingBehavior("onblur") {
        @Override/* www. j  a  v a 2s.  c o  m*/
        protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
        }
    });
    text.setRequired(required);
    text.setEnabled(false);
    textWrapper.add(text);

    FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text));
    textWrapper.add(feedback);

    AjaxLink edit = new AjaxLink(ID_EDIT) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            editValuePerformed(target);
        }
    };
    edit.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return model.getObject().isEmpty();
        }
    });
    textWrapper.add(edit);
    add(textWrapper);

    initDialog(type, values);

}

From source file:com.francetelecom.clara.cloud.presentation.applications.ApplicationActionPanel.java

License:Apache License

private void initComponent() {
    AjaxLink<Application> deleteBtn = new AjaxLink<Application>("app-delete", getModel()) {
        private static final long serialVersionUID = -3624723770141461652L;

        @Override//  ww w .ja  v a2s  .co m
        public void onClick(AjaxRequestTarget target) {
            parentPage.deleteApplication(target, getModelObject());
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            attributes.getAjaxCallListeners()
                    .add(new DeleteConfirmationDecorator(WicketUtils
                            .getStringResourceModel(this, "portal.application.action.delete.confirm",
                                    new Model<String[]>(new String[] { getModelObject().getLabel() }))
                            .getObject()));

        }

        @Override
        public boolean isVisible() {
            return canBeDeleted;
        }
    };

    WebMarkupContainer deleteDisabledSpan = new WebMarkupContainer("app-delete-disable");
    if (canBeDeleted) {
        deleteDisabledSpan.setVisible(false);
    }
    add(deleteDisabledSpan);

    deleteSpan = new WebMarkupContainer("deleteImg");
    deleteBtn.add(deleteSpan);
    add(deleteBtn);

    Link<Application> editBtn = new Link<Application>("app-edit", getModel()) {

        private static final long serialVersionUID = -5024306917768033030L;

        @Override
        public void onClick() {
            PageParameters params = new PageParameters();
            params.set("appUid", getModelObject().getUID());
            params.set("edit", "1");

            SelectedAppPage appPage = new SelectedAppPage(params);
            setResponsePage(appPage);
        }

        @Override
        public boolean isVisible() {
            return getModelObject().isEditable();
        }
    };
    editBtn.add(new AttributeAppender("title", new ResourceModel("portal.application.action.modify")));

    WebMarkupContainer editDisabledSpan = new WebMarkupContainer("app-edit-disable");
    if (getModelObject().isEditable()) {
        editDisabledSpan.setVisible(false);
    }
    add(editDisabledSpan);

    editSpan = new WebMarkupContainer("editImg");
    editBtn.add(editSpan);
    add(editBtn);
}

From source file:com.francetelecom.clara.cloud.presentation.environments.EnvironmentDetailsPanel.java

License:Apache License

private void initEnvErrorMessages() {

    String envErrorMsg = getModelObject().getStatusMessage();
    AjaxLink showHideEllipsis = new AjaxLink("env-status-link") {
        @Override/*from   www  . j ava  2s . c o  m*/
        public void onClick(AjaxRequestTarget target) {
            if (!isAllStatusMessageVisible) {
                target.appendJavaScript("document.getElementById('" + envErrorMsgLabel.getMarkupId()
                        + "').removeAttribute('style',0);");
                isAllStatusMessageVisible = true;
            } else {
                envErrorMsgLabel.add(new AttributeModifier("style", new Model<String>("max-height:50px")));
                isAllStatusMessageVisible = false;
            }
            target.add(envErrorMsgLabel);
        }
    };
    add(showHideEllipsis);

    if ("".equals(envErrorMsg) || envErrorMsg == null) {
        envErrorMsgLabel = new Label("env-activation-error",
                new Model(getString("portal.environment.details.activation.nostatus.msg")));
    } else {
        envErrorMsgLabel = new Label("env-activation-error", getModelObject().getStatusMessage());
    }
    envErrorMsgLabel.setOutputMarkupId(true);
    envErrorMsgLabel.add(new AttributeModifier("title", new Model<String>(envErrorMsg)));
    envErrorMsgLabel.add(new AttributeModifier("style", new Model<String>("max-height:50px")));
    showHideEllipsis.add(envErrorMsgLabel);
    refreshContainer.add(showHideEllipsis);
}

From source file:com.norconex.commons.wicket.bootstrap.table.BootstrapAjaxPagingNavigator.java

License:Apache License

@Override
protected AbstractLink newPagingNavigationLink(final String id, IPageable pageable, int pageNumber) {
    final AjaxPagingNavigationLink link = new AjaxPagingNavigationLink(id, pageable, pageNumber) {
        private static final long serialVersionUID = -4537725137974552570L;

        protected long cullPageNumber(long pageNumber) {
            long idx = pageNumber;
            if (id.startsWith("first")) {
                return 0;
            }//from  w w w. j av  a  2  s  . c o m
            if (id.startsWith("last")) {
                return pageable.getPageCount() - 1;
            }
            if (id.startsWith("prev")) {
                idx = pageable.getCurrentPage() - 1;
            } else if (id.startsWith("next")) {
                idx = pageable.getCurrentPage() + 1;
            }
            if (idx < 0) {
                idx = 0;
            }
            if (idx > (pageable.getPageCount() - 1)) {
                idx = pageable.getPageCount() - 1;
            }
            if (idx < 0) {
                idx = 0;
            }
            return idx;
        }
    };
    AjaxLink<String> navCont = new AjaxLink<String>(id + "Cont") {
        private static final long serialVersionUID = -7566811745303329592L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            link.onClick(target);
        }
    };
    navCont.add(link);

    // add css for enable/disable link
    long pageIndex = pageable.getCurrentPage() + pageNumber;
    navCont.add(new AttributeModifier("class", new BootstrapPageLinkCssModel(pageable, pageIndex, "disabled")));
    return navCont;
}

From source file:com.norconex.commons.wicket.bootstrap.table.BootstrapAjaxPagingNavigator.java

License:Apache License

@Override
protected AbstractLink newPagingNavigationIncrementLink(final String id, IPageable pageable, int increment) {
    final AjaxPagingNavigationLink link = new AjaxPagingNavigationLink(id, pageable, increment) {
        private static final long serialVersionUID = 6737074324471003133L;

        protected long cullPageNumber(long pageNumber) {
            long idx = pageNumber;
            if (id.startsWith("first")) {
                return 0;
            }//from   w  w  w .  j a  v  a2  s .  c o m
            if (id.startsWith("last")) {
                return pageable.getPageCount() - 1;
            }
            if (id.startsWith("prev")) {
                idx = pageable.getCurrentPage() - 1;
            } else if (id.startsWith("next")) {
                idx = pageable.getCurrentPage() + 1;
            }
            if (idx < 0) {
                idx = 0;
            }
            if (idx > (pageable.getPageCount() - 1)) {
                idx = pageable.getPageCount() - 1;
            }
            if (idx < 0) {
                idx = 0;
            }
            return idx;
        }
    };
    AjaxLink<String> navCont = new AjaxLink<String>(id + "Cont") {
        private static final long serialVersionUID = -7414576817418282720L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            link.onClick(target);
        }
    };
    navCont.add(link);

    // add css for enable/disable link
    long pageIndex = pageable.getCurrentPage() + increment;
    navCont.add(new AttributeModifier("class", new BootstrapPageLinkIncrementCssModel(pageable, pageIndex)));
    return navCont;
}

From source file:com.norconex.jefmon.instances.InstancesPanel.java

License:Apache License

private DataView<InstanceSummary> createDataView() {
    ListDataProvider<InstanceSummary> dataProvider = new ListDataProvider<InstanceSummary>(
            InstancesManager.loadInstances());
    DataView<InstanceSummary> dataView = new DataView<InstanceSummary>("instances", dataProvider) {
        private static final long serialVersionUID = 4462642058300231730L;

        @Override// w ww.j  a v  a2 s .  co m
        public void populateItem(final Item<InstanceSummary> item) {
            final InstanceSummary instance = item.getModelObject();
            Label nameLabel = new Label("name", instance.getName());
            if (instance.isInvalid()) {
                nameLabel.add(new CssStyle("font-weight: bold;"));
            }
            item.add(nameLabel);
            String url = instance.getUrl();
            if (url == null) {
                url = "<" + getString("instance.this") + ">";
            }
            item.add(new Label("url", url));
            item.add(createJobStateListView(instance));

            String totalLabel;
            if (instance.isInvalid()) {
                totalLabel = StringUtils.EMPTY;
            } else {
                totalLabel = Integer.toString(instance.getTotalRoots());
            }
            item.add(new Label("status-total", totalLabel));

            AjaxLink<String> removeButton = new AjaxLink<String>("remove") {
                private static final long serialVersionUID = -7913473337936429743L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    InstancesManager.removeInstance(instance.getUrl());
                    target.add(instancesTable);
                }
            };
            removeButton.add(new BootstrapTooltip(new ResourceModel("btn.remove")));
            if (instance.isThisInstance()) {
                removeButton.setVisible(false);
            }
            item.add(removeButton);
        }

        @Override
        protected Item<InstanceSummary> newItem(String id, int index, final IModel<InstanceSummary> model) {
            Item<InstanceSummary> row = super.newItem(id, index, model);
            InstanceSummary instance = model.getObject();
            if (instance.isInvalid()) {
                row.add(new CssClass("danger"));
                row.add(new CssStyle("cursor: default;"));
                row.add(new BootstrapTooltip(getString("instance.error") + instance.getRemoteError()));
            } else {
                row.add(new CssStyle("cursor: pointer;"));
                row.add(new OnClickBehavior() {
                    private static final long serialVersionUID = 7484946666996050240L;

                    @Override
                    protected void onClick(AjaxRequestTarget target) {
                        onInstanceClick(target, model.getObject());
                    }
                });
            }
            return row;
        }
    };
    return dataView;
}

From source file:com.norconex.jefmon.settings.update.SettingsPage.java

License:Apache License

private void initializeComponents() {
    try {//from ww w . ja va2 s.  c om
        PropertyUtils.copyProperties(dirtyConfig, getJEFMonConfig());
    } catch (Exception e) {
        throw new WicketRuntimeException(e);
    }

    AjaxLink<String> nameBack = new AjaxLink<String>("nameBack") {
        private static final long serialVersionUID = -7790485617549321158L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            setResponsePage(InstancePage.class);
        }
    };
    nameBack.add(new Label("name", getJEFMonConfig().getInstanceName()));
    add(nameBack);

    Form<Void> form = new Form<Void>("form");
    form.setOutputMarkupId(true);
    add(form);

    final FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    form.add(feedback);

    form.add(createConfigPanel("configPanel", dirtyConfig));

    final AjaxButton saveButton = new AjaxButton("save") {
        private static final long serialVersionUID = 8835758195954072646L;

        @Override
        protected void onAfterSubmit(AjaxRequestTarget target, Form<?> theform) {
            try {
                ConfigurationDAO.saveConfig(dirtyConfig);
                PropertyUtils.copyProperties(getJEFMonConfig(), dirtyConfig);
            } catch (IOException | IllegalAccessException | InvocationTargetException
                    | NoSuchMethodException e) {
                throw new WicketRuntimeException("Cannot save configuration.", e);
            }
            success(getString("success"));
            setResponsePage(InstancePage.class);
        }

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

    AjaxLink<String> closeButton = new AjaxLink<String>("close") {
        private static final long serialVersionUID = 6062171472516887030L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            setResponsePage(InstancePage.class);
        }
    };
    form.add(closeButton);

}

From source file:com.romeikat.datamessie.core.base.ui.panel.TaskExecutionsPanel.java

License:Open Source License

public TaskExecutionsPanel(final String id) {
    super(id);/*from  w w  w  . j a  v a  2s . c  om*/

    // Model
    taskExecutionsModel = new LoadableDetachableModel<List<TaskExecutionDto>>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected List<TaskExecutionDto> load() {
            final List<TaskExecutionDto> taskExecutions = taskExecutionService
                    .getVisibleTaskExecutionsOrderedByLatestActivityDesc();
            // Reverse so the latest one is the first one
            return taskExecutions;
        }
    };

    // Task executions
    taskExecutionsList = new ListView<TaskExecutionDto>("taskExecutionsList", taskExecutionsModel) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<TaskExecutionDto> item) {
            final IModel<TaskExecutionDto> taskExecutionModel = item.getModel();
            final TaskExecutionDto taskExecution = taskExecutionModel.getObject();
            // Link to works
            final AjaxLink<Void> modalContentWindowLink = new AjaxLink<Void>("modalContentWindowLink") {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    final ModalContentWindow modalContentWindow = TaskExecutionsPanel.this
                            .allocateModalWindow();
                    if (modalContentWindow != null) {
                        final TaskExecutionWorksPanel detailsPanel = new TaskExecutionWorksPanel(
                                modalContentWindow, taskExecutionModel);
                        detailsPanel.show(target);
                    }
                }
            };
            String taskLabelContent = taskExecution.getName();
            if (taskExecution.getStatus() != null) {
                taskLabelContent += " (" + taskExecution.getStatus().getName().toLowerCase() + ")";
            }
            final Label taskLabel = new Label("taskLabel", taskLabelContent);
            modalContentWindowLink.add(taskLabel);
            item.add(modalContentWindowLink);
        }
    };
    taskExecutionsList.setOutputMarkupId(true);
    add(taskExecutionsList);
}