如何在Eclipse中的应用程序编辑器中添加监听器?
我正在编写一个 Eclipse RCP 插件,用于显示应用程序编辑器中显示的对象的属性。 我的插件扩展了 PageBookView。每次,我选择在应用程序编辑器(即 Canvas 小部件)上打开一个新对象时,我都会创建一个新页面并创建一个新对象。保存旧页面。
ApplicationEditor 扩展了 EditorPart。当对象(活动编辑器上的)发生更改时,它会触发 propertyChange 事件。我想要的只是向 applicationEditor 添加监听器。当所需的事件触发时,我必须更新我的页面。
让我简单地说一下。
public Class MyPage implements IPage implements **WHICH_LISTENER**
{
public MyPage(ApplicationEditor editor)
{
this.addPropertyChangeListener(editor);
}
. . . . . .
}
我应该实现哪个监听器来通过 propertyChange() 刷新页面。?
PS:提前感谢您的宝贵建议。为了进一步澄清问题,请随时向我提问!我无法更改编辑器设计或代码,因为我正在尝试为开源项目 OpenVXML 做出贡献。
I am writing a Eclipse RCP Plug-in for displaying the properties of objects displayed in application editor.
My plug-in extends PageBookView. Every time, i select a new object is opened on the ApplicationEditor(which is Canvas widget),i create a new page & save the old page.
ApplicationEditor extends EditorPart. It fires propertyChange events when the objects (on the active editor changes). All i want is to add listener to applicationEditor. When the required event fires, i have to update my page.
Let me put it in a simmple way.
public Class MyPage implements IPage implements **WHICH_LISTENER**
{
public MyPage(ApplicationEditor editor)
{
this.addPropertyChangeListener(editor);
}
. . . . . .
}
Which Listener should i implement to refresh the page by propertyChange().?
PS: Thanks in advance for your precious advices. Feel free to question me for further clarity in the Question! I cannot change the editor design or code, as i am trying to contribute to an open source project OpenVXML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您通知 UI-Elements 的方法不是最佳的。您的 UI 元素应该向正在更改的对象注册侦听器。对编辑器实施哪个侦听器的问题取决于编辑器正在侦听哪个对象。在您的情况下,PageBookView 需要引用 ApplicationEditor 来注册自身,这不好,因为 1. PageBookView 对编辑器有不必要的依赖性,2)编辑器不负责传播更改,而是负责传播更改。我会做以下事情。
您的编辑:
您的 pageBook 也需要做同样的事情。
正如您所看到的,两个 UI 元素都直接对模型中的更改做出反应。
在编辑器中显示对象的另一种方法是使用 ProperyViews,有关详细说明,请参阅 http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html
不久前,我在 Eclipse 中为所有这些通知内容编写了一个简单的示例,请参阅 此处。
汤姆·HTH
Your approach of notifying UI-Elements is not optimal. Your UI-Elements should register listeners to the objects which are changing. The question which listener to implement to the editor depends on which object the editor is listen to. In your case the PageBookView needs a reference to ApplicationEditor to register itself, which is not good, because 1. the PageBookView has an unneccessary dependency to the editor and 2) the editor is not responsible for propagating changes, but the object itself. I would do the following.
Your Editor:
The same thing needs to be done on your pageBook.
As you can see both UI Elements are reacting directly to the changes in the model.
Another way of displaying objects in an editor is to use ProperyViews, for an further description see http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html
A time ago, I've written a simple example for all this notification stuff in Eclipse see here.
HTH Tom