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 AssignmentConflictPanel method initLayout.
private void initLayout() {
setOutputMarkupId(true);
Form container = new com.evolveum.midpoint.web.component.form.Form<>(ID_PANEL_CONTAINER);
container.setOutputMarkupId(true);
add(container);
Label statusIconLabel = new Label(ID_STATUS_ICON);
statusIconLabel.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
return getModelObject() != null ? (getModelObject().isSolved() ? STATUS_FIXED : (getModelObject().isError() ? STATUS_ERROR : STATUS_WARNING)) : STATUS_ERROR;
}
}));
container.add(statusIconLabel);
Label existingAssignment = new Label(ID_EXISTING_ASSIGNMENT, new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
if (getModelObject() != null) {
String name = getModelObject().getExistingAssignmentTargetObj().asObjectable().getName() != null ? getModelObject().getExistingAssignmentTargetObj().asObjectable().getName().getOrig() : getModelObject().getExistingAssignmentTargetObj().getOid();
return name + " " + createStringResource("AssignmentConflictPanel.existingAssignmentLabelMessage").getString();
}
return "";
}
});
existingAssignment.add(new AttributeAppender("style", new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
return getModelObject() != null && getModelObject().isRemovedOld() ? "text-decoration: line-through;" : "";
}
}));
container.add(existingAssignment);
Label addedAssignment = new Label(ID_ADDED_ASSIGNMENT, new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
if (getModelObject() != null) {
String name = getModelObject().getAddedAssignmentTargetObj().asObjectable().getName() != null ? getModelObject().getAddedAssignmentTargetObj().asObjectable().getName().getOrig() : getModelObject().getAddedAssignmentTargetObj().getOid();
return name + " " + createStringResource("AssignmentConflictPanel.addedAssignmentLabelMessage").getString();
}
return "";
}
});
addedAssignment.add(new AttributeAppender("style", new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
return getModelObject() != null && getModelObject().isUnassignedNew() ? "text-decoration: line-through;" : "";
}
}));
container.add(addedAssignment);
AbstractReadOnlyModel<String> removeButtonTitleModel = new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
return getModelObject().isRemovedOld() ? createStringResource("AssignmentConflictPanel.undoAction").getString() : createStringResource("AssignmentConflictPanel.removeButton").getString();
}
};
AjaxSubmitButton removeButton = new AjaxSubmitButton(ID_REMOVE_BUTTON, removeButtonTitleModel) {
@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
AssignmentConflictPanel.this.removeAssignmentPerformed(target);
}
};
removeButton.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return getModelObject() != null;
}
@Override
public boolean isEnabled() {
return !getModelObject().isUnassignedNew();
}
});
container.add(removeButton);
AbstractReadOnlyModel<String> unselectButtonTitleModel = new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
return getModelObject().isUnassignedNew() ? createStringResource("AssignmentConflictPanel.undoAction").getString() : createStringResource("AssignmentConflictPanel.unselectButton").getString();
}
};
AjaxSubmitButton unselectButton = new AjaxSubmitButton(ID_UNSELECT_BUTTON, unselectButtonTitleModel) {
@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
AssignmentConflictPanel.this.unselectAssignmentPerformed(target);
}
};
unselectButton.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return getModelObject() != null;
}
@Override
public boolean isEnabled() {
return !getModelObject().isRemovedOld();
}
});
container.add(unselectButton);
}
use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.
the class OperationResultPanel method initHeader.
private void initHeader(WebMarkupContainer box) {
WebMarkupContainer iconType = new WebMarkupContainer(ID_ICON_TYPE);
iconType.setOutputMarkupId(true);
iconType.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
StringBuilder sb = new StringBuilder();
OpResult message = getModelObject();
switch(message.getStatus()) {
case IN_PROGRESS:
case NOT_APPLICABLE:
sb.append(" fa-info");
break;
case SUCCESS:
sb.append(" fa-check");
break;
case FATAL_ERROR:
sb.append(" fa-ban");
break;
case PARTIAL_ERROR:
case UNKNOWN:
case WARNING:
case HANDLED_ERROR:
default:
sb.append(" fa-warning");
}
return sb.toString();
}
}));
box.add(iconType);
Label message = createMessage();
AjaxLink<String> showMore = new AjaxLink<String>(ID_MESSAGE) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
OpResult result = OperationResultPanel.this.getModelObject();
result.setShowMore(!result.isShowMore());
// hack to be able to expand/collapse OpResult after rendered.
result.setAlreadyShown(false);
target.add(OperationResultPanel.this);
}
};
showMore.add(message);
box.add(showMore);
AjaxLink<String> backgroundTask = new AjaxLink<String>(ID_BACKGROUND_TASK) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
final OpResult opResult = OperationResultPanel.this.getModelObject();
String oid = opResult.getBackgroundTaskOid();
if (oid == null || !opResult.isBackgroundTaskVisible()) {
// just for safety
return;
}
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(oid, ObjectTypes.TASK);
WebComponentUtil.dispatchToObjectDetailsPage(ref, getPageBase(), false);
}
};
backgroundTask.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return getModelObject().getBackgroundTaskOid() != null && getModelObject().isBackgroundTaskVisible();
}
});
box.add(backgroundTask);
AjaxLink<String> showAll = new AjaxLink<String>(ID_SHOW_ALL) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
showHideAll(true, OperationResultPanel.this.getModelObject(), target);
}
};
showAll.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return !OperationResultPanel.this.getModelObject().isShowMore();
}
});
box.add(showAll);
AjaxLink<String> hideAll = new AjaxLink<String>(ID_HIDE_ALL) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
showHideAll(false, OperationResultPanel.this.getModel().getObject(), target);
}
};
hideAll.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible() {
return OperationResultPanel.this.getModelObject().isShowMore();
}
});
box.add(hideAll);
AjaxLink<String> close = new AjaxLink<String>("close") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
close(target);
}
};
box.add(close);
DownloadLink downloadXml = new DownloadLink("downloadXml", new AbstractReadOnlyModel<File>() {
private static final long serialVersionUID = 1L;
@Override
public File getObject() {
String home = getPageBase().getMidpointConfiguration().getMidpointHome();
File f = new File(home, "result");
DataOutputStream dos = null;
try {
dos = new DataOutputStream(new FileOutputStream(f));
dos.writeBytes(OperationResultPanel.this.getModel().getObject().getXml());
} catch (IOException e) {
LOGGER.error("Could not download result: {}", e.getMessage(), e);
} finally {
IOUtils.closeQuietly(dos);
}
return f;
}
});
downloadXml.setDeleteAfterDownload(true);
box.add(downloadXml);
}
use of org.apache.wicket.model.AbstractReadOnlyModel in project midpoint by Evolveum.
the class ValidationErrorPanel method initHeader.
private void initHeader(WebMarkupContainer box) {
WebMarkupContainer iconType = new WebMarkupContainer("iconType");
iconType.setOutputMarkupId(true);
iconType.add(new AttributeAppender("class", new AbstractReadOnlyModel() {
@Override
public Object getObject() {
FeedbackMessage result = getModelObject();
if (result == null) {
return " fa-info";
}
switch(result.getLevel()) {
case FeedbackMessage.INFO:
case FeedbackMessage.DEBUG:
return " fa-info";
case FeedbackMessage.SUCCESS:
return " fa-check";
case FeedbackMessage.ERROR:
case FeedbackMessage.FATAL:
return " fa-ban";
case FeedbackMessage.UNDEFINED:
// TODO:
case FeedbackMessage.WARNING:
default:
return " fa-warning";
}
}
}));
box.add(iconType);
Label message = new Label(ID_MESSAGE, new PropertyModel<Serializable>(getModel(), "message"));
box.add(message);
AjaxLink close = new AjaxLink("close") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
close(target);
}
};
box.add(close);
}
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);
}
Aggregations