Search in sources :

Example 21 with IBindingInfo

use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.

the class ViewerObservableTest method test_Viewer_Input_List_InputCollection.

public void test_Viewer_Input_List_InputCollection() throws Exception {
    setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", "  public String getName() {", "    return null;", "  }", "  public java.util.List getBeans() {", "    return null;", "  }", "}"));
    waitForAutoBuild();
    // 
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", "  private DataBindingContext m_bindingContext;", "  protected Shell m_shell;", "  private TableViewer m_viewer;", "  private java.util.List m_beans;", "  public static void main(String[] args) {", "    Test test = new Test();", "    test.open();", "  }", "  public void open() {", "    Display display = new Display();", "    createContents();", "    m_shell.open();", "    m_shell.layout();", "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {", "        display.sleep();", "      }", "    }", "  }", "  protected void createContents() {", "    m_shell = new Shell();", "    m_shell.setLayout(new GridLayout());", "    m_viewer = new TableViewer(m_shell, SWT.BORDER);", "    m_bindingContext = initDataBindings();", "  }", "  private DataBindingContext initDataBindings() {", "    DataBindingContext bindingContext = new DataBindingContext();", "    //", "    ObservableListContentProvider viewerContentProvider = new ObservableListContentProvider();", "    m_viewer.setContentProvider(viewerContentProvider);", "    IObservableMap[] viewerLabelProviderMaps = BeansObservables.observeMaps(viewerContentProvider.getKnownElements(), TestBean.class, new String[]{\"name\"});", "    m_viewer.setLabelProvider(new ObservableMapLabelProvider(viewerLabelProviderMaps));", "    //", "    m_viewer.setInput(new WritableList(m_beans, TestBean.class));", "    //", "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);
    // 
    DatabindingsProvider provider = getDatabindingsProvider();
    // 
    IObserveInfo shellObserve = provider.getObserves(ObserveType.WIDGETS).get(0);
    IObserveInfo viewerObserve = shellObserve.getChildren(ChildrenContext.ChildrenForMasterTable).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0);
    IObserveInfo viewerInputProperty = viewerObserve.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(4);
    // 
    IObserveInfo beanObserve = provider.getObserves(ObserveType.BEANS).get(3);
    IObserveInfo beanInputCollectionProperty = beanObserve.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(0);
    // 
    List<IBindingInfo> bindings = provider.getBindings();
    assertEquals(1, bindings.size());
    assertInstanceOf(ViewerInputBindingInfo.class, bindings.get(0));
    // 
    ViewerInputBindingInfo binding = (ViewerInputBindingInfo) bindings.get(0);
    // 
    assertSame(viewerObserve, binding.getViewer());
    assertSame(viewerObserve, binding.getTarget());
    assertSame(viewerInputProperty, binding.getTargetProperty());
    // 
    assertSame(beanObserve, binding.getModel());
    assertSame(beanInputCollectionProperty, binding.getModelProperty());
    // 
    assertNotNull(binding.getInputObservable());
    assertInstanceOf(WritableListBeanObservableInfo.class, binding.getInputObservable());
    // 
    ObservableInfo inputObservable = binding.getInputObservable();
    assertSame(beanObserve, inputObservable.getBindableObject());
    assertSame(beanInputCollectionProperty, inputObservable.getBindableProperty());
    // 
    assertEquals("WritableList(m_beans, TestBean.class)", inputObservable.getPresentationText());
    // 
    assertNull(binding.getVariableIdentifier());
    assertEquals("m_viewer.input(ObservableListContentProvider, ObservableMaps[name])", binding.getPresentationText());
    // 
    assertNotNull(binding.getElementType());
    assertEquals("test.TestBean", binding.getElementType().getName());
    // 
    ObservableMapLabelProviderInfo labelProvider = binding.getLabelProvider();
    assertNotNull(labelProvider);
    assertEquals("org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider", labelProvider.getClassName());
    assertEquals("ObservableMaps[name]", labelProvider.getPresentationText());
    assertNull(labelProvider.getVariableIdentifier());
    // 
    MapsBeanObservableInfo mapsObservable = labelProvider.getMapsObservable();
    assertNotNull(mapsObservable);
    assertNotNull(mapsObservable.getElementType());
    assertEquals("test.TestBean", mapsObservable.getElementType().getName());
    assertNull(mapsObservable.getBindableObject());
    assertNull(mapsObservable.getBindableProperty());
    // 
    String[] properties = mapsObservable.getProperties();
    assertNotNull(properties);
    assertEquals(1, properties.length);
    assertEquals("name", properties[0]);
    // 
    assertNotNull(mapsObservable.getDomainObservable());
    assertInstanceOf(KnownElementsObservableInfo.class, mapsObservable.getDomainObservable());
    // 
    KnownElementsObservableInfo knownElementsObservableInfo = (KnownElementsObservableInfo) mapsObservable.getDomainObservable();
    assertNull(knownElementsObservableInfo.getBindableObject());
    assertNull(knownElementsObservableInfo.getBindableProperty());
    // 
    assertNotNull(knownElementsObservableInfo.getParent());
    assertSame(knownElementsObservableInfo.getParent(), ReflectionUtils.getFieldObject(binding, "m_contentProvider"));
    assertInstanceOf(ObservableListContentProviderInfo.class, knownElementsObservableInfo.getParent());
    // 
    ObservableListContentProviderInfo contentProvider = (ObservableListContentProviderInfo) knownElementsObservableInfo.getParent();
    assertEquals("org.eclipse.jface.databinding.viewers.ObservableListContentProvider", contentProvider.getClassName());
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) DetailListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo) SetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo) SingleSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo) DetailSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo) ListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo) ViewerObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) ObservableMapLabelProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableMapLabelProviderInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo) TreeViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo) ViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo) ObservableListContentProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableListContentProviderInfo) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)

