Search in sources :

Example 6 with TmfCollapseFilter

use of org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter in project tracecompass by tracecompass.

the class TmfEventsTable method applyEventFilter.

private ITmfFilterTreeNode applyEventFilter(ITmfFilter filter) {
    stopFilterThread();
    stopSearchThread();
    fFilterMatchCount = 0;
    fFilterCheckCount = 0;
    ITmfFilterTreeNode rootFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ);
    if (rootFilter == null) {
        rootFilter = new TmfFilterRootNode();
    }
    if (filter instanceof TmfFilterRootNode) {
        TmfFilterRootNode parentFilter = (TmfFilterRootNode) filter;
        for (ITmfFilterTreeNode child : parentFilter.getChildren()) {
            rootFilter.addChild(child);
        }
    } else if (filter instanceof TmfCollapseFilter) {
        fCollapseFilterEnabled = true;
    } else if (filter instanceof ITmfFilterTreeNode) {
        rootFilter.addChild((ITmfFilterTreeNode) filter);
    } else {
        rootFilter.addChild(new TmfFilterObjectNode(filter));
    }
    fCache.applyFilter(rootFilter, fCollapseFilterEnabled);
    fHeaderBar.addFilter(filter);
    fTable.clearAll();
    fTable.setData(Key.FILTER_OBJ, rootFilter);
    /* +1 for header row, +2 for top and bottom filter status rows */
    fTable.setItemCount(3);
    startFilterThread();
    return rootFilter;
}
Also used : ITmfFilterTreeNode(org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode) TmfFilterRootNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode) TmfCollapseFilter(org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter) TmfFilterObjectNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterObjectNode)

Example 7 with TmfCollapseFilter

use of org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter in project tracecompass by tracecompass.

the class TmfEventTableDataProvider method fetchLines.

