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
31 final class TmfTraceContext
{
33 static final TmfTraceContext NULL_CONTEXT
=
34 new TmfTraceContext(TmfTimestamp
.BIG_CRUNCH
, TmfTimestamp
.BIG_CRUNCH
, TmfTimeRange
.NULL_RANGE
, null);
36 private final TmfTimeRange fSelection
;
37 private final TmfTimeRange fWindowRange
;
38 private final IFile fEditorFile
;
39 private final ITmfFilter fFilter
;
41 public TmfTraceContext(ITmfTimestamp beginTs
, ITmfTimestamp endTs
, TmfTimeRange tr
, IFile editorFile
) {
42 fSelection
= new TmfTimeRange(beginTs
, endTs
);
44 fEditorFile
= editorFile
;
48 public TmfTraceContext(TmfTraceContext prevCtx
, ITmfTimestamp beginTs
, ITmfTimestamp endTs
) {
49 fSelection
= new TmfTimeRange(beginTs
, endTs
);
50 fWindowRange
= prevCtx
.fWindowRange
;
51 fEditorFile
= prevCtx
.fEditorFile
;
52 fFilter
= prevCtx
.fFilter
;
55 public TmfTraceContext(TmfTraceContext prevCtx
, TmfTimeRange tr
) {
56 fSelection
= prevCtx
.fSelection
;
58 fEditorFile
= prevCtx
.fEditorFile
;
59 fFilter
= prevCtx
.fFilter
;
64 * The previous context
68 public TmfTraceContext(TmfTraceContext prevCtx
, ITmfFilter filter
) {
69 fSelection
= prevCtx
.fSelection
;
70 fWindowRange
= prevCtx
.fWindowRange
;
71 fEditorFile
= prevCtx
.fEditorFile
;
75 public ITmfTimestamp
getSelectionBegin() {
76 return fSelection
.getStartTime();
79 public ITmfTimestamp
getSelectionEnd() {
80 return fSelection
.getEndTime();
83 public TmfTimeRange
getWindowRange() {
87 public IFile
getEditorFile() {
92 * @return the current filter applied to the trace
94 public ITmfFilter
getFilter() {
98 public boolean isValid() {
99 if (fSelection
.getStartTime().compareTo(TmfTimestamp
.ZERO
) <= 0 ||
100 fSelection
.getEndTime().compareTo(TmfTimestamp
.ZERO
) <= 0 ||
101 fWindowRange
.getEndTime().compareTo(fWindowRange
.getStartTime()) <= 0) {
108 public String
toString() {
109 return getClass().getSimpleName() + "[fSelection=" + fSelection
+ //$NON-NLS-1$
110 ", fWindowRange=" + fWindowRange
+ ']'; //$NON-NLS-1$