Search in sources :

Example 1 with DateLabelComponent

use of com.evolveum.midpoint.web.component.DateLabelComponent in project midpoint by Evolveum.

the class PageCreatedReports method initColumns.

//TODO - consider adding Author name, File Type and ReportType to columns
private List<IColumn<SelectableBean<ReportOutputType>, String>> initColumns(final AjaxDownloadBehaviorFromStream ajaxDownloadBehavior) {
    List<IColumn<SelectableBean<ReportOutputType>, String>> columns = new ArrayList<>();
    IColumn column;
    column = new CheckBoxHeaderColumn();
    columns.add(column);
    column = new PropertyColumn(createStringResource("pageCreatedReports.table.name"), "name", "value.name");
    columns.add(column);
    column = new PropertyColumn(createStringResource("pageCreatedReports.table.description"), "value.description");
    columns.add(column);
    column = new AbstractColumn<SelectableBean<ReportOutputType>, String>(createStringResource("pageCreatedReports.table.time"), "createTimestamp") {

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<ReportOutputType>>> cellItem, String componentId, final IModel<SelectableBean<ReportOutputType>> rowModel) {
            cellItem.add(new DateLabelComponent(componentId, new AbstractReadOnlyModel<Date>() {

                @Override
                public Date getObject() {
                    ReportOutputType object = rowModel.getObject().getValue();
                    MetadataType metadata = object != null ? object.getMetadata() : null;
                    if (metadata == null) {
                        return null;
                    }
                    return XmlTypeConverter.toDate(metadata.getCreateTimestamp());
                }
            }, DateLabelComponent.LONG_MEDIUM_STYLE));
        }
    };
    columns.add(column);
    column = new AbstractColumn<SelectableBean<ReportOutputType>, String>(new Model(), null) {

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<ReportOutputType>>> cellItem, String componentId, final IModel<SelectableBean<ReportOutputType>> model) {
            DownloadButtonPanel panel = new DownloadButtonPanel(componentId) {

                @Override
                protected void deletePerformed(AjaxRequestTarget target) {
                    deleteSelectedPerformed(target, ReportDeleteDialogDto.Operation.DELETE_SINGLE, model.getObject().getValue());
                }

                @Override
                protected void downloadPerformed(AjaxRequestTarget target) {
                    currentReport = model.getObject().getValue();
                    PageCreatedReports.this.downloadPerformed(target, model.getObject().getValue(), ajaxDownloadBehavior);
                }
            };
            cellItem.add(panel);
        }
    };
    columns.add(column);
    column = new InlineMenuHeaderColumn<InlineMenuable>(initInlineMenu()) {

        @Override
        public void populateItem(Item<ICellPopulator<InlineMenuable>> cellItem, String componentId, IModel<InlineMenuable> rowModel) {
            cellItem.add(new Label(componentId));
        }
    };
    columns.add(column);
    return columns;
}
Also used : PropertyColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn) Label(org.apache.wicket.markup.html.basic.Label) ReportOutputType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportOutputType) CheckBoxHeaderColumn(com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) MetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType) DateLabelComponent(com.evolveum.midpoint.web.component.DateLabelComponent) InlineMenuable(com.evolveum.midpoint.web.component.data.column.InlineMenuable) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DownloadButtonPanel(com.evolveum.midpoint.web.page.admin.reports.component.DownloadButtonPanel) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) IModel(org.apache.wicket.model.IModel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel)

Example 2 with DateLabelComponent

use of com.evolveum.midpoint.web.component.DateLabelComponent in project midpoint by Evolveum.

the class PageTasks method addCustomColumns.

