Search in sources :

Example 1 with AssignmentTablePanel

use of com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel in project midpoint by Evolveum.

the class PageAssignmentsList method initLayout.

public void initLayout() {
    setOutputMarkupId(true);
    MidpointForm mainForm = new MidpointForm(ID_FORM);
    mainForm.setOutputMarkupId(true);
    add(mainForm);
    AssignmentTablePanel panel = new AssignmentTablePanel<UserType>(ID_ASSIGNMENT_TABLE_PANEL, assignmentsModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected List<InlineMenuItem> createAssignmentMenu() {
            List<InlineMenuItem> items = new ArrayList<>();
            InlineMenuItem item = new InlineMenuItem(createStringResource("PageAssignmentsList.deleteAllItemsFromShoppingCart")) {

                private static final long serialVersionUID = 1L;

                @Override
                public InlineMenuItemAction initAction() {
                    return new InlineMenuItemAction() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            getModelObject().forEach(assignmentEditorDto -> assignmentEditorDto.setSelected(true));
                            deleteAssignmentPerformed(target, null);
                        }
                    };
                }
            };
            items.add(item);
            return items;
        }

        @Override
        public IModel<String> getLabel() {
            return createStringResource("PageAssignmentsList.assignmentsToRequest");
        }

        @Override
        protected boolean isRelationEditable() {
            return false;
        }

        @Override
        protected void reloadMainFormButtons(AjaxRequestTarget target) {
            Component requestButton = PageAssignmentsList.this.get(createComponentPath(ID_FORM, ID_REQUEST_BUTTON));
            if (requestButton != null) {
                refreshRequestButton(requestButton);
            }
            target.add(getFeedbackPanel());
            target.add(requestButton);
        }
    };
    mainForm.add(panel);
    UserSelectionButton targetUserPanel = new UserSelectionButton(ID_TARGET_USER_PANEL, new IModel<List<UserType>>() {

        @Override
        public List<UserType> getObject() {
            return WebComponentUtil.loadTargetUsersListForShoppingCart(OPERATION_LOAD_ASSIGNMENT_TARGET_USER_OBJECT, PageAssignmentsList.this);
        }
    }, true, createStringResource("AssignmentCatalogPanel.selectTargetUser")) {

        private static final long serialVersionUID = 1L;

        @Override
        protected String getUserButtonLabel() {
            return getTargetUserSelectionButtonLabel(getModelObject());
        }

        @Override
        protected void onDeleteSelectedUsersPerformed(AjaxRequestTarget target) {
            super.onDeleteSelectedUsersPerformed(target);
            getSessionStorage().getRoleCatalog().setTargetUserOidsList(new ArrayList<>());
            targetUserChangePerformed(target);
        }

        @Override
        protected void multipleUsersSelectionPerformed(AjaxRequestTarget target, List<UserType> usersList) {
            if (CollectionUtils.isNotEmpty(usersList)) {
                List<String> usersOidsList = new ArrayList<>();
                usersList.forEach(user -> usersOidsList.add(user.getOid()));
                getSessionStorage().getRoleCatalog().setTargetUserOidsList(usersOidsList);
            }
            targetUserChangePerformed(target);
        }
    };
    targetUserPanel.setOutputMarkupId(true);
    mainForm.add(targetUserPanel);
    TextArea<String> descriptionInput = new TextArea<>(ID_DESCRIPTION, descriptionModel);
    descriptionInput.add(new AjaxFormComponentUpdatingBehavior("blur") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            getSessionStorage().getRoleCatalog().setRequestDescription(getDescriptionComponent().getValue());
        }
    });
    mainForm.add(descriptionInput);
    AjaxButton back = new AjaxButton(ID_BACK, createStringResource("PageAssignmentDetails.backButton")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            redirectBack();
        }
    };
    mainForm.add(back);
    AjaxButton requestAssignments = new AjaxButton(ID_REQUEST_BUTTON, createStringResource("PageAssignmentsList.requestButton")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (getSessionStorage().getRoleCatalog().getTargetUserOidsList() == null || getSessionStorage().getRoleCatalog().getTargetUserOidsList().size() <= 1) {
                onSingleUserRequestPerformed(target);
            } else {
                onMultiUserRequestPerformed(target);
            }
        }
    };
    requestAssignments.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isEnabled() {
            return isRequestButtonEnabled();
        }
    });
    mainForm.add(requestAssignments);
    refreshRequestButton(requestAssignments);
    AjaxSubmitButton resolveAssignments = new AjaxSubmitButton(ID_RESOLVE_CONFLICTS_BUTTON, createStringResource("PageAssignmentsList.resolveConflicts")) {

        @Override
        protected void onError(AjaxRequestTarget target) {
            target.add(getFeedbackPanel());
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            PageAssignmentsList.this.navigateToNext(PageAssignmentConflicts.class);
        }
    };
    resolveAssignments.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !getSessionStorage().getRoleCatalog().isMultiUserRequest() && !areConflictsResolved();
        }
    });
    mainForm.add(resolveAssignments);
}
Also used : AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) UserSelectionButton(com.evolveum.midpoint.web.component.assignment.UserSelectionButton) TextArea(org.apache.wicket.markup.html.form.TextArea) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) AssignmentTablePanel(com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) Component(org.apache.wicket.Component)

