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