Tmf: Trace synchronization using network events
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / synchronization / TmfSynchronizationView.java
1 /*******************************************************************************
2 * Copyright (c) 2013 É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.linuxtools.tmf.ui.views.synchronization;
14
15 import java.util.Map;
16
17 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
18 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSynchronizedSignal;
19 import org.eclipse.linuxtools.tmf.core.synchronization.SynchronizationAlgorithm;
20 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.swt.widgets.Tree;
25 import org.eclipse.swt.widgets.TreeColumn;
26 import org.eclipse.swt.widgets.TreeItem;
27
28 /**
29 * Small view to display statistics about a synchronization
30 *
31 * @author Geneviève Bastien
32 * @since 3.0
33 */
34 public class TmfSynchronizationView extends TmfView {
35
36 /**
37 * The ID corresponds to the package in which this class is embedded.
38 */
39 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.synchronization"; //$NON-NLS-1$
40
41 /**
42 * The view name.
43 */
44 public static final String TMF_SYNCHRONIZATION_VIEW = "SynchronizationView"; //$NON-NLS-1$
45
46 /**
47 * The synchronization algorithm to display stats for
48 */
49 private SynchronizationAlgorithm fAlgoSync;
50
51 private Tree fTree;
52
53 /**
54 * Default constructor
55 */
56 public TmfSynchronizationView() {
57 super(TMF_SYNCHRONIZATION_VIEW);
58 }
59
60 @Override
61 public void createPartControl(Composite parent) {
62 fTree = new Tree(parent, SWT.NONE);
63 TreeColumn nameCol = new TreeColumn(fTree, SWT.NONE, 0);
64 TreeColumn valueCol = new TreeColumn(fTree, SWT.NONE, 1);
65 nameCol.setText(Messages.TmfSynchronizationView_NameColumn);
66 valueCol.setText(Messages.TmfSynchronizationView_ValueColumn);
67
68 fTree.setItemCount(0);
69
70 fTree.setHeaderVisible(true);
71 nameCol.pack();
72 valueCol.pack();
73
74 }
75
76 private void updateTable() {
77 fTree.setItemCount(0);
78 if (fAlgoSync == null) {
79 return;
80 }
81
82 for (Map.Entry<String, Map<String, Object>> entry : fAlgoSync.getStats().entrySet()) {
83 TreeItem item = new TreeItem(fTree, SWT.NONE);
84 item.setText(0, entry.getKey().toString());
85 item.setText(1, entry.getValue().toString());
86
87 for (Map.Entry<String, Object> subentry : entry.getValue().entrySet()) {
88 TreeItem subitem = new TreeItem(item, SWT.NONE);
89 subitem.setText(0, subentry.getKey().toString());
90 subitem.setText(1, subentry.getValue().toString());
91 }
92 }
93
94 /* Expand the tree items */
95 for (int i = 0; i < fTree.getItemCount(); i++) {
96 fTree.getItem(i).setExpanded(true);
97 }
98
99 for (TreeColumn column : fTree.getColumns()) {
100 column.pack();
101 }
102 }
103
104 @Override
105 public void setFocus() {
106 fTree.setFocus();
107 }
108
109 /**
110 * Handler called when traces are synchronized
111 *
112 * @param signal
113 * Contains the information about the selection.
114 */
115 @TmfSignalHandler
116 public void traceSynchronized(TmfTraceSynchronizedSignal signal) {
117 if (signal.getSyncAlgo() != fAlgoSync) {
118 fAlgoSync = signal.getSyncAlgo();
119 Display.getDefault().asyncExec(new Runnable() {
120 @Override
121 public void run() {
122 updateTable();
123 }
124 });
125 }
126 }
127 }
This page took 0.035023 seconds and 5 git commands to generate.