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();
}
});
}
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);
}
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();
}
};
}
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));
}
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;
}
Aggregations