use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class BindListTest method strategy_converter.
private void strategy_converter(String line0, String line1, String testString) throws Exception {
createModelCompilationUnit("test", "TestConverter.java", DatabindingTestUtils.getTestSource("public class TestConverter extends Converter {", " public TestConverter() {", " super(null, null);", " }", " public Object convert(Object fromObject) {", " return null;", " }", "}"));
waitForAutoBuild();
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 Combo m_combo;", " 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_combo = new Combo(m_shell, SWT.BORDER);", " m_bindingContext = initDataBindings();", " }", " private DataBindingContext initDataBindings() {", " IObservableList observeList = BeansObservables.observeList(Realm.getDefault(), m_bean, \"names\");", " IObservableList observeWidget = SWTObservables.observeItems(m_combo);", " DataBindingContext bindingContext = new DataBindingContext();", " UpdateListStrategy strategy = new UpdateListStrategy();", line0, line1, " bindingContext.bindList(observeWidget, observeList, null, strategy);", " return bindingContext;", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IBindingInfo> bindings = provider.getBindings();
//
assertNotNull(bindings);
assertEquals(1, bindings.size());
//
assertInstanceOf(ListBindingInfo.class, bindings.get(0));
BindingInfo binding = (BindingInfo) bindings.get(0);
//
assertStrategy(binding.getTargetStrategy(), null, UpdateStrategyInfo.StrategyType.Null, UpdateListStrategyInfo.Value.POLICY_UPDATE, "POLICY_UPDATE|POLICY_UPDATE");
//
assertStrategy(binding.getModelStrategy(), "strategy", UpdateStrategyInfo.StrategyType.DefaultConstructor, UpdateListStrategyInfo.Value.POLICY_UPDATE, "POLICY_UPDATE|POLICY_UPDATE", testString);
}
use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class BindSetTest method strategy_converter.
private void strategy_converter(String line0, String line1, String testString) throws Exception {
createModelCompilationUnit("test", "TestConverter.java", DatabindingTestUtils.getTestSource("public class TestConverter extends Converter {", " public TestConverter() {", " super(null, null);", " }", " public Object convert(Object fromObject) {", " return null;", " }", "}"));
waitForAutoBuild();
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, String.class);", " DataBindingContext bindingContext = new DataBindingContext();", " UpdateSetStrategy strategy = new UpdateSetStrategy();", line0, line1, " bindingContext.bindSet(observeWidget, observeSet, null, strategy);", " return bindingContext;", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IBindingInfo> bindings = provider.getBindings();
//
assertNotNull(bindings);
assertEquals(1, bindings.size());
//
assertInstanceOf(SetBindingInfo.class, bindings.get(0));
BindingInfo binding = (BindingInfo) bindings.get(0);
//
assertStrategy(binding.getTargetStrategy(), null, UpdateStrategyInfo.StrategyType.Null, UpdateSetStrategyInfo.Value.POLICY_UPDATE, "POLICY_UPDATE|POLICY_UPDATE");
//
assertStrategy(binding.getModelStrategy(), "strategy", UpdateStrategyInfo.StrategyType.DefaultConstructor, UpdateSetStrategyInfo.Value.POLICY_UPDATE, "POLICY_UPDATE|POLICY_UPDATE", testString);
}
use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class BindSetTest method test_bindSet.
// //////////////////////////////////////////////////////////////////////////
//
// Tests
//
// //////////////////////////////////////////////////////////////////////////
public void test_bindSet() 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, String.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());
//
assertInstanceOf(SetBindingInfo.class, bindings.get(0));
BindingInfo binding = (BindingInfo) bindings.get(0);
//
assertNotNull(binding.getTarget());
assertNotNull(binding.getTargetProperty());
assertNotNull(binding.getTargetObservable());
assertSame(binding.getTarget(), binding.getTargetObservable().getBindableObject());
assertSame(binding.getTargetProperty(), binding.getTargetObservable().getBindableProperty());
assertInstanceOf(CheckedElementsObservableInfo.class, binding.getTargetObservable());
assertEquals("observeWidget", binding.getTargetObservable().getVariableIdentifier());
//
assertNotNull(binding.getModel());
assertNotNull(binding.getModelProperty());
assertNotNull(binding.getModelObservable());
assertSame(binding.getModel(), binding.getModelObservable().getBindableObject());
assertSame(binding.getModelProperty(), binding.getModelObservable().getBindableProperty());
assertInstanceOf(SetBeanObservableInfo.class, binding.getModelObservable());
assertEquals("observeSet", binding.getModelObservable().getVariableIdentifier());
//
assertStrategy(binding.getTargetStrategy(), null, UpdateStrategyInfo.StrategyType.Null, UpdateSetStrategyInfo.Value.POLICY_UPDATE, "POLICY_UPDATE|POLICY_UPDATE");
//
assertStrategy(binding.getModelStrategy(), null, UpdateStrategyInfo.StrategyType.Null, UpdateSetStrategyInfo.Value.POLICY_UPDATE, "POLICY_UPDATE|POLICY_UPDATE");
}
use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class BindSetTest method strategy_constructors.
private void strategy_constructors(String line, Object value, String presentation) 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, String.class);", " DataBindingContext bindingContext = new DataBindingContext();", line, " return bindingContext;", " }", "}" });
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IBindingInfo> bindings = provider.getBindings();
//
assertNotNull(bindings);
assertEquals(1, bindings.size());
//
assertInstanceOf(SetBindingInfo.class, bindings.get(0));
BindingInfo binding = (BindingInfo) bindings.get(0);
//
assertStrategy(binding.getTargetStrategy(), null, UpdateStrategyInfo.StrategyType.DefaultConstructor, UpdateSetStrategyInfo.Value.POLICY_UPDATE, "POLICY_UPDATE|POLICY_UPDATE");
//
assertStrategy(binding.getModelStrategy(), null, UpdateStrategyInfo.StrategyType.IntConstructor, value, presentation);
}
use of org.eclipse.wb.internal.core.databinding.model.IBindingInfo in project windowbuilder by eclipse.
the class BeanObservableTest method test_WritableList.
private void test_WritableList(String line) 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 DataBindingContext m_bindingContext;", " private TestBean m_bean0;", " private java.util.ArrayList m_list;", " 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() {", " IObservableList observeList = BeansObservables.observeList(Realm.getDefault(), m_bean0, \"names\", java.lang.String.class);", line, " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindList(observeList, writableList, 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(ListBeanObservableInfo.class, binding.getTargetObservable());
ListBeanObservableInfo targetObservable = (ListBeanObservableInfo) binding.getTargetObservable();
//
assertEquals("observeList", targetObservable.getVariableIdentifier());
//
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.List", targetObservable.getBindableProperty());
//
assertInstanceOf(WritableListBeanObservableInfo.class, binding.getModelObservable());
WritableListBeanObservableInfo modelObservable = (WritableListBeanObservableInfo) binding.getModelObservable();
//
assertEquals("writableList", modelObservable.getVariableIdentifier());
assertEquals("WritableList(m_list, String.class)", modelObservable.getPresentationText());
assertNotNull(modelObservable.getElementType());
assertSame(String.class, modelObservable.getElementType());
//
BeanBindableTest.assertBindable(FieldBeanBindableInfo.class, null, true, "m_list - ArrayList|m_list|java.util.ArrayList", modelObservable.getBindableObject());
BeanBindableTest.assertBindable(CollectionPropertyBindableInfo.class, null, false, "Collection as WritableList/Properties.selfList()|m_list|java.util.ArrayList", modelObservable.getBindableProperty());
//
modelObservable.setElementType(null);
assertEquals("WritableList(m_list, ?????.class)", modelObservable.getPresentationText());
}
Aggregations