Example 22 with IBindingInfo

use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.

the class ViewerObservableTest method test_Viewer_Input_Set.

public void test_Viewer_Input_Set() throws Exception {
    setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", "  public String getName() {", "    return null;", "  }", "  public java.util.Set getBeans() {", "    return null;", "  }", "}"));
    waitForAutoBuild();
    // 
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", "  private DataBindingContext m_bindingContext;", "  protected Shell m_shell;", "  private TableViewer m_viewer;", "  private TestBean m_bean;", "  public static void main(String[] args) {", "    Test test = new Test();", "    test.open();", "  }", "  public void open() {", "    Display display = new Display();", "    createContents();", "    m_shell.open();", "    m_shell.layout();", "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {", "        display.sleep();", "      }", "    }", "  }", "  protected void createContents() {", "    m_shell = new Shell();", "    m_shell.setLayout(new GridLayout());", "    m_viewer = new TableViewer(m_shell, SWT.BORDER);", "    m_bindingContext = initDataBindings();", "  }", "  private DataBindingContext initDataBindings() {", "    DataBindingContext bindingContext = new DataBindingContext();", "    //", "    ObservableSetContentProvider viewerContentProvider = new ObservableSetContentProvider();", "    m_viewer.setContentProvider(viewerContentProvider);", "    IObservableMap[] viewerLabelProviderMaps = BeansObservables.observeMaps(viewerContentProvider.getKnownElements(), TestBean.class, new String[]{\"name\"});", "    m_viewer.setLabelProvider(new ObservableMapLabelProvider(viewerLabelProviderMaps));", "    //", "    IObservableSet beanObserveSet = BeansObservables.observeSet(Realm.getDefault(), m_bean, \"beans\");", "    m_viewer.setInput(beanObserveSet);", "    //", "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);
    // 
    DatabindingsProvider provider = getDatabindingsProvider();
    // 
    IObserveInfo shellObserve = provider.getObserves(ObserveType.WIDGETS).get(0);
    IObserveInfo viewerObserve = shellObserve.getChildren(ChildrenContext.ChildrenForMasterTable).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0);
    IObserveInfo viewerInputProperty = viewerObserve.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(4);
    // 
    IObserveInfo beanObserve = provider.getObserves(ObserveType.BEANS).get(3);
    IObserveInfo beanBeansProperty = beanObserve.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(0);
    // 
    List<IBindingInfo> bindings = provider.getBindings();
    assertEquals(1, bindings.size());
    assertInstanceOf(ViewerInputBindingInfo.class, bindings.get(0));
    // 
    ViewerInputBindingInfo binding = (ViewerInputBindingInfo) bindings.get(0);
    // 
    assertSame(viewerObserve, binding.getViewer());
    assertSame(viewerObserve, binding.getTarget());
    assertSame(viewerInputProperty, binding.getTargetProperty());
    // 
    assertSame(beanObserve, binding.getModel());
    assertSame(beanBeansProperty, binding.getModelProperty());
    // 
    assertNotNull(binding.getInputObservable());
    assertInstanceOf(SetBeanObservableInfo.class, binding.getInputObservable());
    // 
    ObservableInfo inputObservable = binding.getInputObservable();
    assertSame(beanObserve, inputObservable.getBindableObject());
    assertSame(beanBeansProperty, inputObservable.getBindableProperty());
    // 
    assertEquals("m_bean.beans(Set)", inputObservable.getPresentationText());
    // 
    assertNull(binding.getVariableIdentifier());
    assertEquals("m_viewer.input(ObservableSetContentProvider, ObservableMaps[name])", binding.getPresentationText());
    // 
    assertNotNull(binding.getElementType());
    assertEquals("test.TestBean", binding.getElementType().getName());
    // 
    ObservableMapLabelProviderInfo labelProvider = binding.getLabelProvider();
    assertNotNull(labelProvider);
    assertEquals("org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider", labelProvider.getClassName());
    assertEquals("ObservableMaps[name]", labelProvider.getPresentationText());
    assertNull(labelProvider.getVariableIdentifier());
    // 
    MapsBeanObservableInfo mapsObservable = labelProvider.getMapsObservable();
    assertNotNull(mapsObservable);
    assertNotNull(mapsObservable.getElementType());
    assertEquals("test.TestBean", mapsObservable.getElementType().getName());
    assertNull(mapsObservable.getBindableObject());
    assertNull(mapsObservable.getBindableProperty());
    // 
    String[] properties = mapsObservable.getProperties();
    assertNotNull(properties);
    assertEquals(1, properties.length);
    assertEquals("name", properties[0]);
    // 
    assertNotNull(mapsObservable.getDomainObservable());
    assertInstanceOf(KnownElementsObservableInfo.class, mapsObservable.getDomainObservable());
    // 
    KnownElementsObservableInfo knownElementsObservableInfo = (KnownElementsObservableInfo) mapsObservable.getDomainObservable();
    assertNull(knownElementsObservableInfo.getBindableObject());
    assertNull(knownElementsObservableInfo.getBindableProperty());
    // 
    assertNotNull(knownElementsObservableInfo.getParent());
    assertSame(knownElementsObservableInfo.getParent(), ReflectionUtils.getFieldObject(binding, "m_contentProvider"));
    assertInstanceOf(ObservableSetContentProviderInfo.class, knownElementsObservableInfo.getParent());
    // 
    ObservableSetContentProviderInfo contentProvider = (ObservableSetContentProviderInfo) knownElementsObservableInfo.getParent();
    assertEquals("org.eclipse.jface.databinding.viewers.ObservableSetContentProvider", contentProvider.getClassName());
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) ObservableSetContentProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableSetContentProviderInfo) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) DetailListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo) SetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo) SingleSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo) DetailSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo) ListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo) ViewerObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) ObservableMapLabelProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableMapLabelProviderInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo) TreeViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo) ViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)

