Commit | Line | Data |
---|---|---|
fc526aef | 1 | /******************************************************************************* |
deaae6e1 | 2 | * Copyright (c) 2013, 2014 Ericsson |
fc526aef AM |
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 | * Contributors: | |
10 | * Alexandre Montplaisir - Initial API and implementation | |
0fcf3b09 | 11 | * Patrick Tasse - Support selection range |
d3de0920 | 12 | * Xavier Raynaud - Support filters tracking |
fc526aef AM |
13 | *******************************************************************************/ |
14 | ||
15 | package org.eclipse.linuxtools.tmf.core.trace; | |
16 | ||
deaae6e1 | 17 | import org.eclipse.core.resources.IFile; |
d3de0920 | 18 | import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter; |
fc526aef AM |
19 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
20 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
21 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
22 | ||
23 | /** | |
24 | * Context of a trace, which is the representation of the "view" the user | |
0fcf3b09 | 25 | * currently has on this trace (window time range, selected time or time range). |
fc526aef AM |
26 | * |
27 | * TODO could be extended to support the notion of current location too. | |
28 | * | |
29 | * @author Alexandre Montplaisir | |
30 | * @since 2.0 | |
31 | */ | |
32 | final class TmfTraceContext { | |
33 | ||
34 | static final TmfTraceContext NULL_CONTEXT = | |
deaae6e1 | 35 | new TmfTraceContext(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH, TmfTimeRange.NULL_RANGE, null); |
fc526aef | 36 | |
0fcf3b09 PT |
37 | private final TmfTimeRange fSelection; |
38 | private final TmfTimeRange fWindowRange; | |
deaae6e1 | 39 | private final IFile fEditorFile; |
d3de0920 | 40 | private final ITmfFilter fFilter; |
fc526aef | 41 | |
deaae6e1 | 42 | public TmfTraceContext(ITmfTimestamp beginTs, ITmfTimestamp endTs, TmfTimeRange tr, IFile editorFile) { |
0fcf3b09 PT |
43 | fSelection = new TmfTimeRange(beginTs, endTs); |
44 | fWindowRange = tr; | |
deaae6e1 | 45 | fEditorFile = editorFile; |
d3de0920 | 46 | fFilter = null; |
fc526aef AM |
47 | } |
48 | ||
0fcf3b09 PT |
49 | public TmfTraceContext(TmfTraceContext prevCtx, ITmfTimestamp beginTs, ITmfTimestamp endTs) { |
50 | fSelection = new TmfTimeRange(beginTs, endTs); | |
51 | fWindowRange = prevCtx.fWindowRange; | |
deaae6e1 | 52 | fEditorFile = prevCtx.fEditorFile; |
d3de0920 | 53 | fFilter = prevCtx.fFilter; |
fc526aef AM |
54 | } |
55 | ||
0fcf3b09 PT |
56 | public TmfTraceContext(TmfTraceContext prevCtx, TmfTimeRange tr) { |
57 | fSelection = prevCtx.fSelection; | |
58 | fWindowRange = tr; | |
deaae6e1 | 59 | fEditorFile = prevCtx.fEditorFile; |
d3de0920 XR |
60 | fFilter = prevCtx.fFilter; |
61 | } | |
62 | ||
63 | /** | |
64 | * @param prevCtx | |
65 | * The previous context | |
66 | * @param filter | |
67 | * The applied filter | |
68 | * @since 2.2 | |
69 | */ | |
70 | public TmfTraceContext(TmfTraceContext prevCtx, ITmfFilter filter) { | |
71 | fSelection = prevCtx.fSelection; | |
72 | fWindowRange = prevCtx.fWindowRange; | |
deaae6e1 | 73 | fEditorFile = prevCtx.fEditorFile; |
d3de0920 | 74 | fFilter = filter; |
fc526aef AM |
75 | } |
76 | ||
0fcf3b09 PT |
77 | public ITmfTimestamp getSelectionBegin() { |
78 | return fSelection.getStartTime(); | |
79 | } | |
80 | ||
81 | public ITmfTimestamp getSelectionEnd() { | |
82 | return fSelection.getEndTime(); | |
83 | } | |
84 | ||
85 | public TmfTimeRange getWindowRange() { | |
86 | return fWindowRange; | |
fc526aef AM |
87 | } |
88 | ||
deaae6e1 PT |
89 | public IFile getEditorFile() { |
90 | return fEditorFile; | |
91 | } | |
92 | ||
d3de0920 XR |
93 | /** |
94 | * @return the current filter applied to the trace | |
95 | * @since 2.2 | |
96 | */ | |
97 | public ITmfFilter getFilter() { | |
98 | return fFilter; | |
99 | } | |
100 | ||
fc526aef | 101 | public boolean isValid() { |
0fcf3b09 PT |
102 | if (fSelection.getStartTime().compareTo(TmfTimestamp.ZERO) <= 0 || |
103 | fSelection.getEndTime().compareTo(TmfTimestamp.ZERO) <= 0 || | |
104 | fWindowRange.getEndTime().compareTo(fWindowRange.getStartTime()) <= 0) { | |
fc526aef AM |
105 | return false; |
106 | } | |
107 | return true; | |
108 | } | |
109 | ||
110 | @Override | |
111 | public String toString() { | |
0fcf3b09 PT |
112 | return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$ |
113 | ", fWindowRange=" + fWindowRange + ']'; //$NON-NLS-1$ | |
fc526aef AM |
114 | } |
115 | } |