Search in sources :

Example 11 with Realm

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

the class ViewerSupport method bind.

/**
 * Binds the viewer to the specified input, using the specified children
 * property to generate child nodes, and the specified label properties to
 * generate labels.
 *
 * @param viewer
 *            the tree viewer to set up
 * @param input
 *            the input to set on the viewer
 * @param childrenProperty
 *            the property to use as the children of an element
 * @param labelProperties
 *            the respective properties to use for labels in each of the
 *            viewer's columns
 */
@SafeVarargs
public static <E> void bind(AbstractTreeViewer viewer, E input, ISetProperty<? super E, ? extends E> childrenProperty, IValueProperty<? super E, ?>... labelProperties) {
    Realm realm = DisplayRealm.getRealm(viewer.getControl().getDisplay());
    ObservableSetTreeContentProvider<? extends E> contentProvider = new ObservableSetTreeContentProvider<>(childrenProperty.setFactory(realm), null);
    if (viewer.getInput() != null)
        viewer.setInput(null);
    viewer.setContentProvider(contentProvider);
    viewer.setLabelProvider(new ObservableMapLabelProvider(Properties.observeEach(contentProvider.getKnownElements(), labelProperties)));
    if (input != null)
        viewer.setInput(input);
}
Also used : Realm(org.eclipse.core.databinding.observable.Realm) DisplayRealm(org.eclipse.jface.databinding.swt.DisplayRealm)

Example 12 with Realm

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

the class ObservableContractTest method testDispose_PreservesRealm.

@Test
public void testDispose_PreservesRealm() throws Exception {
    Realm realm = observable.getRealm();
    observable.dispose();
    assertSame(realm, observable.getRealm());
}
Also used : Realm(org.eclipse.core.databinding.observable.Realm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 13 with Realm

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

the class ObservableContractTest method testDispose_RemovesListeners.

@Test
public void testDispose_RemovesListeners() throws Exception {
    ChangeListener disposedObservableListener = new ChangeListener();
    Realm realm = observable.getRealm();
    observable.addChangeListener(disposedObservableListener);
    observable.dispose();
    // create a new observable to fire a change from
    observable = delegate.createObservable(realm);
    delegate.change(observable);
    assertEquals(formatFail("After being disposed listeners should not receive change events."), 0, disposedObservableListener.count);
}
Also used : IChangeListener(org.eclipse.core.databinding.observable.IChangeListener) Realm(org.eclipse.core.databinding.observable.Realm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) Test(org.junit.Test)

Example 14 with Realm

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

the class JavaBeanObservableMapTest method testConstructor_SkipRegisterListeners.

@Test
public void testConstructor_SkipRegisterListeners() throws Exception {
    Realm realm = new CurrentRealm(true);
    WritableSet set = new WritableSet(realm);
    Bean bean = new Bean();
    set.add(bean);
    IObservableMap observable = PojoObservables.observeMap(set, Bean.class, "value");
    assertFalse(bean.hasListeners("value"));
    ChangeEventTracker.observe(observable);
    assertFalse(bean.hasListeners("value"));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) Realm(org.eclipse.core.databinding.observable.Realm) ThreadRealm(org.eclipse.core.tests.databinding.observable.ThreadRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Example 15 with Realm

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

the class JavaBeanObservableMapTest method testConstructor_RegistersListeners.

@Test
public void testConstructor_RegistersListeners() throws Exception {
    Realm realm = new CurrentRealm(true);
    WritableSet set = new WritableSet(realm);
    Bean bean = new Bean();
    set.add(bean);
    IObservableMap observable = BeansObservables.observeMap(set, Bean.class, "value");
    assertFalse(bean.hasListeners("value"));
    ChangeEventTracker.observe(observable);
    assertTrue(bean.hasListeners("value"));
}
Also used : IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) Realm(org.eclipse.core.databinding.observable.Realm) ThreadRealm(org.eclipse.core.tests.databinding.observable.ThreadRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) CurrentRealm(org.eclipse.jface.databinding.conformance.util.CurrentRealm) WritableSet(org.eclipse.core.databinding.observable.set.WritableSet) Test(org.junit.Test)

Aggregations

Realm (org.eclipse.core.databinding.observable.Realm)22 Test (org.junit.Test)10 CurrentRealm (org.eclipse.jface.databinding.conformance.util.CurrentRealm)8 Event (org.eclipse.swt.widgets.Event)7 Listener (org.eclipse.swt.widgets.Listener)7 DisplayRealm (org.eclipse.jface.databinding.swt.DisplayRealm)6 Button (org.eclipse.swt.widgets.Button)6 Group (org.eclipse.swt.widgets.Group)6 Text (org.eclipse.swt.widgets.Text)3 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)2 IObservableMap (org.eclipse.core.databinding.observable.map.IObservableMap)2 WritableSet (org.eclipse.core.databinding.observable.set.WritableSet)2 ComputedValue (org.eclipse.core.databinding.observable.value.ComputedValue)2 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)2 IValueChangeListener (org.eclipse.core.databinding.observable.value.IValueChangeListener)2 ValueChangeEvent (org.eclipse.core.databinding.observable.value.ValueChangeEvent)2 ThreadRealm (org.eclipse.core.tests.databinding.observable.ThreadRealm)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 GridData (org.eclipse.swt.layout.GridData)2 Control (org.eclipse.swt.widgets.Control)2