Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b2a3e689f21b9256d0c1371c292d8f44bdd99748 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*******************************************************************************
 * Copyright (c) 2013, 2014 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Alexandre Montplaisir - Initial API and implementation
 *   Patrick Tasse - Support selection range
 *   Xavier Raynaud - Support filters tracking
 *******************************************************************************/

package org.eclipse.linuxtools.tmf.core.trace;

import org.eclipse.core.resources.IFile;
import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;

/**
 * Context of a trace, which is the representation of the "view" the user
 * currently has on this trace (window time range, selected time or time range).
 *
 * TODO could be extended to support the notion of current location too.
 *
 * @author Alexandre Montplaisir
 * @since 2.0
 */
final class TmfTraceContext {

    static final TmfTraceContext NULL_CONTEXT =
            new TmfTraceContext(TmfTimestamp.BIG_CRUNCH, TmfTimestamp.BIG_CRUNCH, TmfTimeRange.NULL_RANGE, 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;
    }

    /**
     * @param prevCtx
     *              The previous context
     * @param filter
     *              The applied filter
     * @since 2.2
     */
    public TmfTraceContext(TmfTraceContext prevCtx, ITmfFilter filter) {
        fSelection = prevCtx.fSelection;
        fWindowRange = prevCtx.fWindowRange;
        fEditorFile = prevCtx.fEditorFile;
        fFilter = filter;
    }

    public ITmfTimestamp getSelectionBegin() {
        return fSelection.getStartTime();
    }

    public ITmfTimestamp getSelectionEnd() {
        return fSelection.getEndTime();
    }

    public TmfTimeRange getWindowRange() {
        return fWindowRange;
    }

    public IFile getEditorFile() {
        return fEditorFile;
    }

    /**
     * @return the current filter applied to the trace
     * @since 2.2
     */
    public 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$
                ", fWindowRange=" + fWindowRange + ']'; //$NON-NLS-1$
    }
}

Back to the top