tmf: Add support for time range selection
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfTraceContext.java
CommitLineData
fc526aef
AM
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
fc526aef
AM
12 *******************************************************************************/
13
14package org.eclipse.linuxtools.tmf.core.trace;
15
16import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
17import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
18import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
19
20/**
21 * Context of a trace, which is the representation of the "view" the user
0fcf3b09 22 * currently has on this trace (window time range, selected time or time range).
fc526aef
AM
23 *
24 * TODO could be extended to support the notion of current location too.
25 *
26 * @author Alexandre Montplaisir
27 * @since 2.0
28 */
29final class TmfTraceContext {
30
31 static final TmfTraceContext NULL_CONTEXT =
0fcf3b09 32 new TmfTraceContext(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH, TmfTimeRange.NULL_RANGE);
fc526aef 33
0fcf3b09
PT
34 private final TmfTimeRange fSelection;
35 private final TmfTimeRange fWindowRange;
fc526aef 36
0fcf3b09
PT
37 public TmfTraceContext(ITmfTimestamp beginTs, ITmfTimestamp endTs, TmfTimeRange tr) {
38 fSelection = new TmfTimeRange(beginTs, endTs);
39 fWindowRange = tr;
fc526aef
AM
40 }
41
0fcf3b09
PT
42 public TmfTraceContext(TmfTraceContext prevCtx, ITmfTimestamp beginTs, ITmfTimestamp endTs) {
43 fSelection = new TmfTimeRange(beginTs, endTs);
44 fWindowRange = prevCtx.fWindowRange;
fc526aef
AM
45 }
46
0fcf3b09
PT
47 public TmfTraceContext(TmfTraceContext prevCtx, TmfTimeRange tr) {
48 fSelection = prevCtx.fSelection;
49 fWindowRange = tr;
fc526aef
AM
50 }
51
0fcf3b09
PT
52 public ITmfTimestamp getSelectionBegin() {
53 return fSelection.getStartTime();
54 }
55
56 public ITmfTimestamp getSelectionEnd() {
57 return fSelection.getEndTime();
58 }
59
60 public TmfTimeRange getWindowRange() {
61 return fWindowRange;
fc526aef
AM
62 }
63
64 public boolean isValid() {
0fcf3b09
PT
65 if (fSelection.getStartTime().compareTo(TmfTimestamp.ZERO) <= 0 ||
66 fSelection.getEndTime().compareTo(TmfTimestamp.ZERO) <= 0 ||
67 fWindowRange.getEndTime().compareTo(fWindowRange.getStartTime()) <= 0) {
fc526aef
AM
68 return false;
69 }
70 return true;
71 }
72
73 @Override
74 public String toString() {
0fcf3b09
PT
75 return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$
76 ", fWindowRange=" + fWindowRange + ']'; //$NON-NLS-1$
fc526aef
AM
77 }
78}
This page took 0.031135 seconds and 5 git commands to generate.