Search in sources :

Example 66 with AbstractReadOnlyModel

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

the class MainMenuPanel method createSubmenu.

private void createSubmenu(final ListItem<MenuItem> listItem) {
    final MenuItem menuItem = listItem.getModelObject();
    listItem.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return menuItem.isMenuActive((WebPage) getPage()) ? "active" : null;
        }
    }));
    Link<String> subLink = new Link<String>(ID_SUB_LINK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick() {
            menuItemPerformed(menuItem);
        }
    };
    listItem.add(subLink);
    Label subLabel = new Label(ID_SUB_LABEL, menuItem.getNameModel());
    subLink.add(subLabel);
    listItem.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            MenuItem mi = listItem.getModelObject();
            boolean visible = true;
            if (mi.getVisibleEnable() != null) {
                visible = mi.getVisibleEnable().isVisible();
            }
            return visible && SecurityUtils.isMenuAuthorized(mi);
        }

        @Override
        public boolean isEnabled() {
            MenuItem mi = listItem.getModelObject();
            if (mi.getVisibleEnable() == null) {
                return true;
            }
            return mi.getVisibleEnable().isEnabled();
        }
    });
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) WebPage(org.apache.wicket.markup.html.WebPage) Label(org.apache.wicket.markup.html.basic.Label) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) Link(org.apache.wicket.markup.html.link.Link) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 67 with AbstractReadOnlyModel

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

the class TextFormGroup method initLayout.

private void initLayout(IModel<String> label, final String tooltipKey, boolean isTooltipInModal, String labelSize, String textSize, final boolean required, final boolean markAsRequired) {
    WebMarkupContainer labelContainer = new WebMarkupContainer(ID_LABEL_CONTAINER);
    add(labelContainer);
    Label l = new Label(ID_LABEL, label);
    if (StringUtils.isNotEmpty(labelSize)) {
        labelContainer.add(AttributeAppender.prepend("class", labelSize));
    }
    labelContainer.add(l);
    Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
    tooltipLabel.add(new AttributeAppender("data-original-title", new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            return getString(tooltipKey);
        }
    }));
    tooltipLabel.add(new InfoTooltipBehavior(isTooltipInModal));
    tooltipLabel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return tooltipKey != null;
        }
    });
    tooltipLabel.setOutputMarkupId(true);
    tooltipLabel.setOutputMarkupPlaceholderTag(true);
    labelContainer.add(tooltipLabel);
    WebMarkupContainer requiredContainer = new WebMarkupContainer(ID_REQUIRED);
    requiredContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return markAsRequired;
        }
    });
    labelContainer.add(requiredContainer);
    WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
    if (StringUtils.isNotEmpty(textSize)) {
        textWrapper.add(AttributeAppender.prepend("class", textSize));
    }
    add(textWrapper);
    TextField text = createText(getModel(), label, required);
    text.setLabel(label);
    textWrapper.add(text);
    FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ContainerFeedbackMessageFilter(this));
    feedback.setOutputMarkupId(true);
    textWrapper.add(feedback);
}
Also used : InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) Label(org.apache.wicket.markup.html.basic.Label) TextField(org.apache.wicket.markup.html.form.TextField) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ContainerFeedbackMessageFilter(org.apache.wicket.feedback.ContainerFeedbackMessageFilter) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 68 with AbstractReadOnlyModel

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

the class PageCertCampaigns method createPageTitleModel.

// endregion
// region Layout
@Override
protected IModel<String> createPageTitleModel() {
    return new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            if (definitionOid == null) {
                return createStringResource("PageCertCampaigns.title", "").getString();
            }
            Task task = createSimpleTask("dummy");
            PrismObject<AccessCertificationDefinitionType> definitionPrismObject = WebModelServiceUtils.loadObject(AccessCertificationDefinitionType.class, definitionOid, PageCertCampaigns.this, task, task.getResult());
            String name = definitionPrismObject == null ? "" : WebComponentUtil.getName(definitionPrismObject);
            return createStringResource("PageCertCampaigns.title", name).getString();
        }
    };
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Task(com.evolveum.midpoint.task.api.Task) AccessCertificationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationDefinitionType)

Example 69 with AbstractReadOnlyModel

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

the class PageCertCampaign method initBasicInfoLayout.

