Search in sources :

Example 1 with EnableBehaviour

use of com.evolveum.midpoint.web.component.util.EnableBehaviour in project midpoint by Evolveum.

the class MultiValueObjectChoosePanel method initEmptyModelInputPanel.

private void initEmptyModelInputPanel() {
    WebMarkupContainer emptyModelContainer = new WebMarkupContainer(ID_EMPTY_MODEL_CONTAINER);
    emptyModelContainer.setOutputMarkupId(true);
    emptyModelContainer.add(new VisibleBehaviour(() -> isEmptyModel() || emptyObjectPanelDisplay));
    add(emptyModelContainer);
    ValueChoosePanel<R> emptyModelPanel = new ValueChoosePanel<R>(ID_EMPTY_MODEL_INPUT, new IModel<R>() {

        @Override
        public R getObject() {
            return null;
        }
    }) {

        private static final long serialVersionUID = 1L;

        @Override
        protected ObjectFilter createCustomFilter() {
            return MultiValueObjectChoosePanel.this.createCustomFilter();
        }

        @Override
        public List<QName> getSupportedTypes() {
            return MultiValueObjectChoosePanel.this.getSupportedTypes();
        }

        @Override
        protected <O extends ObjectType> void choosePerformed(AjaxRequestTarget target, O object) {
            emptyObjectPanelDisplay = false;
            chooseObjectPerformed(target, object);
            target.add(MultiValueObjectChoosePanel.this);
        }
    };
    emptyModelPanel.setOutputMarkupId(true);
    emptyModelContainer.add(emptyModelPanel);
    WebMarkupContainer buttonsWhenEmptyContainer = new WebMarkupContainer(ID_BUTTONS_WHEN_EMPTY_CONTAINER);
    buttonsWhenEmptyContainer.setOutputMarkupId(true);
    emptyModelContainer.add(buttonsWhenEmptyContainer);
    AjaxButton addWhenEmptyButton = new AjaxButton(ID_ADD_WHEN_EMPTY_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
        // will be disabled all the time, nothing to do here
        }
    };
    addWhenEmptyButton.setOutputMarkupId(true);
    addWhenEmptyButton.add(new EnableBehaviour(() -> false));
    buttonsWhenEmptyContainer.add(addWhenEmptyButton);
    AjaxButton removeWhenEmptyButton = new AjaxButton(ID_REMOVE_WHEN_EMPTY_BUTTON) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
        // will be disabled all the time, nothing to do here
        }
    };
    removeWhenEmptyButton.setOutputMarkupId(true);
    removeWhenEmptyButton.add(new EnableBehaviour(() -> false));
    buttonsWhenEmptyContainer.add(removeWhenEmptyButton);
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) QName(javax.xml.namespace.QName) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) ValueChoosePanel(com.evolveum.midpoint.web.component.form.ValueChoosePanel) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Example 2 with EnableBehaviour

use of com.evolveum.midpoint.web.component.util.EnableBehaviour in project midpoint by Evolveum.

the class InlineMenuButtonColumn method getPanel.

