2

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.

CSchulz
  • 10,882
  • 11
  • 60
  • 114

2 Answers2

0

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
                }
            }

        });
    }
}
Bela Vizer
  • 2,527
  • 22
  • 26
  • Thanks for your answer. But I can't use it in my case, because my class extends the MarkerSupportView and overwrite the method createPartControl isn't allowed. – CSchulz May 08 '12 at 11:38
  • I do the same, extending MarkerSupportView which extends ExtendedMarkersView, problem I am aware of is that it is in an internal package, however that is the best I could come up, if somebody else had a brilliant idea than I would do the same however that is the only way I found so far to solve this requirement. – Bela Vizer May 08 '12 at 15:03
  • I found a work around with the help of the SelectionService, see my answer. :) It is not the best way ... – CSchulz May 08 '12 at 15:47
0

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 ...
            }
        }
    }
});
CSchulz
  • 10,882
  • 11
  • 60
  • 114