Example 23 with IBindingInfo

use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.

the class ViewerObservableTest method test_observeCheckedElements.

public void test_observeCheckedElements() throws Exception {
    setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", "  public java.util.Set getNames() {", "    return null;", "  }", "}"));
    waitForAutoBuild();
    // 
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", "  protected Shell m_shell;", "  private CheckboxTreeViewer m_viewer;", "  private TestBean m_bean;", "  private DataBindingContext m_bindingContext;", "  public static void main(String[] args) {", "    Test test = new Test();", "    test.open();", "  }", "  public void open() {", "    Display display = new Display();", "    createContents();", "    m_shell.open();", "    m_shell.layout();", "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {", "        display.sleep();", "      }", "    }", "  }", "  protected void createContents() {", "    m_shell = new Shell();", "    m_shell.setLayout(new GridLayout());", "    m_viewer = new CheckboxTreeViewer(m_shell, SWT.BORDER);", "    m_bindingContext = initDataBindings();", "  }", "  private DataBindingContext initDataBindings() {", "    IObservableSet observeSet = BeansObservables.observeSet(Realm.getDefault(), m_bean, \"names\");", "    IObservableSet observeWidget = ViewersObservables.observeCheckedElements(m_viewer, Integer.class);", "    DataBindingContext bindingContext = new DataBindingContext();", "    bindingContext.bindSet(observeWidget, observeSet, null, null);", "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);
    // 
    DatabindingsProvider provider = getDatabindingsProvider();
    List<IBindingInfo> bindings = provider.getBindings();
    // 
    assertNotNull(bindings);
    assertEquals(1, bindings.size());
    // 
    BindingInfo binding = (BindingInfo) bindings.get(0);
    // 
    assertInstanceOf(CheckedElementsObservableInfo.class, binding.getTargetObservable());
    CheckedElementsObservableInfo observable = (CheckedElementsObservableInfo) binding.getTargetObservable();
    // 
    assertEquals("observeWidget", observable.getVariableIdentifier());
    assertEquals("m_viewer.checkedElements(Integer.class)", observable.getPresentationText());
    // 
    WidgetBindableTest.assertBindable(shell.getChildrenControls().get(0).getChildren().get(0), WidgetBindableInfo.class, provider.getObserves(ObserveType.WIDGETS).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0), false, "m_viewer|m_viewer|org.eclipse.jface.viewers.CheckboxTreeViewer", observable.getBindableObject());
    // 
    WidgetBindableTest.assertBindableProperty(WidgetPropertyBindableInfo.class, "checked elements|observeCheckedElements|java.lang.Object", observable.getBindableProperty());
    // 
    assertNotNull(observable.getElementType());
    assertEquals("java.lang.Integer", observable.getElementType().getName());
    // 
    observable.setElementType(null);
    assertEquals("m_viewer.checkedElements(?????.class)", observable.getPresentationText());
}
Also used : IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) TreeViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo) ViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo) BindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)

