use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class SchrodingerComponentInitListener method handleLocalization.
private void handleLocalization(Component component) {
if (component instanceof PrismPropertyPanel || component instanceof PrismReferencePanel) {
ItemPanel ppp = (ItemPanel) component;
ItemWrapper iw = (ItemWrapper) ppp.getModel().getObject();
String key = iw.getDisplayName();
QName qname = iw.getItemName();
writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
writeDataAttribute(component, ATTR_QNAME, qnameToString(qname));
return;
}
if (component instanceof PrismHeaderPanel) {
PrismHeaderPanel php = (PrismHeaderPanel) component;
String key = php.getLabel();
writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
return;
}
IModel model = null;
if (component.getDefaultModel() instanceof StringResourceModel) {
model = component.getDefaultModel();
} else if (component.getInnermostModel() instanceof StringResourceModel) {
model = component.getInnermostModel();
} else if (component.getDefaultModel() instanceof ReadOnlyModel) {
try {
if (component.getDefaultModelObject() instanceof String) {
model = component.getDefaultModel();
}
} catch (Exception e) {
LOGGER.error("Schrodinger localization handling failed", e);
}
}
if (model == null) {
return;
}
try {
String key = model instanceof StringResourceModel ? (String) FieldUtils.readField(model, "resourceKey", true) : (String) model.getObject();
if (key.startsWith("${")) {
String expression = key.substring(2, key.length() - 1);
key = new PropertyModel<String>(FieldUtils.readField(model, "model", true), expression).getObject();
}
if (key != null) {
writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
}
} catch (Exception ex) {
// we don't care, should be all right, unless selenium tests starts failing
}
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class WebComponentUtil method getIconUrlModel.
public static IModel<String> getIconUrlModel(IconType icon) {
return new ReadOnlyModel<>(() -> {
if (icon == null || StringUtils.isEmpty(icon.getImageUrl())) {
return null;
}
String sUrl = icon.getImageUrl();
if (URI.create(sUrl).isAbsolute()) {
return sUrl;
}
List<String> segments = RequestCycle.get().getUrlRenderer().getBaseUrl().getSegments();
if (segments == null || segments.size() < 2) {
return sUrl;
}
String prefix = StringUtils.repeat("../", segments.size() - 1);
if (!sUrl.startsWith("/")) {
return prefix + sUrl;
}
return StringUtils.left(prefix, prefix.length() - 1) + sUrl;
});
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class WebComponentUtil method createMappingDescription.
public static IModel<String> createMappingDescription(IModel<PrismContainerValueWrapper<MappingType>> model) {
return new ReadOnlyModel<>(() -> {
if (model == null || model.getObject() == null) {
return null;
}
MappingType mappingType = model.getObject().getRealValue();
if (mappingType == null) {
return null;
}
List<VariableBindingDefinitionType> sources = mappingType.getSource();
String sourceString = String.join(", ", sources.stream().map(s -> s != null && s.getPath() != null ? s.getPath().toString() : "").collect(Collectors.toList()));
// String sourceString = "";
// for (VariableBindingDefinitionType s : sources) {
// if (s == null) {
// continue;
// }
// sourceString += s.getPath().toString() + ", ";
// }
String strength = "";
if (mappingType.getStrength() != null) {
strength = mappingType.getStrength().toString();
}
String target = "";
VariableBindingDefinitionType targetv = mappingType.getTarget();
if (targetv != null) {
target += targetv.getPath().toString();
}
if (target.isBlank()) {
return sourceString + (strength.isBlank() ? "" : "(" + strength + ")");
}
return target + (strength.isBlank() ? "" : "(" + strength + ")");
});
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class CompositedButtonPanel method initLayout.
private void initLayout() {
WebMarkupContainer buttonContainer = new WebMarkupContainer(ID_COMPOSITED_BUTTON);
add(buttonContainer);
CompositedIconPanel compositedIconPanel = new CompositedIconPanel(ID_COMPOSITED_ICON, new PropertyModel<>(getModel(), CompositedIconButtonDto.F_COMPOSITED_ICON));
buttonContainer.add(compositedIconPanel);
Label label = new Label(ID_LABEL, new ReadOnlyModel<>(() -> {
DisplayType displayType = getModelObject().getAdditionalButtonDisplayType();
return WebComponentUtil.getTranslatedPolyString(displayType.getLabel());
}));
buttonContainer.add(label);
buttonContainer.add(AttributeAppender.append("title", new ReadOnlyModel<>(() -> {
DisplayType displayType = getModelObject().getAdditionalButtonDisplayType();
return WebComponentUtil.getTranslatedPolyString(displayType.getTooltip());
})));
buttonContainer.add(new TooltipBehavior());
buttonContainer.add(new AjaxEventBehavior("click") {
@Override
protected void onEvent(AjaxRequestTarget target) {
onButtonClicked(target, getModelObject());
}
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
attributes.setPreventDefault(true);
super.updateAjaxAttributes(attributes);
}
});
// Label description = new Label(ID_DESCRIPTION, new ReadOnlyModel<>(() -> {
// DisplayType displayType = getModelObject().getAdditionalButtonDisplayType();
// return WebComponentUtil.getTranslatedPolyString(displayType.getTooltip());
// }));
// buttonContainer.add(description);
}
use of com.evolveum.midpoint.gui.api.model.ReadOnlyModel in project midpoint by Evolveum.
the class FocusProjectionsTabPanel method initLayout.
private void initLayout() {
IModel<Integer> deadShadows = new ReadOnlyModel<>(() -> countDeadShadows());
Label label = new Label(ID_DEAD_SHADOWS, deadShadows);
label.add(new VisibleBehaviour(() -> deadShadows.getObject() > 0));
add(label);
MultivalueContainerListPanelWithDetailsPanel<ShadowType> multivalueContainerListPanel = new MultivalueContainerListPanelWithDetailsPanel<ShadowType>(ID_SHADOW_TABLE, ShadowType.class) {
private static final long serialVersionUID = 1L;
@Override
protected ISelectableDataProvider<ShadowType, PrismContainerValueWrapper<ShadowType>> createProvider() {
return new ProjectionsListProvider(FocusProjectionsTabPanel.this, getSearchModel(), loadShadowModel()) {
@Override
protected PageStorage getPageStorage() {
PageStorage storage = getSession().getSessionStorage().getPageStorageMap().get(SessionStorage.KEY_FOCUS_PROJECTION_TABLE);
if (storage == null) {
storage = getSession().getSessionStorage().initPageStorage(SessionStorage.KEY_FOCUS_PROJECTION_TABLE);
}
return storage;
}
};
}
@Override
protected void newItemPerformed(AjaxRequestTarget target, AssignmentObjectRelation relation) {
List<QName> supportedTypes = new ArrayList<>(1);
supportedTypes.add(ResourceType.COMPLEX_TYPE);
PageBase pageBase = FocusProjectionsTabPanel.this.getPageBase();
ObjectBrowserPanel<ResourceType> resourceSelectionPanel = new ObjectBrowserPanel<ResourceType>(pageBase.getMainPopupBodyId(), ResourceType.class, supportedTypes, true, pageBase) {
private static final long serialVersionUID = 1L;
@Override
protected void addPerformed(AjaxRequestTarget target, QName type, List<ResourceType> selected) {
FocusProjectionsTabPanel.this.addSelectedAccountPerformed(target, selected);
}
};
resourceSelectionPanel.setOutputMarkupId(true);
pageBase.showMainPopup(resourceSelectionPanel, target);
}
@Override
protected boolean isCreateNewObjectVisible() {
PrismObjectDefinition<F> def = getObjectWrapper().getObject().getDefinition();
PrismReferenceDefinition ref = def.findReferenceDefinition(UserType.F_LINK_REF);
return (ref.canRead() && ref.canAdd());
}
@Override
protected IModel<PrismContainerWrapper<ShadowType>> getContainerModel() {
return null;
}
@Override
protected TableId getTableId() {
return UserProfileStorage.TableId.FOCUS_PROJECTION_TABLE;
}
@Override
protected List<IColumn<PrismContainerValueWrapper<ShadowType>, String>> createDefaultColumns() {
return initBasicColumns();
}
@Override
public void editItemPerformed(AjaxRequestTarget target, IModel<PrismContainerValueWrapper<ShadowType>> rowModel, List<PrismContainerValueWrapper<ShadowType>> listItems) {
loadShadowIfNeeded(rowModel, target);
if (listItems != null) {
listItems.forEach(value -> {
if (((ShadowWrapper) value.getParent()).isLoadWithNoFetch()) {
((PageAdminFocus) getPage()).loadFullShadow((PrismObjectValueWrapper) value, target);
}
});
}
super.editItemPerformed(target, rowModel, listItems);
}
@Override
protected Search createSearch(Class<ShadowType> type) {
Search search = super.createSearch(type);
PropertySearchItem<Boolean> defaultDeadItem = search.findPropertySearchItem(ShadowType.F_DEAD);
if (defaultDeadItem != null) {
defaultDeadItem.setVisible(false);
}
addDeadSearchItem(search);
return search;
}
@Override
protected List<SearchItemDefinition> initSearchableItems(PrismContainerDefinition<ShadowType> containerDef) {
List<SearchItemDefinition> defs = new ArrayList<>();
SearchFactory.addSearchRefDef(containerDef, ShadowType.F_RESOURCE_REF, defs, AreaCategoryType.ADMINISTRATION, getPageBase());
SearchFactory.addSearchPropertyDef(containerDef, ShadowType.F_NAME, defs);
SearchFactory.addSearchPropertyDef(containerDef, ShadowType.F_INTENT, defs);
SearchFactory.addSearchPropertyDef(containerDef, ShadowType.F_KIND, defs);
return defs;
}
@Override
protected MultivalueContainerDetailsPanel<ShadowType> getMultivalueContainerDetailsPanel(ListItem<PrismContainerValueWrapper<ShadowType>> item) {
return FocusProjectionsTabPanel.this.getMultivalueContainerDetailsPanel(item);
}
};
add(multivalueContainerListPanel);
setOutputMarkupId(true);
}
Aggregations