2011-02-19 76 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

相關問題