Search in sources :

Example 11 with ITmfFilter

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

the class TmfEventsTable method eventFilterApplied.

/**
 * Receive a signal to apply a filter. This will apply the filter if the
 * source is not this viewer already
 *
 * @param signal
 *            The signal
 * @since 4.2
 */
@TmfSignalHandler
public void eventFilterApplied(TmfFilterAppliedSignal signal) {
    if (signal.getSource() == this) {
        // This view is the source of the signal, ignore
        return;
    }
    Runnable runnable = () -> {
        if (fTable.isDisposed()) {
            return;
        }
        ITmfFilter eventFilter = signal.getFilter().getEventFilter();
        if (eventFilter == null) {
            fTable.setData(Key.SEARCH_OBJ, null);
            fTable.refresh();
        } else {
            fTable.setData(Key.SEARCH_OBJ, eventFilter);
            fTable.refresh();
            searchNext();
        }
    };
    Display display = PlatformUI.getWorkbench().getDisplay();
    if (display == Display.getCurrent()) {
        runnable.run();
    } else {
        Display.getDefault().asyncExec(runnable);
    }
}
Also used : ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) SafeRunnable(org.eclipse.jface.util.SafeRunnable) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) Display(org.eclipse.swt.widgets.Display) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler)

Example 12 with ITmfFilter

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

the class TmfEventsTable method setItemData.

/**
 * Set a table item's data.
 *
 * @param item
 *            The item to set
 * @param event
 *            Which trace event to link with this entry
 * @param rank
 *            Which rank this event has in the trace/experiment
 */
protected void setItemData(final TableItem item, final ITmfEvent event, final long rank) {
    String[] itemStrings = getItemStrings(fColumns, event);
    // Get the actual ITmfEvent from the CachedEvent
    ITmfEvent tmfEvent = event;
    if (event instanceof CachedEvent) {
        tmfEvent = ((CachedEvent) event).event;
    }
    item.setText(itemStrings);
    item.setData(tmfEvent);
    item.setData(Key.TIMESTAMP, tmfEvent.getTimestamp());
    item.setData(Key.RANK, rank);
    final Collection<Long> markerIds = fBookmarksMap.get(rank);
    if (!markerIds.isEmpty()) {
        // $NON-NLS-1$
        Joiner joiner = Joiner.on("\n -").skipNulls();
        List<Object> parts = new ArrayList<>();
        if (markerIds.size() > 1) {
            parts.add(Messages.TmfEventsTable_MultipleBookmarksToolTip);
        }
        try {
            for (long markerId : markerIds) {
                final IMarker marker = fBookmarksFile.findMarker(markerId);
                if (marker != null) {
                    parts.add(marker.getAttribute(IMarker.MESSAGE));
                }
            }
        } catch (CoreException e) {
            TraceUtils.displayErrorMsg(e);
        }
        item.setData(Key.BOOKMARK, joiner.join(parts));
    } else {
        item.setData(Key.BOOKMARK, null);
    }
    boolean searchMatch = false;
    boolean searchNoMatch = false;
    final ITmfFilter searchFilter = (ITmfFilter) fTable.getData(Key.SEARCH_OBJ);
    if (searchFilter != null) {
        if (searchFilter.matches(tmfEvent)) {
            searchMatch = true;
        } else {
            searchNoMatch = true;
        }
    }
    final ColorSetting colorSetting = ColorSettingsManager.getColorSetting(tmfEvent);
    if (searchNoMatch) {
        item.setForeground(colorSetting.getDimmedForegroundColor());
        item.setBackground(colorSetting.getDimmedBackgroundColor());
    } else {
        Color fc = colorSetting.getForegroundColor();
        item.setData(Key.IS_DEFAULT_FG_COLOR, fc == null);
        item.setForeground(fc);
        item.setBackground(colorSetting.getBackgroundColor());
    }
    item.setFont(fFont);
    if (searchMatch) {
        if (!markerIds.isEmpty()) {
            item.setImage(SEARCH_MATCH_BOOKMARK_IMAGE);
        } else {
            item.setImage(SEARCH_MATCH_IMAGE);
        }
    } else if (!markerIds.isEmpty()) {
        item.setImage(BOOKMARK_IMAGE);
    } else {
        item.setImage((Image) null);
    }
    List<StyleRange> styleRanges = new ArrayList<>();
    for (int index = 0; index < fTable.getColumns().length; index++) {
        TableColumn column = fTable.getColumns()[index];
        String regex = null;
        if (fHeaderState == HeaderState.SEARCH) {
            if (searchMatch) {
                regex = (String) column.getData(Key.SEARCH_TXT);
            }
        } else {
            regex = (String) column.getData(Key.FILTER_TXT);
        }
        if (regex != null) {
            String text = item.getText(index);
            try {
                Pattern pattern = Pattern.compile(regex);
                Matcher matcher = pattern.matcher(text);
                while (matcher.find()) {
                    int start = matcher.start();
                    int length = matcher.end() - start;
                    Color foreground = colorSetting.getForegroundColor();
                    Color background = fHighlightColor;
                    StyleRange styleRange = new StyleRange(start, length, foreground, background);
                    styleRange.data = index;
                    styleRanges.add(styleRange);
                }
            } catch (PatternSyntaxException e) {
            /* ignored */
            }
        }
    }
    if (styleRanges.isEmpty()) {
        item.setData(Key.STYLE_RANGES, null);
    } else {
        item.setData(Key.STYLE_RANGES, styleRanges);
    }
    item.getParent().redraw();
    if ((itemStrings[MARGIN_COLUMN_INDEX] != null) && !itemStrings[MARGIN_COLUMN_INDEX].isEmpty()) {
        packMarginColumn();
    }
    TmfUiRefreshHandler.getInstance().queueUpdate(this, () -> {
        if (fTable.isDisposed()) {
            return;
        }
        packColumns();
    });
}
Also used : Matcher(java.util.regex.Matcher) StyleRange(org.eclipse.swt.custom.StyleRange) ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Image(org.eclipse.swt.graphics.Image) PatternSyntaxException(java.util.regex.PatternSyntaxException) ColorSetting(org.eclipse.tracecompass.tmf.ui.views.colors.ColorSetting) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) CachedEvent(org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsCache.CachedEvent) Color(org.eclipse.swt.graphics.Color) TmfEventTableColumn(org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) CoreException(org.eclipse.core.runtime.CoreException) IMarker(org.eclipse.core.resources.IMarker)

