在*不是JFace视图的东西上使用Selection服务

时间:2022-03-14 22:45:09

I am building an image Editor as an Eclipse plugin.

我正在构建一个图像编辑器作为Eclipse插件。

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).

..在createPartControl中,并在我的EditorPart实现中实现ISelectionProvider接口,以便模型作为选择返回(因此必须实现ISelection接口)。

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

下一步是编辑器实现IAdaptable以为所选对象提供适配器。

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.

然而,我的问题是从不使用IPropertySource.class调用getAdapter,因此Properties View永远不会获得理解图像模型所需的内容。

Your help is much appreciated.

非常感谢您的帮助。

M.

1 个解决方案

#1


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.

1.)当您的选择确实发生变化时(例如,如果用户放大了图像),请务必告诉Eclipse。否则就不会发生这种情况。

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

2.)发送SelectionChangedEvent时,在StructuredSelection对象中包装IAdaptable - 否则Properties视图将忽略它。

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.

...在一个实现了ISelectionProvider和IAdaptable的类上。

M.

#1


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.

1.)当您的选择确实发生变化时(例如,如果用户放大了图像),请务必告诉Eclipse。否则就不会发生这种情况。

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

2.)发送SelectionChangedEvent时,在StructuredSelection对象中包装IAdaptable - 否则Properties视图将忽略它。

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.

...在一个实现了ISelectionProvider和IAdaptable的类上。

M.