@Override
public TmfModelResponse<ITmfVirtualTableModel<EventTableLine>> fetchLines(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    if (!fetchParameters.containsKey(DataProviderParameterUtils.REQUESTED_TABLE_INDEX_KEY) && fetchParameters.containsKey(DataProviderParameterUtils.REQUESTED_TIME_KEY)) {
        fetchParameters.put(DataProviderParameterUtils.REQUESTED_TABLE_INDEX_KEY, getTableIndex(fetchParameters));
    }
    if (!fetchParameters.containsKey(DataProviderParameterUtils.REQUESTED_COLUMN_IDS_KEY)) {
        fetchParameters.put(DataProviderParameterUtils.REQUESTED_COLUMN_IDS_KEY, Collections.emptyList());
    }
    VirtualTableQueryFilter queryFilter = FetchParametersUtils.createVirtualTableQueryFilter(fetchParameters);
    if (queryFilter == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    @Nullable ITmfFilter filter = extractFilter(fetchParameters);
    @Nullable ITmfFilter searchFilter = extractSearchFilter(fetchParameters);
    @Nullable TmfCollapseFilter collapseFilter = extractCollapseFilter(fetchParameters);
    Map<Long, ITmfEventAspect<?>> aspects = getAspectsFromColumnsId(queryFilter.getColumnsId());
    if (aspects.isEmpty()) {
        return new TmfModelResponse<>(new TmfVirtualTableModel<>(Collections.emptyList(), Collections.emptyList(), queryFilter.getIndex(), 0), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    List<Long> columnsIds = new ArrayList<>(aspects.keySet());
    if (getTrace().getNbEvents() == 0) {
        return new TmfModelResponse<>(new TmfVirtualTableModel<>(columnsIds, Collections.emptyList(), queryFilter.getIndex(), 0), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    /*
         * Search for the next or previous event starting from the given event index
         */
    Object directionValue = fetchParameters.get(TABLE_SEARCH_DIRECTION_KEY);
    // ///////////////////////////////////
    // TODO remove isFiltered when Theia front-end is updated to use TABLE_SEARCH_DIRECTION_KEY instead
    Boolean isFiltered = DataProviderParameterUtils.extractIsFiltered(fetchParameters);
    boolean isIndexRequest = isFiltered != null && isFiltered;
    if (isIndexRequest && directionValue == null) {
        directionValue = Direction.NEXT.name();
    }
    if (searchFilter != null && directionValue != null) {
        Direction direction = directionValue.equals(Direction.PREVIOUS.name()) ? Direction.PREVIOUS : Direction.NEXT;
        @Nullable WrappedEvent event = null;
        Predicate<@NonNull ITmfEvent> predicate;
        if (filter == null) {
            predicate = searchFilter::matches;
        } else {
            predicate = e -> (filter.matches(e) && searchFilter.matches(e));
        }
        if (direction == Direction.NEXT) {
            event = getNextWrappedEventMatching(getTrace(), Math.abs(queryFilter.getIndex()), predicate, monitor);
        } else if (direction == Direction.PREVIOUS) {
            event = getPreviousWrappedEventMatching(getTrace(), Math.abs(queryFilter.getIndex()), predicate, monitor);
        }
        List<EventTableLine> lines = new ArrayList<>();
        long rank = queryFilter.getIndex();
        if (event != null) {
            rank = event.getRank();
            // create new queryFilter with updated start rank to get number of events starting from first matching event
            queryFilter = new VirtualTableQueryFilter(queryFilter.getColumnsId(), rank, queryFilter.getCount());
            lines.add(buildEventTableLine(aspects, event.getOriginalEvent(), rank, rank, true));
        }
        if ((queryFilter.getCount() == 1) || (event == null)) {
            /**
             * If no event was found or the number of requested events is one
             * reply here since all required data for the reply is available.
             */
            TmfVirtualTableModel<EventTableLine> model = new TmfVirtualTableModel<>(columnsIds, lines, rank, getTrace().getNbEvents());
            return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
        }
    }
    /*
         * Collect queryFilter.getCount() number of events from start rank
         */
    /*
         * TODO implement upper limit of queryFilter.getCount() to avoid running out of memory.
         * TBD if the check and should be handled here or in the calling methods.
         */
    TableEventRequest request;
    if (filter != null) {
        request = filteredTableRequest(Math.abs(queryFilter.getCount()), queryFilter.getIndex(), aspects, filter, searchFilter, collapseFilter, monitor);
    } else {
        request = tableRequest(Math.abs(queryFilter.getCount()), queryFilter.getIndex(), aspects, searchFilter, collapseFilter, monitor);
        request.setEventCount(getTrace().getNbEvents());
    }
    getTrace().sendRequest(request);
    try {
        request.waitForCompletion();
    } catch (InterruptedException e) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, NonNullUtils.nullToEmptyString(e.getMessage()));
    }
    if (request.isCancelled()) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
    }
    TmfVirtualTableModel<EventTableLine> model = new TmfVirtualTableModel<>(columnsIds, request.getEventLines(), queryFilter.getIndex(), request.getCurrentCount());
    return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : ITmfEventAspect(org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect) VirtualTableQueryFilter(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filters.VirtualTableQueryFilter) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) TmfVirtualTableModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.TmfVirtualTableModel) ITmfVirtualTableModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.ITmfVirtualTableModel) TmfCollapseFilter(org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) Nullable(org.eclipse.jdt.annotation.Nullable) EventTableLine(org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.EventTableLine)

Aggregations

TmfCollapseFilter (org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter)7 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)3 ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)3 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)3 ArrayList (java.util.ArrayList)2 TmfFilterObjectNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterObjectNode)2 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)2 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)2 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Command (org.eclipse.core.commands.Command)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 NotEnabledException (org.eclipse.core.commands.NotEnabledException)1 NotHandledException (org.eclipse.core.commands.NotHandledException)1 ParameterizedCommand (org.eclipse.core.commands.ParameterizedCommand)1 NotDefinedException (org.eclipse.core.commands.common.NotDefinedException)1 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)1