views:

165

answers:

1

I am building an image Editor as an Eclipse plugin.

I would like to use the Properties view to view & edit properties of the model underneath the image. Accordingly I am calling ..

getSite().setSelectionProvider( this );

.. within createPartControl, and implementing the ISelectionProvider interface in my EditorPart implementation, so that the model is returned as the selection (which must therefore implement the ISelection interface).

The next step is for the Editor to implement IAdaptable to supply an adapter for the selected object.

My problem however is that getAdapter is never called with IPropertySource.class, and therefore the Properties View never gets what it needs to make sense of the image model.

Your help is much appreciated.

M.

+1  A: 

The answer in the end broke down into a few pieces ...

1.) When your selection does change (if a user has zoomed into the image, for example) be sure to tell Eclipse this. It won't happen otherwise.

2.) When sending your SelectionChangedEvent, wrap up your IAdaptable in a StructuredSelection object - otherwise the Properties view will ignore it.

This boiled down to the following method

public void fireSelectionChanged()
{
    final SelectionChangedEvent event = new SelectionChangedEvent( this, new StructuredSelection( this  ) );
    Object[] listeners = selectionChangedListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) 
    {
        final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {
            public void run() {
                l.selectionChanged( event );
            }
        });
    }
}

... on an class that implemented ISelectionProvider & IAdaptable.

M.

Martin Cowie