2010-04-11 102 views
1

我正在使用PropertySheetView組件來可視化和編輯節點的屬性。該視圖應始終反映該對象的最新屬性;如果在另一個進程中對象發生更改,我想以某種方式刷新視圖並查看更新的屬性。NetBeans平臺 - 如何刷新節點的屬性表視圖?

我能夠做到這一點的最好辦法是像下面(利用EventBus庫中的對象發佈和訂閱變化):

public DomainObjectWrapperNode(DomainObject obj) { 
    super (Children.LEAF, Lookups.singleton(obj)); 
    EventBus.subscribe(DomainObject.class, this); 
} 

public void onEvent(DomainObject event) { 
    // Do a check to determine if the updated object is the one wrapped by this node; 
    // if so fire a property sets change 

    firePropertySetsChange(null, this.getPropertySets()); 
} 

這工作,但我在滾動的地方紙張刷新時丟失;它將視圖重置爲列表頂部,我必須回滾到刷新操作前的位置。

所以我的問題是,是否有更好的方式來刷新節點的屬性表視圖,特別是我的屬性列表中的位置刷新後不會丟失?

firePropertySetsChange的解決方案來自this thread

回答

1

解決方法是針對更新對象的每個更改屬性觸發屬性更改。所以,在這個問題的片段的背景下,這可能是這樣的:

public void onEvent(DomainObject event) { 
    // Do a check to determine if the updated object is the one wrapped by this node; 
    // if so fire a property sets change 

    Set<Property> changes = new HashSet<Property>(); 
    // Populate the set from property set of the node using the event 
    // (or add all properties to force updating all properties) 

    for (Property change : changes) { 
     firePropertyChange(change.getName(), null, change.getValue()); 
    } 
} 

注意屬性集不應該改變,因爲這將與屬性編輯器一塌糊塗。因此,實際的Property對象必須支持更改屬性後面的域對象。

1

您也可以將節點的屬性表設置爲null,因此createSheet方法再次被調用。

2

只是作爲一個未註冊用戶澄清我的舊回答:調用createSheet(null)將提高NullPointerException。改爲使用setSheet(createSheet())