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