ss: Move plugins to Trace Compass namespace
[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.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;
31
32 /**
33 * Small view to display statistics about a synchronization
34 *
35 * @author Geneviève Bastien
36 * @since 3.0
37 */
38 public class TmfSynchronizationView extends TmfView {
39
40 /**
41 * The ID corresponds to the package in which this class is embedded.
42 */
43 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.synchronization"; //$NON-NLS-1$
44
45 /**
46 * The view name.
47 */
48 public static final String TMF_SYNCHRONIZATION_VIEW = "SynchronizationView"; //$NON-NLS-1$
49
50 /**
51 * The synchronization algorithm to display stats for
52 */
53 private SynchronizationAlgorithm fAlgoSync;
54
55 private Tree fTree;
56
57 /**
58 * Default constructor
59 */
60 public TmfSynchronizationView() {
61 super(TMF_SYNCHRONIZATION_VIEW);
62 }
63
64 @Override
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);
71
72 fTree.setItemCount(0);
73
74 fTree.setHeaderVisible(true);
75 nameCol.pack();
76 valueCol.pack();
77
78 ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
79 if (trace != null) {
80 traceSelected(new TmfTraceSelectedSignal(this, trace));
81 }
82 }
83
84 private void updateTable() {
85 fTree.setItemCount(0);
86 if (fAlgoSync == null) {
87 return;
88 }
89
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());
94
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());
99 }
100 }
101
102 /* Expand the tree items */
103 for (int i = 0; i < fTree.getItemCount(); i++) {
104 fTree.getItem(i).setExpanded(true);
105 }
106
107 for (TreeColumn column : fTree.getColumns()) {
108 column.pack();
109 }
110 }
111
112 @Override
113 public void setFocus() {
114 fTree.setFocus();
115 }
116
117 /**
118 * Handler called when a trace is selected
119 *
120 * @param signal
121 * Contains information about the selected trace
122 * @since 3.1
123 */
124 @TmfSignalHandler
125 public void traceSelected(TmfTraceSelectedSignal signal) {
126 fAlgoSync = null;
127 if (signal.getTrace() instanceof TmfExperiment) {
128 fAlgoSync = ((TmfExperiment) signal.getTrace()).synchronizeTraces();
129 }
130 Display.getDefault().asyncExec(new Runnable() {
131 @Override
132 public void run() {
133 updateTable();
134 }
135 });
136 }
137
138 /**
139 * Handler called when traces are synchronized
140 *
141 * @param signal
142 * Contains the information about the selection.
143 */
144 @TmfSignalHandler
145 public void traceSynchronized(TmfTraceSynchronizedSignal signal) {
146 if (signal.getSyncAlgo() != fAlgoSync) {
147 fAlgoSync = signal.getSyncAlgo();
148 Display.getDefault().asyncExec(new Runnable() {
149 @Override
150 public void run() {
151 updateTable();
152 }
153 });
154 }
155 }
156 }
This page took 0.044713 seconds and 5 git commands to generate.