问题
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