【问题标题】:Using the Selection service on something that is *not* a JFace view在*不是* JFace 视图的东西上使用选择服务
【发布时间】:2009-04-24 12:39:59
【问题描述】:

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

我想使用属性视图来查看和编辑图像下方模型的属性。因此我打电话给..

getSite().setSelectionProvider( this );

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

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

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

非常感谢您的帮助。

M.

【问题讨论】:

    标签: eclipse eclipse-rcp jface


    【解决方案1】:

    最后的答案分解成几块……

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

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

    这归结为以下方法

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

    ...在实现 ISelectionProvider 和 IAdaptable 的类上。

    M.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 2016-08-25
      • 1970-01-01
      • 2016-04-05
      • 2010-12-07
      • 1970-01-01
      相关资源
      最近更新 更多