Search in sources :

Example 1 with ItemPanelSettings

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);
    }
}
Also used : java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Trace(com.evolveum.midpoint.util.logging.Trace) ItemVisibility(com.evolveum.midpoint.web.component.prism.ItemVisibility) StringUtils(org.apache.commons.lang3.StringUtils) RestartResponseException(org.apache.wicket.RestartResponseException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) PrismPropertyWrapperModel(com.evolveum.midpoint.web.model.PrismPropertyWrapperModel) ValueStatus(com.evolveum.midpoint.web.component.prism.ValueStatus) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) Component(org.apache.wicket.Component) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Panel(org.apache.wicket.markup.html.panel.Panel) TaskHandler(com.evolveum.midpoint.task.api.TaskHandler) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) PrismObjectWrapperFactory(com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory) com.evolveum.midpoint.gui.api.prism.wrapper(com.evolveum.midpoint.gui.api.prism.wrapper) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ItemPanelSettingsBuilder(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) ItemPanelSettingsBuilder(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) TaskHandler(com.evolveum.midpoint.task.api.TaskHandler) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Panel(org.apache.wicket.markup.html.panel.Panel) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 2 with ItemPanelSettings

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;
}
Also used : ItemPanelSettingsBuilder(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder) DisplayNamePanel(com.evolveum.midpoint.gui.api.component.DisplayNamePanel) PanelTab(com.evolveum.midpoint.gui.api.component.tabs.PanelTab) AbstractTab(org.apache.wicket.extensions.markup.html.tabs.AbstractTab) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) ItemVisibility(com.evolveum.midpoint.web.component.prism.ItemVisibility) ArrayList(java.util.ArrayList) Panel(org.apache.wicket.markup.html.panel.Panel) ContainerPanelConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ContainerPanelConfigurationType) List(java.util.List) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) ItemMandatoryHandler(com.evolveum.midpoint.gui.api.prism.wrapper.ItemMandatoryHandler) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) ITab(org.apache.wicket.extensions.markup.html.tabs.ITab) ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) IModel(org.apache.wicket.model.IModel) Containerable(com.evolveum.midpoint.prism.Containerable) NotNull(org.jetbrains.annotations.NotNull) TabbedPanel(com.evolveum.midpoint.web.component.TabbedPanel) PrismContainerValueWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper) ItemPanelSettingsBuilder(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) DisplayNamePanel(com.evolveum.midpoint.gui.api.component.DisplayNamePanel) Panel(org.apache.wicket.markup.html.panel.Panel) BasePanel(com.evolveum.midpoint.gui.api.component.BasePanel) TabbedPanel(com.evolveum.midpoint.web.component.TabbedPanel)

Example 3 with ItemPanelSettings

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);
    }
}
Also used : ErrorPanel(com.evolveum.midpoint.gui.impl.error.ErrorPanel) IModel(org.apache.wicket.model.IModel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) InvocationTargetException(java.lang.reflect.InvocationTargetException) ItemPanelSettings(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings) LocalePanel(com.evolveum.midpoint.web.component.menu.top.LocalePanel) UserMenuPanel(com.evolveum.midpoint.web.component.menu.UserMenuPanel) ErrorPanel(com.evolveum.midpoint.gui.impl.error.ErrorPanel) PrismContainerValuePanel(com.evolveum.midpoint.gui.impl.prism.panel.PrismContainerValuePanel) Panel(org.apache.wicket.markup.html.panel.Panel) LeftMenuPanel(com.evolveum.midpoint.gui.impl.component.menu.LeftMenuPanel)

Aggregations

ItemPanelSettings (com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings)3 Panel (org.apache.wicket.markup.html.panel.Panel)3 IModel (org.apache.wicket.model.IModel)3 BasePanel (com.evolveum.midpoint.gui.api.component.BasePanel)2 WebComponentUtil (com.evolveum.midpoint.gui.api.util.WebComponentUtil)2 ItemPanelSettingsBuilder (com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder)2 ItemVisibility (com.evolveum.midpoint.web.component.prism.ItemVisibility)2 DisplayNamePanel (com.evolveum.midpoint.gui.api.component.DisplayNamePanel)1 PanelTab (com.evolveum.midpoint.gui.api.component.tabs.PanelTab)1 PrismObjectWrapperFactory (com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory)1 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)1 com.evolveum.midpoint.gui.api.prism.wrapper (com.evolveum.midpoint.gui.api.prism.wrapper)1 ItemMandatoryHandler (com.evolveum.midpoint.gui.api.prism.wrapper.ItemMandatoryHandler)1 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)1 PrismContainerValueWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismContainerValueWrapper)1 LeftMenuPanel (com.evolveum.midpoint.gui.impl.component.menu.LeftMenuPanel)1 ErrorPanel (com.evolveum.midpoint.gui.impl.error.ErrorPanel)1 PrismContainerValuePanel (com.evolveum.midpoint.gui.impl.prism.panel.PrismContainerValuePanel)1 Containerable (com.evolveum.midpoint.prism.Containerable)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1