timing: Add a generic table view for any segment provider
[deliverable/tracecompass.git] / tmf / 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 java.util.HashMap;
18 import java.util.Map;
19
20 import org.eclipse.core.resources.IFile;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
25 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
26 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
27
28 import com.google.common.collect.ImmutableMap;
29
30 /**
31 * Context of a trace, which is the representation of the "view" the user
32 * currently has on this trace (window time range, selected time or time range).
33 *
34 * TODO could be extended to support the notion of current location too.
35 *
36 * FIXME Is this really the right place for the Editor File ?
37 *
38 * @author Alexandre Montplaisir
39 * @since 1.0
40 */
41 @NonNullByDefault
42 public class TmfTraceContext implements ITraceContextSignalHandler {
43
44 static final TmfTraceContext NULL_CONTEXT = new TmfTraceContext(new TmfTimeRange(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH),
45 TmfTimeRange.NULL_RANGE, null, null);
46
47 private final TmfTimeRange fSelection;
48 private final TmfTimeRange fWindowRange;
49 private final @Nullable IFile fEditorFile;
50 private final @Nullable ITmfFilter fFilter;
51 private final Map<@NonNull String, @NonNull Object> fData = new HashMap<>();
52
53 /**
54 * Build a new trace context.
55 *
56 * @param selection
57 * The selected time range
58 * @param windowRange
59 * The visible window's time range
60 * @param editorFile
61 * The file representing the selected editor
62 * @param filter
63 * The currently applied filter. 'null' for none.
64 */
65 public TmfTraceContext(TmfTimeRange selection, TmfTimeRange windowRange,
66 @Nullable IFile editorFile, @Nullable ITmfFilter filter) {
67 fSelection = selection;
68 fWindowRange = windowRange;
69 fEditorFile = editorFile;
70 fFilter = filter;
71 fData.clear();
72 }
73
74 /**
75 * Return the time range representing the current active selection.
76 *
77 * @return The selected time range
78 */
79 public TmfTimeRange getSelectionRange() {
80 return fSelection;
81 }
82
83 /**
84 * Return the current window time range.
85 *
86 * @return The current window time range
87 */
88 public TmfTimeRange getWindowRange() {
89 return fWindowRange;
90 }
91
92 /**
93 * Get the editor's file
94 *
95 * @return The editor file
96 */
97 public @Nullable IFile getEditorFile() {
98 return fEditorFile;
99 }
100
101 /**
102 * Gets the filter applied to the current trace
103 *
104 * @return The current filter, or <code>null</code> if there is none
105 */
106 public @Nullable ITmfFilter getFilter() {
107 return fFilter;
108 }
109
110 /**
111 * Store a data for the trace
112 *
113 * @param key
114 * The id of the data
115 * @param value
116 * The value of the data
117 * @since 2.1
118 */
119 public synchronized void setData(String key, Object value) {
120 fData.put(key, value);
121 }
122
123 /**
124 * Copy data into the data map
125 *
126 * @param data
127 * The map of data to copy
128 * @since 2.1
129 */
130 public synchronized void setData(Map<String, Object> data) {
131 fData.putAll(data);
132 }
133
134 /**
135 * Get the data for the specific key
136 *
137 * @param key
138 * The id of the data
139 * @return The data or null if the key do not exist
140 * @since 2.1
141 */
142 public synchronized @Nullable Object getData(String key) {
143 return fData.get(key);
144 }
145
146 /**
147 * Get a copy of the data map
148 *
149 * @return The data map copy
150 * @since 2.1
151 */
152 public synchronized Map<String, Object> getData() {
153 return ImmutableMap.copyOf(fData);
154 }
155
156 @Override
157 public String toString() {
158 return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$
159 ", fWindowRange=" + fWindowRange + ']'; //$NON-NLS-1$
160 }
161
162 }
This page took 0.041642 seconds and 5 git commands to generate.