Example 24 with IBindingInfo

use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.

the class ViewerObservableTest method test_Viewer_Input_Set_InputCollection.

public void test_Viewer_Input_Set_InputCollection() throws Exception {
    setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", "  public String getName() {", "    return null;", "  }", "  public java.util.Set getBeans() {", "    return null;", "  }", "}"));
    waitForAutoBuild();
    // 
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", "  private DataBindingContext m_bindingContext;", "  protected Shell m_shell;", "  private TableViewer m_viewer;", "  private java.util.Set m_beans;", "  public static void main(String[] args) {", "    Test test = new Test();", "    test.open();", "  }", "  public void open() {", "    Display display = new Display();", "    createContents();", "    m_shell.open();", "    m_shell.layout();", "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {", "        display.sleep();", "      }", "    }", "  }", "  protected void createContents() {", "    m_shell = new Shell();", "    m_shell.setLayout(new GridLayout());", "    m_viewer = new TableViewer(m_shell, SWT.BORDER);", "    m_bindingContext = initDataBindings();", "  }", "  private DataBindingContext initDataBindings() {", "    DataBindingContext bindingContext = new DataBindingContext();", "    //", "    ObservableSetContentProvider viewerContentProvider = new ObservableSetContentProvider();", "    m_viewer.setContentProvider(viewerContentProvider);", "    IObservableMap[] viewerLabelProviderMaps = BeansObservables.observeMaps(viewerContentProvider.getKnownElements(), TestBean.class, new String[]{\"name\"});", "    m_viewer.setLabelProvider(new ObservableMapLabelProvider(viewerLabelProviderMaps));", "    //", "    m_viewer.setInput(new WritableSet(m_beans, TestBean.class));", "    //", "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);
    // 
    DatabindingsProvider provider = getDatabindingsProvider();
    // 
    IObserveInfo shellObserve = provider.getObserves(ObserveType.WIDGETS).get(0);
    IObserveInfo viewerObserve = shellObserve.getChildren(ChildrenContext.ChildrenForMasterTable).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0);
    IObserveInfo viewerInputProperty = viewerObserve.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(4);
    // 
    IObserveInfo beanObserve = provider.getObserves(ObserveType.BEANS).get(3);
    IObserveInfo beanInputCollectionProperty = beanObserve.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(0);
    // 
    List<IBindingInfo> bindings = provider.getBindings();
    assertEquals(1, bindings.size());
    assertInstanceOf(ViewerInputBindingInfo.class, bindings.get(0));
    // 
    ViewerInputBindingInfo binding = (ViewerInputBindingInfo) bindings.get(0);
    // 
    assertSame(viewerObserve, binding.getViewer());
    assertSame(viewerObserve, binding.getTarget());
    assertSame(viewerInputProperty, binding.getTargetProperty());
    // 
    assertSame(beanObserve, binding.getModel());
    assertSame(beanInputCollectionProperty, binding.getModelProperty());
    // 
    assertNotNull(binding.getInputObservable());
    assertInstanceOf(WritableSetBeanObservableInfo.class, binding.getInputObservable());
    // 
    ObservableInfo inputObservable = binding.getInputObservable();
    assertSame(beanObserve, inputObservable.getBindableObject());
    assertSame(beanInputCollectionProperty, inputObservable.getBindableProperty());
    // 
    assertEquals("WritableSet(m_beans, TestBean.class)", inputObservable.getPresentationText());
    // 
    assertNull(binding.getVariableIdentifier());
    assertEquals("m_viewer.input(ObservableSetContentProvider, ObservableMaps[name])", binding.getPresentationText());
    // 
    assertNotNull(binding.getElementType());
    assertEquals("test.TestBean", binding.getElementType().getName());
    // 
    ObservableMapLabelProviderInfo labelProvider = binding.getLabelProvider();
    assertNotNull(labelProvider);
    assertEquals("org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider", labelProvider.getClassName());
    assertEquals("ObservableMaps[name]", labelProvider.getPresentationText());
    assertNull(labelProvider.getVariableIdentifier());
    // 
    MapsBeanObservableInfo mapsObservable = labelProvider.getMapsObservable();
    assertNotNull(mapsObservable);
    assertNotNull(mapsObservable.getElementType());
    assertEquals("test.TestBean", mapsObservable.getElementType().getName());
    assertNull(mapsObservable.getBindableObject());
    assertNull(mapsObservable.getBindableProperty());
    // 
    String[] properties = mapsObservable.getProperties();
    assertNotNull(properties);
    assertEquals(1, properties.length);
    assertEquals("name", properties[0]);
    // 
    assertNotNull(mapsObservable.getDomainObservable());
    assertInstanceOf(KnownElementsObservableInfo.class, mapsObservable.getDomainObservable());
    // 
    KnownElementsObservableInfo knownElementsObservableInfo = (KnownElementsObservableInfo) mapsObservable.getDomainObservable();
    assertNull(knownElementsObservableInfo.getBindableObject());
    assertNull(knownElementsObservableInfo.getBindableProperty());
    // 
    assertNotNull(knownElementsObservableInfo.getParent());
    assertSame(knownElementsObservableInfo.getParent(), ReflectionUtils.getFieldObject(binding, "m_contentProvider"));
    assertInstanceOf(ObservableSetContentProviderInfo.class, knownElementsObservableInfo.getParent());
    // 
    ObservableSetContentProviderInfo contentProvider = (ObservableSetContentProviderInfo) knownElementsObservableInfo.getParent();
    assertEquals("org.eclipse.jface.databinding.viewers.ObservableSetContentProvider", contentProvider.getClassName());
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) ObservableSetContentProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableSetContentProviderInfo) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) DetailListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo) SetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo) SingleSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo) DetailSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo) ListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo) ViewerObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) ObservableMapLabelProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableMapLabelProviderInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo) TreeViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo) ViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)