private Component getPanel(String componentId, IModel<T> rowModel, int numberOfButtons, boolean isHeaderPanel) {
    List<InlineMenuItem> filteredMenuItems = new ArrayList<>();
    for (InlineMenuItem menuItem : menuItems) {
        if (isHeaderPanel && !menuItem.isHeaderMenuItem()) {
            continue;
        }
        if (rowModel != null && menuItem.getAction() != null && menuItem.getAction() instanceof ColumnMenuAction) {
            ((ColumnMenuAction) menuItem.getAction()).setRowModel(rowModel);
        }
        if (menuItem.getVisibilityChecker() != null && !menuItem.getVisibilityChecker().isVisible(rowModel, isHeaderPanel)) {
            continue;
        }
        filteredMenuItems.add(menuItem);
    }
    List<ButtonInlineMenuItem> buttonMenuItems = new ArrayList<>();
    menuItems.forEach(menuItem -> {
        if (menuItem instanceof ButtonInlineMenuItem) {
            if (isHeaderPanel && !menuItem.isHeaderMenuItem() || !menuItem.getVisible().getObject()) {
                return;
            }
            if (menuItem.getVisibilityChecker() != null && !menuItem.getVisibilityChecker().isVisible(rowModel, isHeaderPanel)) {
                return;
            }
            buttonMenuItems.add((ButtonInlineMenuItem) menuItem);
        }
    });
    if (filteredMenuItems.isEmpty()) {
        // this is hack, TODO: cleanup and refactor soif there aren't any inline (row) actions, nothing is displayed
        return new Label(componentId);
    }
    return new MenuMultiButtonPanel<T>(componentId, rowModel, buttonMenuItems.size(), Model.ofList(filteredMenuItems)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Component createButton(int index, String componentId, IModel<T> model) {
            CompositedIconBuilder builder = getIconCompositedBuilder(index, buttonMenuItems);
            AjaxCompositedIconButton btn = new AjaxCompositedIconButton(componentId, builder.build(), Model.of(getButtonTitle(index, buttonMenuItems))) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    setRowModelToButtonAction(rowModel, buttonMenuItems);
                    buttonMenuItemClickPerformed(index, buttonMenuItems, target);
                }
            };
            btn.add(AttributeAppender.append("class", " btn btn-default btn-xs"));
            btn.add(new EnableBehaviour(() -> isButtonMenuItemEnabled(model)));
            return btn;
        }

        @Override
        protected void onBeforeClickMenuItem(AjaxRequestTarget target, InlineMenuItemAction action, IModel<InlineMenuItem> item) {
            if (action instanceof ColumnMenuAction) {
                if (!isHeaderPanel) {
                    ((ColumnMenuAction) action).setRowModel(rowModel);
                } else {
                    ((ColumnMenuAction) action).setRowModel(null);
                }
            }
        }
    };
}
Also used : AjaxCompositedIconButton(com.evolveum.midpoint.gui.impl.component.AjaxCompositedIconButton) IModel(org.apache.wicket.model.IModel) MenuMultiButtonPanel(com.evolveum.midpoint.web.component.data.MenuMultiButtonPanel) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) CompositedIconBuilder(com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Example 3 with EnableBehaviour

use of com.evolveum.midpoint.web.component.util.EnableBehaviour in project midpoint by Evolveum.

the class PageCertDecisions method initColumns.

// private void addVisibleOnWarningBehavior(Component c) {
// c.add(new VisibleEnableBehaviour() {
// @Override
// public boolean isVisible() {
// return PageCertDecisions.this.getFeedbackMessages().hasMessage(FeedbackMessage.WARNING);
// }
// });
// }
private List<IColumn<CertWorkItemDto, String>> initColumns() {
    List<IColumn<CertWorkItemDto, String>> columns = new ArrayList<>();
    IColumn<CertWorkItemDto, String> column;
    column = new CheckBoxHeaderColumn<>();
    columns.add(column);
    column = helper.createTypeColumn(OBJECT, this);
    columns.add(column);
    column = helper.createObjectNameColumn(this, "PageCertDecisions.table.objectName");
    columns.add(column);
    column = helper.createTypeColumn(TARGET, this);
    columns.add(column);
    column = helper.createTargetNameColumn(this, "PageCertDecisions.table.targetName");
    columns.add(column);
    if (isDisplayingAllItems()) {
        column = helper.createReviewerNameColumn(this, "PageCertDecisions.table.reviewer");
        columns.add(column);
    }
    column = helper.createDetailedInfoColumn(this);
    columns.add(column);
    column = helper.createConflictingNameColumn(this, "PageCertDecisions.table.conflictingTargetName");
    columns.add(column);
    if (WebComponentUtil.isAuthorized(AuthorizationConstants.AUTZ_UI_CERTIFICATION_ALL_URL, AuthorizationConstants.AUTZ_UI_CERTIFICATION_CAMPAIGN_URL)) {
        column = new AjaxLinkColumn<CertWorkItemDto>(createStringResource("PageCertDecisions.table.campaignName"), SearchingUtils.CAMPAIGN_NAME, CertWorkItemDto.F_CAMPAIGN_NAME) {

            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String componentId, IModel<CertWorkItemDto> rowModel) {
                super.populateItem(item, componentId, rowModel);
                AccessCertificationCampaignType campaign = rowModel.getObject().getCampaign();
                if (campaign != null && campaign.getDescription() != null) {
                    item.add(AttributeModifier.replace("title", campaign.getDescription()));
                    item.add(new TooltipBehavior());
                }
            }

            @Override
            public void onClick(AjaxRequestTarget target, IModel<CertWorkItemDto> rowModel) {
                CertWorkItemDto dto = rowModel.getObject();
                PageParameters parameters = new PageParameters();
                parameters.add(OnePageParameterEncoder.PARAMETER, dto.getCampaignRef().getOid());
                navigateToNext(PageCertCampaign.class, parameters);
            }
        };
    } else {
        column = new AbstractColumn<CertWorkItemDto, String>(createStringResource("PageCertDecisions.table.campaignName"), SearchingUtils.CAMPAIGN_NAME) {

            private static final long serialVersionUID = 1L;

            @Override
            public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String componentId, final IModel<CertWorkItemDto> rowModel) {
                item.add(new Label(componentId, new IModel<Object>() {

                    @Override
                    public Object getObject() {
                        return rowModel.getObject().getCampaignName();
                    }
                }));
            }
        };
    }
    columns.add(column);
    column = new PropertyColumn<CertWorkItemDto, String>(createStringResource("PageCertDecisions.table.iteration"), CertCaseOrWorkItemDto.F_ITERATION) {

        private static final long serialVersionUID = 1L;

        @Override
        public String getCssClass() {
            return "countLabel";
        }
    };
    columns.add(column);
    column = new AbstractColumn<CertWorkItemDto, String>(createStringResource("PageCertDecisions.table.campaignStage")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String componentId, final IModel<CertWorkItemDto> rowModel) {
            item.add(new Label(componentId, new IModel<String>() {

                @Override
                public String getObject() {
                    CertWorkItemDto dto = rowModel.getObject();
                    return dto.getCampaignStageNumber() + "/" + dto.getCampaignStageCount();
                }
            }));
            String stageName = rowModel.getObject().getCurrentStageName();
            if (stageName != null) {
                item.add(AttributeModifier.replace("title", stageName));
                item.add(new TooltipBehavior());
            }
        }

        @Override
        public String getCssClass() {
            return "countLabel";
        }
    };
    columns.add(column);
    column = new AbstractColumn<CertWorkItemDto, String>(createStringResource("PageCertDecisions.table.escalation")) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String componentId, final IModel<CertWorkItemDto> rowModel) {
            item.add(new Label(componentId, new IModel<String>() {

                @Override
                public String getObject() {
                    CertWorkItemDto dto = rowModel.getObject();
                    Integer n = dto.getEscalationLevelNumber();
                    return n != null ? String.valueOf(n) : null;
                }
            }));
            String info = rowModel.getObject().getEscalationLevelInfo();
            if (info != null) {
                item.add(AttributeModifier.replace("title", info));
                item.add(new TooltipBehavior());
            }
        }

        @Override
        public String getCssClass() {
            return "countLabel";
        }
    };
    columns.add(column);
    column = new PropertyColumn<CertWorkItemDto, String>(createStringResource("PageCertDecisions.table.requested"), SearchingUtils.CURRENT_REVIEW_REQUESTED_TIMESTAMP, CertWorkItemDto.F_REVIEW_REQUESTED) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String componentId, IModel<CertWorkItemDto> rowModel) {
            super.populateItem(item, componentId, rowModel);
            CertWorkItemDto dto = rowModel.getObject();
            Date started = dto.getStageStarted();
            if (started != null) {
                item.add(AttributeModifier.replace("title", WebComponentUtil.getShortDateTimeFormattedValue(started, PageCertDecisions.this)));
                item.add(new TooltipBehavior());
            }
        }
    };
    columns.add(column);
    column = new PropertyColumn<CertWorkItemDto, String>(createStringResource("PageCertDecisions.table.deadline"), SearchingUtils.CURRENT_REVIEW_DEADLINE, CertWorkItemDto.F_DEADLINE_AS_STRING) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<CertWorkItemDto>> item, String componentId, final IModel<CertWorkItemDto> rowModel) {
            super.populateItem(item, componentId, rowModel);
            XMLGregorianCalendar deadline = rowModel.getObject().getCertCase().getCurrentStageDeadline();
            if (deadline != null) {
                item.add(AttributeModifier.replace("title", WebComponentUtil.formatDate(deadline)));
                item.add(new TooltipBehavior());
            }
        }
    };
    columns.add(column);
    final AvailableResponses availableResponses = new AvailableResponses(this);
    final int responses = availableResponses.getResponseKeys().size();
    column = new AbstractColumn<CertWorkItemDto, String>(new Model<>()) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(Item<ICellPopulator<CertWorkItemDto>> cellItem, String componentId, IModel<CertWorkItemDto> rowModel) {
            cellItem.add(new MultiButtonPanel<CertWorkItemDto>(componentId, rowModel, responses + 1) {

                private static final long serialVersionUID = 1L;

                @Override
                protected Component createButton(int index, String componentId, IModel<CertWorkItemDto> model) {
                    AjaxIconButton btn;
                    if (index < responses) {
                        btn = buildDefaultButton(componentId, null, new Model(availableResponses.getTitle(index)), new Model<>("btn btn-sm " + getDecisionButtonColor(model, availableResponses.getResponseValues().get(index))), target -> recordActionPerformed(target, model.getObject(), availableResponses.getResponseValues().get(index)));
                        btn.add(new EnableBehaviour(() -> !decisionEquals(model, availableResponses.getResponseValues().get(index))));
                    } else {
                        btn = buildDefaultButton(componentId, null, new Model(availableResponses.getTitle(index)), new Model<>("btn btn-sm " + ButtonColorClass.DANGER), null);
                        btn.setEnabled(false);
                        btn.add(new VisibleBehaviour(() -> !availableResponses.isAvailable(model.getObject().getResponse())));
                    }
                    return btn;
                }
            });
        }
    };
    columns.add(column);
    column = new DirectlyEditablePropertyColumn<CertWorkItemDto>(createStringResource("PageCertDecisions.table.comment"), CertWorkItemDto.F_COMMENT) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onBlur(AjaxRequestTarget target, IModel model) {
            // TODO determine somehow if the model.comment was really changed
            recordActionPerformed(target, (CertWorkItemDto) model.getObject(), null);
        }
    };
    columns.add(column);
    columns.add(new InlineMenuHeaderColumn(createInlineMenu(availableResponses)));
    return columns;
}
Also used : VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) Date(java.util.Date) PageDescriptor(com.evolveum.midpoint.authentication.api.authorization.PageDescriptor) AuthorizationConstants(com.evolveum.midpoint.security.api.AuthorizationConstants) ButtonColorClass(com.evolveum.midpoint.web.component.data.column.DoubleButtonColumn.ButtonColorClass) com.evolveum.midpoint.web.page.admin.certification.dto(com.evolveum.midpoint.web.page.admin.certification.dto) AbstractColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) BoxedTablePanel(com.evolveum.midpoint.web.component.data.BoxedTablePanel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) IModel(org.apache.wicket.model.IModel) Label(org.apache.wicket.markup.html.basic.Label) AjaxIconButton(com.evolveum.midpoint.web.component.AjaxIconButton) Model(org.apache.wicket.model.Model) Component(org.apache.wicket.Component) MarkupContainer(org.apache.wicket.MarkupContainer) WebComponentUtil(com.evolveum.midpoint.gui.api.util.WebComponentUtil) Task(com.evolveum.midpoint.task.api.Task) AttributeModifier(org.apache.wicket.AttributeModifier) OnePageParameterEncoder(com.evolveum.midpoint.web.util.OnePageParameterEncoder) List(java.util.List) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) Item(org.apache.wicket.markup.repeater.Item) SystemException(com.evolveum.midpoint.util.exception.SystemException) SortOrder(org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType) Form(org.apache.wicket.markup.html.form.Form) com.evolveum.midpoint.web.component.data.column(com.evolveum.midpoint.web.component.data.column) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) InlineMenuItemAction(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItemAction) Trace(com.evolveum.midpoint.util.logging.Trace) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) OBJECT(com.evolveum.midpoint.web.page.admin.certification.CertDecisionHelper.WhichObject.OBJECT) Table(com.evolveum.midpoint.web.component.data.Table) AvailableResponses(com.evolveum.midpoint.web.page.admin.certification.helpers.AvailableResponses) CheckBox(org.apache.wicket.markup.html.form.CheckBox) ArrayList(java.util.ArrayList) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) Fragment(org.apache.wicket.markup.html.panel.Fragment) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) TooltipBehavior(com.evolveum.midpoint.web.util.TooltipBehavior) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour) Url(com.evolveum.midpoint.authentication.api.authorization.Url) CertDecisionsStorage(com.evolveum.midpoint.web.session.CertDecisionsStorage) DataTable(org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable) AccessCertificationResponseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationResponseType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) MultiButtonPanel(com.evolveum.midpoint.web.component.data.MultiButtonPanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) HeaderMenuAction(com.evolveum.midpoint.web.page.admin.configuration.component.HeaderMenuAction) PropertyColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn) TARGET(com.evolveum.midpoint.web.page.admin.certification.CertDecisionHelper.WhichObject.TARGET) AuthorizationAction(com.evolveum.midpoint.authentication.api.authorization.AuthorizationAction) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) AvailableResponses(com.evolveum.midpoint.web.page.admin.certification.helpers.AvailableResponses) TooltipBehavior(com.evolveum.midpoint.web.util.TooltipBehavior) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour) IModel(org.apache.wicket.model.IModel) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Date(java.util.Date) ICellPopulator(org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) AjaxIconButton(com.evolveum.midpoint.web.component.AjaxIconButton) MultiButtonPanel(com.evolveum.midpoint.web.component.data.MultiButtonPanel)

