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