Search in sources :

Example 46 with AttributeAppender

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

the class DoubleButtonPanel method initLayout.

private void initLayout() {
    AjaxButton firstButton = new AjaxButton(ID_BUTTON_FIRST, createButtonStringResource(getFirstCaption())) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            firstPerformed(target, DoubleButtonPanel.this.getModel());
        }

        @Override
        public boolean isEnabled() {
            return isFirstEnabled(DoubleButtonPanel.this.getModel());
        }
    };
    firstButton.add(new AttributeAppender("class", getFirstCssClass()));
    AjaxButton secondButton = new AjaxButton(ID_BUTTON_SECOND, createButtonStringResource(getSecondCaption())) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            secondPerformed(target, DoubleButtonPanel.this.getModel());
        }

        @Override
        public boolean isEnabled() {
            return isSecondEnabled(DoubleButtonPanel.this.getModel());
        }
    };
    secondButton.add(new AttributeAppender("class", getSecondCssClass()));
    add(firstButton);
    add(secondButton);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 47 with AttributeAppender

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

the class MetadataPanel method initLayout.

private void initLayout() {
    WebMarkupContainer metadataBlock = new WebMarkupContainer(ID_METADATA_BLOCK);
    metadataBlock.setOutputMarkupId(true);
    add(metadataBlock);
    WebMarkupContainer headerContainer = new WebMarkupContainer(ID_HEADER_CONTAINER);
    headerContainer.setOutputMarkupId(true);
    headerContainer.add(new AttributeAppender("class", "prism-header " + additionalHeaderStyle));
    metadataBlock.add(headerContainer);
    Label metadataHeader = new Label(ID_METADATA_LABEL, createStringResource("AssignmentEditorPanel.metadataBlock", header != null ? header : ""));
    metadataHeader.setOutputMarkupId(true);
    headerContainer.add(metadataHeader);
    RepeatingView metadataRowRepeater = new RepeatingView(ID_METADATA_ROW);
    metadataBlock.add(metadataRowRepeater);
    for (QName qname : metadataFieldsList) {
        WebMarkupContainer metadataRow = new WebMarkupContainer(metadataRowRepeater.newChildId());
        metadataRow.setOutputMarkupId(true);
        if (metadataFieldsList.indexOf(qname) % 2 != 0) {
            metadataRow.add(new AttributeAppender("class", "stripe"));
        }
        metadataRowRepeater.add(metadataRow);
        metadataRow.add(new Label(ID_METADATA_PROPERTY_KEY, createStringResource(DOT_CLASS + qname.getLocalPart())));
        AbstractReadOnlyModel<String> metadataFieldModel = new AbstractReadOnlyModel<String>() {

            @Override
            public String getObject() {
                PropertyModel<Object> tempModel = new PropertyModel<Object>(getModel(), qname.getLocalPart());
                if (tempModel.getObject() instanceof XMLGregorianCalendar) {
                    return WebComponentUtil.getLocalizedDate((XMLGregorianCalendar) tempModel.getObject(), DateLabelComponent.MEDIUM_MEDIUM_STYLE);
                } else if (tempModel.getObject() instanceof ObjectReferenceType) {
                    ObjectReferenceType ref = (ObjectReferenceType) tempModel.getObject();
                    return WebComponentUtil.getName(ref, getPageBase(), OPERATION_LOAD_USER);
                } else if (tempModel.getObject() instanceof List) {
                    List list = (List) tempModel.getObject();
                    String result = "";
                    for (Object o : list) {
                        if (o instanceof ObjectReferenceType) {
                            if (result.length() > 0) {
                                result += ", ";
                            }
                            result += WebComponentUtil.getName((ObjectReferenceType) o, getPageBase(), OPERATION_LOAD_USER);
                        }
                    }
                    return result;
                }
                return "";
            }
        };
        metadataRow.add(new Label(ID_METADATA_FILED, metadataFieldModel));
        metadataRow.add(new VisibleEnableBehaviour() {

            @Override
            public boolean isVisible() {
                return StringUtils.isNotEmpty(metadataFieldModel.getObject());
            }
        });
    }
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) QName(javax.xml.namespace.QName) Label(org.apache.wicket.markup.html.basic.Label) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) PropertyModel(org.apache.wicket.model.PropertyModel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ArrayList(java.util.ArrayList) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 48 with AttributeAppender

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

the class NameStep method createConnectorDropDown.

private DropDownFormGroup<PrismObject<ConnectorType>> createConnectorDropDown() {
    return new DropDownFormGroup<PrismObject<ConnectorType>>(ID_CONNECTOR, selectedConnectorModel, relevantConnectorsModel, new IChoiceRenderer<PrismObject<ConnectorType>>() {

        @Override
        public PrismObject<ConnectorType> getObject(String id, IModel<? extends List<? extends PrismObject<ConnectorType>>> choices) {
            return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
        }

        @Override
        public Object getDisplayValue(PrismObject<ConnectorType> object) {
            return WebComponentUtil.getName(object);
        }

        @Override
        public String getIdValue(PrismObject<ConnectorType> object, int index) {
            return Integer.toString(index);
        }
    }, createStringResource("NameStep.connectorType"), "col-md-3", "col-md-6", true) {

        @Override
        protected DropDownChoice<PrismObject<ConnectorType>> createDropDown(String id, IModel<List<PrismObject<ConnectorType>>> choices, IChoiceRenderer<PrismObject<ConnectorType>> renderer, boolean required) {
            DropDownChoice<PrismObject<ConnectorType>> choice = super.createDropDown(id, choices, renderer, required);
            choice.add(new AjaxFormComponentUpdatingBehavior("change") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(getConnectorDropDown().getAdditionalInfoComponent());
                }
            });
            choice.setOutputMarkupId(true);
            return choice;
        }

        @Override
        protected Component createAdditionalInfoComponent(String id) {
            Label l = new Label(id, schemaChangeWarningModel);
            l.add(new AttributeAppender("class", "text-danger"));
            l.setOutputMarkupId(true);
            return l;
        }
    };
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) IModel(org.apache.wicket.model.IModel) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) DropDownFormGroup(com.evolveum.midpoint.web.component.form.DropDownFormGroup) Label(org.apache.wicket.markup.html.basic.Label) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) AttributeAppender(org.apache.wicket.behavior.AttributeAppender)

