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
.internal
.tmf
.ui
.Activator
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSynchronizedSignal
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.synchronization
.SynchronizationAlgorithm
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTraceManager
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.TmfView
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Display
;
30 import org
.eclipse
.swt
.widgets
.Tree
;
31 import org
.eclipse
.swt
.widgets
.TreeColumn
;
32 import org
.eclipse
.swt
.widgets
.TreeItem
;
35 * Small view to display statistics about a synchronization
37 * @author Geneviève Bastien
40 public class TmfSynchronizationView
extends TmfView
{
43 * The ID corresponds to the package in which this class is embedded.
45 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.synchronization"; //$NON-NLS-1$
50 public static final String TMF_SYNCHRONIZATION_VIEW
= "SynchronizationView"; //$NON-NLS-1$
53 * The synchronization algorithm to display stats for
55 private SynchronizationAlgorithm fAlgoSync
;
62 public TmfSynchronizationView() {
63 super(TMF_SYNCHRONIZATION_VIEW
);
67 public void createPartControl(Composite parent
) {
68 fTree
= new Tree(parent
, SWT
.NONE
);
69 TreeColumn nameCol
= new TreeColumn(fTree
, SWT
.NONE
, 0);
70 TreeColumn valueCol
= new TreeColumn(fTree
, SWT
.NONE
, 1);
71 nameCol
.setText(Messages
.TmfSynchronizationView_NameColumn
);
72 valueCol
.setText(Messages
.TmfSynchronizationView_ValueColumn
);
74 fTree
.setItemCount(0);
76 fTree
.setHeaderVisible(true);
80 ITmfTrace trace
= TmfTraceManager
.getInstance().getActiveTrace();
82 traceSelected(new TmfTraceSelectedSignal(this, trace
));
86 private void updateTable() {
87 fTree
.setItemCount(0);
88 if (fAlgoSync
== null) {
92 for (Map
.Entry
<String
, Map
<String
, Object
>> entry
: fAlgoSync
.getStats().entrySet()) {
93 TreeItem item
= new TreeItem(fTree
, SWT
.NONE
);
94 item
.setText(0, entry
.getKey().toString());
95 item
.setText(1, entry
.getValue().toString());
97 for (Map
.Entry
<String
, Object
> subentry
: entry
.getValue().entrySet()) {
98 TreeItem subitem
= new TreeItem(item
, SWT
.NONE
);
99 subitem
.setText(0, subentry
.getKey().toString());
100 subitem
.setText(1, subentry
.getValue().toString());
104 /* Expand the tree items */
105 for (int i
= 0; i
< fTree
.getItemCount(); i
++) {
106 fTree
.getItem(i
).setExpanded(true);
109 for (TreeColumn column
: fTree
.getColumns()) {
115 public void setFocus() {
120 * Handler called when a trace is selected
123 * Contains information about the selected trace
127 public void traceSelected(TmfTraceSelectedSignal signal
) {
129 if (signal
.getTrace() instanceof TmfExperiment
) {
131 fAlgoSync
= ((TmfExperiment
) signal
.getTrace()).synchronizeTraces();
132 } catch (TmfTraceException e
) {
133 Activator
.getDefault().logError("Error while getting the synchronization data of experiment", e
); //$NON-NLS-1$
136 Display
.getDefault().asyncExec(new Runnable() {
145 * Handler called when traces are synchronized
148 * Contains the information about the selection.
151 public void traceSynchronized(TmfTraceSynchronizedSignal signal
) {
152 if (signal
.getSyncAlgo() != fAlgoSync
) {
153 fAlgoSync
= signal
.getSyncAlgo();
154 Display
.getDefault().asyncExec(new Runnable() {