private void initBasicInfoLayout(Form mainForm) {
    mainForm.add(new Label(ID_CAMPAIGN_NAME, new PropertyModel<>(campaignModel, CertCampaignDto.F_NAME)));
    mainForm.add(new Label(ID_CAMPAIGN_DESCRIPTION, new PropertyModel<>(campaignModel, CertCampaignDto.F_DESCRIPTION)));
    mainForm.add(new Label(ID_CAMPAIGN_OWNER, new PropertyModel<>(campaignModel, CertCampaignDto.F_OWNER_NAME)));
    mainForm.add(new Label(ID_CAMPAIGN_NUMBER_OF_STAGES, new PropertyModel<>(campaignModel, CertCampaignDto.F_NUMBER_OF_STAGES)));
    mainForm.add(new Label(ID_CAMPAIGN_CURRENT_STATE, new PropertyModel<>(campaignModel, CertCampaignDto.F_CURRENT_STATE)));
    mainForm.add(new Label(ID_CAMPAIGN_TIME, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            CertCampaignDto dto = campaignModel.getObject();
            return formatDuration(dto.getCampaignStart(), dto.getCampaignEnd());
        }
    }));
    mainForm.add(new Label(ID_STAGE_TIME, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            CertCampaignDto dto = campaignModel.getObject();
            return formatStageDuration(dto.getStageStart(), dto.getStageDeadline(), dto.getStageEnd());
        }
    }));
    WebMarkupContainer escalationLevelInfoContainer = new WebMarkupContainer(ID_ESCALATION_LEVEL_INFO_CONTAINER);
    mainForm.add(escalationLevelInfoContainer);
    escalationLevelInfoContainer.add(new Label(ID_ESCALATION_LEVEL_INFO, new PropertyModel<String>(campaignModel, CertCampaignDto.F_ESCALATION_LEVEL_INFO)));
    escalationLevelInfoContainer.add(new VisibleBehaviour(() -> campaignModel.getObject().getEscalationLevelInfo() != null));
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) CertCampaignDto(com.evolveum.midpoint.web.page.admin.certification.dto.CertCampaignDto) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 70 with AbstractReadOnlyModel

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

the class PageTasks method initTaskColumns.

