Commit | Line | Data |
---|---|---|
25a042b3 MD |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011, 2012 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 | * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.statistics; | |
14 | ||
15 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
16 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; | |
17 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; | |
18 | import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; | |
19 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; | |
cfd22ad0 MD |
20 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo; |
21 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.Messages; | |
22 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.TmfStatisticsViewer; | |
23 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree; | |
24 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeRootFactory; | |
25a042b3 MD |
25 | |
26 | /** | |
27 | * Class for the TMF event requests specific to the statistics view. | |
28 | * @version 2.0 | |
29 | */ | |
30 | class TmfStatisticsRequest extends TmfEventRequest { | |
31 | ||
32 | /** | |
33 | * Reference to the statistics viewer that sent the request | |
34 | */ | |
35 | private final TmfStatisticsView fSender; | |
36 | ||
cfd22ad0 MD |
37 | /** |
38 | * The viewer that displays the statistics data | |
39 | */ | |
40 | private TmfStatisticsViewer fViewer; | |
41 | ||
25a042b3 MD |
42 | /** |
43 | * The experiment for which to send the request | |
44 | */ | |
45 | private final TmfExperiment fExperiment; | |
46 | ||
47 | /** | |
48 | * Tells if the request is for the whole trace or for a smaller time range | |
49 | */ | |
50 | private final boolean fGlobal; | |
51 | ||
52 | /** | |
53 | * The statistics tree that will be updated from the requested data | |
54 | */ | |
55 | private final AbsTmfStatisticsTree fStatisticsData; | |
56 | ||
57 | /** | |
58 | * Constructor | |
59 | * | |
60 | * @param sender | |
61 | * Sender of this request | |
62 | * @param experiment | |
63 | * Experiment targeted by this request | |
64 | * @param range | |
65 | * The target time range | |
66 | * @param index | |
67 | * The starting index | |
68 | * @param prio | |
69 | * The priority of the request | |
70 | * @param global | |
71 | * Is this for a global statistics request (true), or a partial | |
72 | * one (false)? | |
73 | */ | |
cfd22ad0 | 74 | TmfStatisticsRequest(TmfStatisticsView sender, TmfStatisticsViewer viewer, TmfExperiment experiment, TmfTimeRange range, long index, ExecutionType prio, boolean global) { |
25a042b3 | 75 | super(ITmfEvent.class, range, index, TmfDataRequest.ALL_DATA, sender.getIndexPageSize(), prio); |
cfd22ad0 | 76 | String treeID = viewer.getTreeID(experiment.getName()); |
25a042b3 MD |
77 | |
78 | fSender = sender; | |
cfd22ad0 | 79 | fViewer = viewer; |
25a042b3 MD |
80 | fExperiment = experiment; |
81 | fGlobal = global; | |
82 | fStatisticsData = TmfStatisticsTreeRootFactory.getStatTree(treeID); | |
83 | } | |
84 | ||
85 | @Override | |
86 | public void handleData(ITmfEvent data) { | |
87 | super.handleData(data); | |
88 | if (data != null) { | |
89 | final String traceName = data.getTrace().getName(); | |
90 | ITmfExtraEventInfo extraInfo = new ITmfExtraEventInfo() { | |
91 | @Override | |
92 | public String getTraceName() { | |
93 | if (traceName == null) { | |
94 | return Messages.TmfStatisticsView_UnknownTraceName; | |
95 | } | |
96 | return traceName; | |
97 | } | |
98 | }; | |
99 | if (fGlobal) { | |
100 | fStatisticsData.registerEvent(data, extraInfo); | |
101 | } else { | |
102 | fStatisticsData.registerEventInTimeRange(data, extraInfo); | |
103 | } | |
104 | fStatisticsData.increase(data, extraInfo, 1); | |
105 | // Refresh view | |
cfd22ad0 | 106 | if ((getNbRead() % fViewer.getInputChangedRefresh()) == 0) { |
25a042b3 MD |
107 | fSender.modelInputChanged(false); |
108 | } | |
109 | } | |
110 | } | |
111 | ||
112 | @Override | |
113 | public void handleSuccess() { | |
114 | super.handleSuccess(); | |
115 | fSender.modelInputChanged(true); | |
116 | if (fGlobal) { | |
cfd22ad0 | 117 | fViewer.waitCursor(false); |
25a042b3 MD |
118 | } |
119 | } | |
120 | ||
121 | @Override | |
122 | public void handleFailure() { | |
123 | super.handleFailure(); | |
124 | fSender.modelIncomplete(fExperiment.getName()); | |
125 | } | |
126 | ||
127 | @Override | |
128 | public void handleCancel() { | |
129 | super.handleCancel(); | |
130 | /* | |
131 | * The global request can be cancelled when another experiment is | |
132 | * selected, but a time range request can also be cancelled when there is | |
133 | * a time range update, which means the model must not be deleted. | |
134 | */ | |
135 | if (fGlobal) { | |
136 | fSender.modelIncomplete(fExperiment.getName()); | |
137 | } | |
138 | } | |
139 | } |