Adapt views plugins to TMF
[deliverable/tracecompass.git] / tmf / org.lttng.scope.tmf2.views.core / src / org / lttng / scope / tmf2 / views / core / timegraph / model / provider / statesystem / StateSystemModelArrowProvider.java
1 /*
2 * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
3 *
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
8 */
9
10 package org.lttng.scope.tmf2.views.core.timegraph.model.provider.statesystem;
11
12 import java.util.concurrent.FutureTask;
13
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
16 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
17 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
18 import org.lttng.scope.tmf2.views.core.TimeRange;
19 import org.lttng.scope.tmf2.views.core.timegraph.model.provider.arrows.TimeGraphModelArrowProvider;
20 import org.lttng.scope.tmf2.views.core.timegraph.model.render.arrows.TimeGraphArrowRender;
21 import org.lttng.scope.tmf2.views.core.timegraph.model.render.arrows.TimeGraphArrowSeries;
22 import org.lttng.scope.tmf2.views.core.timegraph.model.render.tree.TimeGraphTreeRender;
23
24 /**
25 * Basic implementation of a {@link TimeGraphModelArrowProvider} backed by a
26 * state system.
27 *
28 * @author Alexandre Montplaisir
29 */
30 public abstract class StateSystemModelArrowProvider extends TimeGraphModelArrowProvider {
31
32 private final String fStateSystemModuleId;
33
34 private transient @Nullable ITmfStateSystem fStateSystem = null;
35
36 /**
37 * Constructor
38 *
39 * @param arrowSeries
40 * The arrow series that will be represented by this arrow
41 * provider
42 * @param stateSystemModuleId
43 * The ID of the state system from which the information should
44 * be fetched
45 */
46 public StateSystemModelArrowProvider(TimeGraphArrowSeries arrowSeries,
47 String stateSystemModuleId) {
48 super(arrowSeries);
49 fStateSystemModuleId = stateSystemModuleId;
50
51 /*
52 * Change listener which will take care of keeping the target state
53 * system up to date.
54 */
55 traceProperty().addListener((obs, oldValue, newValue) -> {
56 ITmfTrace trace = newValue;
57 if (trace == null) {
58 fStateSystem = null;
59 return;
60 }
61
62 // FIXME Remove the extra thread once we move to Jabberwocky
63 Thread thread = new Thread(() -> {
64 fStateSystem = TmfStateSystemAnalysisModule.getStateSystem(trace, fStateSystemModuleId);
65 });
66 thread.start();
67 });
68 }
69
70 /**
71 * The state system from which the data should be fetched. This will be kept
72 * in sync with the {@link #traceProperty}.
73 *
74 * @return The target state system. It will be null if the current trace is
75 * null.
76 */
77 protected final @Nullable ITmfStateSystem getStateSystem() {
78 return fStateSystem;
79 }
80
81 @Override
82 public abstract TimeGraphArrowRender getArrowRender(TimeGraphTreeRender treeRender, TimeRange timeRange, @Nullable FutureTask<?> task);
83 }
This page took 0.031131 seconds and 5 git commands to generate.