Example 4 with EnableBehaviour

use of com.evolveum.midpoint.web.component.util.EnableBehaviour in project midpoint by Evolveum.

the class RelationDropDownChoicePanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    ListModel supportedRelationsModel = new ListModel<>(supportedRelations);
    if (!allowNull && defaultRelation == null) {
        if (CollectionUtils.isNotEmpty(supportedRelations)) {
            List<QName> sortedRelations = WebComponentUtil.sortDropDownChoices(supportedRelationsModel, getRenderer());
            defaultRelation = sortedRelations.get(0);
        } else {
            defaultRelation = PrismConstants.Q_ANY;
        }
        defaultRelation = supportedRelations.size() > 0 ? supportedRelations.get(0) : PrismConstants.Q_ANY;
    }
    DropDownFormGroup<QName> input = new DropDownFormGroup<QName>(ID_INPUT, Model.of(defaultRelation), supportedRelationsModel, getRenderer(), getRelationLabelModel(), "relationDropDownChoicePanel.tooltip.relation", "col-md-4", getRelationLabelModel() == null || StringUtils.isEmpty(getRelationLabelModel().getObject()) ? "" : "col-md-8", !allowNull) {

        private static final long serialVersionUID = 1L;

        @Override
        protected String getNullValidDisplayValue() {
            return RelationDropDownChoicePanel.this.getNullValidDisplayValue();
        }
    };
    input.getInput().add(new EnableBehaviour(() -> isRelationDropDownEnabled()));
    input.getInput().add(new EmptyOnChangeAjaxFormUpdatingBehavior());
    input.getInput().add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            RelationDropDownChoicePanel.this.onValueChanged(target);
        }
    });
    add(input);
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) EmptyOnChangeAjaxFormUpdatingBehavior(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) QName(javax.xml.namespace.QName) ListModel(org.apache.wicket.model.util.ListModel) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Example 5 with EnableBehaviour