Example 2 with AssignmentTablePanel

use of com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel in project midpoint by Evolveum.

the class FocusAssignmentsTabPanel method initLayout.

private void initLayout() {
    WebMarkupContainer assignments = new WebMarkupContainer(ID_ASSIGNMENTS);
    assignments.setOutputMarkupId(true);
    add(assignments);
    AssignmentTablePanel panel = new AssignmentTablePanel(ID_ASSIGNMENTS_PANEL, createStringResource("FocusType.assignment"), assignmentsModel) {

        @Override
        protected boolean getAssignmentMenuVisibility() {
            return !getObjectWrapper().isReadonly();
        }

        @Override
        protected void showAllAssignments(AjaxRequestTarget target) {
            List<AssignmentsPreviewDto> assignmentsPreviewDtos = ((PageAdminFocus) getPageBase()).recomputeAssignmentsPerformed(target);
            AssignmentPreviewDialog dialog = new AssignmentPreviewDialog(getPageBase().getMainPopupBodyId(), assignmentsPreviewDtos, new ArrayList<String>(), getPageBase());
            getPageBase().showMainPopup(dialog, target);
        }
    };
    assignments.add(panel);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PageAdminFocus(com.evolveum.midpoint.web.page.admin.PageAdminFocus) AssignmentTablePanel(com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 3 with AssignmentTablePanel

use of com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel in project midpoint by Evolveum.

the class UserDelegationsPanel method initLayout.

protected void initLayout() {
    WebMarkupContainer delegations = new WebMarkupContainer(ID_DELEGATIONS_CONTAINER);
    delegations.setOutputMarkupId(true);
    add(delegations);
    AssignmentTablePanel panel = new AssignmentTablePanel<UserType>(ID_DELEGATIONS_PANEL, getObjectDetailsModels().getDelegationsModel()) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateAssignmentDetailsPanel(ListItem<AssignmentEditorDto> item) {
            DelegationEditorPanel editor = new DelegationEditorPanel(ID_ROW, item.getModel(), false, getObjectDetailsModels().getPrivilegesListModel());
            item.add(editor);
        }

        @Override
        public String getExcludeOid() {
            return getObjectWrapper().getOid();
        }

        public IModel<String> getLabel() {
            return createStringResource("FocusType.delegations");
        }

        @Override
        protected List<InlineMenuItem> createAssignmentMenu() {
            List<InlineMenuItem> items = new ArrayList<>();
            InlineMenuItem item;
            if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_DELEGATE_ACTION_URL)) {
                item = new InlineMenuItem(createStringResource("AssignmentTablePanel.menu.addDelegation")) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public InlineMenuItemAction initAction() {
                        return new InlineMenuItemAction() {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                List<QName> supportedTypes = new ArrayList<>();
                                supportedTypes.add(UserType.COMPLEX_TYPE);
                                ObjectFilter filter = getPrismContext().queryFactory().createInOid(getObjectWrapper().getOid());
                                ObjectFilter notFilter = getPrismContext().queryFactory().createNot(filter);
                                ObjectBrowserPanel<UserType> panel = new ObjectBrowserPanel<UserType>(getPageBase().getMainPopupBodyId(), UserType.class, supportedTypes, false, getPageBase(), notFilter) {

                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    protected void onSelectPerformed(AjaxRequestTarget target, UserType user) {
                                        getPageBase().hideMainPopup(target);
                                        List<ObjectType> newAssignmentsList = new ArrayList<>();
                                        newAssignmentsList.add(user);
                                        addSelectedAssignablePerformed(target, newAssignmentsList, null, getPageBase().getMainPopup().getId());
                                    }
                                };
                                panel.setOutputMarkupId(true);
                                getPageBase().showMainPopup(panel, target);
                            }
                        };
                    }
                };
                items.add(item);
            }
            if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_UNASSIGN_ACTION_URI)) {
                item = new InlineMenuItem(createStringResource("AssignmentTablePanel.menu.deleteDelegation")) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public InlineMenuItemAction initAction() {
                        return new InlineMenuItemAction() {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                deleteAssignmentPerformed(target, null);
                            }
                        };
                    }
                };
                items.add(item);
            }
            return items;
        }

        @Override
        protected String getNoAssignmentsSelectedMessage() {
            return getString("AssignmentTablePanel.message.noDelegationsSelected");
        }

        @Override
        protected String getAssignmentsDeleteMessage(AssignmentEditorDto dto) {
            return createStringResource("AssignmentTablePanel.modal.message.deleteDelegation", getSelectedAssignments().size()).getString();
        }

        @Override
        protected List<AssignmentEditorDto> getAssignmentListToProcess(AssignmentEditorDto dto) {
            if (dto != null) {
                return Collections.singletonList(dto);
            } else {
                return getSelectedAssignments();
            }
        }

        @Override
        protected void addSelectedAssignablePerformed(AjaxRequestTarget target, List<ObjectType> newAssignments, QName relation, String popupId) {
            ModalWindow window = (ModalWindow) get(popupId);
            if (window != null) {
                window.close(target);
            }
            getPageBase().hideMainPopup(target);
            if (newAssignments.isEmpty()) {
                warn(getString("AssignmentTablePanel.message.noAssignmentSelected"));
                target.add(getPageBase().getFeedbackPanel());
                return;
            }
            for (ObjectType object : newAssignments) {
                try {
                    AssignmentEditorDto dto = AssignmentEditorDto.createDtoAddFromSelectedObject(((PrismObject<UserType>) getObjectWrapper().getObject()).asObjectable(), WebComponentUtil.getDefaultRelationOrFail(RelationKindType.DELEGATION), getPageBase(), (UserType) object);
                    dto.setPrivilegeLimitationList(getPrivilegesListModel().getObject());
                    getDelegationModel().getObject().add(dto);
                } catch (Exception e) {
                    error(getString("AssignmentTablePanel.message.couldntAssignObject", object.getName(), e.getMessage()));
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't assign object", e);
                }
            }
            reloadAssignmentsPanel(target);
            reloadMainFormButtons(target);
        }
    };
    delegations.add(panel);
}
Also used : DelegationEditorPanel(com.evolveum.midpoint.web.component.assignment.DelegationEditorPanel) AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AssignmentTablePanel(com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow)

