use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class LinkedReferencePanel method initLayout.
private void initLayout() {
setOutputMarkupId(true);
IModel<DisplayType> displayModel = new ReadOnlyModel<>(() -> {
PrismReferenceValue ref = referenceModel.getObject();
if (ref == null) {
return null;
}
DisplayType displayType = GuiDisplayTypeUtil.getDisplayTypeForObject(ref.getObject(), null, getPageBase());
if (displayType == null) {
displayType = new DisplayType();
}
if (displayType.getIcon() == null) {
displayType.setIcon(WebComponentUtil.createIconType(WebComponentUtil.createDefaultBlackIcon(ref.getTargetType())));
}
return displayType;
});
ImagePanel imagePanel = new ImagePanel(ID_ICON, displayModel);
imagePanel.setOutputMarkupId(true);
add(imagePanel);
AjaxLink<PrismReferenceValue> nameLink = new AjaxLink<PrismReferenceValue>(ID_NAME, referenceModel) {
@Override
public void onClick(AjaxRequestTarget ajaxRequestTarget) {
WebComponentUtil.dispatchToObjectDetailsPage(referenceModel.getObject(), LinkedReferencePanel.this, false);
}
};
nameLink.add(new EnableBehaviour(() -> {
PrismReferenceValue ref = referenceModel.getObject();
if (ref == null) {
return false;
}
return ref.getObject() != null;
}));
nameLink.setOutputMarkupId(true);
add(nameLink);
Label nameLinkText = new Label(ID_NAME_TEXT, new ReadOnlyModel<>(() -> {
PrismReferenceValue ref = referenceModel.getObject();
if (ref == null) {
return "";
}
return WebComponentUtil.getReferencedObjectDisplayNameAndName(ref.asReferencable(), false, getPageBase());
}));
nameLinkText.setOutputMarkupId(true);
nameLink.add(nameLinkText);
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class CountIconPanel method initLayout.
private void initLayout() {
getModelObject().sort((d1, d2) -> {
if (d1 == null || d1.getIcon() == null || d1.getIcon().getCssClass() == null || d2 == null || d2.getIcon() == null || d2.getIcon().getCssClass() == null) {
return 0;
}
return d1.getIcon().getCssClass().compareTo(d2.getIcon().getCssClass());
});
ListView<DisplayType> iconsPanel = new ListView<DisplayType>(ID_ICONS, getModel()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<DisplayType> item) {
Label icon = new Label(ID_ICON);
icon.add(AttributeModifier.replace("class", new PropertyModel<>(item.getModel(), "icon.cssClass")));
if (item.getModelObject() != null && item.getModelObject().getTooltip() != null) {
icon.add(AttributeModifier.replace("title", getPageBase().createStringResource(item.getModelObject().getTooltip().getOrig())));
}
icon.add(AttributeAppender.append("style", new ReadOnlyModel<>(() -> StringUtils.isNotBlank(getColor(item.getModelObject())) ? "color: " + getColor(item.getModelObject()) + ";" : "")));
icon.setOutputMarkupId(true);
icon.add(new VisibleBehaviour(() -> item.getModelObject() != null && item.getModelObject().getIcon() != null && StringUtils.isNotEmpty(item.getModelObject().getIcon().getCssClass())));
item.add(icon);
Integer count = icons.get(item.getModelObject());
Label countPanel = new Label(ID_COUNT, Model.of(count));
item.add(countPanel);
}
};
add(iconsPanel);
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class ResourceDetailsTabPanel method createSchemaStatusInfoBoxModel.
private ReadOnlyModel<InfoBoxType> createSchemaStatusInfoBoxModel() {
return new ReadOnlyModel<>(() -> {
String backgroundColor = "bg-gray";
String icon = "fa fa-times";
String numberMessage;
String description = null;
Integer progress = null;
ResourceSchema refinedSchema;
try {
refinedSchema = getObjectDetailsModels().getRefinedSchema();
if (refinedSchema != null) {
backgroundColor = "bg-purple";
icon = "fa fa-cubes";
// TODO is this correct?
int numObjectTypes = refinedSchema.getObjectTypeDefinitions().size();
int numAllDefinitions = numObjectTypes + refinedSchema.getObjectClassDefinitions().size();
numberMessage = numObjectTypes + " " + getPageBase().getString("PageResource.resource.objectTypes");
if (numAllDefinitions != 0) {
progress = numObjectTypes * 100 / numAllDefinitions;
if (progress > 100) {
progress = 100;
}
}
description = numAllDefinitions + " " + getPageBase().getString("PageResource.resource.schemaDefinitions");
} else {
numberMessage = getPageBase().getString("PageResource.resource.noSchema");
}
} catch (SchemaException e) {
backgroundColor = "bg-danger";
icon = "fa fa-warning";
numberMessage = getPageBase().getString("PageResource.resource.schemaError");
}
InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon, getPageBase().getString("PageResource.resource.schema"));
infoBoxType.setNumber(numberMessage);
infoBoxType.setProgress(progress);
infoBoxType.setDescription(description);
return infoBoxType;
});
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class ResourceDetailsTabPanel method createSourceTargetInfoBoxModel.
private ReadOnlyModel<InfoBoxType> createSourceTargetInfoBoxModel() {
return new ReadOnlyModel<>(() -> {
PrismObjectWrapper<ResourceType> resource = getObjectDetailsModels().getObjectWrapper();
String backgroundColor = "bg-aqua";
SourceTarget sourceTarget = determineIfSourceOrTarget(resource);
String numberKey;
switch(sourceTarget) {
case SOURCE:
numberKey = "PageResource.resource.source";
break;
case TARGET:
numberKey = "PageResource.resource.target";
break;
case SOURCE_TARGET:
numberKey = "PageResource.resource.sourceAndTarget";
break;
default:
backgroundColor = "bg-gray";
numberKey = "PageResource.resource.noMappings";
break;
}
InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, sourceTarget.getCssClass(), getPageBase().getString("PageResource.resource.mappings"));
infoBoxType.setNumber(getPageBase().getString(numberKey));
if (isSynchronizationDefined(resource)) {
infoBoxType.setDescription(getPageBase().getString("PageResource.resource.sync"));
}
return infoBoxType;
});
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class ResourceDetailsTabPanel method createResourceConfigListModel.
private ReadOnlyModel<List<ResourceConfigurationDto>> createResourceConfigListModel() {
return new ReadOnlyModel<>(() -> {
ResourceType resource = getObjectDetailsModels().getObjectType();
OperationResult result = new OperationResult(OPERATION_SEARCH_TASKS_FOR_RESOURCE);
List<PrismObject<TaskType>> tasks = WebModelServiceUtils.searchObjects(TaskType.class, getPageBase().getPrismContext().queryFor(TaskType.class).item(TaskType.F_OBJECT_REF).ref(resource.getOid()).and().item(TaskType.F_PARENT).isNull().build(), result, getPageBase());
List<ResourceConfigurationDto> configs = new ArrayList<>();
if (resource.getSchemaHandling() == null) {
return configs;
}
List<ResourceObjectTypeDefinitionType> objectTypes = resource.getSchemaHandling().getObjectType();
if (objectTypes == null) {
return configs;
}
try {
for (ResourceObjectTypeDefinitionType objectType : objectTypes) {
ObjectSynchronizationType objectSynchronization = null;
if (resource.getSynchronization() != null && resource.getSynchronization().getObjectSynchronization() != null) {
objectSynchronization = getSynchronizationFor(objectType, resource.getSynchronization().getObjectSynchronization(), resource.asPrismObject());
}
List<TaskType> syncTask = new ArrayList<>();
if (objectSynchronization != null) {
syncTask = getTaskFor(tasks, objectSynchronization, resource.asPrismObject());
}
ResourceConfigurationDto resourceConfig = new ResourceConfigurationDto(objectType, objectSynchronization != null, syncTask);
configs.add(resourceConfig);
}
} catch (SchemaException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Could not determine resource configuration", ex);
}
return configs;
});
}
Aggregations