private void addCustomColumns(List<IColumn<SelectableBean<TaskType>, String>> columns) {
    columns.add(2, new ObjectReferenceColumn<>(createStringResource("pageTasks.task.objectRef"), SelectableBeanImpl.F_VALUE + "." + TaskType.F_OBJECT_REF.getLocalPart()) {

        private static final long serialVersionUID = 1L;

        @Override
        public IModel<ObjectReferenceType> extractDataModel(IModel<SelectableBean<TaskType>> rowModel) {
            SelectableBean<TaskType> bean = rowModel.getObject();
            return Model.of(bean.getValue().getObjectRef());
        }
    });
    columns.add(4, new AbstractExportableColumn<>(createStringResource("pageTasks.task.currentRunTime"), TaskType.F_COMPLETION_TIMESTAMP.getLocalPart()) {

        private static final long serialVersionUID = 1L;

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

                private static final long serialVersionUID = 1L;

                @Override
                public Date getObject() {
                    Date date = getCurrentRuntime(rowModel);
                    SelectableBean<TaskType> task = rowModel.getObject();
                    if (task.getValue().getExecutionState() == TaskExecutionStateType.CLOSED && date != null) {
                        ((DateLabelComponent) item.get(componentId)).setBefore(createStringResource("pageTasks.task.closedAt").getString() + " ");
                    } else if (date != null) {
                        ((DateLabelComponent) item.get(componentId)).setBefore(WebComponentUtil.formatDurationWordsForLocal(date.getTime(), true, true, PageTasks.this));
                    }
                    return date;
                }
            }, WebComponentUtil.getShortDateTimeFormat(PageTasks.this));
            item.add(dateLabel);
        }

        @Override
        public IModel<String> getDataModel(IModel<SelectableBean<TaskType>> rowModel) {
            SelectableBean<TaskType> task = rowModel.getObject();
            Date date = getCurrentRuntime(rowModel);
            String displayValue = "";
            if (date != null) {
                if (task.getValue().getExecutionState() == TaskExecutionStateType.CLOSED) {
                    displayValue = createStringResource("pageTasks.task.closedAt").getString() + WebComponentUtil.getShortDateTimeFormattedValue(date, PageTasks.this);
                } else {
                    displayValue = WebComponentUtil.formatDurationWordsForLocal(date.getTime(), true, true, PageTasks.this);
                }
            }
            return Model.of(displayValue);
        }
    });
    columns.add(5, new AbstractExportableColumn<>(createStringResource("pageTasks.task.scheduledToRunAgain")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<TaskType>>> item, String componentId, final IModel<SelectableBean<TaskType>> rowModel) {
            item.add(new Label(componentId, () -> createScheduledToRunAgain(rowModel)));
        }

        @Override
        public IModel<String> getDataModel(IModel<SelectableBean<TaskType>> rowModel) {
            return Model.of(createScheduledToRunAgain(rowModel));
        }
    });
}
Also used : IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) DateLabelComponent(com.evolveum.midpoint.web.component.DateLabelComponent) Date(java.util.Date) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean)

Example 3 with DateLabelComponent

use of com.evolveum.midpoint.web.component.DateLabelComponent 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)

Example 4 with DateLabelComponent

use of com.evolveum.midpoint.web.component.DateLabelComponent in project midpoint by Evolveum.

the class PersonalInfoPanel method initLayout.

protected void initLayout(PageBase parentPage) {
    DateLabelComponent lastLoginDate = new DateLabelComponent(ID_LAST_LOGIN_DATE, new AbstractReadOnlyModel<Date>() {

        @Override
        public Date getObject() {
            PersonalInfoDto dto = getModel().getObject();
            return dto == null ? null : dto.getLastLoginDate();
        }
    }, DateLabelComponent.LONG_MEDIUM_STYLE);
    lastLoginDate.setBeforeTextOnDateNull(parentPage.getString("PersonalInfoPanel.never"));
    add(lastLoginDate);
    Label lastLoginFrom = new Label(ID_LAST_LOGIN_FROM, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            PersonalInfoDto dto = getModel().getObject();
            return StringUtils.isNotEmpty(dto.getLastLoginFrom()) ? dto.getLastLoginFrom() : PersonalInfoPanel.this.getString("PersonalInfoPanel.undefined");
        }
    });
    add(lastLoginFrom);
    DateLabelComponent lastFailDate = new DateLabelComponent(ID_LAST_FAIL_DATE, new AbstractReadOnlyModel<Date>() {

        @Override
        public Date getObject() {
            PersonalInfoDto dto = getModel().getObject();
            return dto == null ? null : dto.getLastFailDate();
        }
    }, DateLabelComponent.LONG_MEDIUM_STYLE);
    lastFailDate.setBeforeTextOnDateNull(parentPage.getString("PersonalInfoPanel.never"));
    add(lastFailDate);
    Label lastFailFrom = new Label(ID_LAST_FAIL_FROM, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            PersonalInfoDto dto = getModel().getObject();
            return StringUtils.isNotEmpty(dto.getLastFailFrom()) ? dto.getLastFailFrom() : PersonalInfoPanel.this.getString("PersonalInfoPanel.undefined");
        }
    });
    add(lastFailFrom);
    Label passwordExp = new Label(ID_PASSWORD_EXP, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            PersonalInfoDto dto = getModel().getObject();
            return dto.getPasswordExp() != null ? WebComponentUtil.formatDate(dto.getPasswordExp()) : PersonalInfoPanel.this.getString("PersonalInfoPanel.undefined");
        }
    });
    add(passwordExp);
}
Also used : PersonalInfoDto(com.evolveum.midpoint.web.page.admin.home.dto.PersonalInfoDto) Label(org.apache.wicket.markup.html.basic.Label) DateLabelComponent(com.evolveum.midpoint.web.component.DateLabelComponent) Date(java.util.Date)

