use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.
the class RolePolicyPanel method createMultiplicityPolicyLabel.
private IModel<String> createMultiplicityPolicyLabel(final IModel<MultiplicityPolicyConstraintType> model) {
return new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
if (model == null || model.getObject() == null || model.getObject().getMultiplicity() == null || model.getObject().getMultiplicity().isEmpty()) {
return getString("PageRoleEditor.label.assignmentConstraint.placeholder");
}
MultiplicityPolicyConstraintType policy = model.getObject();
sb.append(policy.getMultiplicity());
if (policy.getEnforcement() != null) {
sb.append(" (");
sb.append(policy.getEnforcement());
sb.append(")");
}
return sb.toString();
}
};
}
use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.
the class ObjectPolicyConfigurationEditor method initLayout.
protected void initLayout() {
final Label label = new Label(ID_LABEL, createStringResource("objectPolicyConfigurationEditor.label"));
add(label);
ListView<ObjectPolicyConfigurationTypeDto> repeater = new ListView<ObjectPolicyConfigurationTypeDto>(ID_REPEATER, getModel()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(final ListItem<ObjectPolicyConfigurationTypeDto> item) {
WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
textWrapper.add(AttributeAppender.prepend("class", new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
if (item.getIndex() > 0) {
return OFFSET_CLASS + " " + CLASS_MULTI_VALUE;
}
return null;
}
}));
item.add(textWrapper);
TextField<String> name = new TextField<>(ID_NAME, createNameModel(item.getModel()));
name.setOutputMarkupId(true);
name.add(new AjaxFormComponentUpdatingBehavior("blur") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
}
});
name.setEnabled(false);
name.add(AttributeAppender.replace("placeholder", createStringResource("objectPolicyConfigurationEditor.name.placeholder")));
textWrapper.add(name);
FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(name));
textWrapper.add(feedback);
AjaxLink<String> edit = new AjaxLink<String>(ID_BUTTON_EDIT) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
editPerformed(target, item);
}
};
textWrapper.add(edit);
WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP);
buttonGroup.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
if (item.getIndex() > 0) {
return CLASS_MULTI_VALUE;
}
return null;
}
}));
item.add(buttonGroup);
initButtons(buttonGroup, item);
}
};
// initDialog();
repeater.setOutputMarkupId(true);
add(repeater);
}
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);
}
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();
}
};
}
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);
}
Aggregations