Search in sources :

Example 76 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.

the class WizardSteps method initLayout.

protected void initLayout() {
    ListView<WizardStepDto> linkContainer = new ListView<WizardStepDto>(ID_LINK_REPEATER, getModel()) {

        @Override
        protected void populateItem(ListItem<WizardStepDto> item) {
            final WizardStepDto dto = item.getModelObject();
            item.setRenderBodyOnly(true);
            AjaxSubmitLink button = new AjaxSubmitLink(ID_LINK) {

                @Override
                protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                    changeStepPerformed(target, dto);
                }

                @Override
                protected void onError(AjaxRequestTarget target, Form<?> form) {
                    target.add(getPageBase().getFeedbackPanel());
                }
            };
            item.add(button);
            button.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isEnabled() {
                    final boolean enabled = ((PageResourceWizard) getPageBase()).isCurrentStepComplete();
                    //						System.out.println(dto.getName() + " enabled = " + enabled);
                    return enabled;
                }

                @Override
                public boolean isVisible() {
                    return dto.isVisible();
                }
            });
            button.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    return dto.getWizardStep() == getActiveStep() ? "current" : null;
                }
            }));
            button.add(AttributeModifier.replace("style", new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    final boolean enabled = ((PageResourceWizard) getPageBase()).isCurrentStepComplete();
                    // TODO respect color scheme (and find a better style for disabled anyway...)
                    return enabled ? null : "color: #FFF;";
                }
            }));
            Label label = new Label(ID_LABEL, createLabelModel(dto.getName()));
            button.add(label);
        }
    };
    add(linkContainer);
    AjaxLink help = new AjaxLink(ID_BUTTON_HELP) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHelpPerformed(target);
        }
    };
    add(help);
    initModals();
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ListView(org.apache.wicket.markup.html.list.ListView) PageResourceWizard(com.evolveum.midpoint.web.page.admin.resources.PageResourceWizard) ListItem(org.apache.wicket.markup.html.list.ListItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 77 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.

the class CapabilityStep method initLayout.

protected void initLayout() {
    final ListDataProvider<CapabilityDto<CapabilityType>> capabilityProvider = new ListDataProvider<>(this, new PropertyModel<List<CapabilityDto<CapabilityType>>>(dtoModel, CapabilityStepDto.F_CAPABILITIES));
    WebMarkupContainer tableBody = new WebMarkupContainer(ID_CAPABILITY_TABLE);
    tableBody.setOutputMarkupId(true);
    add(tableBody);
    WebMarkupContainer configBody = new WebMarkupContainer(ID_CAPABILITY_CONFIG);
    configBody.setOutputMarkupId(true);
    add(configBody);
    DataView<CapabilityDto<CapabilityType>> capabilityDataView = new DataView<CapabilityDto<CapabilityType>>(ID_CAPABILITY_ROW, capabilityProvider) {

        @Override
        protected void populateItem(final Item<CapabilityDto<CapabilityType>> capabilityRow) {
            final CapabilityDto<CapabilityType> dto = capabilityRow.getModelObject();
            AjaxLink name = new AjaxLink(ID_CAPABILITY_LINK) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    editCapabilityPerformed(target, dto);
                }
            };
            Label label = new Label(ID_CAPABILITY_NAME, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    String rv = dto.getDisplayName();
                    if (Boolean.FALSE.equals(dto.getCapability().isEnabled())) {
                        rv += " " + getString("CapabilityStep.disabled");
                    }
                    return rv;
                }
            });
            name.add(label);
            capabilityRow.add(name);
            Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
            if (dto.getTooltipKey() != null) {
                tooltipLabel.add(new AttributeAppender("data-original-title", getString(dto.getTooltipKey())));
                tooltipLabel.add(new InfoTooltipBehavior());
            } else {
                tooltipLabel.setVisible(false);
            }
            tooltipLabel.setOutputMarkupId(true);
            tooltipLabel.setOutputMarkupPlaceholderTag(true);
            name.add(tooltipLabel);
            AjaxLink deleteLink = new AjaxLink(ID_CAPABILITY_DELETE) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    deleteCapabilityPerformed(target, dto);
                }
            };
            deleteLink.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    return !dto.isAmongNativeCapabilities() && !parentPage.isReadOnly();
                }
            });
            name.add(deleteLink);
            capabilityRow.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<Object>() {

                @Override
                public Object getObject() {
                    return isSelected(capabilityRow.getModelObject()) ? "success" : null;
                }
            }));
        }
    };
    tableBody.add(capabilityDataView);
    AjaxLink addLink = new AjaxLink(ID_CAPABILITY_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addCapabilityPerformed(target);
        }
    };
    parentPage.addEditingVisibleBehavior(addLink);
    add(addLink);
    ModalWindow dialog = new AddCapabilityDialog(DIALOG_SELECT_CAPABILITY, dtoModel) {

        @Override
        protected void addPerformed(AjaxRequestTarget target) {
            addCapabilitiesPerformed(target, getSelectedData());
        }
    };
    add(dialog);
}
Also used : ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 78 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.

