Commit | Line | Data |
---|---|---|
6de2f761 PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 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 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.internal.gdbtrace.ui.views.events; | |
14 | ||
baafe54c AM |
15 | import java.util.Collection; |
16 | ||
e9a6e38e MAL |
17 | import org.eclipse.core.runtime.IProgressMonitor; |
18 | import org.eclipse.core.runtime.IStatus; | |
19 | import org.eclipse.core.runtime.Status; | |
20 | import org.eclipse.core.runtime.jobs.Job; | |
6de2f761 PT |
21 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
22 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
8343b1f5 PT |
23 | import org.eclipse.linuxtools.internal.gdbtrace.core.event.GdbTraceEvent; |
24 | import org.eclipse.linuxtools.internal.gdbtrace.core.event.GdbTraceEventContent; | |
25 | import org.eclipse.linuxtools.internal.gdbtrace.core.trace.GdbTrace; | |
6de2f761 | 26 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
6de2f761 PT |
27 | import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler; |
28 | import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal; | |
6b6e81de | 29 | import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; |
6de2f761 PT |
30 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
31 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; | |
32 | import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; | |
baafe54c AM |
33 | import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableColumn; |
34 | import org.eclipse.linuxtools.tmf.ui.viewers.events.columns.TmfEventTableFieldColumn; | |
6de2f761 PT |
35 | import org.eclipse.swt.SWT; |
36 | import org.eclipse.swt.widgets.Composite; | |
37 | import org.eclipse.swt.widgets.TableItem; | |
38 | ||
baafe54c AM |
39 | import com.google.common.collect.ImmutableList; |
40 | ||
6de2f761 PT |
41 | /** |
42 | * GDB Events Table | |
43 | * @author Patrick Tasse | |
6de2f761 PT |
44 | */ |
45 | public class GdbEventsTable extends TmfEventsTable { | |
46 | ||
baafe54c AM |
47 | // ------------------------------------------------------------------------ |
48 | // Column definition | |
49 | // ------------------------------------------------------------------------ | |
50 | ||
51 | private static final Collection<TmfEventTableColumn> GDB_COLUMNS = ImmutableList.of( | |
52 | new GdbTraceFrameColumn(), | |
53 | new GdbTracepointColumn(), | |
54 | new GdbFileColumn() | |
55 | ); | |
56 | ||
57 | private static class GdbTraceFrameColumn extends TmfEventTableFieldColumn { | |
58 | public GdbTraceFrameColumn() { | |
59 | super(GdbTraceEventContent.TRACE_FRAME); | |
60 | } | |
61 | } | |
62 | ||
63 | private static class GdbTracepointColumn extends TmfEventTableFieldColumn { | |
64 | public GdbTracepointColumn() { | |
65 | super(GdbTraceEventContent.TRACEPOINT); | |
66 | } | |
67 | } | |
68 | ||
69 | private static class GdbFileColumn extends TmfEventTableColumn { | |
70 | ||
71 | public GdbFileColumn() { | |
72 | super("File"); //$NON-NLS-1$ | |
73 | } | |
74 | ||
75 | @Override | |
76 | public String getItemString(ITmfEvent event) { | |
77 | String ret = event.getReference(); | |
78 | return (ret == null ? EMPTY_STRING : ret); | |
79 | } | |
80 | ||
81 | @Override | |
82 | public String getFilterFieldId() { | |
83 | return ITmfEvent.EVENT_FIELD_REFERENCE; | |
84 | } | |
85 | } | |
86 | ||
87 | // ------------------------------------------------------------------------ | |
88 | // Fields | |
89 | // ------------------------------------------------------------------------ | |
6de2f761 PT |
90 | |
91 | private GdbTrace fSelectedTrace = null; | |
92 | private long fSelectedFrame = 0; | |
93 | ||
baafe54c AM |
94 | // ------------------------------------------------------------------------ |
95 | // Constructor | |
96 | // ------------------------------------------------------------------------ | |
97 | ||
6de2f761 PT |
98 | /** |
99 | * Constructor | |
baafe54c AM |
100 | * |
101 | * @param parent | |
102 | * the parent | |
103 | * @param cacheSize | |
104 | * the cache size | |
6de2f761 PT |
105 | */ |
106 | public GdbEventsTable(Composite parent, int cacheSize) { | |
baafe54c AM |
107 | super(parent, cacheSize, GDB_COLUMNS); |
108 | // Set the alignment of the first two columns | |
109 | fTable.getColumns()[0].setAlignment(SWT.RIGHT); | |
110 | fTable.getColumns()[1].setAlignment(SWT.RIGHT); | |
6de2f761 PT |
111 | |
112 | // Synchronize currently selected frame in GDB with table selection | |
113 | addSelectionChangedListener(new ISelectionChangedListener() { | |
114 | @Override | |
115 | public void selectionChanged(SelectionChangedEvent e) { | |
116 | TableItem[] selection = fTable.getSelection(); | |
117 | if (selection.length > 0) { | |
118 | TableItem selectedTableItem = selection[0]; | |
119 | if (selectedTableItem != null) { | |
120 | Object data = selectedTableItem.getData(); | |
121 | if (data instanceof GdbTraceEvent) { | |
122 | GdbTraceEvent event = (GdbTraceEvent) data; | |
123 | GdbTrace gdbTrace = (GdbTrace) event.getTrace(); | |
6db12af8 | 124 | GdbTraceEventContent content = event.getContent(); |
e9a6e38e | 125 | selectFrame(gdbTrace, content.getFrameNumber()); |
6de2f761 PT |
126 | return; |
127 | } | |
128 | } | |
129 | } | |
130 | fSelectedTrace = null; | |
131 | } | |
132 | }); | |
133 | } | |
134 | ||
135 | @Override | |
136 | public void setTrace(ITmfTrace trace, boolean disposeOnClose) { | |
137 | super.setTrace(trace, disposeOnClose); | |
138 | if (trace instanceof GdbTrace) { | |
139 | fSelectedTrace = (GdbTrace) trace; | |
140 | fSelectedFrame = 0; | |
141 | } else if (trace instanceof TmfExperiment) { | |
142 | TmfExperiment experiment = (TmfExperiment) trace; | |
143 | if (experiment.getTraces().length > 0) { | |
144 | fSelectedTrace = (GdbTrace) experiment.getTraces()[0]; | |
145 | fSelectedFrame = 0; | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
6de2f761 PT |
150 | @Override |
151 | @TmfSignalHandler | |
152 | public void currentTimeUpdated(final TmfTimeSynchSignal signal) { | |
153 | // do not synchronize on time | |
154 | } | |
e9a6e38e MAL |
155 | |
156 | private void selectFrame(final GdbTrace gdbTrace, final long frameNumber) { | |
157 | Job b = new Job("GDB Trace select frame") { //$NON-NLS-1$ | |
158 | @Override | |
159 | protected IStatus run(IProgressMonitor monitor) { | |
160 | // This sends commands to GDB and can potentially wait on the UI | |
161 | // thread (gdb traces console buffer full) so it needs to be | |
162 | // exectued on a non-UI thread | |
163 | gdbTrace.selectFrame(frameNumber); | |
164 | fSelectedTrace = gdbTrace; | |
165 | fSelectedFrame = frameNumber; | |
166 | return Status.OK_STATUS; | |
167 | } | |
168 | }; | |
169 | b.setSystem(true); | |
170 | b.schedule(); | |
171 | } | |
6b6e81de MAL |
172 | |
173 | @Override | |
174 | @TmfSignalHandler | |
175 | public void traceUpdated(TmfTraceUpdatedSignal signal) { | |
176 | super.traceUpdated(signal); | |
177 | if (fSelectedTrace.getNbFrames() == fSelectedTrace.getNbEvents()) { | |
178 | selectFrame(fSelectedTrace, fSelectedFrame); | |
179 | } | |
180 | } | |
6de2f761 | 181 | } |