use of com.evolveum.midpoint.web.component.util.EnableBehaviour in project midpoint by Evolveum.

the class WorkItemDetailsPanel method initLayout.

private void initLayout() {
    LinkedReferencePanel requestedBy = new LinkedReferencePanel(ID_REQUESTED_BY, Model.of(WorkItemTypeUtil.getRequestorReference(getModelObject())));
    requestedBy.setOutputMarkupId(true);
    add(requestedBy);
    LinkedReferencePanel requestedFor;
    AssignmentHolderType object = WebComponentUtil.getObjectFromAddDeltyForCase(CaseTypeUtil.getCase(getModelObject()));
    if (object == null) {
        requestedFor = new LinkedReferencePanel(ID_REQUESTED_FOR, Model.of(WorkItemTypeUtil.getObjectReference(getModelObject())));
    } else {
        ObjectReferenceType ort = new ObjectReferenceType();
        ort.setOid(object.getOid());
        ort.setType(WebComponentUtil.classToQName(getPageBase().getPrismContext(), object.getClass()));
        PrismReferenceValue referenceValue = getPageBase().getPrismContext().itemFactory().createReferenceValue(object.getOid(), WebComponentUtil.classToQName(getPageBase().getPrismContext(), object.getClass()));
        referenceValue.setObject(object.asPrismObject());
        ort.setupReferenceValue(referenceValue);
        requestedFor = new LinkedReferencePanel(ID_REQUESTED_FOR, Model.of(ort));
    }
    requestedFor.setOutputMarkupId(true);
    add(requestedFor);
    LinkedReferencePanel approver = new LinkedReferencePanel(ID_APPROVER, getApproverModel());
    approver.setOutputMarkupId(true);
    add(approver);
    WebMarkupContainer candidateContainer = new WebMarkupContainer(ID_CANDIDATE_CONTAINER);
    candidateContainer.setOutputMarkupId(true);
    candidateContainer.add(new VisibleBehaviour(() -> CaseWorkItemUtil.isWorkItemClaimable(getModelObject())));
    add(candidateContainer);
    RepeatingView candidateLinksPanel = new RepeatingView(ID_CANDIDATE);
    candidateLinksPanel.setOutputMarkupId(true);
    List<ObjectReferenceType> candidates = getModelObject() != null ? getModelObject().getCandidateRef() : null;
    if (candidates != null) {
        candidates.forEach(candidate -> {
            LinkedReferencePanel candidatePanel = new LinkedReferencePanel(candidateLinksPanel.newChildId(), Model.of(candidate));
            candidatePanel.setOutputMarkupId(true);
            candidateLinksPanel.add(candidatePanel);
        });
    }
    candidateContainer.add(candidateLinksPanel);
    WebMarkupContainer parentCaseContainer = new WebMarkupContainer(ID_PARENT_CASE_CONTAINER);
    parentCaseContainer.add(new VisibleBehaviour(() -> getPageBase() instanceof PageCaseWorkItem));
    parentCaseContainer.setOutputMarkupId(true);
    add(parentCaseContainer);
    CaseType parentCaseObj = getModelObject() != null && CaseTypeUtil.getCase(getModelObject()) != null ? CaseTypeUtil.getCase(getModelObject()) : null;
    ObjectReferenceType parentCaseRef = null;
    if (parentCaseObj != null) {
        parentCaseRef = new ObjectReferenceType();
        parentCaseRef.setOid(parentCaseObj.getOid());
        parentCaseRef.setType(CaseType.COMPLEX_TYPE);
        parentCaseRef.setupReferenceValue(getPageBase().getPrismContext().itemFactory().createReferenceValue(parentCaseObj.asPrismObject()));
    }
    LinkedReferencePanel parentCaseLink = new LinkedReferencePanel(ID_PARENT_CASE, Model.of(parentCaseRef));
    parentCaseLink.setOutputMarkupId(true);
    parentCaseContainer.add(parentCaseLink);
    LinkedReferencePanel target = new LinkedReferencePanel(ID_TARGET, Model.of(WorkItemTypeUtil.getTargetReference(getModelObject())));
    target.setOutputMarkupId(true);
    add(target);
    CaseType parentCase = CaseTypeUtil.getCase(getModelObject());
    add(new Label(ID_COMMENT, CaseTypeUtil.getRequesterComment(parentCase)));
    EvaluatedTriggerGroupListPanel reasonPanel = new EvaluatedTriggerGroupListPanel(ID_REASON, Model.ofList(WebComponentUtil.computeTriggers(parentCase != null ? parentCase.getApprovalContext() : null, parentCase != null && parentCase.getStageNumber() != null ? parentCase.getStageNumber() : 0)));
    reasonPanel.setOutputMarkupId(true);
    add(reasonPanel);
    if (CaseTypeUtil.isApprovalCase(parentCase) || CaseTypeUtil.isManualProvisioningCase(parentCase)) {
        ScenePanel scenePanel = new ScenePanel(ID_DELTAS_TO_APPROVE, sceneModel);
        scenePanel.setOutputMarkupId(true);
        add(scenePanel);
    } else if (CaseTypeUtil.isCorrelationCase(parentCase)) {
        add(new CorrelationContextPanel(ID_DELTAS_TO_APPROVE, new CaseDetailsModels(caseModel, getPageBase()), new ContainerPanelConfigurationType()));
    } else {
        add(new WebMarkupContainer(ID_DELTAS_TO_APPROVE));
    }
    InformationListPanel additionalInformation = new InformationListPanel(ID_ADDITIONAL_INFORMATION, Model.ofList(getModelObject().getAdditionalInformation()));
    additionalInformation.setOutputMarkupId(true);
    add(additionalInformation);
    ApprovalStageDefinitionType level = ApprovalContextUtil.getCurrentStageDefinition(parentCase);
    WebMarkupContainer additionalAttributes = new WebMarkupContainer(ID_ADDITIONAL_ATTRIBUTES);
    add(additionalAttributes);
    additionalAttributes.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        public boolean isVisible() {
            return (level != null && level.getFormRef() != null && level.getFormRef().getOid() != null);
        }
    });
    if (level != null && level.getFormRef() != null && level.getFormRef().getOid() != null) {
        String formOid = level.getFormRef().getOid();
        ObjectType focus = getCaseFocusObject(parentCase);
        if (focus == null) {
            // TODO (this should not occur anyway)
            focus = new UserType(getPageBase().getPrismContext());
        }
        Task task = getPageBase().createSimpleTask(OPERATION_LOAD_CUSTOM_FORM);
        DynamicFormPanel<?> customForm = new DynamicFormPanel<>(ID_CUSTOM_FORM, focus.asPrismObject(), formOid, null, task, getPageBase(), false);
        additionalAttributes.add(customForm);
    } else {
        additionalAttributes.add(new Label(ID_CUSTOM_FORM));
    }
    Form evidenceForm = new Form(ID_CASE_WORK_ITEM_EVIDENCE_FORM);
    evidenceForm.add(new VisibleBehaviour(() -> CaseTypeUtil.isManualProvisioningCase(parentCase) && (!isParentCaseClosed() || WorkItemTypeUtil.getEvidence(getModelObject()) != null)));
    evidenceForm.setMultiPart(true);
    add(evidenceForm);
    UploadDownloadPanel evidencePanel = new UploadDownloadPanel(ID_CASE_WORK_ITEM_EVIDENCE, isParentCaseClosed() && WorkItemTypeUtil.getEvidence(getModelObject()) != null) {

        private static final long serialVersionUID = 1L;

        @Override
        public void updateValue(byte[] file) {
            if (file != null) {
                WorkItemTypeUtil.setEvidence(getModelObject(), file);
            }
        }

        @Override
        public InputStream getStream() {
            byte[] evidenceFile = WorkItemTypeUtil.getEvidence(getModelObject());
            return evidenceFile != null ? new ByteArrayInputStream((byte[]) evidenceFile) : new ByteArrayInputStream(new byte[0]);
        }

        @Override
        public String getDownloadContentType() {
            return "image/jpeg";
        }
    };
    evidenceForm.add(evidencePanel);
    evidencePanel.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    evidencePanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            CaseWorkItemType workItem = WorkItemDetailsPanel.this.getModelObject();
            CaseType caseObj = CaseTypeUtil.getCase(workItem);
            return CaseTypeUtil.isManualProvisioningCase(caseObj);
        }
    });
    WebMarkupContainer commentContainer = new WebMarkupContainer(ID_APPROVER_CONTAINER);
    commentContainer.setOutputMarkupId(true);
    commentContainer.add(new VisibleBehaviour(() -> isAuthorizedForActions()));
    add(commentContainer);
    TextArea<String> approverComment = new TextArea<String>(ID_APPROVER_COMMENT, new PropertyModel<>(getModel(), "output.comment"));
    approverComment.add(new EnableBehaviour(() -> !isParentCaseClosed()));
    approverComment.setOutputMarkupId(true);
    approverComment.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    commentContainer.add(approverComment);
}
Also used : CorrelationContextPanel(com.evolveum.midpoint.gui.impl.page.admin.cases.component.CorrelationContextPanel) ScenePanel(com.evolveum.midpoint.web.component.prism.show.ScenePanel) Task(com.evolveum.midpoint.task.api.Task) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) Form(org.apache.wicket.markup.html.form.Form) TextArea(org.apache.wicket.markup.html.form.TextArea) UploadDownloadPanel(com.evolveum.midpoint.web.component.input.UploadDownloadPanel) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) Label(org.apache.wicket.markup.html.basic.Label) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) CaseDetailsModels(com.evolveum.midpoint.gui.impl.page.admin.cases.CaseDetailsModels) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PageCaseWorkItem(com.evolveum.midpoint.web.page.admin.cases.PageCaseWorkItem) LinkedReferencePanel(com.evolveum.midpoint.web.component.data.LinkedReferencePanel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) DynamicFormPanel(com.evolveum.midpoint.web.component.prism.DynamicFormPanel) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

EnableBehaviour (com.evolveum.midpoint.web.component.util.EnableBehaviour)17 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)13 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)10 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)9 ArrayList (java.util.ArrayList)7 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)6 Label (org.apache.wicket.markup.html.basic.Label)6 QName (javax.xml.namespace.QName)5 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)4 EmptyOnBlurAjaxFormUpdatingBehaviour (com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour)4 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)3 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)3 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)3 Form (org.apache.wicket.markup.html.form.Form)3 IModel (org.apache.wicket.model.IModel)3 CountablePanelTab (com.evolveum.midpoint.gui.api.component.tabs.CountablePanelTab)2 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)2 CompositedIconBuilder (com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder)2 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)2 Task (com.evolveum.midpoint.task.api.Task)2