private List<IColumn<TaskDto, String>> initTaskColumns() {
    List<IColumn<TaskDto, String>> columns = new ArrayList<IColumn<TaskDto, String>>();
    IColumn column = new CheckBoxHeaderColumn<>();
    columns.add(column);
    column = createTaskNameColumn(this, "pageTasks.task.name");
    columns.add(column);
    columns.add(createTaskCategoryColumn(this, "pageTasks.task.category"));
    columns.add(new IconColumn<TaskDto>(createStringResource("")) {

        @Override
        protected IModel<String> createIconModel(IModel<TaskDto> rowModel) {
            ObjectReferenceType ref = rowModel.getObject().getObjectRef();
            if (ref == null || ref.getType() == null) {
                return Model.of("");
            }
            ObjectTypeGuiDescriptor guiDescriptor = getObjectTypeDescriptor(ref.getType());
            String icon = guiDescriptor != null ? guiDescriptor.getBlackIcon() : ObjectTypeGuiDescriptor.ERROR_ICON;
            return new Model<>(icon);
        }

        private ObjectTypeGuiDescriptor getObjectTypeDescriptor(QName type) {
            return ObjectTypeGuiDescriptor.getDescriptor(ObjectTypes.getObjectTypeFromTypeQName(type));
        }

        @Override
        public void populateItem(Item<ICellPopulator<TaskDto>> item, String componentId, IModel<TaskDto> rowModel) {
            super.populateItem(item, componentId, rowModel);
            ObjectReferenceType ref = rowModel.getObject().getObjectRef();
            if (ref != null && ref.getType() != null) {
                ObjectTypeGuiDescriptor guiDescriptor = getObjectTypeDescriptor(ref.getType());
                if (guiDescriptor != null) {
                    item.add(AttributeModifier.replace("title", createStringResource(guiDescriptor.getLocalizationKey())));
                    item.add(new TooltipBehavior());
                }
            }
        }
    });
    columns.add(new AbstractExportableColumn<TaskDto, String>(createStringResource("pageTasks.task.objectRef")) {

        @Override
        public void populateItem(Item<ICellPopulator<TaskDto>> item, String componentId, final IModel<TaskDto> rowModel) {
            item.add(new Label(componentId, new AbstractReadOnlyModel<Object>() {

                @Override
                public Object getObject() {
                    return createObjectRef(rowModel);
                }
            }));
        }

        @Override
        public IModel<String> getDataModel(IModel<TaskDto> rowModel) {
            return Model.of(createObjectRef(rowModel));
        }
    });
    columns.add(createTaskExecutionStatusColumn(this, "pageTasks.task.execution"));
    columns.add(new PropertyColumn<TaskDto, String>(createStringResource("pageTasks.task.executingAt"), "executingAt"));
    columns.add(new AbstractExportableColumn<TaskDto, String>(createStringResource("pageTasks.task.progress")) {

        @Override
        public void populateItem(Item<ICellPopulator<TaskDto>> cellItem, String componentId, final IModel<TaskDto> rowModel) {
            cellItem.add(new Label(componentId, new AbstractReadOnlyModel<Object>() {

                @Override
                public Object getObject() {
                    return createProgress(rowModel);
                }
            }));
        }

        @Override
        public IModel<String> getDataModel(IModel<TaskDto> rowModel) {
            return Model.of(createProgress(rowModel));
        }
    });
    columns.add(new AbstractExportableColumn<TaskDto, String>(createStringResource("pageTasks.task.currentRunTime")) {

        @Override
        public void populateItem(final Item<ICellPopulator<TaskDto>> item, final String componentId, final IModel<TaskDto> rowModel) {
            DateLabelComponent dateLabel = new DateLabelComponent(componentId, new AbstractReadOnlyModel<Date>() {

                @Override
                public Date getObject() {
                    Date date = createCurrentRuntime(rowModel);
                    TaskDto task = rowModel.getObject();
                    if (task.getRawExecutionStatus() == TaskExecutionStatus.CLOSED) {
                        ((DateLabelComponent) item.get(componentId)).setBefore("closed at ");
                    } else if (date != null) {
                        ((DateLabelComponent) item.get(componentId)).setBefore(DurationFormatUtils.formatDurationWords(date.getTime(), true, true));
                    }
                    return date;
                }
            }, DateLabelComponent.MEDIUM_MEDIUM_STYLE);
            item.add(dateLabel);
        }

        @Override
        public IModel<String> getDataModel(IModel<TaskDto> rowModel) {
            TaskDto task = rowModel.getObject();
            Date date = createCurrentRuntime(rowModel);
            String displayValue = "";
            if (date != null) {
                if (task.getRawExecutionStatus() == TaskExecutionStatus.CLOSED) {
                    displayValue = "closed at " + WebComponentUtil.getLocalizedDate(date, DateLabelComponent.LONG_MEDIUM_STYLE);
                } else {
                    displayValue = DurationFormatUtils.formatDurationWords(date.getTime(), true, true);
                }
            }
            return Model.of(displayValue);
        }
    });
    columns.add(new AbstractExportableColumn<TaskDto, String>(createStringResource("pageTasks.task.scheduledToRunAgain")) {

        @Override
        public void populateItem(Item<ICellPopulator<TaskDto>> item, String componentId, final IModel<TaskDto> rowModel) {
            item.add(new Label(componentId, new AbstractReadOnlyModel<Object>() {

                @Override
                public Object getObject() {
                    return createScheduledToRunAgain(rowModel);
                }
            }));
        }

        @Override
        public IModel<String> getDataModel(IModel<TaskDto> rowModel) {
            return Model.of(createScheduledToRunAgain(rowModel));
        }
    });
    columns.add(new IconColumn<TaskDto>(createStringResource("pageTasks.task.status")) {

        @Override
        protected IModel<String> createTitleModel(final IModel<TaskDto> rowModel) {
            return new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    TaskDto dto = rowModel.getObject();
                    if (dto != null && dto.getStatus() != null) {
                        return createStringResourceStatic(PageTasks.this, dto.getStatus()).getString();
                    } else {
                        return createStringResourceStatic(PageTasks.this, OperationResultStatus.UNKNOWN).getString();
                    }
                }
            };
        }

        @Override
        protected IModel<String> createIconModel(final IModel<TaskDto> rowModel) {
            return new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    if (rowModel != null && rowModel.getObject() != null && rowModel.getObject().getStatus() != null) {
                        return OperationResultStatusPresentationProperties.parseOperationalResultStatus(rowModel.getObject().getStatus().createStatusType()).getIcon() + " fa-lg";
                    } else
                        return OperationResultStatusPresentationProperties.UNKNOWN.getIcon() + " fa-lg";
                }
            };
        }
    });
    IColumn<TaskDto, String> menuColumn = new InlineMenuButtonColumn<TaskDto>(createTasksInlineMenu(false), 2, PageTasks.this) {

        @Override
        protected int getHeaderNumberOfButtons() {
            return 2;
        }

        @Override
        protected List<InlineMenuItem> getHeaderMenuItems() {
            return createTasksInlineMenu(true);
        }
    };
    columns.add(menuColumn);
    return columns;
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) TooltipBehavior(com.evolveum.midpoint.web.util.TooltipBehavior) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) IModel(org.apache.wicket.model.IModel) QName(javax.xml.namespace.QName) DateLabelComponent(com.evolveum.midpoint.web.component.DateLabelComponent) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) ObjectTypeGuiDescriptor(com.evolveum.midpoint.web.util.ObjectTypeGuiDescriptor) PrismObject(com.evolveum.midpoint.prism.PrismObject)

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