-
Notifications
You must be signed in to change notification settings - Fork 11
/
Ros2MessagesView.java
168 lines (149 loc) · 7.02 KB
/
Ros2MessagesView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**********************************************************************
* Copyright (c) 2022 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.tracecompass.incubator.internal.ros2.ui.views.messages;
import java.util.Iterator;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.tracecompass.incubator.internal.ros2.core.analysis.Ros2ObjectTimeGraphEntryModel;
import org.eclipse.tracecompass.incubator.internal.ros2.core.analysis.messages.Ros2MessagesDataProvider;
import org.eclipse.tracecompass.incubator.internal.ros2.ui.Activator;
import org.eclipse.tracecompass.incubator.internal.ros2.ui.actions.Ros2FollowMessageAction;
import org.eclipse.tracecompass.incubator.internal.ros2.ui.views.AbstractRos2DataProviderTimeGraphView;
import org.eclipse.tracecompass.incubator.internal.ros2.ui.views.Ros2HideInternalObjectsAction;
import org.eclipse.tracecompass.incubator.internal.ros2.ui.views.Ros2ObjectTreeLabelProvider;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
import org.eclipse.ui.IWorkbenchActionConstants;
/**
* View for ROS 2 Messages.
*
* @author Christophe Bedard
*/
public class Ros2MessagesView extends AbstractRos2DataProviderTimeGraphView {
private static final String ID_SUFFIX = ".messages"; //$NON-NLS-1$
private Ros2FollowMessageAction fFollowAction;
private class Ros2MessagesViewTreeLabelProvider extends TreeLabelProvider {
@Override
public String getColumnText(Object element, int columnIndex) {
return Ros2ObjectTreeLabelProvider.getColumnText(element, columnIndex);
}
}
/**
* Constructor
*/
public Ros2MessagesView() {
super(getFullViewId(), new Ros2MessagesPresentationProvider(), Ros2MessagesDataProvider.getFullDataProviderId());
setTreeColumns(Ros2ObjectTreeLabelProvider.TREE_COLUMNS);
setTreeLabelProvider(new Ros2MessagesViewTreeLabelProvider());
setFilterColumns(Ros2ObjectTreeLabelProvider.TREE_COLUMNS);
setFilterLabelProvider(new Ros2MessagesViewTreeLabelProvider());
}
/**
* @return the full ID of this view
*/
public static @NonNull String getFullViewId() {
return AbstractRos2DataProviderTimeGraphView.getViewIdFromSuffix(ID_SUFFIX);
}
@Override
protected void fillLocalToolBar(IToolBarManager manager) {
IDialogSettings settings = Objects.requireNonNull(Activator.getDefault()).getDialogSettings();
IDialogSettings section = settings.getSection(getClass().getName());
if (section == null) {
section = settings.addNewSection(getClass().getName());
}
// Message flow action
fFollowAction = new Ros2FollowMessageAction(this, getTimeGraphViewer());
fFollowAction.setEnabled(false);
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, fFollowAction);
// Hide arrows button
IAction hideArrowsAction = getTimeGraphViewer().getHideArrowsAction(section);
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, hideArrowsAction);
// Hide internal objects
IAction hideInternalAction = new Ros2HideInternalObjectsAction(getTimeGraphViewer());
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, hideInternalAction);
// Add a separator to local tool bar
manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new Separator());
super.fillLocalToolBar(manager);
}
/**
* {@link TmfSignalHandler} for when the selection is updated
*
* @param signal
* the selection range updated signal
*/
@TmfSignalHandler
public synchronized void selection(TmfSelectionRangeUpdatedSignal signal) {
updateFollowMessageAction(signal.getSource());
}
private void updateFollowMessageAction(Object source) {
if (null != fFollowAction) {
boolean isValid = false;
ITimeGraphEntry selection = getTimeGraphViewer().getSelection();
// FIXME an event is still selected in the view even if the focus is
// on another view, so it could still be considered valid
if (selection != null && source == this) {
@Nullable
ITimeEvent event = getReferenceEvent(selection, getTimeGraphViewer().getSelectionBegin());
isValid = (event != null && event.getLabel() != null);
}
fFollowAction.setEnabled(isValid);
}
}
/**
* Get the event corresponding to an entry and timestamp.
*
* @param selectedEntry
* the selected entry
* @param timestamp
* the selected timestamp
* @return the reference event if found and valid, or <code>null</null>
* otherwise
*/
public static @Nullable ITimeEvent getReferenceEvent(ITimeGraphEntry selectedEntry, long timestamp) {
// Make sure the selected timegraph entry is valid (pub/sub/timer)
if (!(selectedEntry instanceof TimeGraphEntry)) {
return null;
}
ITmfTreeDataModel model = ((TimeGraphEntry) selectedEntry).getEntryModel();
if (!(model instanceof Ros2ObjectTimeGraphEntryModel)) {
return null;
}
Ros2ObjectTimeGraphEntryModel messagesModel = (Ros2ObjectTimeGraphEntryModel) model;
if (!messagesModel.isLeafObject()) {
return null;
}
// Find the corresponding time event by comparing timestamps
ITimeEvent refEvent = null;
Iterator<@NonNull ? extends ITimeEvent> timeEventsIt = selectedEntry.getTimeEventsIterator();
boolean searchDone = false;
while (timeEventsIt.hasNext() && !searchDone) {
ITimeEvent event = timeEventsIt.next();
long duration = event.getDuration();
long time = event.getTime();
if (duration > 0 && (time <= timestamp && timestamp < (time + duration))) {
refEvent = event;
searchDone = true;
} else if (time > timestamp) {
searchDone = true;
}
}
return refEvent;
}
}