Search in sources :

Example 36 with AttributeAppender

use of org.apache.wicket.behavior.AttributeAppender in project midpoint by Evolveum.

the class AssignmentConflictPanel method initLayout.

private void initLayout() {
    setOutputMarkupId(true);
    Form container = new com.evolveum.midpoint.web.component.form.Form<>(ID_PANEL_CONTAINER);
    container.setOutputMarkupId(true);
    add(container);
    Label statusIconLabel = new Label(ID_STATUS_ICON);
    statusIconLabel.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject() != null ? (getModelObject().isSolved() ? STATUS_FIXED : (getModelObject().isError() ? STATUS_ERROR : STATUS_WARNING)) : STATUS_ERROR;
        }
    }));
    container.add(statusIconLabel);
    Label existingAssignment = new Label(ID_EXISTING_ASSIGNMENT, new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            if (getModelObject() != null) {
                String name = getModelObject().getExistingAssignmentTargetObj().asObjectable().getName() != null ? getModelObject().getExistingAssignmentTargetObj().asObjectable().getName().getOrig() : getModelObject().getExistingAssignmentTargetObj().getOid();
                return name + " " + createStringResource("AssignmentConflictPanel.existingAssignmentLabelMessage").getString();
            }
            return "";
        }
    });
    existingAssignment.add(new AttributeAppender("style", new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject() != null && getModelObject().isRemovedOld() ? "text-decoration: line-through;" : "";
        }
    }));
    container.add(existingAssignment);
    Label addedAssignment = new Label(ID_ADDED_ASSIGNMENT, new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            if (getModelObject() != null) {
                String name = getModelObject().getAddedAssignmentTargetObj().asObjectable().getName() != null ? getModelObject().getAddedAssignmentTargetObj().asObjectable().getName().getOrig() : getModelObject().getAddedAssignmentTargetObj().getOid();
                return name + " " + createStringResource("AssignmentConflictPanel.addedAssignmentLabelMessage").getString();
            }
            return "";
        }
    });
    addedAssignment.add(new AttributeAppender("style", new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject() != null && getModelObject().isUnassignedNew() ? "text-decoration: line-through;" : "";
        }
    }));
    container.add(addedAssignment);
    AbstractReadOnlyModel<String> removeButtonTitleModel = new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject().isRemovedOld() ? createStringResource("AssignmentConflictPanel.undoAction").getString() : createStringResource("AssignmentConflictPanel.removeButton").getString();
        }
    };
    AjaxSubmitButton removeButton = new AjaxSubmitButton(ID_REMOVE_BUTTON, removeButtonTitleModel) {

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            AssignmentConflictPanel.this.removeAssignmentPerformed(target);
        }
    };
    removeButton.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getModelObject() != null;
        }

        @Override
        public boolean isEnabled() {
            return !getModelObject().isUnassignedNew();
        }
    });
    container.add(removeButton);
    AbstractReadOnlyModel<String> unselectButtonTitleModel = new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getModelObject().isUnassignedNew() ? createStringResource("AssignmentConflictPanel.undoAction").getString() : createStringResource("AssignmentConflictPanel.unselectButton").getString();
        }
    };
    AjaxSubmitButton unselectButton = new AjaxSubmitButton(ID_UNSELECT_BUTTON, unselectButtonTitleModel) {

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            AssignmentConflictPanel.this.unselectAssignmentPerformed(target);
        }
    };
    unselectButton.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getModelObject() != null;
        }

        @Override
        public boolean isEnabled() {
            return !getModelObject().isRemovedOld();
        }
    });
    container.add(unselectButton);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 37 with AttributeAppender

use of org.apache.wicket.behavior.AttributeAppender in project midpoint by Evolveum.

the class OperationResultPanel method initHeader.