Example 4 with AssignmentTablePanel

use of com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel in project midpoint by Evolveum.

the class UserDelegationsTabPanel method initLayout.

private void initLayout() {
    WebMarkupContainer delegations = new WebMarkupContainer(ID_DELEGATIONS_CONTAINER);
    delegations.setOutputMarkupId(true);
    add(delegations);
    AssignmentTablePanel panel = new AssignmentTablePanel<UserType>(ID_DELEGATIONS_PANEL, delegationsModel) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateAssignmentDetailsPanel(ListItem<AssignmentEditorDto> item) {
            DelegationEditorPanel editor = new DelegationEditorPanel(ID_ROW, item.getModel(), false, privilegesListModel);
            item.add(editor);
        }

        @Override
        public String getExcludeOid() {
            return getObjectWrapper().getOid();
        }

        public IModel<String> getLabel() {
            return createStringResource("FocusType.delegations");
        }

        @Override
        protected List<InlineMenuItem> createAssignmentMenu() {
            List<InlineMenuItem> items = new ArrayList<>();
            InlineMenuItem item;
            if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_DELEGATE_ACTION_URL)) {
                item = new InlineMenuItem(createStringResource("AssignmentTablePanel.menu.addDelegation")) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public InlineMenuItemAction initAction() {
                        return new InlineMenuItemAction() {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                List<QName> supportedTypes = new ArrayList<>();
                                supportedTypes.add(UserType.COMPLEX_TYPE);
                                ObjectFilter filter = getPrismContext().queryFactory().createInOid(getObjectWrapper().getOid());
                                ObjectFilter notFilter = getPrismContext().queryFactory().createNot(filter);
                                ObjectBrowserPanel<UserType> panel = new ObjectBrowserPanel<UserType>(getPageBase().getMainPopupBodyId(), UserType.class, supportedTypes, false, getPageBase(), notFilter) {

                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    protected void onSelectPerformed(AjaxRequestTarget target, UserType user) {
                                        getPageBase().hideMainPopup(target);
                                        List<ObjectType> newAssignmentsList = new ArrayList<>();
                                        newAssignmentsList.add(user);
                                        addSelectedAssignablePerformed(target, newAssignmentsList, null, getPageBase().getMainPopup().getId());
                                    }
                                };
                                panel.setOutputMarkupId(true);
                                getPageBase().showMainPopup(panel, target);
                            }
                        };
                    }
                };
                items.add(item);
            }
            if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_ADMIN_UNASSIGN_ACTION_URI)) {
                item = new InlineMenuItem(createStringResource("AssignmentTablePanel.menu.deleteDelegation")) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public InlineMenuItemAction initAction() {
                        return new InlineMenuItemAction() {

                            private static final long serialVersionUID = 1L;

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                deleteAssignmentPerformed(target, null);
                            }
                        };
                    }
                };
                items.add(item);
            }
            return items;
        }

        @Override
        protected String getNoAssignmentsSelectedMessage() {
            return getString("AssignmentTablePanel.message.noDelegationsSelected");
        }

        @Override
        protected String getAssignmentsDeleteMessage(AssignmentEditorDto dto) {
            return createStringResource("AssignmentTablePanel.modal.message.deleteDelegation", getSelectedAssignments().size()).getString();
        }

        @Override
        protected List<AssignmentEditorDto> getAssignmentListToProcess(AssignmentEditorDto dto) {
            if (dto != null) {
                return Collections.singletonList(dto);
            } else {
                return getSelectedAssignments();
            }
        }

        @Override
        protected void addSelectedAssignablePerformed(AjaxRequestTarget target, List<ObjectType> newAssignments, QName relation, String popupId) {
            ModalWindow window = (ModalWindow) get(popupId);
            if (window != null) {
                window.close(target);
            }
            getPageBase().hideMainPopup(target);
            if (newAssignments.isEmpty()) {
                warn(getString("AssignmentTablePanel.message.noAssignmentSelected"));
                target.add(getPageBase().getFeedbackPanel());
                return;
            }
            for (ObjectType object : newAssignments) {
                try {
                    AssignmentEditorDto dto = AssignmentEditorDto.createDtoAddFromSelectedObject(((PrismObject<UserType>) getObjectWrapper().getObject()).asObjectable(), WebComponentUtil.getDefaultRelationOrFail(RelationKindType.DELEGATION), getPageBase(), (UserType) object);
                    dto.setPrivilegeLimitationList(privilegesListModel.getObject());
                    delegationsModel.getObject().add(dto);
                } catch (Exception e) {
                    error(getString("AssignmentTablePanel.message.couldntAssignObject", object.getName(), e.getMessage()));
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't assign object", e);
                }
            }
            reloadAssignmentsPanel(target);
            reloadMainFormButtons(target);
        }
    };
    delegations.add(panel);
}
Also used : DelegationEditorPanel(com.evolveum.midpoint.web.component.assignment.DelegationEditorPanel) AssignmentEditorDto(com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AssignmentTablePanel(com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ArrayList(java.util.ArrayList) List(java.util.List) ListItem(org.apache.wicket.markup.html.list.ListItem) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow)

Aggregations

AssignmentTablePanel (com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel)4 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)3 InlineMenuItemAction (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction)3 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)3 ObjectBrowserPanel (com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel)2 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)2 AssignmentEditorDto (com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto)2 DelegationEditorPanel (com.evolveum.midpoint.web.component.assignment.DelegationEditorPanel)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 QName (javax.xml.namespace.QName)2 ModalWindow (org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow)2 ListItem (org.apache.wicket.markup.html.list.ListItem)2 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)1 UserSelectionButton (com.evolveum.midpoint.web.component.assignment.UserSelectionButton)1 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 PageAdminFocus (com.evolveum.midpoint.web.page.admin.PageAdminFocus)1