Search in sources :

Example 1 with WritableListBeanObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo in project windowbuilder by eclipse.

the class BeansObserveTypeContainer method createWritableList.

/**
 * Create {@link WritableListBeanObservableInfo}.
 */
AstObjectInfo createWritableList(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
    WritableListBeanObservableInfo observable = new WritableListBeanObservableInfo(bindableObject, bindableProperty, elementType);
    observable.setCodeSupport(new WritableListCodeSupport());
    return observable;
}
Also used : CollectionPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.CollectionPropertyBindableInfo) WritableListCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableListCodeSupport) FieldBeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.FieldBeanBindableInfo) BeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo) MethodBeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)

Example 2 with WritableListBeanObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo 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);");
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) CollectionPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.CollectionPropertyBindableInfo) WritableSetCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableSetCodeSupport) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) WritableListCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableListCodeSupport) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo) BeanBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)

Example 3 with WritableListBeanObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo 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());
}
Also used : IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) DatabindingsProvider(org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider) BindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) DetailListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo) ListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo) CompositeInfo(org.eclipse.wb.internal.swt.model.widgets.CompositeInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)

Example 4 with WritableListBeanObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo 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;
        }
    };
}
Also used : SelfListCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.properties.SelfListCodeSupport) BindableInfo(org.eclipse.wb.internal.rcp.databinding.model.BindableInfo) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) SelfSetCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.properties.SelfSetCodeSupport) WritableSetCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableSetCodeSupport) IObservableFactory(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory) WritableListCodeSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableListCodeSupport) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)

Example 5 with WritableListBeanObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo in project windowbuilder by eclipse.

the class SelfListCodeSupport method createObservable.

// //////////////////////////////////////////////////////////////////////////
// 
// Parser
// 
// //////////////////////////////////////////////////////////////////////////
@Override
protected ObservableInfo createObservable(AstEditor editor, BeanBindableInfo bindableObject) throws Exception {
    CollectionPropertyBindableInfo bindableProperty = (CollectionPropertyBindableInfo) bindableObject.resolvePropertyReference(bindableObject.getReference());
    Assert.isNotNull(bindableProperty);
    WritableListBeanObservableInfo observable = new WritableListBeanObservableInfo(bindableObject, bindableProperty, m_parserPropertyType);
    observable.setCodeSupport(this);
    return observable;
}
Also used : CollectionPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.CollectionPropertyBindableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)

Aggregations

WritableListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)5 CollectionPropertyBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.CollectionPropertyBindableInfo)3 WritableListCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableListCodeSupport)3 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)2 BeanBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanBindableInfo)2 WritableSetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo)2 WritableSetCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableSetCodeSupport)2 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)2 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)1 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)1 BindableInfo (org.eclipse.wb.internal.rcp.databinding.model.BindableInfo)1 IObservableFactory (org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory)1 FieldBeanBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.FieldBeanBindableInfo)1 MethodBeanBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.MethodBeanBindableInfo)1 DetailListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo)1 ListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo)1 SelfListCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.properties.SelfListCodeSupport)1 SelfSetCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.properties.SelfSetCodeSupport)1 BindingInfo (org.eclipse.wb.internal.rcp.databinding.model.context.BindingInfo)1