2

我有以下模型:

public class HoverDescriptor {

    private String id;
    private String label;
    private boolean enabled;
    private String description;
    private int stateMask;
    private String modifierString;

    public HoverDescriptor(String id, String label, boolean isEnabled, String description,
        ...
}

public class HoverViewModel {

    Set<HoverDescriptor> mHovers;

    private HoverViewModel() {
        mHovers = new HashSet<HoverDescriptor>();
        mHovers.add(new HoverDescriptor("Mock1", "Label1", true, "Desc1", SWT.DEFAULT, ""));
        mHovers.add(new HoverDescriptor("Mock2", "Label2", false, "Desc2",SWT.DEFAULT, ""));
        mHovers.add(new HoverDescriptor("Mock3", "Label3", false, "Desc3", SWT.DEFAULT, ""));
    }

    public static HoverViewModel newInstance() {
        return new HoverViewModel();
    }

    public Set<HoverDescriptor> getHovers() {
        return mHovers;
    }

我想绑定:

final IObservableSet checkedElements = ViewersObservables.observeCheckedElements(viewer, HoverDescriptor.class);

到以下 ObservableMap:

IBeanSetProperty descriptors = PojoProperties.set("hovers", HoverDescriptor.class);
IObservableMap observeMap = PojoObservables.observeMap(descriptors.observe(fViewModel), HoverDescriptor.class, "enabled");

但是,除了不推荐使用的MappedSetDataBindingContext.bindSet(?)之外,我找不到任何惯用的方式。我怎样才能有效地做到这一点?

4

0 回答 0