Commit | Line | Data |
---|---|---|
e73a4ba5 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
e73a4ba5 GB |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are made | |
5 | * 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 | * Geneviève Bastien - Initial implementation and API | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.views.synchronization; |
e73a4ba5 GB |
14 | |
15 | import java.util.Map; | |
16 | ||
e73a4ba5 GB |
17 | import org.eclipse.swt.SWT; |
18 | import org.eclipse.swt.widgets.Composite; | |
19 | import org.eclipse.swt.widgets.Display; | |
20 | import org.eclipse.swt.widgets.Tree; | |
21 | import org.eclipse.swt.widgets.TreeColumn; | |
22 | import org.eclipse.swt.widgets.TreeItem; | |
2bdf0193 AM |
23 | import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; |
24 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal; | |
25 | import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSynchronizedSignal; | |
26 | import org.eclipse.tracecompass.tmf.core.synchronization.SynchronizationAlgorithm; | |
27 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
2bdf0193 | 28 | import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; |
5c5fa260 | 29 | import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; |
2bdf0193 | 30 | import org.eclipse.tracecompass.tmf.ui.views.TmfView; |
e73a4ba5 GB |
31 | |
32 | /** | |
33 | * Small view to display statistics about a synchronization | |
34 | * | |
35 | * @author Geneviève Bastien | |
36 | * @since 3.0 | |
37 | */ | |
38 | public class TmfSynchronizationView extends TmfView { | |
39 | ||
40 | /** | |
41 | * The ID corresponds to the package in which this class is embedded. | |
42 | */ | |
43 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.synchronization"; //$NON-NLS-1$ | |
44 | ||
45 | /** | |
46 | * The view name. | |
47 | */ | |
48 | public static final String TMF_SYNCHRONIZATION_VIEW = "SynchronizationView"; //$NON-NLS-1$ | |
49 | ||
50 | /** | |
51 | * The synchronization algorithm to display stats for | |
52 | */ | |
53 | private SynchronizationAlgorithm fAlgoSync; | |
54 | ||
55 | private Tree fTree; | |
56 | ||
57 | /** | |
58 | * Default constructor | |
59 | */ | |
60 | public TmfSynchronizationView() { | |
61 | super(TMF_SYNCHRONIZATION_VIEW); | |
62 | } | |
63 | ||
64 | @Override | |
65 | public void createPartControl(Composite parent) { | |
66 | fTree = new Tree(parent, SWT.NONE); | |
67 | TreeColumn nameCol = new TreeColumn(fTree, SWT.NONE, 0); | |
68 | TreeColumn valueCol = new TreeColumn(fTree, SWT.NONE, 1); | |
69 | nameCol.setText(Messages.TmfSynchronizationView_NameColumn); | |
70 | valueCol.setText(Messages.TmfSynchronizationView_ValueColumn); | |
71 | ||
72 | fTree.setItemCount(0); | |
73 | ||
74 | fTree.setHeaderVisible(true); | |
75 | nameCol.pack(); | |
76 | valueCol.pack(); | |
77 | ||
72aef47a GB |
78 | ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace(); |
79 | if (trace != null) { | |
80 | traceSelected(new TmfTraceSelectedSignal(this, trace)); | |
81 | } | |
e73a4ba5 GB |
82 | } |
83 | ||
84 | private void updateTable() { | |
85 | fTree.setItemCount(0); | |
86 | if (fAlgoSync == null) { | |
87 | return; | |
88 | } | |
89 | ||
90 | for (Map.Entry<String, Map<String, Object>> entry : fAlgoSync.getStats().entrySet()) { | |
91 | TreeItem item = new TreeItem(fTree, SWT.NONE); | |
92 | item.setText(0, entry.getKey().toString()); | |
93 | item.setText(1, entry.getValue().toString()); | |
94 | ||
95 | for (Map.Entry<String, Object> subentry : entry.getValue().entrySet()) { | |
96 | TreeItem subitem = new TreeItem(item, SWT.NONE); | |
97 | subitem.setText(0, subentry.getKey().toString()); | |
98 | subitem.setText(1, subentry.getValue().toString()); | |
99 | } | |
100 | } | |
101 | ||
102 | /* Expand the tree items */ | |
103 | for (int i = 0; i < fTree.getItemCount(); i++) { | |
104 | fTree.getItem(i).setExpanded(true); | |
105 | } | |
106 | ||
107 | for (TreeColumn column : fTree.getColumns()) { | |
108 | column.pack(); | |
109 | } | |
110 | } | |
111 | ||
112 | @Override | |
113 | public void setFocus() { | |
114 | fTree.setFocus(); | |
115 | } | |
116 | ||
72aef47a GB |
117 | /** |
118 | * Handler called when a trace is selected | |
119 | * | |
120 | * @param signal | |
121 | * Contains information about the selected trace | |
5825eb49 | 122 | * @since 3.1 |
72aef47a GB |
123 | */ |
124 | @TmfSignalHandler | |
125 | public void traceSelected(TmfTraceSelectedSignal signal) { | |
126 | fAlgoSync = null; | |
127 | if (signal.getTrace() instanceof TmfExperiment) { | |
04ba3554 | 128 | fAlgoSync = ((TmfExperiment) signal.getTrace()).synchronizeTraces(); |
72aef47a GB |
129 | } |
130 | Display.getDefault().asyncExec(new Runnable() { | |
131 | @Override | |
132 | public void run() { | |
133 | updateTable(); | |
134 | } | |
135 | }); | |
136 | } | |
137 | ||
e73a4ba5 GB |
138 | /** |
139 | * Handler called when traces are synchronized | |
140 | * | |
141 | * @param signal | |
142 | * Contains the information about the selection. | |
143 | */ | |
144 | @TmfSignalHandler | |
145 | public void traceSynchronized(TmfTraceSynchronizedSignal signal) { | |
146 | if (signal.getSyncAlgo() != fAlgoSync) { | |
147 | fAlgoSync = signal.getSyncAlgo(); | |
148 | Display.getDefault().asyncExec(new Runnable() { | |
149 | @Override | |
150 | public void run() { | |
151 | updateTable(); | |
152 | } | |
153 | }); | |
154 | } | |
155 | } | |
156 | } |