use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo in project windowbuilder by eclipse.
the class BeansObserveTypeContainer method createWritableSet.
/**
* Create {@link WritableSetBeanObservableInfo}.
*/
AstObjectInfo createWritableSet(AstEditor editor, Expression[] arguments, IModelResolver resolver, int startIndex) throws Exception {
// prepare object
BeanBindableInfo bindableObject = getBindableObject(arguments[startIndex]);
if (bindableObject == null) {
AbstractParser.addError(editor, MessageFormat.format(Messages.BeansObserveTypeContainer_argumentNotFound, arguments[startIndex]), new Throwable());
return null;
}
// prepare property
CollectionPropertyBindableInfo bindableProperty = (CollectionPropertyBindableInfo) bindableObject.resolvePropertyReference(bindableObject.getReference());
Assert.isNotNull(bindableProperty);
// prepare element type
Class<?> elementType = CoreUtils.evaluate(Class.class, editor, arguments[startIndex + 1]);
// create observable
WritableSetBeanObservableInfo observable = new WritableSetBeanObservableInfo(bindableObject, bindableProperty, elementType);
observable.setCodeSupport(new WritableSetCodeSupport());
return observable;
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo in project windowbuilder by eclipse.
the class SelfSetCodeSupport method createObservable.
// //////////////////////////////////////////////////////////////////////////
//
// Parser
//
// //////////////////////////////////////////////////////////////////////////
@Override
protected ObservableInfo createObservable(AstEditor editor, BeanBindableInfo bindableObject) throws Exception {
CollectionPropertyBindableInfo bindableProperty = (CollectionPropertyBindableInfo) bindableObject.resolvePropertyReference(bindableObject.getReference());
Assert.isNotNull(bindableProperty);
WritableSetBeanObservableInfo observable = new WritableSetBeanObservableInfo(bindableObject, bindableProperty, m_parserPropertyType);
observable.setCodeSupport(this);
return observable;
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo in project windowbuilder by eclipse.
the class CodeGenerationTest method test_CollectionObservableInfo.
public void test_CollectionObservableInfo() throws Exception {
CompositeInfo shell = parseComposite("public class Test {", " private java.util.List m_bean0;", " private java.util.Set m_bean1;", " protected Shell m_shell;", " 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();", " }", "}");
assertNotNull(shell);
//
DatabindingsProvider provider = getDatabindingsProvider();
List<IObserveInfo> observes = provider.getObserves(ObserveType.BEANS);
//
BeanBindableInfo bindableObjectList = (BeanBindableInfo) observes.get(0);
CollectionPropertyBindableInfo bindablePropertyList = (CollectionPropertyBindableInfo) bindableObjectList.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(0);
//
assertObservableInfo(new WritableListBeanObservableInfo(bindableObjectList, bindablePropertyList, String.class), new WritableListCodeSupport(), "writableList", "org.eclipse.core.databinding.observable.list.WritableList writableList = new org.eclipse.core.databinding.observable.list.WritableList(m_bean0, java.lang.String.class);", "org.eclipse.core.databinding.observable.list.WritableList writableList = new org.eclipse.core.databinding.observable.list.WritableList(m_bean0, java.lang.String.class);");
//
WritableListBeanObservableInfo listObservable = new WritableListBeanObservableInfo(bindableObjectList, bindablePropertyList, null);
listObservable.setElementType(String.class);
assertObservableInfo(listObservable, new WritableListCodeSupport(), "writableList", "org.eclipse.core.databinding.observable.list.WritableList writableList = new org.eclipse.core.databinding.observable.list.WritableList(m_bean0, java.lang.String.class);", "org.eclipse.core.databinding.observable.list.WritableList writableList = new org.eclipse.core.databinding.observable.list.WritableList(m_bean0, java.lang.String.class);");
//
BeanBindableInfo bindableObjectSet = (BeanBindableInfo) observes.get(1);
CollectionPropertyBindableInfo bindablePropertySet = (CollectionPropertyBindableInfo) bindableObjectSet.getChildren(ChildrenContext.ChildrenForPropertiesTable).get(0);
//
WritableSetBeanObservableInfo setObservable = new WritableSetBeanObservableInfo(bindableObjectSet, bindablePropertySet, null);
setObservable.setElementType(String.class);
assertObservableInfo(setObservable, new WritableSetCodeSupport(), "writableSet", "org.eclipse.core.databinding.observable.set.WritableSet writableSet = new org.eclipse.core.databinding.observable.set.WritableSet(m_bean1, java.lang.String.class);", "org.eclipse.core.databinding.observable.set.WritableSet writableSet = new org.eclipse.core.databinding.observable.set.WritableSet(m_bean1, java.lang.String.class);");
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo in project windowbuilder by eclipse.
the class BeanObservableTest method test_WritableSet.
private void test_WritableSet(String line) 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;", " private java.util.HashSet m_set;", " 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() {", " IObservableSet observeSet = BeansObservables.observeSet(Realm.getDefault(), m_bean0, \"names\", java.lang.String.class);", line, " DataBindingContext bindingContext = new DataBindingContext();", " bindingContext.bindSet(observeSet, writableSet, 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("observeSet", 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.Set", targetObservable.getBindableProperty());
//
assertInstanceOf(WritableSetBeanObservableInfo.class, binding.getModelObservable());
WritableSetBeanObservableInfo modelObservable = (WritableSetBeanObservableInfo) binding.getModelObservable();
//
assertEquals("writableSet", modelObservable.getVariableIdentifier());
assertEquals("WritableSet(m_set, String.class)", modelObservable.getPresentationText());
assertNotNull(modelObservable.getElementType());
assertSame(String.class, modelObservable.getElementType());
//
BeanBindableTest.assertBindable(FieldBeanBindableInfo.class, null, true, "m_set - HashSet|m_set|java.util.HashSet", modelObservable.getBindableObject());
BeanBindableTest.assertBindable(CollectionPropertyBindableInfo.class, null, false, "Collection as WritableSet/Properties.selfSet()|m_set|java.util.HashSet", modelObservable.getBindableProperty());
//
modelObservable.setElementType(null);
assertEquals("WritableSet(m_set, ?????.class)", modelObservable.getPresentationText());
}
use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo in project windowbuilder by eclipse.
the class CollectionPropertyBindableInfo method getObservableFactory.
// //////////////////////////////////////////////////////////////////////////
//
// PropertyBindableInfo
//
// //////////////////////////////////////////////////////////////////////////
@Override
public IObservableFactory getObservableFactory() throws Exception {
return new IObservableFactory() {
@Override
public Type getType() throws Exception {
return Type.InputCollection;
}
@Override
public ObservableInfo createObservable(BindableInfo object, BindableInfo property, Type type, boolean version_1_3) throws Exception {
BeanBindableInfo bindableObject = (BeanBindableInfo) object;
CollectionPropertyBindableInfo bindableProperty = (CollectionPropertyBindableInfo) property;
//
if (List.class.isAssignableFrom(getObjectType())) {
WritableListBeanObservableInfo observable = new WritableListBeanObservableInfo(bindableObject, bindableProperty, null);
if (version_1_3) {
observable.setCodeSupport(new SelfListCodeSupport());
} else {
observable.setCodeSupport(new WritableListCodeSupport());
}
return observable;
}
WritableSetBeanObservableInfo observable = new WritableSetBeanObservableInfo(bindableObject, bindableProperty, null);
if (version_1_3) {
observable.setCodeSupport(new SelfSetCodeSupport());
} else {
observable.setCodeSupport(new WritableSetCodeSupport());
}
return observable;
}
};
}
Aggregations