Search in sources :

Example 1 with PrismObjectWrapperFactory

use of com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory 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 PrismObjectWrapperFactory

use of com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory in project midpoint by Evolveum.

the class PageResource method createTabsPanel.

private AjaxTabbedPanel<ITab> createTabsPanel() {
    List<ITab> tabs = new ArrayList<>();
    tabs.add(new PanelTab(createStringResource("PageResource.tab.details")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceDetailsTabPanel(panelId, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.tasks")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceTasksPanel(panelId, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.account")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceContentTabPanel(panelId, ShadowKindType.ACCOUNT, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.entitlement")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceContentTabPanel(panelId, ShadowKindType.ENTITLEMENT, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.generic")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceContentTabPanel(panelId, ShadowKindType.GENERIC, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.content.others")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceContentTabPanel(panelId, null, resourceModel);
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.connector")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            return new ResourceConnectorPanel(panelId, loadWrapperModel(resourceModel));
        }
    });
    tabs.add(new PanelTab(createStringResource("PageResource.tab.schemaHandling")) {

        private static final long serialVersionUID = 1L;

        @Override
        public WebMarkupContainer createPanel(String panelId) {
            PrismObjectWrapperFactory<ResourceType> resourceFactory = PageResource.this.findObjectWrapperFactory(resourceModel.getObject().getDefinition());
            Task task = createSimpleTask("Create resource wrapper");
            OperationResult result = task.getResult();
            WrapperContext ctx = new WrapperContext(task, result);
            PrismObjectWrapper<ResourceType> resourceWrapper;
            try {
                resourceWrapper = resourceFactory.createObjectWrapper(resourceModel.getObject(), ItemStatus.NOT_CHANGED, ctx);
            } catch (SchemaException e) {
                resourceWrapper = null;
            }
            if (resourceWrapper == null) {
                return new WebMarkupContainer(panelId);
            }
            return new ResourceSchemaHandlingTabPanel(panelId, PrismContainerWrapperModel.fromContainerWrapper(Model.of(resourceWrapper), ResourceType.F_SCHEMA_HANDLING));
        }
    });
    AjaxTabbedPanel<ITab> resourceTabs = new AjaxTabbedPanel<ITab>(ID_TAB_PANEL, tabs) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onTabChange(int index) {
            updateBreadcrumbParameters(PARAMETER_SELECTED_TAB, index);
        }
    };
    resourceTabs.setOutputMarkupId(true);
    return resourceTabs;
}
Also used : PanelTab(com.evolveum.midpoint.gui.api.component.tabs.PanelTab) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ITab(org.apache.wicket.extensions.markup.html.tabs.ITab) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObjectWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper) WrapperContext(com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext) AjaxTabbedPanel(com.evolveum.midpoint.web.component.AjaxTabbedPanel) PrismObjectWrapperFactory(com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory)

Aggregations

PrismObjectWrapperFactory (com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory)2 WrapperContext (com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 BasePanel (com.evolveum.midpoint.gui.api.component.BasePanel)1 PanelTab (com.evolveum.midpoint.gui.api.component.tabs.PanelTab)1 com.evolveum.midpoint.gui.api.prism.wrapper (com.evolveum.midpoint.gui.api.prism.wrapper)1 PrismObjectWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper)1 WebComponentUtil (com.evolveum.midpoint.gui.api.util.WebComponentUtil)1 ItemPanelSettings (com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettings)1 ItemPanelSettingsBuilder (com.evolveum.midpoint.gui.impl.prism.panel.ItemPanelSettingsBuilder)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)1 TaskHandler (com.evolveum.midpoint.task.api.TaskHandler)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 Trace (com.evolveum.midpoint.util.logging.Trace)1 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)1 AjaxTabbedPanel (com.evolveum.midpoint.web.component.AjaxTabbedPanel)1