1 /*******************************************************************************
2 * Copyright (c) 2013 É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
.linuxtools
.tmf
.ui
.views
.synchronization
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSynchronizedSignal
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.SynchronizationAlgorithm
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.swt
.widgets
.Tree
;
29 import org
.eclipse
.swt
.widgets
.TreeColumn
;
30 import org
.eclipse
.swt
.widgets
.TreeItem
;
33 * Small view to display statistics about a synchronization
35 * @author Geneviève Bastien
38 public class TmfSynchronizationView
extends TmfView
{
41 * The ID corresponds to the package in which this class is embedded.
43 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.synchronization"; //$NON-NLS-1$
48 public static final String TMF_SYNCHRONIZATION_VIEW
= "SynchronizationView"; //$NON-NLS-1$
51 * The synchronization algorithm to display stats for
53 private SynchronizationAlgorithm fAlgoSync
;
60 public TmfSynchronizationView() {
61 super(TMF_SYNCHRONIZATION_VIEW
);
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
);
72 fTree
.setItemCount(0);
74 fTree
.setHeaderVisible(true);
78 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
80 traceSelected(new TmfTraceSelectedSignal(this, trace
));
84 private void updateTable() {
85 fTree
.setItemCount(0);
86 if (fAlgoSync
== null) {
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());
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());
102 /* Expand the tree items */
103 for (int i
= 0; i
< fTree
.getItemCount(); i
++) {
104 fTree
.getItem(i
).setExpanded(true);
107 for (TreeColumn column
: fTree
.getColumns()) {
113 public void setFocus() {
118 * Handler called when a trace is selected
121 * Contains information about the selected trace
125 public void traceSelected(TmfTraceSelectedSignal signal
) {
127 if (signal
.getTrace() instanceof TmfExperiment
) {
128 fAlgoSync
= ((TmfExperiment
) signal
.getTrace()).synchronizeTraces();
130 Display
.getDefault().asyncExec(new Runnable() {
139 * Handler called when traces are synchronized
142 * Contains the information about the selection.
145 public void traceSynchronized(TmfTraceSynchronizedSignal signal
) {
146 if (signal
.getSyncAlgo() != fAlgoSync
) {
147 fAlgoSync
= signal
.getSyncAlgo();
148 Display
.getDefault().asyncExec(new Runnable() {