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);
}
}
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();
});
}
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);
}
}
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;
}
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;
}
Aggregations