Search in sources :

Example 11 with ObjectBrowserPanel

use of com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel in project midpoint by Evolveum.

the class ResourceContentPanel method createRowMenuItems.

private List<InlineMenuItem> createRowMenuItems() {
    List<InlineMenuItem> items = new ArrayList<>();
    items.add(new InlineMenuItem(createStringResource("pageContentAccounts.menu.enableAccount"), true) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<ShadowType>>() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onSubmit(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        updateResourceObjectStatusPerformed(null, target, true);
                    } else {
                        SelectableBeanImpl<ShadowType> shadow = getRowModel().getObject();
                        updateResourceObjectStatusPerformed(shadow.getValue(), target, true);
                    }
                }
            };
        }
    });
    items.add(new InlineMenuItem(createStringResource("pageContentAccounts.menu.disableAccount"), true) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<ShadowType>>() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onSubmit(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        updateResourceObjectStatusPerformed(null, target, false);
                    } else {
                        SelectableBeanImpl<ShadowType> shadow = getRowModel().getObject();
                        updateResourceObjectStatusPerformed(shadow.getValue(), target, false);
                    }
                }
            };
        }
    });
    items.add(new InlineMenuItem(createStringResource("pageContentAccounts.menu.deleteAccount"), true) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<ShadowType>>() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onSubmit(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        deleteResourceObjectPerformed(null, target);
                    } else {
                        SelectableBeanImpl<ShadowType> shadow = getRowModel().getObject();
                        deleteResourceObjectPerformed(shadow.getValue(), target);
                    }
                }
            };
        }
    });
    items.add(new ButtonInlineMenuItem(createStringResource("pageContentAccounts.menu.importAccount"), true) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<ShadowType>>() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onSubmit(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        importResourceObject(null, target);
                    } else {
                        SelectableBeanImpl<ShadowType> shadow = getRowModel().getObject();
                        importResourceObject(shadow.getValue(), target);
                    }
                }
            };
        }

        @Override
        public CompositedIconBuilder getIconCompositedBuilder() {
            return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_IMPORT_MENU_ITEM);
        }
    });
    // items.add(new InlineMenuItem());
    items.add(new InlineMenuItem(createStringResource("pageContentAccounts.menu.removeOwner"), true) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<ShadowType>>() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onSubmit(AjaxRequestTarget target) {
                    if (getRowModel() == null) {
                        changeOwner(null, target, null, Operation.REMOVE);
                    } else {
                        SelectableBeanImpl<ShadowType> shadow = getRowModel().getObject();
                        changeOwner(shadow.getValue(), target, null, Operation.REMOVE);
                    }
                }
            };
        }
    });
    items.add(new ButtonInlineMenuItem(createStringResource("pageContentAccounts.menu.changeOwner"), true) {

        private static final long serialVersionUID = 1L;

        @Override
        public InlineMenuItemAction initAction() {
            return new ColumnMenuAction<SelectableBeanImpl<ShadowType>>() {

                private static final long serialVersionUID = 1L;

                @Override
                public void onSubmit(AjaxRequestTarget target) {
                    final SelectableBeanImpl<ShadowType> shadow = getRowModel().getObject();
                    ObjectBrowserPanel<FocusType> browser = new ObjectBrowserPanel<>(getPageBase().getMainPopupBodyId(), UserType.class, WebComponentUtil.createFocusTypeList(), false, getPageBase()) {

                        @Override
                        protected void onSelectPerformed(AjaxRequestTarget target, FocusType focus) {
                            changeOwner(shadow.getValue(), target, focus, Operation.MODIFY);
                        }
                    };
                    getPageBase().showMainPopup(browser, target);
                }
            };
        }

        @Override
        public CompositedIconBuilder getIconCompositedBuilder() {
            return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_RECONCILE_MENU_ITEM);
        }

        @Override
        public boolean isHeaderMenuItem() {
            return false;
        }
    });
    return items;
}
Also used : SelectableBeanImpl(com.evolveum.midpoint.web.component.util.SelectableBeanImpl) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)

Example 12 with ObjectBrowserPanel

use of com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel 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 13 with ObjectBrowserPanel

use of com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel 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)

Example 14 with ObjectBrowserPanel

use of com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel in project midpoint by Evolveum.

the class ConstructionAssociationPanel method addNewShadowRefValuePerformed.

private void addNewShadowRefValuePerformed(AjaxRequestTarget target, ResourceAssociationDefinition def) {
    ObjectFilter filter = WebComponentUtil.createAssociationShadowRefFilter(def, getPageBase().getPrismContext(), resourceModel.getObject().getOid());
    ObjectBrowserPanel<ShadowType> objectBrowserPanel = new ObjectBrowserPanel<ShadowType>(getPageBase().getMainPopupBodyId(), ShadowType.class, Collections.singletonList(ShadowType.COMPLEX_TYPE), false, getPageBase(), filter) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSelectPerformed(AjaxRequestTarget target, ShadowType object) {
            getPageBase().hideMainPopup(target);
            try {
                PrismContainerWrapper<ConstructionType> constructionContainerWrapper = ConstructionAssociationPanel.this.getModelObject();
                PrismContainerWrapper<ResourceObjectAssociationType> associationWrapper = constructionContainerWrapper.findContainer(ConstructionType.F_ASSOCIATION);
                List<PrismContainerValue<ResourceObjectAssociationType>> associationValueList = associationWrapper.getItem().getValues();
                PrismContainerValue<ResourceObjectAssociationType> associationValue;
                if (CollectionUtils.isEmpty(associationValueList)) {
                    associationValue = associationWrapper.getItem().createNewValue();
                } else {
                    associationValue = associationValueList.get(0);
                }
                ItemName associationRefPath = def.getName();
                associationValue.asContainerable().setRef(new ItemPathType(associationRefPath));
                ExpressionType newAssociationExpression = associationValue.asContainerable().beginOutbound().beginExpression();
                ExpressionUtil.addShadowRefEvaluatorValue(newAssociationExpression, object.getOid(), getPageBase().getPrismContext());
            } catch (SchemaException ex) {
                LOGGER.error("Couldn't find association container: {}", ex.getLocalizedMessage());
            }
            target.add(ConstructionAssociationPanel.this);
        }
    };
    getPageBase().showMainPopup(objectBrowserPanel, target);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) ItemName(com.evolveum.midpoint.prism.path.ItemName)

Aggregations

ObjectBrowserPanel (com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel)14 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)14 QName (javax.xml.namespace.QName)11 ArrayList (java.util.ArrayList)8 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)6 ListItem (org.apache.wicket.markup.html.list.ListItem)6 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)4 List (java.util.List)4 IModel (org.apache.wicket.model.IModel)4 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)3 InlineMenuItemAction (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction)3 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)3 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)3 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)2 MultivalueContainerListPanelWithDetailsPanel (com.evolveum.midpoint.gui.impl.component.MultivalueContainerListPanelWithDetailsPanel)2 AssignmentObjectRelation (com.evolveum.midpoint.model.api.AssignmentObjectRelation)2 AssignmentEditorDto (com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto)2 AssignmentTablePanel (com.evolveum.midpoint.web.component.assignment.AssignmentTablePanel)2 DelegationEditorPanel (com.evolveum.midpoint.web.component.assignment.DelegationEditorPanel)2 GenericMultiValueLabelEditPanel (com.evolveum.midpoint.web.component.form.multivalue.GenericMultiValueLabelEditPanel)2