Custom marker view with own interactions

末鹿安然 提交于 2020-01-15 03:51:14

问题


I am trying to create my own problem view.
I found the following tutorial and all works fine.

But is there any possibility to add an own DoubleClickListener or something like that?
I want to react on user actions, which are executed on the list.

Thanks for any advices.


回答1:


Here is what I would do:

by overriding public void createPartControl(final Composite parent) you will have the parent composite. By calling parent.getChildren() you can iterate over the available Controls. ExtendedMarkersView "default" control is MarkersTreeViewer which is a treeViewer, so the control would be a tree. You have the tree, you can add any listener you want, here is the snippet:

@Override
public void createPartControl(final Composite parent) {
    super.createPartControl(parent);

    for (final Control control : parent.getChildren()) {
        if (!(control instanceof Tree)) {
            continue;
        }

        tree = (Tree) control;

        final Listener[] listeners = tree.getListeners(SWT.DefaultSelection);
        if (listeners != null) {
            for (final Listener listener : listeners) {
                tree.removeListener(SWT.DefaultSelection, listener);
            }
        }
        tree.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(final MouseEvent e) {
                if (e.widget instanceof Tree) {
                    final Tree tree = (Tree) e.widget;

                    // do whatever you want
                }
            }

        });
    }
}



回答2:


I found a solution, not the best one, but an acceptable way.
I use the SelectionService in my ViewPart and register a new SelectionListener.

My solution only accepts a selection in the problem view, perhaps there is a better way to differ the events.

site.getWorkbenchWindow().getSelectionService().addSelectionListener(new ISelectionListener() {
    @Override
    public void selectionChanged(IWorkbenchPart part, ISelection selection) {
        IStructuredSelection s = (IStructuredSelection) selection;

        if (s.getFirstElement() instanceof MarkerItem) {
            MarkerItem marker = (MarkerItem) s.getFirstElement();
            if (marker != null && marker.getMarker() != null) {
                IMarker iMarker = marker.getMarker();

                // More Code here ...
            }
        }
    }
});


来源:https://stackoverflow.com/questions/10486570/custom-marker-view-with-own-interactions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!