use of com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeElement in project lttng-scope by lttng.
the class NavigationModeFollowStateChanges method navigate.
private static void navigate(TimeGraphWidget viewer, boolean forward) {
StateRectangle state = viewer.getSelectedState();
if (state == null) {
return;
}
long stateStartTime = state.getStateInterval().getStartEvent().getTimestamp();
long stateEndTime = state.getStateInterval().getEndEvent().getTimestamp();
/* Aim to go to the start/end of the next/previous interval */
long targetTimestamp = (forward ? stateEndTime + 1 : stateStartTime - 1);
TimeGraphTreeElement treeElement = state.getStateInterval().getStartEvent().getTreeElement();
List<StateRectangle> potentialStates = getPotentialStates(viewer, targetTimestamp, treeElement, forward);
if (potentialStates.isEmpty()) {
/*
* We either reached the end of our model or an edge of the trace.
* Go to the end/start of the current state.
*/
long bound = (forward ? stateEndTime : stateStartTime);
NavUtils.selectNewTimestamp(viewer, bound);
return;
}
/*
* Also compute the intervals that intersect the target timestamp.
* We will prefer those, but if there aren't any, we'll pick the
* best "potential" state.
*/
List<StateRectangle> intersectingStates = getIntersectingStates(potentialStates, targetTimestamp, forward);
StateRectangle newState;
if (intersectingStates.isEmpty()) {
/*
* Let's look back into 'potentialStates' (non-intersecting)
* and pick the interval with the closest bound.
*/
Optional<StateRectangle> optState = getBestPotentialState(potentialStates, forward);
if (!optState.isPresent()) {
/* We did our best and didn't find anything. */
return;
}
newState = optState.get();
} else if (intersectingStates.size() == 1) {
/* There is only one match, must be the right one. */
newState = intersectingStates.get(0);
} else {
/*
* There is more than one match (overlapping intervals, can
* happen sometimes with multi-states). Pick the one with the
* earliest start time (for backwards) or latest end time (for
* forwards), to ensure we "move out" on the next action.
*/
newState = intersectingStates.stream().sorted(forward ? LATEST_END_TIME_COMPARATOR : EARLIEST_START_TIME_COMPARATOR).findFirst().get();
}
viewer.setSelectedState(newState, true);
newState.showTooltip(forward);
NavUtils.selectNewTimestamp(viewer, targetTimestamp);
}
Aggregations