Skip to content

Commit

Permalink
ros2: add action for hiding internal objects in ROS 2 views
Browse files Browse the repository at this point in the history
This allows hiding internal publishers or subscriptions that are mostly
internal to ROS 2. It thus allows simplifying the views a bit.

Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Change-Id: Id32125292c5e16cc6cf22c0ef5924dc3b1caef51
Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/192548
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
  • Loading branch information
christophebedard committed May 25, 2023
1 parent 7649029 commit a57a4aa
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,84 @@
/**********************************************************************
* 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;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.tracecompass.incubator.internal.ros2.ui.Activator;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;

/**
* Action to hide internal ROS 2 objects in the time graph viewer.
*
* @author Christophe Bedard
*/
public class Ros2HideInternalObjectsAction extends Action {

private static final @NonNull String IMG_UI = "icons/elcl16/hide_internal.gif"; //$NON-NLS-1$
private static final @NonNull String ACTION_TEXT = "Hide ROS 2 internal"; //$NON-NLS-1$
private static final @NonNull String ACTION_TOOLTIP_TEXT = "Hide internal ROS 2 objects"; //$NON-NLS-1$

private static final List<String> HIDDEN_TOPICS = Arrays.asList("/parameter_events", "/rosout"); //$NON-NLS-1$ //$NON-NLS-2$

private final TimeGraphViewer fTimeGraphViewer;
private final @NonNull Ros2HideInternalViewerFilter fFilter;

private class Ros2HideInternalViewerFilter extends ViewerFilter {

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (!(element instanceof ITimeGraphEntry)) {
return true;
}
ITimeGraphEntry entry = (ITimeGraphEntry) element;
return !HIDDEN_TOPICS.contains(entry.getName());
}
}

/**
* Constructor
*
* @param timeGraphViewer
* the time graph viewer
*/
public Ros2HideInternalObjectsAction(TimeGraphViewer timeGraphViewer) {
super(ACTION_TEXT, IAction.AS_CHECK_BOX);
fTimeGraphViewer = timeGraphViewer;
fFilter = new Ros2HideInternalViewerFilter();
setToolTipText(ACTION_TOOLTIP_TEXT);
setImageDescriptor(Objects.requireNonNull(Activator.getDefault()).getImageDescripterFromPath(IMG_UI));

update();
}

@Override
public void run() {
update();
}

private void update() {
if (isChecked()) {
fTimeGraphViewer.addFilter(fFilter);
} else {
fTimeGraphViewer.removeFilter(fFilter);
}
fTimeGraphViewer.refresh();
}
}
Expand Up @@ -21,6 +21,7 @@
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.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.ui.IWorkbenchActionConstants;

Expand Down Expand Up @@ -70,6 +71,10 @@ protected void fillLocalToolBar(IToolBarManager manager) {
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());

Expand Down

0 comments on commit a57a4aa

Please sign in to comment.