use of com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings in project midpoint by Evolveum.
the class TaskBasicTabPanel method initLayout.
private void initLayout() {
ItemPanelSettings settings = new ItemPanelSettingsBuilder().editabilityHandler(wrapper -> getTask().getHandlerUri() == null).build();
TaskHandlerSelectorPanel handlerSelectorPanel = new TaskHandlerSelectorPanel(ID_HANDLER, PrismPropertyWrapperModel.fromContainerWrapper(getModel(), TaskType.F_HANDLER_URI), settings) {
@Override
protected void onUpdatePerformed(AjaxRequestTarget target) {
String newHandlerUri = getTask().getHandlerUri();
if (StringUtils.isBlank(newHandlerUri) || !newHandlerUri.startsWith("http://")) {
LOGGER.trace("Nothing to do, handler still not set");
return;
}
TaskHandler taskHandler = getPageBase().getTaskManager().getHandler(newHandlerUri);
if (taskHandler == null) {
LOGGER.trace("Nothing to do, cannot find TaskHandler for {}", newHandlerUri);
return;
}
if (!WebComponentUtil.hasAnyArchetypeAssignment(getTask())) {
String archetypeOid = taskHandler.getArchetypeOid(newHandlerUri);
WebComponentUtil.addNewArchetype(TaskBasicTabPanel.this.getModelObject(), archetypeOid, target, getPageBase());
}
PrismObjectWrapperFactory<TaskType> wrapperFactory = TaskBasicTabPanel.this.getPageBase().findObjectWrapperFactory(getTask().asPrismObject().getDefinition());
Task task = getPageBase().createSimpleTask(OPERATION_UPDATE_WRAPPER);
OperationResult result = task.getResult();
WrapperContext ctx = new WrapperContext(task, result);
ctx.setDetailsPageTypeConfiguration(getDetailsPanelsConfiguration(getTask().asPrismObject()));
try {
wrapperFactory.updateWrapper(TaskBasicTabPanel.this.getModelObject(), ctx);
// TODO ugly hack: after updateWrapper method is called, both previously set items (handlerUri and assignments)
// are marked as NOT_CHANGED with the same value. We need to find a way how to force the ValueStatus
// or change the mechanism for computing deltas. Probably only the first will work
PrismPropertyWrapper<String> handlerWrapper = TaskBasicTabPanel.this.getModelObject().findProperty(ItemPath.create(TaskType.F_HANDLER_URI));
handlerWrapper.getValue().setStatus(ValueStatus.ADDED);
PrismContainerWrapper<AssignmentType> assignmentWrapper = TaskBasicTabPanel.this.getModelObject().findContainer(ItemPath.create(TaskType.F_ASSIGNMENT));
for (PrismContainerValueWrapper<AssignmentType> assignmentWrapperValue : assignmentWrapper.getValues()) {
if (WebComponentUtil.isArchetypeAssignment(assignmentWrapperValue.getRealValue())) {
assignmentWrapperValue.setStatus(ValueStatus.ADDED);
}
}
} catch (SchemaException | IllegalArgumentException e) {
LOGGER.error("Unexpected problem occurs during updating wrapper. Reason: {}", e.getMessage(), e);
}
updateHandlerPerformed(target);
}
};
handlerSelectorPanel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return satisfyArchetypeAssignment();
}
});
add(handlerSelectorPanel);
ItemVisibilityHandler visibilityHandler = wrapper -> getBasicTabVisibility(wrapper.getPath());
ItemEditabilityHandler editabilityHandler = wrapper -> getBasicTabEditability(wrapper.getPath());
try {
ItemPanelSettingsBuilder builder = new ItemPanelSettingsBuilder().visibilityHandler(visibilityHandler).editabilityHandler(editabilityHandler).mandatoryHandler(getItemMandatoryHandler());
Panel panel = getPageBase().initItemPanel(ID_MAIN_PANEL, TaskType.COMPLEX_TYPE, getModel(), builder.build());
add(panel);
} catch (SchemaException e) {
LOGGER.error("Cannot create task basic panel: {}", e.getMessage(), e);
// TODO opertion result? localization?
getSession().error("Cannot create task basic panel");
throw new RestartResponseException(PageTasks.class);
}
}
use of com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings in project midpoint by Evolveum.
the class MultivalueContainerDetailsPanel method getBasicContainerValuePanel.
protected Panel getBasicContainerValuePanel(String idPanel) {
ItemPanelSettingsBuilder builder = new ItemPanelSettingsBuilder().visibilityHandler(wrapper -> getBasicTabVisibity(wrapper)).editabilityHandler(wrapper -> getBasicTabEditability(wrapper));
if (getMandatoryHandler() != null) {
builder.mandatoryHandler(getMandatoryHandler());
}
if (config != null) {
builder.panelConfiguration(config);
}
ItemPanelSettings settings = builder.build();
Panel containerValue = getPageBase().initContainerValuePanel(idPanel, getModel(), settings);
return containerValue;
}
use of com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings in project midpoint by Evolveum.
the class PageBase method initItemPanel.
public <IW extends ItemWrapper> Panel initItemPanel(String panelId, QName typeName, IModel<IW> wrapperModel, ItemPanelSettings itemPanelSettings) throws SchemaException {
Class<?> panelClass = getWrapperPanel(typeName);
if (panelClass == null) {
ErrorPanel errorPanel = new ErrorPanel(panelId, () -> "Cannot create panel for " + typeName);
errorPanel.add(new VisibleBehaviour(() -> getApplication().usesDevelopmentConfig()));
return errorPanel;
}
Constructor<?> constructor;
try {
constructor = panelClass.getConstructor(String.class, IModel.class, ItemPanelSettings.class);
return (Panel) constructor.newInstance(panelId, wrapperModel, itemPanelSettings);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new SystemException("Cannot instantiate " + panelClass, e);
}
}
Aggregations