Search in sources :

Example 6 with TimeGraphTreeElement

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);
}
Also used : StateRectangle(org.lttng.scope.views.timeline.widgets.timegraph.StateRectangle) TimeGraphTreeElement(com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeElement)

Aggregations

TimeGraphTreeElement (com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeElement)6 TimeRange (com.efficios.jabberwocky.common.TimeRange)2 TimeGraphModelStateProvider (com.efficios.jabberwocky.views.timegraph.model.provider.states.TimeGraphModelStateProvider)2 TimeGraphEvent (com.efficios.jabberwocky.views.timegraph.model.render.TimeGraphEvent)2 TimeGraphArrow (com.efficios.jabberwocky.views.timegraph.model.render.arrows.TimeGraphArrow)2 TimeGraphArrowRender (com.efficios.jabberwocky.views.timegraph.model.render.arrows.TimeGraphArrowRender)2 TimeGraphArrowSeries (com.efficios.jabberwocky.views.timegraph.model.render.arrows.TimeGraphArrowSeries)2 TimeGraphStateRender (com.efficios.jabberwocky.views.timegraph.model.render.states.TimeGraphStateRender)2 Collections (java.util.Collections)2 List (java.util.List)2 FutureTask (java.util.concurrent.FutureTask)2 Collectors (java.util.stream.Collectors)2 Nullable (org.jetbrains.annotations.Nullable)2 ColorDefinition (com.efficios.jabberwocky.views.common.ColorDefinition)1 LineThickness (com.efficios.jabberwocky.views.timegraph.model.render.LineThickness)1 StateDefinition (com.efficios.jabberwocky.views.timegraph.model.render.StateDefinition)1 BasicTimeGraphStateInterval (com.efficios.jabberwocky.views.timegraph.model.render.states.BasicTimeGraphStateInterval)1 TimeGraphStateInterval (com.efficios.jabberwocky.views.timegraph.model.render.states.TimeGraphStateInterval)1 TimeGraphTreeRender (com.efficios.jabberwocky.views.timegraph.model.render.tree.TimeGraphTreeRender)1 ImmutableList (com.google.common.collect.ImmutableList)1