private void initHeader(WebMarkupContainer box) {
    WebMarkupContainer iconType = new WebMarkupContainer(ID_ICON_TYPE);
    iconType.setOutputMarkupId(true);
    iconType.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            StringBuilder sb = new StringBuilder();
            OpResult message = getModelObject();
            switch(message.getStatus()) {
                case IN_PROGRESS:
                case NOT_APPLICABLE:
                    sb.append(" fa-info");
                    break;
                case SUCCESS:
                    sb.append(" fa-check");
                    break;
                case FATAL_ERROR:
                    sb.append(" fa-ban");
                    break;
                case PARTIAL_ERROR:
                case UNKNOWN:
                case WARNING:
                case HANDLED_ERROR:
                default:
                    sb.append(" fa-warning");
            }
            return sb.toString();
        }
    }));
    box.add(iconType);
    Label message = createMessage();
    AjaxLink<String> showMore = new AjaxLink<String>(ID_MESSAGE) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            OpResult result = OperationResultPanel.this.getModelObject();
            result.setShowMore(!result.isShowMore());
            // hack to be able to expand/collapse OpResult after rendered.
            result.setAlreadyShown(false);
            target.add(OperationResultPanel.this);
        }
    };
    showMore.add(message);
    box.add(showMore);
    AjaxLink<String> backgroundTask = new AjaxLink<String>(ID_BACKGROUND_TASK) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            final OpResult opResult = OperationResultPanel.this.getModelObject();
            String oid = opResult.getBackgroundTaskOid();
            if (oid == null || !opResult.isBackgroundTaskVisible()) {
                // just for safety
                return;
            }
            ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(oid, ObjectTypes.TASK);
            WebComponentUtil.dispatchToObjectDetailsPage(ref, getPageBase(), false);
        }
    };
    backgroundTask.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getModelObject().getBackgroundTaskOid() != null && getModelObject().isBackgroundTaskVisible();
        }
    });
    box.add(backgroundTask);
    AjaxLink<String> showAll = new AjaxLink<String>(ID_SHOW_ALL) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHideAll(true, OperationResultPanel.this.getModelObject(), target);
        }
    };
    showAll.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !OperationResultPanel.this.getModelObject().isShowMore();
        }
    });
    box.add(showAll);
    AjaxLink<String> hideAll = new AjaxLink<String>(ID_HIDE_ALL) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            showHideAll(false, OperationResultPanel.this.getModel().getObject(), target);
        }
    };
    hideAll.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return OperationResultPanel.this.getModelObject().isShowMore();
        }
    });
    box.add(hideAll);
    AjaxLink<String> close = new AjaxLink<String>("close") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            close(target);
        }
    };
    box.add(close);
    DownloadLink downloadXml = new DownloadLink("downloadXml", new AbstractReadOnlyModel<File>() {

        private static final long serialVersionUID = 1L;

        @Override
        public File getObject() {
            String home = getPageBase().getMidpointConfiguration().getMidpointHome();
            File f = new File(home, "result");
            DataOutputStream dos = null;
            try {
                dos = new DataOutputStream(new FileOutputStream(f));
                dos.writeBytes(OperationResultPanel.this.getModel().getObject().getXml());
            } catch (IOException e) {
                LOGGER.error("Could not download result: {}", e.getMessage(), e);
            } finally {
                IOUtils.closeQuietly(dos);
            }
            return f;
        }
    });
    downloadXml.setDeleteAfterDownload(true);
    box.add(downloadXml);
}
Also used : DownloadLink(org.apache.wicket.markup.html.link.DownloadLink) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) DataOutputStream(java.io.DataOutputStream) Label(org.apache.wicket.markup.html.basic.Label) IOException(java.io.IOException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) FileOutputStream(java.io.FileOutputStream) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) File(java.io.File) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 38 with AttributeAppender

use of org.apache.wicket.behavior.AttributeAppender in project midpoint by Evolveum.

the class OperationResultPanel method initDetails.

