tmf: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / trace / TmfTraceContext.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
11 * Patrick Tasse - Support selection range
12 * Xavier Raynaud - Support filters tracking
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.tmf.core.trace;
16
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;
22
23 /**
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).
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 =
35 new TmfTraceContext(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH, TmfTimeRange.NULL_RANGE, null);
36
37 private final TmfTimeRange fSelection;
38 private final TmfTimeRange fWindowRange;
39 private final IFile fEditorFile;
40 private final ITmfFilter fFilter;
41
42 public TmfTraceContext(ITmfTimestamp beginTs, ITmfTimestamp endTs, TmfTimeRange tr, IFile editorFile) {
43 fSelection = new TmfTimeRange(beginTs, endTs);
44 fWindowRange = tr;
45 fEditorFile = editorFile;
46 fFilter = null;
47 }
48
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;
54 }
55
56 public TmfTraceContext(TmfTraceContext prevCtx, TmfTimeRange tr) {
57 fSelection = prevCtx.fSelection;
58 fWindowRange = tr;
59 fEditorFile = prevCtx.fEditorFile;
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;
73 fEditorFile = prevCtx.fEditorFile;
74 fFilter = filter;
75 }
76
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;
87 }
88
89 public IFile getEditorFile() {
90 return fEditorFile;
91 }
92
93 /**
94 * @return the current filter applied to the trace
95 * @since 2.2
96 */
97 public ITmfFilter getFilter() {
98 return fFilter;
99 }
100
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) {
105 return false;
106 }
107 return true;
108 }
109
110 @Override
111 public String toString() {
112 return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$
113 ", fWindowRange=" + fWindowRange + ']'; //$NON-NLS-1$
114 }
115 }
This page took 0.039351 seconds and 5 git commands to generate.