Search in sources :

Example 1 with WritableSet

use of org.eclipse.core.databinding.observable.set.WritableSet in project gda-core by openGDA.

the class ClientBindingElements method bindCheckBoxToSet.

public static final <T> void bindCheckBoxToSet(DataBindingContext dbc, Set target, String modelProperty, final Object model, final Class<T> clazz) {
    IObservableSet<T> iTarget = new WritableSet<>(target, clazz);
    IObservableSet<T> iModel = PojoProperties.set(modelProperty, clazz).observe(model);
    UpdateSetStrategy iTargetToModelStrategy = new UpdateSetStrategy();
    UpdateSetStrategy iModelToTargetStrategy = new UpdateSetStrategy();
    dbc.bindSet(iTarget, iModel, iTargetToModelStrategy, iModelToTargetStrategy);
}
Also used : SWT(org.eclipse.swt.SWT) UpdateSetStrategy(org.eclipse.core.databinding.UpdateSetStrategy) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet)

Example 2 with WritableSet

use of org.eclipse.core.databinding.observable.set.WritableSet in project eclipse.platform.ui by eclipse-platform.

the class SetBindingTest method testErrorDuringRemoveIsLogged.

/**
 * We test common functionality from UpdateStrategy here, because that base
 * class would need much more stubbing and mocking to test it.
 */
@Test
public void testErrorDuringRemoveIsLogged() {
    IObservableSet<String> target = new WritableSet<String>() {

        @Override
        public boolean remove(Object elem) {
            throw new IllegalArgumentException();
        }
    };
    Binding binding = dbc.bindSet(target, model, new UpdateSetStrategy<>(), new UpdateSetStrategy<>());
    CountDownLatch latch = new CountDownLatch(1);
    Policy.setLog(status -> {
        latch.countDown();
        assertEquals(IStatus.ERROR, status.getSeverity());
        assertTrue(status.getException() instanceof IllegalArgumentException);
    });
    model.add("first");
    model.remove("first");
    assertEquals(0, latch.getCount());
    assertEquals(IStatus.ERROR, binding.getValidationStatus().getValue().getSeverity());
}
Also used : SetBinding(org.eclipse.core.databinding.SetBinding) Binding(org.eclipse.core.databinding.Binding) CountDownLatch(java.util.concurrent.CountDownLatch) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Example 3 with WritableSet

use of org.eclipse.core.databinding.observable.set.WritableSet in project eclipse.platform.ui by eclipse-platform.

the class PojoObservablesTest method testObservableMap_DoesNotAttachListeners.

@Test
public void testObservableMap_DoesNotAttachListeners() throws Exception {
    IObservableSet set = new WritableSet();
    set.add(pojo);
    IObservableMap map = PojoObservables.observeMap(set, Bean.class, propertyName);
    assertFalse(pojo.hasListeners(propertyName));
    ChangeEventTracker.observe(map);
    assertFalse(pojo.hasListeners(propertyName));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Example 4 with WritableSet

use of org.eclipse.core.databinding.observable.set.WritableSet in project eclipse.platform.ui by eclipse-platform.

the class PojoObservablesTest method testObserveMaps_ReturnsMaps.

@Test
public void testObserveMaps_ReturnsMaps() throws Exception {
    IObservableSet set = new WritableSet();
    set.add(pojo);
    IObservableMap[] maps = PojoObservables.observeMaps(set, Bean.class, new String[] { "value", "class" });
    assertEquals(2, maps.length);
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) IObservableSet(org.eclipse.core.databinding.observable.set.IObservableSet) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Example 5 with WritableSet

use of org.eclipse.core.databinding.observable.set.WritableSet in project eclipse.platform.ui by eclipse-platform.

the class BindSetTest method defaultDirectionIsTargetToModel.

@Test
public void defaultDirectionIsTargetToModel() {
    var target = new WritableSet<String>();
    var model = new WritableSet<String>();
    Binding binding = Bind.oneWay().from(target).to(model).bindWithNewContext();
    assertSame(target, binding.getTarget());
    assertSame(model, binding.getModel());
}
Also used : Binding(org.eclipse.core.databinding.Binding) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Aggregations

WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)31 Test (org.junit.Test)27 SetDetailValueObservableMap (org.eclipse.core.internal.databinding.observable.masterdetail.SetDetailValueObservableMap)12 SimplePerson (org.eclipse.jface.examples.databinding.model.SimplePerson)8 IObservableMap (org.eclipse.core.databinding.observable.map.IObservableMap)6 Binding (org.eclipse.core.databinding.Binding)4 IObservableSet (org.eclipse.core.databinding.observable.set.IObservableSet)4 HashSet (java.util.HashSet)3 Realm (org.eclipse.core.databinding.observable.Realm)3 WritableValue (org.eclipse.core.databinding.observable.value.WritableValue)3 ThreadRealm (org.eclipse.core.tests.databinding.observable.ThreadRealm)3 CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)3 MapChangeEventTracker (org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker)3 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)2 IObservableFactory (org.eclipse.core.databinding.observable.masterdetail.IObservableFactory)2 DetailObservableSet (org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableSet)2 MutableObservableSetContractTest (org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest)2 ObservableMapLabelProvider (org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider)2 SWT (org.eclipse.swt.SWT)2 Arrays (java.util.Arrays)1