Example 13 with ITmfFilter

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

the class TmfEventsTable method applySearchAsFilter.

/**
 * Apply the current search condition as a new filter.
 *
 * @since 2.0
 */
protected void applySearchAsFilter() {
    Object searchObj = fTable.getData(Key.SEARCH_OBJ);
    if (searchObj instanceof ITmfFilter) {
        ITmfFilter filter = (ITmfFilter) searchObj;
        fTable.setData(Key.SEARCH_OBJ, null);
        fireSearchApplied(null);
        fHeaderState = HeaderState.NO_SEARCH;
        for (final TableColumn col : fTable.getColumns()) {
            col.setData(Key.FILTER_TXT, col.getData(Key.SEARCH_TXT));
            col.setData(Key.SEARCH_TXT, null);
            col.setData(Key.SEARCH_OBJ, null);
        }
        applyFilter(filter);
    }
}
Also used : ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) TmfEventTableColumn(org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 14 with ITmfFilter

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

the class ColorSettingsManager method getColorSettingPriority.

/**
 * Gets the color settings priority for the given event.
 *
 * @param event A event the event to check
 * @return the priority defined for the filter else PRIORITY_NONE
 */
public static int getColorSettingPriority(ITmfEvent event) {
    for (int i = 0; i < fColorSettings.length; i++) {
        ColorSetting colorSetting = fColorSettings[i];
        ITmfFilter filter = colorSetting.getFilter();
        if (filter != null && filter.matches(event)) {
            return i;
        }
    }
    return PRIORITY_NONE;
}
Also used : ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter)

Example 15 with ITmfFilter

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

the class ExportToTextCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    List<TmfEventTableColumn> columns = getColumns(event.getApplicationContext());
    ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
    ITmfFilter filter = TmfTraceManager.getInstance().getCurrentTraceContext().getFilter();
    if (trace != null) {
        FileDialog fd = TmfFileDialogFactory.create(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        fd.setFilterExtensions(new String[] { "*.csv", "*.*", "*" });
        fd.setOverwrite(true);
        final String s = fd.open();
        if (s != null) {
            Job j = new ExportToTextJob(trace, filter, columns, s);
            j.setUser(true);
            j.schedule();
        }
    }
    return null;
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) TmfEventTableColumn(org.eclipse.tracecompass.tmf.ui.viewers.events.columns.TmfEventTableColumn) Job(org.eclipse.core.runtime.jobs.Job) FileDialog(org.eclipse.swt.widgets.FileDialog)

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