Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / events / TmfEventsView.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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 * Francois Chouinard - Initial API and implementation
11 * Patrick Tasse - Factored out events table
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.tmf.ui.views.events;
15
16 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
17 import org.eclipse.linuxtools.tmf.core.experiment.TmfExperiment;
18 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentDisposedSignal;
19 import org.eclipse.linuxtools.tmf.core.signal.TmfExperimentSelectedSignal;
20 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
21 import org.eclipse.linuxtools.tmf.ui.TmfUiPlugin;
22 import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
23 import org.eclipse.linuxtools.tmf.ui.views.TmfView;
24 import org.eclipse.swt.widgets.Composite;
25
26 /**
27 * <b><u>TmfEventsView</u></b>
28 * <p>
29 *
30 * TODO: Implement me. Please.
31 * TODO: Handle column selection, sort, ... generically (nothing less...)
32 * TODO: Implement hide/display columns
33 */
34 public class TmfEventsView extends TmfView {
35
36 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.events"; //$NON-NLS-1$
37
38 private TmfExperiment<TmfEvent> fExperiment;
39 private TmfEventsTable fEventsTable;
40 private static final int DEFAULT_CACHE_SIZE = 100;
41 private final int fCacheSize;
42 private String fTitlePrefix;
43
44 // ------------------------------------------------------------------------
45 // Constructor
46 // ------------------------------------------------------------------------
47
48 public TmfEventsView(int cacheSize) {
49 super("TmfEventsView"); //$NON-NLS-1$
50 fCacheSize = cacheSize;
51 }
52
53 public TmfEventsView() {
54 this(DEFAULT_CACHE_SIZE);
55 }
56
57 // ------------------------------------------------------------------------
58 // ViewPart
59 // ------------------------------------------------------------------------
60
61 @Override
62 @SuppressWarnings("unchecked")
63 public void createPartControl(Composite parent) {
64 fEventsTable = createEventsTable(parent, fCacheSize);
65
66 fTitlePrefix = getTitle();
67
68 // If an experiment is already selected, update the table
69 fExperiment = (TmfExperiment<TmfEvent>) TmfExperiment.getCurrentExperiment();
70 if (fExperiment != null) {
71 experimentSelected(new TmfExperimentSelectedSignal<TmfEvent>(fEventsTable, fExperiment));
72 }
73 }
74
75 @Override
76 public void dispose() {
77 if (fEventsTable != null) {
78 fEventsTable.dispose();
79 }
80 super.dispose();
81 }
82
83 protected TmfEventsTable createEventsTable(Composite parent, int cacheSize) {
84 return new TmfEventsTable(parent, cacheSize);
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
89 */
90 @Override
91 public void setFocus() {
92 fEventsTable.setFocus();
93 }
94
95 /* (non-Javadoc)
96 * @see java.lang.Object#toString()
97 */
98 @Override
99 @SuppressWarnings("nls")
100 public String toString() {
101 return "[TmfEventsView]";
102 }
103
104 // ------------------------------------------------------------------------
105 // Signal handlers
106 // ------------------------------------------------------------------------
107
108 @SuppressWarnings("unchecked")
109 @TmfSignalHandler
110 public void experimentSelected(TmfExperimentSelectedSignal<TmfEvent> signal) {
111 // Update the trace reference
112 TmfExperiment<TmfEvent> exp = (TmfExperiment<TmfEvent>) signal.getExperiment();
113 if (!exp.equals(fExperiment)) {
114 fExperiment = exp;
115 setPartName(fTitlePrefix + " - " + fExperiment.getName()); //$NON-NLS-1$
116 if (fEventsTable != null) {
117 fEventsTable.setTrace(fExperiment, false);
118 }
119 }
120 }
121
122 @SuppressWarnings("unchecked")
123 @TmfSignalHandler
124 public void experimentDisposed(TmfExperimentDisposedSignal<TmfEvent> signal) {
125 // Clear the trace reference
126 TmfExperiment<TmfEvent> experiment = (TmfExperiment<TmfEvent>) signal.getExperiment();
127 if (experiment.equals(fExperiment)) {
128 fEventsTable.setTrace(null, false);
129 }
130
131 TmfUiPlugin.getDefault().getWorkbench().getWorkbenchWindows()[0].getShell().getDisplay().syncExec(new Runnable() {
132 @Override
133 public void run() {
134 setPartName(fTitlePrefix);
135 }
136 });
137 }
138
139 }
This page took 0.032491 seconds and 5 git commands to generate.