1

我正在使用 PropertySheetView 组件来可视化和编辑节点的属性。此视图应始终反映对象的最新属性;如果在另一个进程中对对象进行了更改,我想以某种方式刷新视图并查看更新的属性。

我能够做到这一点的最好方法如下(利用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 的解决方案来自这个线程

4

3 回答 3

3

只是为了澄清我作为未注册用户的旧答案:调用createSheet(null)将引发NullPointerException. 改为使用setSheet(createSheet())

于 2016-11-15T02:51:42.570 回答
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 对象必须支持更改属性背后的域对象。

于 2010-07-26T14:29:24.037 回答
1

您还可以将节点的属性表设置为null,以便createSheet再次调用该方法。

于 2012-08-22T14:59:17.043 回答