package org.eclipse.tracecompass.tmf.core.trace;
import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.tmf.core.filter.ITmfFilter;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
*
* TODO could be extended to support the notion of current location too.
*
+ * FIXME Is this really the right place for the Editor File ?
+ *
* @author Alexandre Montplaisir
- * @since 2.0
+ * @since 1.0
*/
-final class TmfTraceContext {
+@NonNullByDefault
+public final class TmfTraceContext {
static final TmfTraceContext NULL_CONTEXT =
- new TmfTraceContext(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH, TmfTimeRange.NULL_RANGE, null);
+ new TmfTraceContext(new TmfTimeRange(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH),
+ TmfTimeRange.NULL_RANGE, null, null);
private final TmfTimeRange fSelection;
private final TmfTimeRange fWindowRange;
- private final IFile fEditorFile;
- private final ITmfFilter fFilter;
-
- public TmfTraceContext(ITmfTimestamp beginTs, ITmfTimestamp endTs, TmfTimeRange tr, IFile editorFile) {
- fSelection = new TmfTimeRange(beginTs, endTs);
- fWindowRange = tr;
- fEditorFile = editorFile;
- fFilter = null;
- }
-
- public TmfTraceContext(TmfTraceContext prevCtx, ITmfTimestamp beginTs, ITmfTimestamp endTs) {
- fSelection = new TmfTimeRange(beginTs, endTs);
- fWindowRange = prevCtx.fWindowRange;
- fEditorFile = prevCtx.fEditorFile;
- fFilter = prevCtx.fFilter;
- }
-
- public TmfTraceContext(TmfTraceContext prevCtx, TmfTimeRange tr) {
- fSelection = prevCtx.fSelection;
- fWindowRange = tr;
- fEditorFile = prevCtx.fEditorFile;
- fFilter = prevCtx.fFilter;
- }
+ private final @Nullable IFile fEditorFile;
+ private final @Nullable ITmfFilter fFilter;
/**
- * @param prevCtx
- * The previous context
+ * Build a new trace context.
+ *
+ * @param selection
+ * The selected time range
+ * @param windowRange
+ * The visible window's time range
+ * @param editorFile
+ * The file representing the selected editor
* @param filter
- * The applied filter
- * @since 2.2
+ * The currently applied filter. 'null' for none.
*/
- public TmfTraceContext(TmfTraceContext prevCtx, ITmfFilter filter) {
- fSelection = prevCtx.fSelection;
- fWindowRange = prevCtx.fWindowRange;
- fEditorFile = prevCtx.fEditorFile;
+ public TmfTraceContext(TmfTimeRange selection, TmfTimeRange windowRange,
+ @Nullable IFile editorFile, @Nullable ITmfFilter filter) {
+ fSelection = selection;
+ fWindowRange = windowRange;
+ fEditorFile = editorFile;
fFilter = filter;
}
- public ITmfTimestamp getSelectionBegin() {
- return fSelection.getStartTime();
- }
-
- public ITmfTimestamp getSelectionEnd() {
- return fSelection.getEndTime();
+ /**
+ * Return the time range representing the current active selection.
+ *
+ * @return The selected time range
+ */
+ public TmfTimeRange getSelectionRange() {
+ return fSelection;
}
+ /**
+ * Return the current window time range.
+ *
+ * @return The current window time range
+ */
public TmfTimeRange getWindowRange() {
return fWindowRange;
}
- public IFile getEditorFile() {
+
+ /**
+ * Get the editor's file
+ *
+ * @return The editor file
+ */
+ public @Nullable IFile getEditorFile() {
return fEditorFile;
}
/**
- * @return the current filter applied to the trace
- * @since 2.2
+ * Gets the filter applied to the current trace
+ *
+ * @return The current filter, or <code>null</code> if there is none
*/
- public ITmfFilter getFilter() {
+ public @Nullable ITmfFilter getFilter() {
return fFilter;
}
- public boolean isValid() {
- if (fSelection.getStartTime().compareTo(TmfTimestamp.ZERO) <= 0 ||
- fSelection.getEndTime().compareTo(TmfTimestamp.ZERO) <= 0 ||
- fWindowRange.getEndTime().compareTo(fWindowRange.getStartTime()) <= 0) {
- return false;
- }
- return true;
- }
-
@Override
public String toString() {
return getClass().getSimpleName() + "[fSelection=" + fSelection + //$NON-NLS-1$