Example 25 with IBindingInfo

use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.

the class ViewerObservableTest method test_observeSingleSelection.

// //////////////////////////////////////////////////////////////////////////
// 
// Viewer
// 
// //////////////////////////////////////////////////////////////////////////
public void test_observeSingleSelection() throws Exception {
    CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", "  protected Shell m_shell;", "  private TableViewer m_viewer;", "  private DataBindingContext m_bindingContext;", "  public static void main(String[] args) {", "    Test test = new Test();", "    test.open();", "  }", "  public void open() {", "    Display display = new Display();", "    createContents();", "    m_shell.open();", "    m_shell.layout();", "    while (!m_shell.isDisposed()) {", "      if (!display.readAndDispatch()) {", "        display.sleep();", "      }", "    }", "  }", "  protected void createContents() {", "    m_shell = new Shell();", "    m_shell.setLayout(new GridLayout());", "    m_viewer = new TableViewer(m_shell, SWT.BORDER);", "    m_bindingContext = initDataBindings();", "  }", "  private DataBindingContext initDataBindings() {", "    IObservableValue observeValue = BeansObservables.observeValue(getClass(), \"name\");", "    IObservableValue observeWidget = ViewersObservables.observeSingleSelection(m_viewer);", "    DataBindingContext bindingContext = new DataBindingContext();", "    bindingContext.bindValue(observeWidget, observeValue, null, null);", "    return bindingContext;", "  }", "}" });
    assertNotNull(shell);
    // 
    DatabindingsProvider provider = getDatabindingsProvider();
    List<IBindingInfo> bindings = provider.getBindings();
    // 
    assertNotNull(bindings);
    assertEquals(1, bindings.size());
    // 
    BindingInfo binding = (BindingInfo) bindings.get(0);
    // 
    assertInstanceOf(SingleSelectionObservableInfo.class, binding.getTargetObservable());
    ViewerObservableInfo observable = (ViewerObservableInfo) binding.getTargetObservable();
    // 
    assertEquals("observeWidget", observable.getVariableIdentifier());
    assertEquals("m_viewer.selection", observable.getPresentationText());
    // 
    WidgetBindableTest.assertBindable(shell.getChildrenControls().get(0).getChildren().get(0), WidgetBindableInfo.class, provider.getObserves(ObserveType.WIDGETS).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0), false, "m_viewer|m_viewer|org.eclipse.jface.viewers.TableViewer", observable.getBindableObject());
    // 
    WidgetBindableTest.assertBindableProperty(WidgetPropertyBindableInfo.class, "single selection|observeSingleSelection|java.lang.Object", observable.getBindableProperty());
    // 
    assertInstanceOf(IMasterDetailProvider.class, observable);
    IMasterDetailProvider detailProvider = (IMasterDetailProvider) observable;
    // 
    ObservableInfo masterObservable = detailProvider.getMasterObservable();
    assertNotNull(masterObservable);
    assertNotSame(masterObservable, observable);
    assertInstanceOf(SingleSelectionObservableInfo.class, masterObservable);
    assertNull(masterObservable.getVariableIdentifier());
    assertEquals("m_viewer.selection", observable.getPresentationText());
    // 
    WidgetBindableTest.assertBindable(shell.getChildrenControls().get(0).getChildren().get(0), WidgetBindableInfo.class, provider.getObserves(ObserveType.WIDGETS).get(0).getChildren(ChildrenContext.ChildrenForMasterTable).get(0), false, "m_viewer|m_viewer|org.eclipse.jface.viewers.TableViewer", masterObservable.getBindableObject());
    // 
    WidgetBindableTest.assertBindableProperty(WidgetPropertyBindableInfo.class, "part of selection|observeSingleSelection|java.lang.Object", masterObservable.getBindableProperty());
}
Also used : CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) DetailListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo) SetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo) SingleSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo) MultiSelectionObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo) DetailSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo) ListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo) ViewerObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) IMasterDetailProvider(org.eclipse.wb.internal.rcp.databinding.model.beans.IMasterDetailProvider) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) TreeViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo) ViewerInputBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo) BindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) ViewerObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)

Aggregations

IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)81 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)51 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)48 BindingInfo (org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo)38 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)18 TreeViewerInputBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo)16 DetailListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo)14 DetailSetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo)14 ListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo)14 SetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo)14 WritableListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)14 WritableSetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo)14 ObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo)13 CheckedElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo)13 ViewerObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo)13 MapsBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)12 KnownElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo)12 ViewerInputBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo)12 MultiSelectionObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo)12 SingleSelectionObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo)12