1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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 * Alexandre Montplaisir - Initial API and implementation
11 * Patrick Tasse - Support selection range
12 * Xavier Raynaud - Support filters tracking
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.tmf
.core
.trace
;
17 import org
.eclipse
.core
.resources
.IFile
;
18 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
19 import org
.eclipse
.jdt
.annotation
.Nullable
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
26 * Context of a trace, which is the representation of the "view" the user
27 * currently has on this trace (window time range, selected time or time range).
29 * TODO could be extended to support the notion of current location too.
31 * @author Alexandre Montplaisir
34 final class TmfTraceContext
{
36 static final TmfTraceContext NULL_CONTEXT
=
37 new TmfTraceContext(TmfTimestamp
.BIG_CRUNCH
, TmfTimestamp
.BIG_CRUNCH
, TmfTimeRange
.NULL_RANGE
, null);
39 private final TmfTimeRange fSelection
;
40 private final TmfTimeRange fWindowRange
;
41 private final @Nullable IFile fEditorFile
;
42 private final @Nullable ITmfFilter fFilter
;
44 public TmfTraceContext(ITmfTimestamp beginTs
, ITmfTimestamp endTs
, TmfTimeRange tr
, @Nullable IFile editorFile
) {
45 fSelection
= new TmfTimeRange(beginTs
, endTs
);
47 fEditorFile
= editorFile
;
51 public TmfTraceContext(TmfTraceContext prevCtx
, ITmfTimestamp beginTs
, ITmfTimestamp endTs
) {
52 fSelection
= new TmfTimeRange(beginTs
, endTs
);
53 fWindowRange
= prevCtx
.fWindowRange
;
54 fEditorFile
= prevCtx
.fEditorFile
;
55 fFilter
= prevCtx
.fFilter
;
58 public TmfTraceContext(TmfTraceContext prevCtx
, TmfTimeRange tr
) {
59 fSelection
= prevCtx
.fSelection
;
61 fEditorFile
= prevCtx
.fEditorFile
;
62 fFilter
= prevCtx
.fFilter
;
67 * The previous context
71 public TmfTraceContext(TmfTraceContext prevCtx
, @Nullable ITmfFilter filter
) {
72 fSelection
= prevCtx
.fSelection
;
73 fWindowRange
= prevCtx
.fWindowRange
;
74 fEditorFile
= prevCtx
.fEditorFile
;
78 public ITmfTimestamp
getSelectionBegin() {
79 return fSelection
.getStartTime();
82 public ITmfTimestamp
getSelectionEnd() {
83 return fSelection
.getEndTime();
86 public TmfTimeRange
getWindowRange() {
90 public @Nullable IFile
getEditorFile() {
95 * @return the current filter applied to the trace
97 public @Nullable ITmfFilter
getFilter() {
101 public boolean isValid() {
102 if (fSelection
.getStartTime().compareTo(TmfTimestamp
.ZERO
) <= 0 ||
103 fSelection
.getEndTime().compareTo(TmfTimestamp
.ZERO
) <= 0 ||
104 fWindowRange
.getEndTime().compareTo(fWindowRange
.getStartTime()) <= 0) {
111 public String
toString() {
112 return getClass().getSimpleName() + "[fSelection=" + fSelection
+ //$NON-NLS-1$
113 ", fWindowRange=" + fWindowRange
+ ']'; //$NON-NLS-1$