1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial implementation and API
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.synchronization
;
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
;
33 * Small view to display statistics about a synchronization
35 * @author Geneviève Bastien
37 public class TmfSynchronizationView
extends TmfView
{
40 * The ID corresponds to the package in which this class is embedded.
42 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.synchronization"; //$NON-NLS-1$
47 public static final String TMF_SYNCHRONIZATION_VIEW
= "SynchronizationView"; //$NON-NLS-1$
50 * The synchronization algorithm to display stats for
52 private SynchronizationAlgorithm fAlgoSync
;
59 public TmfSynchronizationView() {
60 super(TMF_SYNCHRONIZATION_VIEW
);
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
);
71 fTree
.setItemCount(0);
73 fTree
.setHeaderVisible(true);
77 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
79 traceSelected(new TmfTraceSelectedSignal(this, trace
));
83 private void updateTable() {
84 fTree
.setItemCount(0);
85 if (fAlgoSync
== null) {
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());
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());
101 /* Expand the tree items */
102 for (int i
= 0; i
< fTree
.getItemCount(); i
++) {
103 fTree
.getItem(i
).setExpanded(true);
106 for (TreeColumn column
: fTree
.getColumns()) {
112 public void setFocus() {
117 * Handler called when a trace is selected
120 * Contains information about the selected trace
123 public void traceSelected(TmfTraceSelectedSignal signal
) {
125 if (signal
.getTrace() instanceof TmfExperiment
) {
126 fAlgoSync
= ((TmfExperiment
) signal
.getTrace()).synchronizeTraces();
128 Display
.getDefault().asyncExec(new Runnable() {
137 * Handler called when traces are synchronized
140 * Contains the information about the selection.
143 public void traceSynchronized(TmfTraceSynchronizedSignal signal
) {
144 if (signal
.getSyncAlgo() != fAlgoSync
) {
145 fAlgoSync
= signal
.getSyncAlgo();
146 Display
.getDefault().asyncExec(new Runnable() {