Question

I have a graphical editor which extends GraphicalEditorWithFlyoutPalette.

There could be appear different markers, so it would be nice, if there is any possibility to connect the marker with the EditPart.

I think one possibility is to extend the TableViewer and the corresponding cell classes. But perhaps there is a better and more easier way.

I create my test markers like following:

IResource resource = (IResource) input.getAdapter(IResource.class);

try 
{
    IMarker marker = resource.createMarker(IMarker.PROBLEM);
    marker.setAttribute(IMarker.TEXT, "text");
    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
    marker.setAttribute(IMarker.MESSAGE, "message");
}
catch (CoreException e) 
{
    e.printStackTrace();
}

input is my IEditorInput.

Was it helpful?

Solution

In my first attempt, I was trying to extends the ExtendedMarkersView, which fails because it is an internal class.
Another way was to write the view and all corresponding stuff new, but it seems to be senseless.

So I found a work around based on https://stackoverflow.com/a/10501971/390177.
While creating the IMarker, I set additional attributes to link the corresponding data object. With the help of the object I can search for the AbstractGraphicalEditPart with the EditPartRegistry.
After that it is possible to create a selection on the EditPart and reveal to it.

@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();
            AbstractGraphicalEditPart editPart = null;

            DataObject object ...
            editPart = (AbstractGraphicalEditPart) getGraphicalViewer().getEditPartRegistry().get(object);

            if (editPart != null) {
                StructuredSelection eSelection = new StructuredSelection(editPart);
                getGraphicalViewer().setSelection(eSelection);
                // once selected if you want to get it so the
                // graphicalviewer scrolls to reveal the part on the
                // screen
                getGraphicalViewer().reveal(editPart);
            }
        }
    } else {
        super.selectionChanged(part, selection);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top