Search in sources :

Example 1 with IDataProvider

use of org.apache.wicket.markup.repeater.data.IDataProvider in project midpoint by Evolveum.

the class CheckBoxHeaderColumn method onUpdateHeader.

/**
     * This method is called after select all checkbox is clicked
     * @param target
     * @param selected
     * @param table
     */
protected void onUpdateHeader(AjaxRequestTarget target, boolean selected, DataTable table) {
    IDataProvider provider = table.getDataProvider();
    if (!(provider instanceof BaseSortableDataProvider)) {
        LOGGER.debug("Select all checkbox work only with {} provider type. Current provider is type of {}.", new Object[] { BaseSortableDataProvider.class.getName(), provider.getClass().getName() });
    }
    //update selected flag in model dto objects based on select all header state
    BaseSortableDataProvider baseProvider = (BaseSortableDataProvider) provider;
    List<T> objects = baseProvider.getAvailableData();
    for (T object : objects) {
        if (object instanceof Selectable) {
            Selectable selectable = (Selectable) object;
            selectable.setSelected(selected);
        }
    }
    //refresh rows with ajax
    ComponentHierarchyIterator iterator = table.visitChildren(SelectableDataTable.SelectableRowItem.class);
    while (iterator.hasNext()) {
        SelectableDataTable.SelectableRowItem row = (SelectableDataTable.SelectableRowItem) iterator.next();
        if (!row.getOutputMarkupId()) {
            //we skip rows that doesn't have outputMarkupId set to true (it would fail)
            continue;
        }
        target.add(row);
    }
}
Also used : ComponentHierarchyIterator(org.apache.wicket.util.iterator.ComponentHierarchyIterator) BaseSortableDataProvider(com.evolveum.midpoint.web.component.data.BaseSortableDataProvider) SelectableDataTable(com.evolveum.midpoint.web.component.data.SelectableDataTable) Selectable(com.evolveum.midpoint.web.component.util.Selectable) IDataProvider(org.apache.wicket.markup.repeater.data.IDataProvider)

Example 2 with IDataProvider

use of org.apache.wicket.markup.repeater.data.IDataProvider 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)

Aggregations

IDataProvider (org.apache.wicket.markup.repeater.data.IDataProvider)2 CanonicalItemPath (com.evolveum.midpoint.prism.path.CanonicalItemPath)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 BaseSortableDataProvider (com.evolveum.midpoint.web.component.data.BaseSortableDataProvider)1 BoxedTablePanel (com.evolveum.midpoint.web.component.data.BoxedTablePanel)1 SelectableDataTable (com.evolveum.midpoint.web.component.data.SelectableDataTable)1 Selectable (com.evolveum.midpoint.web.component.util.Selectable)1 AuditEventRecordProvider (com.evolveum.midpoint.web.page.admin.reports.dto.AuditEventRecordProvider)1 AuditSearchDto (com.evolveum.midpoint.web.page.admin.reports.dto.AuditSearchDto)1 UserProfileStorage (com.evolveum.midpoint.web.session.UserProfileStorage)1 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 AttributeAppender (org.apache.wicket.behavior.AttributeAppender)1