the class ProgressPanel method initLayout.

private void initLayout(ProgressReportingAwarePage page) {
    progressForm = new Form<>(ID_PROGRESS_FORM, true);
    add(progressForm);
    contentsPanel = new WebMarkupContainer(ID_CONTENTS_PANEL);
    contentsPanel.setOutputMarkupId(true);
    progressForm.add(contentsPanel);
    ListView statusItemsListView = new ListView<ProgressReportActivityDto>(ID_ACTIVITIES, new AbstractReadOnlyModel<List<ProgressReportActivityDto>>() {

        @Override
        public List<ProgressReportActivityDto> getObject() {
            ProgressDto progressDto = ProgressPanel.this.getModelObject();
            return progressDto.getProgressReportActivities();
        }
    }) {

        protected void populateItem(final ListItem<ProgressReportActivityDto> item) {
            item.add(new Label(ID_ACTIVITY_DESCRIPTION, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    ProgressReportActivityDto si = item.getModelObject();
                    if (si.getActivityType() == RESOURCE_OBJECT_OPERATION && si.getResourceShadowDiscriminator() != null) {
                        ResourceShadowDiscriminator rsd = si.getResourceShadowDiscriminator();
                        return createStringResource(rsd.getKind()).getString() + " (" + rsd.getIntent() + ") on " + // TODO correct i18n
                        si.getResourceName();
                    } else {
                        return createStringResource(si.getActivityType()).getString();
                    }
                }
            }));
            item.add(createImageLabel(ID_ACTIVITY_STATE, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    OperationResultStatusType statusType = item.getModelObject().getStatus();
                    if (statusType == null) {
                        return null;
                    } else {
                        return OperationResultStatusPresentationProperties.parseOperationalResultStatus(statusType).getIcon() + " fa-lg";
                    }
                }
            }, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    // TODO why this does not work???
                    // TODO i18n
                    OperationResultStatusType statusType = item.getModelObject().getStatus();
                    if (statusType == null) {
                        return null;
                    } else {
                        return statusType.toString();
                    }
                }
            }));
            item.add(new Label(ID_ACTIVITY_COMMENT, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    ProgressReportActivityDto si = item.getModelObject();
                    if (si.getResourceName() != null || si.getResourceOperationResultList() != null) {
                        StringBuilder sb = new StringBuilder();
                        boolean first = true;
                        if (si.getResourceOperationResultList() != null) {
                            for (ResourceOperationResult ror : si.getResourceOperationResultList()) {
                                if (!first) {
                                    sb.append(", ");
                                } else {
                                    first = false;
                                }
                                sb.append(createStringResource("ChangeType." + ror.getChangeType()).getString());
                                sb.append(":");
                                sb.append(createStringResource(ror.getResultStatus()).getString());
                            }
                        }
                        if (si.getResourceObjectName() != null) {
                            if (!first) {
                                sb.append(" -> ");
                            }
                            sb.append(si.getResourceObjectName());
                        }
                        return sb.toString();
                    } else {
                        return null;
                    }
                }
            }));
        }

        private Label createImageLabel(String id, IModel<String> cssClass, IModel<String> title) {
            Label label = new Label(id);
            label.add(AttributeModifier.replace("class", cssClass));
            // does not work, currently
            label.add(AttributeModifier.replace("title", title));
            return label;
        }
    };
    contentsPanel.add(statusItemsListView);
    statisticsPanel = new StatisticsPanel(ID_STATISTICS, new StatisticsDtoModel());
    contentsPanel.add(statisticsPanel);
    ListView logItemsListView = new ListView(ID_LOG_ITEMS, new AbstractReadOnlyModel<List>() {

        @Override
        public List getObject() {
            ProgressDto progressDto = ProgressPanel.this.getModelObject();
            return progressDto.getLogItems();
        }
    }) {

        protected void populateItem(ListItem item) {
            item.add(new Label(ID_LOG_ITEM, item.getModel()));
        }
    };
    contentsPanel.add(logItemsListView);
    Label executionTime = new Label(ID_EXECUTION_TIME, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            if (operationDurationTime > 0) {
                return createStringResource("ProgressPanel.ExecutionTimeWhenFinished", operationDurationTime).getString();
            } else if (operationStartTime > 0) {
                return createStringResource("ProgressPanel.ExecutionTimeWhenRunning", (System.currentTimeMillis() - operationStartTime) / 1000).getString();
            } else {
                return null;
            }
        }
    });
    contentsPanel.add(executionTime);
    initButtons(progressForm, page);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) OperationResultStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ListView(org.apache.wicket.markup.html.list.ListView) List(java.util.List) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ListItem(org.apache.wicket.markup.html.list.ListItem) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult)

