Search in sources :

Example 1 with MapsBeanObservableInfo

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

the class ViewerInputBindingInfo method setDefaultProviders.

@Override
public void setDefaultProviders(boolean asList, Class<?> elementType, boolean useViewerSupport) throws Exception {
    boolean[] useViewerSupports = { useViewerSupport };
    // create content provider
    if (asList) {
        m_contentProvider = new ObservableListContentProviderInfo();
    } else {
        m_contentProvider = new ObservableSetContentProviderInfo();
    }
    // create content provider accessor
    KnownElementsObservableInfo knownElementsObservable = new KnownElementsObservableInfo(m_contentProvider);
    // create label provider
    MapsBeanObservableInfo observeMaps = GlobalFactoryHelper.createObserveMaps(m_inputObservable, knownElementsObservable, elementType, useViewerSupports);
    if (observeMaps == null) {
        observeMaps = new MapsBeanObservableInfo(knownElementsObservable, elementType, null);
    }
    setLabelProvider(new ObservableMapLabelProviderInfo(observeMaps));
    // 
    if (useViewerSupports[0]) {
        setCodeSupport(new ViewerCodeSupport(this));
    }
}
Also used : MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)

Example 2 with MapsBeanObservableInfo

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

the class BeansObserveTypeContainer method createMaps.

/**
 * Create {@link MapsBeanObservableInfo}.
 */
AstObjectInfo createMaps(AstEditor editor, Expression[] arguments, IModelResolver resolver) throws Exception {
    // prepare domain
    ObservableInfo domainObservable = (ObservableInfo) resolver.getModel(arguments[0]);
    if (domainObservable == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.BeansObserveTypeContainer_domainObservableArgumentNotFound, arguments[0]), new Throwable());
        return null;
    }
    // prepare element type
    Class<?> elementType = CoreUtils.evaluate(Class.class, editor, arguments[1]);
    // prepare properties
    String[] properties = CoreUtils.evaluate(String[].class, editor, arguments[2]);
    // create observable
    return new MapsBeanObservableInfo(domainObservable, elementType, properties);
}
Also used : 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) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) DetailSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) ValueBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ValueBeanObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo) ListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo) DetailValueBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailValueBeanObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)

Example 3 with MapsBeanObservableInfo

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

the class BeansObserveTypeContainer method createMap.

/**
 * Create {@link MapsBeanObservableInfo}.
 */
AstObjectInfo createMap(AstEditor editor, Expression[] arguments, IModelResolver resolver) throws Exception {
    // prepare domain
    ObservableInfo domainObservable = (ObservableInfo) resolver.getModel(arguments[0]);
    if (domainObservable == null) {
        AbstractParser.addError(editor, MessageFormat.format(Messages.BeansObserveTypeContainer_domainObservableArgumentNotFound, arguments[0]), new Throwable());
        return null;
    }
    // prepare element type
    Class<?> elementType = CoreUtils.evaluate(Class.class, editor, arguments[1]);
    // prepare properties
    String property = CoreUtils.evaluate(String.class, editor, arguments[2]);
    // create observable
    return new MapsBeanObservableInfo(domainObservable, elementType, new String[] { property });
}
Also used : 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) WritableSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) DetailSetBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo) WritableListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo) CheckedElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo) ValueBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ValueBeanObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo) ListBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo) DetailValueBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailValueBeanObservableInfo) MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)

Example 4 with MapsBeanObservableInfo

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

the class InputElementUiContentProvider method updateFromObject.

// //////////////////////////////////////////////////////////////////////////
// 
// Update
// 
// //////////////////////////////////////////////////////////////////////////
@Override
public void updateFromObject() throws Exception {
    // prepare input element type
    Class<?> elementType = m_viewerBinding.getElementType();
    if (elementType == null) {
        calculateFinish();
    } else {
        // prepare initial properties
        MapsBeanObservableInfo mapsObservable = m_viewerBinding.getLabelProvider().getMapsObservable();
        String[] properties = mapsObservable.getProperties();
        if (properties == null) {
            setClassName(CoreUtils.getClassName(elementType));
        } else {
            List<String> checkedProperties = Lists.newArrayList();
            for (int i = 0; i < properties.length; i++) {
                checkedProperties.add("\"" + properties[i] + "\"");
            }
            setClassNameAndProperties(elementType, null, checkedProperties);
        }
    }
}
Also used : MapsBeanObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)

Example 5 with MapsBeanObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo 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)

Aggregations

MapsBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)14 ObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo)10 DetailListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailListBeanObservableInfo)10 DetailSetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.DetailSetBeanObservableInfo)10 ListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.ListBeanObservableInfo)10 SetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.SetBeanObservableInfo)10 WritableListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)10 WritableSetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo)10 CheckedElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.CheckedElementsObservableInfo)10 MultiSelectionObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.MultiSelectionObservableInfo)10 SingleSelectionObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.SingleSelectionObservableInfo)10 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)8 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)8 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)8 KnownElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo)8 ObservableMapLabelProviderInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableMapLabelProviderInfo)8 TreeViewerInputBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo)8 ViewerInputBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo)8 ViewerObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo)8 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)8