use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class ViewerObservableTest method test_observeMultiSelection.
public void test_observeMultiSelection() throws Exception {
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public java.util.List getNames() {", " return null;", " }", "}"));
waitForAutoBuild();
//
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", " protected Shell m_shell;", " private TableViewer 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 TableViewer(m_shell, SWT.BORDER);", " m_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " IObservableList observeList = BeansObservables.observeList(Realm.getDefault(), m_bean, \"names\");", " IObservableList observeWidget = ViewersObservables.observeMultiSelection(m_viewer);", " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindList(observeWidget, observeList, 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(MultiSelectionObservableInfo.class, binding.getTargetObservable());
ViewerObservableInfo observable = (ViewerObservableInfo) binding.getTargetObservable();
//
assertEquals("observeWidget", observable.getVariableIdentifier());
assertEquals("m_viewer.multiSelection", 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, "multi selection|observeMultiSelection|java.lang.Object", observable.getBindableProperty());
}
use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class ViewerObservableTest method test_Viewer_TreeInput_Set_InputCollection.
public void test_Viewer_TreeInput_Set_InputCollection() throws Exception {
DataBindingsCodeUtils.ensureDesignerResources(m_testProject.getJavaProject());
//
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public String getName() {", " return null;", " }", " public java.util.List getBeans() {", " return null;", " }", " public TestBean getParent() {", " return null;", " }", " public boolean getHasChildren() {", " return false;", " }", " public org.eclipse.swt.graphics.Image getImage() {", " return null;", " }", "}"));
waitForAutoBuild();
//
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "import org.eclipse.wb.rcp.databinding.BeansSetObservableFactory;", "import org.eclipse.wb.rcp.databinding.TreeBeanAdvisor;", "import org.eclipse.wb.rcp.databinding.TreeObservableLabelProvider;", "public class Test {", " private DataBindingContext m_bindingContext;", " protected Shell m_shell;", " private TreeViewer 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 TreeViewer(m_shell, SWT.BORDER);", " m_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " DataBindingContext bindingContext = new DataBindingContext();", " //", " BeansSetObservableFactory treeViewerFactorySet = new BeansSetObservableFactory(TestBean.class, \"beans\");", " TreeBeanAdvisor treeViewerAdvisor = new TreeBeanAdvisor(TestBean.class, \"parent\", \"beans\", \"hasChildren\");", " ObservableSetTreeContentProvider treeViewerContentProviderSet = new ObservableSetTreeContentProvider(treeViewerFactorySet, treeViewerAdvisor);", " m_viewer.setContentProvider(treeViewerContentProviderSet);", " //", " m_viewer.setLabelProvider(new TreeObservableLabelProvider(treeViewerContentProviderSet.getKnownElements(), TestBean.class, \"name\", \"image\"));", " //", " WritableSet beansWritableSet = new WritableSet(m_beans, TestBean.class);", " m_viewer.setInput(beansWritableSet);", " //", " 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(TreeViewerInputBindingInfo.class, bindings.get(0));
//
TreeViewerInputBindingInfo binding = (TreeViewerInputBindingInfo) 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(ObservableSetTreeContentProvider[parent, beans, hasChildren], TreeObservableLabelProvider[name, image])", binding.getPresentationText());
//
assertNotNull(binding.getElementType());
assertEquals("test.TestBean", binding.getElementType().getName());
//
assertNotNull(binding.getLabelProvider());
assertInstanceOf(TreeObservableLabelProviderInfo.class, binding.getLabelProvider());
//
TreeObservableLabelProviderInfo labelProvider = (TreeObservableLabelProviderInfo) binding.getLabelProvider();
assertEquals("org.eclipse.wb.rcp.databinding.TreeObservableLabelProvider", labelProvider.getClassName());
assertSame(binding.getElementType(), ReflectionUtils.getFieldObject(labelProvider, "m_elementType"));
assertEquals("name", labelProvider.getTextProperty());
assertEquals("image", labelProvider.getImageProperty());
//
assertInstanceOf(KnownElementsObservableInfo.class, ReflectionUtils.getFieldObject(labelProvider, "m_allElementsObservable"));
//
KnownElementsObservableInfo knownElementsObservableInfo = (KnownElementsObservableInfo) ReflectionUtils.getFieldObject(labelProvider, "m_allElementsObservable");
assertNull(knownElementsObservableInfo.getBindableObject());
assertNull(knownElementsObservableInfo.getBindableProperty());
//
assertNotNull(knownElementsObservableInfo.getParent());
assertSame(knownElementsObservableInfo.getParent(), binding.getContentProvider());
//
assertInstanceOf(ObservableSetTreeContentProviderInfo.class, binding.getContentProvider());
//
ObservableSetTreeContentProviderInfo contentProvider = (ObservableSetTreeContentProviderInfo) binding.getContentProvider();
assertEquals("org.eclipse.jface.databinding.viewers.ObservableSetTreeContentProvider", contentProvider.getClassName());
assertEquals("ObservableSetTreeContentProvider[parent, beans, hasChildren]", contentProvider.getPresentationText());
//
assertNotNull(contentProvider.getFactoryInfo());
assertInstanceOf(BeansSetObservableFactoryInfo.class, contentProvider.getFactoryInfo());
//
BeansSetObservableFactoryInfo factory = (BeansSetObservableFactoryInfo) contentProvider.getFactoryInfo();
assertSame(factory.getElementType(), binding.getElementType());
assertEquals("beans", ReflectionUtils.getFieldString(factory, "m_propertyName"));
assertEquals("org.eclipse.wb.rcp.databinding.BeansSetObservableFactory", factory.getClassName());
//
assertNotNull(contentProvider.getAdvisorInfo());
assertInstanceOf(TreeBeanAdvisorInfo.class, contentProvider.getAdvisorInfo());
//
TreeBeanAdvisorInfo advisor = (TreeBeanAdvisorInfo) contentProvider.getAdvisorInfo();
assertEquals("org.eclipse.wb.rcp.databinding.TreeBeanAdvisor", advisor.getClassName());
assertEquals("parent", advisor.getParentProperty());
assertEquals("beans", advisor.getChildrenProperty());
assertEquals("hasChildren", advisor.getHasChildrenProperty());
}
use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class BeanObservableTest method observeDetailValue.
private void observeDetailValue(String line) throws Exception {
setFileContentSrc("test/TestBean.java", getSourceDQ("package test;", "public class TestBean {", " public String getName() {", " return null;", " }", " public int getValue() {", " return 0;", " }", "}"));
waitForAutoBuild();
//
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", " protected Shell m_shell;", " private DataBindingContext m_bindingContext;", " private TestBean m_bean0;", " 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_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " IObservableValue observeValue0 = BeansObservables.observeValue(m_bean0, \"name\");", line, " IObservableValue observeValue1 = BeansObservables.observeValue(getBean1(), \"value\");", " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindValue(observeDetailsValue, observeValue1, null, null);", " return bindingContext;", " }", " public TestBean getBean1() {", " return null;", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IBindingInfo> bindings = provider.getBindings();
//
assertNotNull(bindings);
assertEquals(1, bindings.size());
//
BindingInfo binding = (BindingInfo) bindings.get(0);
//
assertInstanceOf(DetailValueBeanObservableInfo.class, binding.getTargetObservable());
DetailValueBeanObservableInfo targetObservable = (DetailValueBeanObservableInfo) binding.getTargetObservable();
//
assertNotNull(targetObservable.getMasterObservable());
assertInstanceOf(ValueBeanObservableInfo.class, targetObservable.getMasterObservable());
//
assertSame(targetObservable.getMasterObservable().getBindableObject(), targetObservable.getBindableObject());
BeanBindableTest.assertBindable(FieldBeanBindableInfo.class, null, true, "m_bean0 - TestBean|m_bean0|test.TestBean", targetObservable.getBindableObject());
//
assertSame(targetObservable.getMasterObservable().getBindableProperty(), targetObservable.getBindableProperty());
BeanBindableTest.assertBindable(BeanPropertyDescriptorBindableInfo.class, null, true, "name|\"name\"|java.lang.String", targetObservable.getBindableProperty());
//
assertEquals("\"empty\"", targetObservable.getDetailPropertyReference());
//
assertNotNull(targetObservable.getDetailPropertyType());
assertEquals("boolean", targetObservable.getDetailPropertyType().getName());
//
assertEquals("m_bean0.name.detailValue(\"empty\", boolean.class)", targetObservable.getPresentationText());
}
use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class BeanObservableTest method test_directObservable_detail.
public void test_directObservable_detail() throws Exception {
CompositeInfo shell = DatabindingTestUtils.parseTestSource(this, new String[] { "public class Test {", " protected Shell m_shell;", " private DataBindingContext m_bindingContext;", " private WritableValue m_value;", " 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_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " DataBindingContext bindingContext = new DataBindingContext();", " IObservableValue observeWidget = SWTObservables.observeText(m_shell);", " IObservableValue observeDetail = BeansObservables.observeDetailValue(m_value, \"name\", String.class);", " bindingContext.bindValue(observeWidget, observeDetail, 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(DetailValueBeanObservableInfo.class, binding.getModelObservable());
DetailValueBeanObservableInfo modelObservable = (DetailValueBeanObservableInfo) binding.getModelObservable();
//
assertNotNull(modelObservable.getMasterObservable());
assertInstanceOf(DirectObservableInfo.class, modelObservable.getMasterObservable());
//
assertSame(modelObservable.getMasterObservable().getBindableObject(), modelObservable.getBindableObject());
BeanBindableTest.assertBindable(FieldBeanBindableInfo.class, null, true, "m_value - WritableValue|m_value|org.eclipse.core.databinding.observable.value.WritableValue", modelObservable.getBindableObject());
//
assertSame(modelObservable.getMasterObservable().getBindableProperty(), modelObservable.getBindableProperty());
BeanBindableTest.assertBindable(DirectPropertyBindableInfo.class, null, false, "Detail for IObservableValue||org.eclipse.core.databinding.observable.value.WritableValue", modelObservable.getBindableProperty());
//
assertEquals("\"name\"", modelObservable.getDetailPropertyReference());
//
assertNotNull(modelObservable.getDetailPropertyType());
assertEquals("java.lang.String", modelObservable.getDetailPropertyType().getName());
}
use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class BeanObservableTest method observeSet.
private void observeSet(String line0, String line1) 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 DataBindingContext m_bindingContext;", " private TestBean m_bean0;", " 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_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", line0, line1, " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindSet(observeSet0, observeSet1, null, null);", " return bindingContext;", " }", " public TestBean getBean1() {", " return null;", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IBindingInfo> bindings = provider.getBindings();
//
assertNotNull(bindings);
assertEquals(1, bindings.size());
//
BindingInfo binding = (BindingInfo) bindings.get(0);
//
assertInstanceOf(SetBeanObservableInfo.class, binding.getTargetObservable());
SetBeanObservableInfo targetObservable = (SetBeanObservableInfo) binding.getTargetObservable();
//
assertEquals("observeSet0", targetObservable.getVariableIdentifier());
assertEquals("m_bean0.names(Set)", targetObservable.getPresentationText());
//
BeanBindableTest.assertBindable(FieldBeanBindableInfo.class, null, true, "m_bean0 - TestBean|m_bean0|test.TestBean", targetObservable.getBindableObject());
BeanBindableTest.assertBindable(BeanPropertyDescriptorBindableInfo.class, null, true, "names|\"names\"|java.util.Set", targetObservable.getBindableProperty());
//
assertInstanceOf(SetBeanObservableInfo.class, binding.getModelObservable());
SetBeanObservableInfo modelObservable = (SetBeanObservableInfo) binding.getModelObservable();
//
assertEquals("observeSet1", modelObservable.getVariableIdentifier());
assertEquals("getBean1().names(Set)", modelObservable.getPresentationText());
//
BeanBindableTest.assertBindable(MethodBeanBindableInfo.class, null, true, "getBean1()|getBean1()|test.TestBean", modelObservable.getBindableObject());
BeanBindableTest.assertBindable(BeanPropertyDescriptorBindableInfo.class, null, true, "names|\"names\"|java.util.Set", modelObservable.getBindableProperty());
}
Aggregations