Search in sources :

Example 21 with ITmfFilter

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

the class TmfEventsTableHeader method addNewFilter.

private void addNewFilter(ITmfFilter filter) {
    CLabel label = new CLabel(this, SWT.SHADOW_OUT);
    label.setBackground(fLabelBackground);
    String text;
    if (filter instanceof TmfFilterNode) {
        text = ((TmfFilterNode) filter).getFilterName();
        label.setData(TOOLTIP_KEY, filter.toString());
    } else {
        text = filter.toString();
    }
    if (fCollapsed) {
        label.setToolTipText(text);
        label.setTopMargin(0);
        label.setBottomMargin(0);
        label.setRightMargin(COLLAPSED_RIGHT_MARGIN);
    } else {
        label.setImage(DELETE);
        label.setText(text);
        label.setToolTipText((String) label.getData(TOOLTIP_KEY));
    }
    label.setData(filter);
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            Rectangle bounds;
            if (fCollapsed) {
                bounds = new Rectangle(0, 0, 2 * COLLAPSED_IMAGE_MARGIN + DELETE_SMALL.getBounds().width, label.getBounds().height);
            } else {
                bounds = DELETE.getBounds();
                bounds.x += label.getLeftMargin();
                bounds.y = (label.getSize().y - bounds.height) / 2;
            }
            if (bounds.contains(e.x, e.y)) {
                fListener.filterRemoved((ITmfFilter) label.getData());
            } else {
                fListener.filterSelected((ITmfFilter) label.getData());
                getParent().layout(true, true);
            }
        }
    });
    label.addPaintListener(e -> {
        if (fCollapsed) {
            e.gc.drawImage(DELETE_SMALL, COLLAPSED_IMAGE_MARGIN, COLLAPSED_IMAGE_MARGIN);
        }
    });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) MouseEvent(org.eclipse.swt.events.MouseEvent) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) TmfFilterNode(org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode)

Example 22 with ITmfFilter

use of org.eclipse.tracecompass.tmf.core.filter.ITmfFilter 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)

Example 23 with ITmfFilter

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

the class TraceCompassFilter method fromRegex.

/**
 * Factory method to get a new filter from a regex
 *
 * @param regex
 *            The regex from which to create the filter
 * @param trace
 *            The trace this filter applies to
 * @return A new filter
 */
public static synchronized TraceCompassFilter fromRegex(Collection<String> regex, ITmfTrace trace) {
    ITmfFilter filter = TmfFilterHelper.buildFilterFromRegex(regex, trace);
    TraceCompassFilter traceCompassFilter = new TraceCompassFilter(filter, regex);
    FILTER_MAP.put(trace, traceCompassFilter);
    return traceCompassFilter;
}
Also used : ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)

Aggregations

ITmfFilter (org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)23 ITmfFilterTreeNode (org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode)11 TmfFilterRootNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode)10 Test (org.junit.Test)10 TmfFilterMatchesNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode)6 ArrayList (java.util.ArrayList)4 ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)4 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)4 TmfEventTableColumn (org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn)4 TableColumn (org.eclipse.swt.widgets.TableColumn)3 TmfCollapseFilter (org.eclipse.tracecompass.internal.tmf.core.filter.TmfCollapseFilter)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 IMarker (org.eclipse.core.resources.IMarker)2 CoreException (org.eclipse.core.runtime.CoreException)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Point (org.eclipse.swt.graphics.Point)2 TmfFilterAndNode (org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterAndNode)2 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)2 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)2