2011-02-19 77 views
0

我正在编写一个Eclipse RCP插件,用于显示应用程序编辑器中显示的对象的属性。 我的插件扩展了PageBookView。每次,我选择一个新的对象在ApplicationEditor上打开(这是Canvas小部件),我创建了一个新页面保存旧页面。如何在Eclipse中将侦听器添加到应用程序编辑器?

ApplicationEditor扩展了EditorPart。当对象(在活动编辑器更改)时它触发propertyChange事件。我想要的是将监听器添加到applicationEditor。当所需的事件触发时,我必须更新我的页面。

让我把它放在一个简单的方式。

public Class MyPage implements IPage implements **WHICH_LISTENER** 
    { 

    public MyPage(ApplicationEditor editor) 
    { 

    this.addPropertyChangeListener(editor); 

    } 
    . . . . . . 

} 

哪个监听器,我应该落实的propertyChange刷新页面()。

PS:在此先感谢您的宝贵意见。随意质疑我在问题中的进一步澄清!我无法更改编辑器设计或代码,因为我试图为开源项目OpenVXML做出贡献。

回答

0

您的通知UI元素的方法并非最佳。你的UI元素应该向正在改变的对象注册监听器。监听器执行到编辑器的问题取决于编辑器正在监听的对象。在你的情况下,PageBookView需要引用ApplicationEditor来注册自身,这是不好的,因为1. PageBookView对编辑器有一个不需要的依赖关系,2)编辑器不负责传播更改,而是对象本身。我会做以下。

编辑器:

public class MyEditor extends EditorPart implements PropertyChangeListener 

public void init(IEditorSite site, IEditorInput input) { 
// Getting the input and setting it to the editor 
this.object = input.getObject(); 
// add PropertyChangeListener 
this.object.addPropertyChangeListener(this) 
} 

public void propertyChanged(PropertyChangeEvents) { 
// some element of the model has changed. Perform here the UI things to react properly on the change. 
} 
} 

同样的事情需要在你的pageBook完成。

public class MyPropertyView extends PageBook implements PropertyChangeListener{ 

initModel() { 
// you have to pass the model from the editor to the depending pageBook. 
this.model = getModelFromEditor() 
this.object.addPropertyChangeListener(this) 

} 
    public void propertyChanged(PropertyChangeEvents) { 
    // some element of the model has changed. Perform here the UI things to react properly on the change. 
    } 
} 

正如您可以看到两个UI元素都直接对模型中的更改作出反应。

在编辑器中显示对象的另一种方法是使用ProperyViews,为进一步的说明,请参见http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html

一个很久以前,我写了一个简单的例子,在Eclipse中所有该通知的东西看here

HTH Tom

相关问题