Example 5 with DateLabelComponent

use of com.evolveum.midpoint.web.component.DateLabelComponent in project midpoint by Evolveum.

the class PageCreatedReports method initColumns.

private List<IColumn<SelectableBean<ReportDataType>, String>> initColumns() {
    List<IColumn<SelectableBean<ReportDataType>, String>> columns = new ArrayList<>();
    IColumn<SelectableBean<ReportDataType>, String> column = new AbstractColumn<SelectableBean<ReportDataType>, String>(createStringResource("pageCreatedReports.table.time"), "createTimestamp") {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<SelectableBean<ReportDataType>>> cellItem, String componentId, final IModel<SelectableBean<ReportDataType>> rowModel) {
            cellItem.add(new DateLabelComponent(componentId, new IModel<Date>() {

                private static final long serialVersionUID = 1L;

                @Override
                public Date getObject() {
                    ReportDataType object = rowModel.getObject().getValue();
                    MetadataType metadata = object != null ? object.getMetadata() : null;
                    if (metadata == null) {
                        return null;
                    }
                    return XmlTypeConverter.toDate(metadata.getCreateTimestamp());
                }
            }, WebComponentUtil.getShortDateTimeFormat(PageCreatedReports.this)));
        }
    };
    columns.add(column);
    column = new PropertyColumn<>(createStringResource("pageCreatedReports.table.description"), SelectableBeanImpl.F_VALUE + "." + ReportDataType.F_DESCRIPTION.getLocalPart());
    columns.add(column);
    column = new EnumPropertyColumn(createStringResource("pageCreatedReports.table.fileFormat"), SelectableBeanImpl.F_VALUE + "." + ReportDataType.F_FILE_FORMAT.getLocalPart()) {

        @Override
        protected String translate(Enum en) {
            return createStringResource(en).getString();
        }
    };
    columns.add(column);
    column = new ObjectReferenceColumn<SelectableBean<ReportDataType>>(createStringResource("pageCreatedReports.table.type"), SelectableBeanImpl.F_VALUE + "." + ReportDataType.F_REPORT_REF.getLocalPart()) {

        @Override
        public IModel<ObjectReferenceType> extractDataModel(IModel<SelectableBean<ReportDataType>> rowModel) {
            SelectableBean<ReportDataType> bean = rowModel.getObject();
            return Model.of(bean.getValue().getReportRef());
        }
    };
    columns.add(column);
    return columns;
}
Also used : IModel(org.apache.wicket.model.IModel) DateLabelComponent(com.evolveum.midpoint.web.component.DateLabelComponent) AbstractColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) Item(org.apache.wicket.markup.repeater.Item) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) EnumPropertyColumn(com.evolveum.midpoint.web.component.data.column.EnumPropertyColumn)

Aggregations

DateLabelComponent (com.evolveum.midpoint.web.component.DateLabelComponent)7 Label (org.apache.wicket.markup.html.basic.Label)6 IModel (org.apache.wicket.model.IModel)4 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)3 Date (java.util.Date)3 ICellPopulator (org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator)3 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)3 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)2 PersonalInfoDto (com.evolveum.midpoint.web.page.admin.home.dto.PersonalInfoDto)2 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 CheckBoxHeaderColumn (com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn)1 EnumPropertyColumn (com.evolveum.midpoint.web.component.data.column.EnumPropertyColumn)1 InlineMenuable (com.evolveum.midpoint.web.component.data.column.InlineMenuable)1 ButtonInlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)1 DownloadButtonPanel (com.evolveum.midpoint.web.page.admin.reports.component.DownloadButtonPanel)1 ObjectTypeGuiDescriptor (com.evolveum.midpoint.web.util.ObjectTypeGuiDescriptor)1 TooltipBehavior (com.evolveum.midpoint.web.util.TooltipBehavior)1 MetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType)1