2 * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 package org
.lttng
.scope
.tmf2
.views
.ui
.timeline
.widgets
.timegraph
.toolbar
.nav
;
12 import static java
.util
.Objects
.requireNonNull
;
14 import java
.util
.function
.Predicate
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.core
.runtime
.jobs
.ISchedulingRule
;
20 import org
.eclipse
.core
.runtime
.jobs
.Job
;
21 import org
.eclipse
.jdt
.annotation
.Nullable
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
28 import org
.lttng
.scope
.tmf2
.views
.ui
.timeline
.widgets
.timegraph
.StateRectangle
;
29 import org
.lttng
.scope
.tmf2
.views
.ui
.timeline
.widgets
.timegraph
.TimeGraphWidget
;
32 * Navigation mode using the current entry's events. It looks through all events
33 * in the trace belonging to the tree entry of the current selected state, and
34 * navigates through them. This allows stopping at events that may not cause a
35 * state change shown in the view.
37 * @author Alexandre Montplaisir
39 public class NavigationModeFollowEvents
extends NavigationMode
{
41 private static final String BACK_ICON_PATH
= "/icons/toolbar/nav_event_back.gif"; //$NON-NLS-1$
42 private static final String FWD_ICON_PATH
= "/icons/toolbar/nav_event_fwd.gif"; //$NON-NLS-1$
45 * Mutex rule for search action jobs, making sure they execute sequentially
47 private final ISchedulingRule fSearchActionMutexRule
= new ISchedulingRule() {
49 public boolean isConflicting(@Nullable ISchedulingRule rule
) {
50 return (rule
== this);
54 public boolean contains(@Nullable ISchedulingRule rule
) {
55 return (rule
== this);
62 public NavigationModeFollowEvents() {
63 super(requireNonNull(Messages
.sfFollowEventsNavModeName
),
69 public void navigateBackwards(TimeGraphWidget viewer
) {
70 navigate(viewer
, false);
74 public void navigateForwards(TimeGraphWidget viewer
) {
75 navigate(viewer
, true);
78 private void navigate(TimeGraphWidget viewer
, boolean forward
) {
79 StateRectangle state
= viewer
.getSelectedState();
80 ITmfTrace trace
= viewer
.getControl().getViewContext().getCurrentTrace();
81 if (state
== null || trace
== null) {
84 Predicate
<ITmfEvent
> predicate
= state
.getStateInterval().getTreeElement().getEventMatching();
85 if (predicate
== null) {
86 /* The tree element does not support navigating by events. */
90 String jobName
= (forward ? Messages
.sfNextEventJobName
: Messages
.sfPreviousEventJobName
);
92 Job job
= new Job(jobName
) {
94 protected IStatus
run(@Nullable IProgressMonitor monitor
) {
95 long currentTime
= TmfTraceManager
.getInstance().getCurrentTraceContext().getSelectionRange().getStartTime().toNanos();
96 ITmfContext ctx
= trace
.seekEvent(TmfTimestamp
.fromNanos(currentTime
));
97 long rank
= ctx
.getRank();
100 ITmfEvent event
= (forward ?
101 TmfTraceUtils
.getNextEventMatching(trace
, rank
, predicate
, monitor
) :
102 TmfTraceUtils
.getPreviousEventMatching(trace
, rank
, predicate
, monitor
));
104 NavUtils
.selectNewTimestamp(viewer
, event
.getTimestamp().toNanos());
106 return Status
.OK_STATUS
;
111 * Make subsequent jobs not run concurrently, but wait after one
114 job
.setRule(fSearchActionMutexRule
);