Example 49 with AttributeAppender

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

the class AuditLogViewerPanel method addOrReplaceTable.

private void addOrReplaceTable(Form mainForm) {
    AuditEventRecordProvider provider = new AuditEventRecordProvider(AuditLogViewerPanel.this) {

        private static final long serialVersionUID = 1L;

        public Map<String, Object> getParameters() {
            Map<String, Object> parameters = new HashMap<String, Object>();
            AuditSearchDto search = auditSearchDto.getObject();
            parameters.put("from", search.getFrom());
            parameters.put("to", search.getTo());
            if (search.getChannel() != null) {
                parameters.put("channel", QNameUtil.qNameToUri(search.getChannel()));
            }
            parameters.put("hostIdentifier", search.getHostIdentifier());
            if (search.getInitiatorName() != null) {
                parameters.put("initiatorName", search.getInitiatorName().getOid());
            }
            if (search.getTargetOwnerName() != null) {
                parameters.put("targetOwnerName", search.getTargetOwnerName().getOid());
            }
            List<String> targetOids = new ArrayList<>();
            if (isNotEmpty(search.getTargetNamesObjects())) {
                targetOids.addAll(search.getTargetNamesObjects().stream().map(ObjectType::getOid).collect(toList()));
            }
            if (isNotEmpty(search.getTargetNames())) {
                targetOids.addAll(search.getTargetNames().stream().map(ObjectReferenceType::getOid).collect(toList()));
            }
            if (!targetOids.isEmpty()) {
                parameters.put("targetNames", targetOids);
            }
            if (search.getChangedItem().toItemPath() != null) {
                ItemPath itemPath = search.getChangedItem().toItemPath();
                parameters.put("changedItem", CanonicalItemPath.create(itemPath).asString());
            }
            parameters.put("eventType", search.getEventType());
            parameters.put("eventStage", search.getEventStage());
            parameters.put("outcome", search.getOutcome());
            if (isNotEmpty(search.getvalueRefTargetNames())) {
                parameters.put(AuditEventRecordProvider.VALUE_REF_TARGET_NAMES_KEY, search.getvalueRefTargetNames().stream().map(ObjectType::getName).map(PolyStringType::getOrig).collect(toList()));
            }
            return parameters;
        }

        @Override
        protected void saveCurrentPage(long from, long count) {
            if (count != 0) {
                auditLogStorage.setPageNumber(from / count);
            }
        }
    };
    UserProfileStorage userProfile = pageBase.getSessionStorage().getUserProfile();
    int pageSize = DEFAULT_PAGE_SIZE;
    if (userProfile.getTables().containsKey(UserProfileStorage.TableId.PAGE_AUDIT_LOG_VIEWER)) {
        pageSize = userProfile.getPagingSize(UserProfileStorage.TableId.PAGE_AUDIT_LOG_VIEWER);
    }
    List<IColumn<AuditEventRecordType, String>> columns = initColumns();
    BoxedTablePanel<AuditEventRecordType> table = new BoxedTablePanel<AuditEventRecordType>(ID_TABLE, provider, columns, UserProfileStorage.TableId.PAGE_AUDIT_LOG_VIEWER, pageSize) {

        private static final long serialVersionUID = 1L;

        @Override
        protected WebMarkupContainer createButtonToolbar(String id) {
            String fileName = "AuditLogViewer_" + createStringResource("MainObjectListPanel.exportFileName").getString();
            CSVDataExporter csvDataExporter = new CSVDataExporter() {

                @Override
                public <T> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T, ?>> columns, OutputStream outputStream) throws IOException {
                    ((AuditEventRecordProvider) dataProvider).setExportSize(true);
                    super.exportData(dataProvider, columns, outputStream);
                    ((AuditEventRecordProvider) dataProvider).setExportSize(false);
                }
            };
            ResourceStreamResource resource = (new ResourceStreamResource() {

                protected IResourceStream getResourceStream() {
                    return new ExportToolbar.DataExportResourceStreamWriter(csvDataExporter, getAuditLogViewerTable().getDataTable());
                }
            }).setFileName(fileName + "." + csvDataExporter.getFileNameExtension());
            AbstractLink exportDataLink = (new ResourceLink(id, resource)).setBody(csvDataExporter.getDataFormatNameModel());
            exportDataLink.add(new AttributeAppender("class", " btn btn-primary btn-sm"));
            return exportDataLink;
        }

        @Override
        public void setShowPaging(boolean show) {
        //we don't need to do anything here
        }
    };
    table.setShowPaging(true);
    table.setCurrentPage(auditLogStorage.getPageNumber());
    table.setOutputMarkupId(true);
    mainForm.addOrReplace(table);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) CSVDataExporter(org.apache.wicket.extensions.markup.html.repeater.data.table.export.CSVDataExporter) HashMap(java.util.HashMap) AuditSearchDto(com.evolveum.midpoint.web.page.admin.reports.dto.AuditSearchDto) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) IDataProvider(org.apache.wicket.markup.repeater.data.IDataProvider) AuditEventRecordProvider(com.evolveum.midpoint.web.page.admin.reports.dto.AuditEventRecordProvider) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) ResourceStreamResource(org.apache.wicket.request.resource.ResourceStreamResource) ResourceLink(org.apache.wicket.markup.html.link.ResourceLink) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) BoxedTablePanel(com.evolveum.midpoint.web.component.data.BoxedTablePanel) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) AbstractLink(org.apache.wicket.markup.html.link.AbstractLink) CanonicalItemPath(com.evolveum.midpoint.prism.path.CanonicalItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 50 with AttributeAppender

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

the class JasperReportConfigurationPanel method createTextPanel.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <J> Component createTextPanel(String componentId, final IModel<J> model, String expression, final Boolean mandatory) {
    TextPanel<String> textPanel = new TextPanel<String>(componentId, new PropertyModel<String>(model, expression));
    FormComponent input = textPanel.getBaseFormComponent();
    input.add(new AttributeAppender("style", "width: 100%"));
    input.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
    input.add(new IValidator() {

        private static final long serialVersionUID = 1L;

        @Override
        public void validate(IValidatable validatable) {
            if (!mandatory) {
                return;
            }
            if (validatable.getValue() == null) {
                validatable.error(new ValidationError("JasperReportConfigurationPanel.errormsg"));
            }
        }
    });
    return textPanel;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) IValidator(org.apache.wicket.validation.IValidator) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) ValidationError(org.apache.wicket.validation.ValidationError) AttributeAppender(org.apache.wicket.behavior.AttributeAppender) IValidatable(org.apache.wicket.validation.IValidatable)

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