views:

262

answers:

1

Hi all,

I am using the PropertySheetView component to visualize and edit the properties of a node. This view should always reflect the most recent properties of the object; if there is a change to the object in another process, I want to somehow refresh the view and see the updated properties.

The best way I was able to do this is something like the following (making use of EventBus library to publish and subscribe to changes in objects):

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());
}

This works, but my place in the scrollpane is lost when the sheet refreshes; it resets the view to the top of the list and I have to scroll back down to where I was before the refresh action.

So my question is, is there a better way to refresh the property sheet view of a node, specifically so my place in the property list is not lost upon refresh?

The solution of firePropertySetsChange comes from this thread.

A: 

The solution is to fire a property change for each of the changed property of the updated object. So, in context of the snippet in the question this could be something like:

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());
    }
}

Note that property set should not be changed as that would mess with the property editors. Consequentially, the actual Property objects have to support changing of the domain object behind the property.

tPeltola