private void initDetails(WebMarkupContainer box, Page parentPage) {
    final WebMarkupContainer details = new WebMarkupContainer("details", getModel());
    details.setOutputMarkupId(true);
    details.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return getModel().getObject().isShowMore();
        }
    });
    box.add(details);
    WebMarkupContainer operationPanel = new WebMarkupContainer("type");
    operationPanel.setOutputMarkupId(true);
    operationPanel.add(new AttributeAppender("class", new LoadableModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            return getLabelCss(getModel());
        }
    }, " "));
    details.add(operationPanel);
    Label operationLabel = new Label("operationLabel", parentPage.getString("FeedbackAlertMessageDetails.operation"));
    operationLabel.setOutputMarkupId(true);
    operationPanel.add(operationLabel);
    Label operation = new Label("operation", new LoadableModel<Object>() {

        private static final long serialVersionUID = 1L;

        @Override
        protected Object load() {
            OpResult result = getModelObject();
            String resourceKey = OPERATION_RESOURCE_KEY_PREFIX + result.getOperation();
            return getPage().getString(resourceKey, null, resourceKey);
        }
    });
    operation.setOutputMarkupId(true);
    operationPanel.add(operation);
    Label count = new Label("countLabel", parentPage.getString("FeedbackAlertMessageDetails.count"));
    count.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            OpResult result = getModelObject();
            return result.getCount() > 1;
        }
    });
    operationPanel.add(count);
    operationPanel.add(initCountPanel(getModel()));
    Label message = new Label("resultMessage", // PageBase.new
    new PropertyModel<String>(getModel(), "message").getObject());
    // PropertyModel<String>(model,
    // "message"));
    message.setOutputMarkupId(true);
    message.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return StringUtils.isNotBlank(getModelObject().getMessage());
        }
    });
    operationPanel.add(message);
    Label messageLabel = new Label("messageLabel", parentPage.getString("FeedbackAlertMessageDetails.message"));
    messageLabel.setOutputMarkupId(true);
    messageLabel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return StringUtils.isNotBlank(getModelObject().getMessage());
        }
    });
    operationPanel.add(messageLabel);
    initParams(operationPanel, getModel(), parentPage);
    initContexts(operationPanel, getModel(), parentPage);
    initError(operationPanel, getModel(), parentPage);
}
Also used : LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) Label(org.apache.wicket.markup.html.basic.Label) PropertyModel(org.apache.wicket.model.PropertyModel) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 39 with AttributeAppender

use of org.apache.wicket.behavior.AttributeAppender in project midpoint by Evolveum.

the class ValidationErrorPanel method initHeader.

private void initHeader(WebMarkupContainer box) {
    WebMarkupContainer iconType = new WebMarkupContainer("iconType");
    iconType.setOutputMarkupId(true);
    iconType.add(new AttributeAppender("class", new AbstractReadOnlyModel() {

        @Override
        public Object getObject() {
            FeedbackMessage result = getModelObject();
            if (result == null) {
                return " fa-info";
            }
            switch(result.getLevel()) {
                case FeedbackMessage.INFO:
                case FeedbackMessage.DEBUG:
                    return " fa-info";
                case FeedbackMessage.SUCCESS:
                    return " fa-check";
                case FeedbackMessage.ERROR:
                case FeedbackMessage.FATAL:
                    return " fa-ban";
                case FeedbackMessage.UNDEFINED:
                // TODO:
                case FeedbackMessage.WARNING:
                default:
                    return " fa-warning";
            }
        }
    }));
    box.add(iconType);
    Label message = new Label(ID_MESSAGE, new PropertyModel<Serializable>(getModel(), "message"));
    box.add(message);
    AjaxLink close = new AjaxLink("close") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            close(target);
        }
    };
    box.add(close);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Serializable(java.io.Serializable) Label(org.apache.wicket.markup.html.basic.Label) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 40 with AttributeAppender

use of org.apache.wicket.behavior.AttributeAppender in project midpoint by Evolveum.

the class CapabilityStep method initLayout.