Example 79 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.

the class SearchItemPanel method createLabelModel.

private IModel<String> createLabelModel() {
    return new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            SearchItem item = getModelObject();
            StringBuilder sb = new StringBuilder();
            sb.append(item.getName());
            sb.append(": ");
            List<String> values = new ArrayList<>();
            for (DisplayableValue value : (List<DisplayableValue>) item.getValues()) {
                if (StringUtils.isNotEmpty(value.getLabel())) {
                    values.add(value.getLabel());
                }
            }
            if (!values.isEmpty()) {
                String or = createStringResource("SearchItemPanel.or").getString();
                sb.append('"');
                sb.append(StringUtils.join(values, "\" " + or + " \""));
                sb.append('"');
            } else {
                String all = createStringResource("SearchItemPanel.all").getString();
                sb.append(all);
            }
            return sb.toString();
        }
    };
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) DisplayableValue(com.evolveum.midpoint.util.DisplayableValue) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 80 with AbstractReadOnlyModel

use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.

the class SearchItemPanel method initPopover.

private void initPopover() {
    WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER);
    popover.setOutputMarkupId(true);
    add(popover);
    WebMarkupContainer popoverBody = new WebMarkupContainer(ID_POPOVER_BODY);
    popoverBody.setOutputMarkupId(true);
    popover.add(popoverBody);
    ListView values = new ListView<DisplayableValue>(ID_VALUES, new PropertyModel<List<DisplayableValue>>(popoverModel, SearchItem.F_VALUES)) {

        @Override
        protected void populateItem(final ListItem<DisplayableValue> item) {
            item.add(AttributeModifier.replace("style", new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    return item.getIndex() != 0 ? "margin-top: 5px;" : null;
                }
            }));
            SearchPopupPanel fragment = createPopoverFragment(item.getModel());
            fragment.setRenderBodyOnly(true);
            item.add(fragment);
        }
    };
    popoverBody.add(values);
    AjaxSubmitButton update = new AjaxSubmitButton(ID_UPDATE, createStringResource("SearchItemPanel.update")) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            updateItemPerformed(target);
        }
    };
    popoverBody.add(update);
    AjaxButton close = new AjaxButton(ID_CLOSE, createStringResource("SearchItemPanel.close")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            closeEditPopoverPerformed(target);
        }
    };
    popoverBody.add(close);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ListView(org.apache.wicket.markup.html.list.ListView) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Aggregations

AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)105 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)60 Label (org.apache.wicket.markup.html.basic.Label)59 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)54 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)41 ArrayList (java.util.ArrayList)34 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)29 ListItem (org.apache.wicket.markup.html.list.ListItem)29 IModel (org.apache.wicket.model.IModel)26 ListView (org.apache.wicket.markup.html.list.ListView)25 List (java.util.List)23 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)23 AttributeModifier (org.apache.wicket.AttributeModifier)21 PropertyModel (org.apache.wicket.model.PropertyModel)20 Model (org.apache.wicket.model.Model)16 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)13 TextField (org.apache.wicket.markup.html.form.TextField)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 Form (org.apache.wicket.markup.html.form.Form)9 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)8