use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper in project midpoint by Evolveum.
the class ItemWrapperModel method getItemWrapperForHeader.
<ID extends ItemDefinition> ItemWrapper getItemWrapperForHeader(Class<ID> type, PageBase pageBase) {
if (path.isEmpty()) {
return null;
}
if (fromContainerValue) {
return null;
}
try {
PrismContainerDefinition container = (PrismContainerDefinition) this.parent.getObject();
ItemDefinition<?> def = container.findItemDefinition(path, type);
if (!type.isAssignableFrom(def.getClass())) {
return null;
}
// keys are mostly useless (unless nicely specified in XSD, which is not very often)
return createItemWrapper(def.instantiate(), pageBase);
} catch (SchemaException e) {
LOGGER.error("Cannot get {} with path {} from parent {}\nReason: {}", ItemWrapper.class, path, this.parent.getObject(), e.getMessage(), e);
return null;
}
}
use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper 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.prism.wrapper.ItemWrapper in project midpoint by Evolveum.
the class AbstractGuiIntegrationTest method getServiceLocator.
protected ModelServiceLocator getServiceLocator(final Task pageTask) {
return new ModelServiceLocator() {
@Override
public ModelService getModelService() {
return modelService;
}
@Override
public ModelInteractionService getModelInteractionService() {
return modelInteractionService;
}
@Override
public DashboardService getDashboardService() {
return dashboardService;
}
@Override
public Task createSimpleTask(String operationName) {
MidPointPrincipal user = AuthUtil.getPrincipalUser();
if (user == null) {
throw new IllegalStateException("No authenticated user");
}
return WebModelServiceUtils.createSimpleTask(operationName, SchemaConstants.CHANNEL_USER_URI, user.getFocus().asPrismObject(), taskManager);
}
@Override
public PrismContext getPrismContext() {
return prismContext;
}
@Override
public SecurityEnforcer getSecurityEnforcer() {
return securityEnforcer;
}
@Override
public SecurityContextManager getSecurityContextManager() {
return securityContextManager;
}
@NotNull
@Override
public CompiledGuiProfile getCompiledGuiProfile() {
Task task = createSimpleTask("getCompiledGuiProfile");
try {
return getModelInteractionService().getCompiledGuiProfile(task, task.getResult());
} catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
throw new SystemException(e.getMessage(), e);
}
}
@Override
public Task getPageTask() {
return pageTask;
}
@Override
public ExpressionFactory getExpressionFactory() {
return expressionFactory;
}
@Override
public LocalizationService getLocalizationService() {
return localizationService;
}
@Override
public Locale getLocale() {
return Locale.US;
}
@Override
public GuiComponentRegistry getRegistry() {
return registry;
}
@Override
public <O extends ObjectType> PrismObjectWrapperFactory<O> findObjectWrapperFactory(PrismObjectDefinition<O> objectDef) {
return registry.getObjectWrapperFactory(objectDef);
}
@Override
public <I extends Item, IW extends ItemWrapper> IW createItemWrapper(I item, ItemStatus status, WrapperContext ctx) throws SchemaException {
ItemWrapperFactory<IW, ?, ?> factory = registry.findWrapperFactory(item.getDefinition(), null);
ctx.setCreateIfEmpty(true);
return factory.createWrapper(null, item, status, ctx);
}
@Override
public <IW extends ItemWrapper, VW extends PrismValueWrapper, PV extends PrismValue> VW createValueWrapper(IW parentWrapper, PV newValue, ValueStatus status, WrapperContext context) throws SchemaException {
ItemWrapperFactory<IW, VW, PV> factory = registry.findWrapperFactory(parentWrapper, null);
return factory.createValueWrapper(parentWrapper, newValue, status, context);
}
@Override
public MidpointFormValidatorRegistry getFormValidatorRegistry() {
return null;
}
@Override
public AdminGuiConfigurationMergeManager getAdminGuiConfigurationMergeManager() {
return null;
}
@Override
public CorrelationService getCorrelationService() {
return null;
}
};
}
use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper in project midpoint by Evolveum.
the class ShadowAssociationWrapperImpl method getDelta.
@Override
public <D extends ItemDelta<?, ?>> Collection<D> getDelta() throws SchemaException {
Collection<D> deltas = new ArrayList<D>();
ContainerDelta<ShadowAssociationType> delta = createEmptyDelta(getDeltaPathForStatus(getStatus()));
switch(getStatus()) {
case ADDED:
if (CollectionUtils.isEmpty(getValues())) {
return null;
}
// we know that there is always only one value
PrismContainerValueWrapper<ShadowAssociationType> containerValueWrappers = getValues().iterator().next();
for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
if (!(itemWrapper instanceof PrismReferenceWrapper)) {
LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
continue;
}
PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
if (updatedRefValue.getNewValue().isEmpty()) {
continue;
}
ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
shadowAssociationType.setName(refWrapper.getItemName());
shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue.getNewValue()));
delta.addValueToAdd(shadowAssociationType.asPrismContainerValue());
}
}
if (delta.isEmpty()) {
return null;
}
return (Collection) MiscUtil.createCollection(delta);
case NOT_CHANGED:
containerValueWrappers = getValues().iterator().next();
for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
if (!(itemWrapper instanceof PrismReferenceWrapper)) {
LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
continue;
}
PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
if (updatedRefValue.getNewValue().isEmpty()) {
continue;
}
ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
shadowAssociationType.setName(refWrapper.getItemName());
shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef(updatedRefValue.getNewValue()));
switch(updatedRefValue.getStatus()) {
case ADDED:
delta.addValueToAdd(shadowAssociationType.asPrismContainerValue());
break;
case NOT_CHANGED:
break;
case DELETED:
delta.addValueToDelete(shadowAssociationType.asPrismContainerValue());
break;
}
}
}
break;
case DELETED:
containerValueWrappers = getValues().iterator().next();
for (ItemWrapper itemWrapper : containerValueWrappers.getItems()) {
if (!(itemWrapper instanceof PrismReferenceWrapper)) {
LOGGER.warn("Item in shadow association value wrapper is not an reference. Should not happen.");
continue;
}
PrismReferenceWrapper refWrapper = (PrismReferenceWrapper) itemWrapper;
for (PrismReferenceValueWrapperImpl updatedRefValue : (List<PrismReferenceValueWrapperImpl>) refWrapper.getValues()) {
if (updatedRefValue.getNewValue().isEmpty()) {
continue;
}
ShadowAssociationType shadowAssociationType = new ShadowAssociationType();
shadowAssociationType.asPrismContainerValue().applyDefinition(getItemDefinition());
shadowAssociationType.setName(refWrapper.getItemName());
shadowAssociationType.setShadowRef(ObjectTypeUtil.createObjectRef((PrismReferenceValue) updatedRefValue.getNewValue()));
delta.addValueToDelete(shadowAssociationType.asPrismContainerValue());
}
}
break;
}
if (!delta.isEmpty()) {
deltas.add((D) delta);
}
if (deltas.isEmpty()) {
return null;
}
return deltas;
}
use of com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper in project midpoint by Evolveum.
the class ListMappingPanel method initLayout.
private void initLayout() {
MultivalueContainerListPanelWithDetailsPanel<MappingType> table = new MultivalueContainerListPanelWithDetailsPanel<MappingType>(ID_TABLE, MappingType.class) {
@Override
protected MultivalueContainerDetailsPanel<MappingType> getMultivalueContainerDetailsPanel(ListItem<PrismContainerValueWrapper<MappingType>> item) {
return new MultivalueContainerDetailsPanel<>(MultivalueContainerListPanelWithDetailsPanel.ID_ITEM_DETAILS, item.getModel(), true) {
@Override
protected DisplayNamePanel<MappingType> createDisplayNamePanel(String displayNamePanelId) {
ItemRealValueModel<MappingType> displayNameModel = new ItemRealValueModel<>(item.getModel());
return new DisplayNamePanel<>(displayNamePanelId, displayNameModel) {
@Override
protected IModel<String> createHeaderModel() {
IModel<String> headerModel = super.createHeaderModel();
if (StringUtils.isEmpty(headerModel.getObject())) {
return getPageBase().createStringResource("feedbackMessagePanel.message.undefined");
}
return headerModel;
}
};
}
@Override
protected ItemVisibility getBasicTabVisibity(ItemWrapper<?, ?> itemWrapper) {
if (itemWrapper.getPath().isSubPathOrEquivalent(ItemPath.create(ItemPath.EMPTY_PATH, MappingType.F_METADATA_MAPPING))) {
return ItemVisibility.HIDDEN;
}
return ItemVisibility.AUTO;
}
};
}
@Override
protected boolean isCreateNewObjectVisible() {
return true;
}
@Override
protected IModel<PrismContainerWrapper<MappingType>> getContainerModel() {
return ListMappingPanel.this.getModel();
}
@Override
protected UserProfileStorage.TableId getTableId() {
return null;
}
@Override
protected List<IColumn<PrismContainerValueWrapper<MappingType>, String>> createDefaultColumns() {
List<IColumn<PrismContainerValueWrapper<MappingType>, String>> columns = new ArrayList<>();
columns.add(new PrismPropertyWrapperColumn<>(ListMappingPanel.this.getModel(), MappingType.F_DESCRIPTION, AbstractItemWrapperColumn.ColumnType.STRING, getPageBase()));
columns.add(new PrismPropertyWrapperColumn<>(ListMappingPanel.this.getModel(), MappingType.F_ENABLED, AbstractItemWrapperColumn.ColumnType.VALUE, getPageBase()));
columns.add(new AbstractColumn<>(createStringResource("ListMappingPanel.mappingDescription")) {
@Override
public void populateItem(Item<ICellPopulator<PrismContainerValueWrapper<MappingType>>> cellItem, String componentId, IModel<PrismContainerValueWrapper<MappingType>> rowModel) {
cellItem.add(new Label(componentId, WebComponentUtil.createMappingDescription(rowModel)));
}
});
List<InlineMenuItem> items = new ArrayList<>();
InlineMenuItem item = new InlineMenuItem(createStringResource("pageAdminFocus.button.delete")) {
private static final long serialVersionUID = 1L;
@Override
public InlineMenuItemAction initAction() {
return new ColumnMenuAction() {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
deleteItemPerformed(target, getPerformedSelectedItems(getRowModel()));
}
};
}
};
items.add(item);
item = new ButtonInlineMenuItem(createStringResource("PageBase.button.edit")) {
private static final long serialVersionUID = 1L;
@Override
public CompositedIconBuilder getIconCompositedBuilder() {
return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_EDIT_MENU_ITEM);
}
@Override
public InlineMenuItemAction initAction() {
return new ColumnMenuAction() {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
editItemPerformed(target, getRowModel(), getSelectedItems());
target.add(getFeedbackPanel());
}
};
}
};
items.add(item);
columns.add(new InlineMenuButtonColumn(items, getPageBase()) {
@Override
public String getCssClass() {
return "col-xs-1";
}
});
return columns;
}
@Override
protected IColumn<PrismContainerValueWrapper<MappingType>, String> createNameColumn(IModel<String> displayModel, GuiObjectColumnType customColumn, ItemPath itemPath, ExpressionType expression) {
return new PrismPropertyWrapperColumn<>(ListMappingPanel.this.getModel(), MappingType.F_NAME, AbstractItemWrapperColumn.ColumnType.LINK, getPageBase()) {
@Override
protected void onClick(AjaxRequestTarget target, IModel<PrismContainerValueWrapper<MappingType>> model) {
itemDetailsPerformed(target, model);
}
};
}
@Override
protected IColumn<PrismContainerValueWrapper<MappingType>, String> createCheckboxColumn() {
return new CheckBoxHeaderColumn<>();
}
@Override
protected PrismContainerDefinition<MappingType> getTypeDefinitionForSearch() {
return getPrismContext().getSchemaRegistry().findContainerDefinitionByType(MappingType.COMPLEX_TYPE);
}
};
add(table);
}
Aggregations