protected void initLayout() {
    final ListDataProvider<CapabilityDto<CapabilityType>> capabilityProvider = new ListDataProvider<>(this, new PropertyModel<List<CapabilityDto<CapabilityType>>>(dtoModel, CapabilityStepDto.F_CAPABILITIES));
    WebMarkupContainer tableBody = new WebMarkupContainer(ID_CAPABILITY_TABLE);
    tableBody.setOutputMarkupId(true);
    add(tableBody);
    WebMarkupContainer configBody = new WebMarkupContainer(ID_CAPABILITY_CONFIG);
    configBody.setOutputMarkupId(true);
    add(configBody);
    DataView<CapabilityDto<CapabilityType>> capabilityDataView = new DataView<CapabilityDto<CapabilityType>>(ID_CAPABILITY_ROW, capabilityProvider) {

        @Override
        protected void populateItem(final Item<CapabilityDto<CapabilityType>> capabilityRow) {
            final CapabilityDto<CapabilityType> dto = capabilityRow.getModelObject();
            AjaxLink name = new AjaxLink(ID_CAPABILITY_LINK) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    editCapabilityPerformed(target, dto);
                }
            };
            Label label = new Label(ID_CAPABILITY_NAME, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    String rv = dto.getDisplayName();
                    if (Boolean.FALSE.equals(dto.getCapability().isEnabled())) {
                        rv += " " + getString("CapabilityStep.disabled");
                    }
                    return rv;
                }
            });
            name.add(label);
            capabilityRow.add(name);
            Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
            if (dto.getTooltipKey() != null) {
                tooltipLabel.add(new AttributeAppender("data-original-title", getString(dto.getTooltipKey())));
                tooltipLabel.add(new InfoTooltipBehavior());
            } else {
                tooltipLabel.setVisible(false);
            }
            tooltipLabel.setOutputMarkupId(true);
            tooltipLabel.setOutputMarkupPlaceholderTag(true);
            name.add(tooltipLabel);
            AjaxLink deleteLink = new AjaxLink(ID_CAPABILITY_DELETE) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    deleteCapabilityPerformed(target, dto);
                }
            };
            deleteLink.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    return !dto.isAmongNativeCapabilities() && !parentPage.isReadOnly();
                }
            });
            name.add(deleteLink);
            capabilityRow.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<Object>() {

                @Override
                public Object getObject() {
                    return isSelected(capabilityRow.getModelObject()) ? "success" : null;
                }
            }));
        }
    };
    tableBody.add(capabilityDataView);
    AjaxLink addLink = new AjaxLink(ID_CAPABILITY_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addCapabilityPerformed(target);
        }
    };
    parentPage.addEditingVisibleBehavior(addLink);
    add(addLink);
    ModalWindow dialog = new AddCapabilityDialog(DIALOG_SELECT_CAPABILITY, dtoModel) {

        @Override
        protected void addPerformed(AjaxRequestTarget target) {
            addCapabilitiesPerformed(target, getSelectedData());
        }
    };
    add(dialog);
}
Also used : ListDataProvider(com.evolveum.midpoint.web.component.util.ListDataProvider) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Label(org.apache.wicket.markup.html.basic.Label) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) DataView(org.apache.wicket.markup.repeater.data.DataView) Item(org.apache.wicket.markup.repeater.Item) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Aggregations

AttributeAppender (org.apache.wicket.behavior.AttributeAppender)53 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)29 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)25 Label (org.apache.wicket.markup.html.basic.Label)25 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)24 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)23 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)17 IModel (org.apache.wicket.model.IModel)12 InfoTooltipBehavior (com.evolveum.midpoint.web.util.InfoTooltipBehavior)8 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)7 ListItem (org.apache.wicket.markup.html.list.ListItem)7 Model (org.apache.wicket.model.Model)7 ListView (org.apache.wicket.markup.html.list.ListView)6 BoxedTablePanel (com.evolveum.midpoint.web.component.data.BoxedTablePanel)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 AttributeModifier (org.apache.wicket.AttributeModifier)5 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)5 TextField (org.apache.wicket.markup.html.form.TextField)5 PropertyModel (org.apache.wicket.model.PropertyModel)5