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
.tracecompass
.tmf
.core
.filter
.ITmfFilter
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
24 * Context of a trace, which is the representation of the "view" the user
25 * currently has on this trace (window time range, selected time or time range).
27 * TODO could be extended to support the notion of current location too.
29 * @author Alexandre Montplaisir
32 final class TmfTraceContext
{
34 static final TmfTraceContext NULL_CONTEXT
=
35 new TmfTraceContext(TmfTimestamp
.BIG_CRUNCH
, TmfTimestamp
.BIG_CRUNCH
, TmfTimeRange
.NULL_RANGE
, null);
37 private final TmfTimeRange fSelection
;
38 private final TmfTimeRange fWindowRange
;
39 private final IFile fEditorFile
;
40 private final ITmfFilter fFilter
;
42 public TmfTraceContext(ITmfTimestamp beginTs
, ITmfTimestamp endTs
, TmfTimeRange tr
, IFile editorFile
) {
43 fSelection
= new TmfTimeRange(beginTs
, endTs
);
45 fEditorFile
= editorFile
;
49 public TmfTraceContext(TmfTraceContext prevCtx
, ITmfTimestamp beginTs
, ITmfTimestamp endTs
) {
50 fSelection
= new TmfTimeRange(beginTs
, endTs
);
51 fWindowRange
= prevCtx
.fWindowRange
;
52 fEditorFile
= prevCtx
.fEditorFile
;
53 fFilter
= prevCtx
.fFilter
;
56 public TmfTraceContext(TmfTraceContext prevCtx
, TmfTimeRange tr
) {
57 fSelection
= prevCtx
.fSelection
;
59 fEditorFile
= prevCtx
.fEditorFile
;
60 fFilter
= prevCtx
.fFilter
;
65 * The previous context
70 public TmfTraceContext(TmfTraceContext prevCtx
, ITmfFilter filter
) {
71 fSelection
= prevCtx
.fSelection
;
72 fWindowRange
= prevCtx
.fWindowRange
;
73 fEditorFile
= prevCtx
.fEditorFile
;
77 public ITmfTimestamp
getSelectionBegin() {
78 return fSelection
.getStartTime();
81 public ITmfTimestamp
getSelectionEnd() {
82 return fSelection
.getEndTime();
85 public TmfTimeRange
getWindowRange() {
89 public IFile
getEditorFile() {
94 * @return the current filter applied to the trace
97 public 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$