Search in sources :

Example 1 with KnownElementsObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo in project windowbuilder by eclipse.

the class EmfObserveTypeContainer method parseExpression.

@Override
public AstObjectInfo parseExpression(AstEditor editor, String signature, ClassInstanceCreation creation, Expression[] arguments, IModelResolver resolver, IDatabindingsProvider provider) throws Exception {
    ITypeBinding binding = AstNodeUtils.getTypeBinding(creation);
    if (binding == null) {
        return null;
    }
    // 
    if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.core.databinding.observable.masterdetail.IObservableFactory")) {
        String className = AstNodeUtils.getFullyQualifiedName(binding, false);
        // 
        if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.EMFBeansListObservableFactory")) {
            return createObserveFactory(editor, signature, arguments, className, false);
        }
        if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.EMFEditBeansListObservableFactory")) {
            return createObserveFactory(editor, signature, arguments, className, true);
        }
    }
    // 
    if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.EMFTreeBeanAdvisor")) {
        Assert.isTrue(signature.endsWith("<init>(org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EStructuralFeature)"));
        // create advisor
        EmfTreeBeanAdvisorInfo advisorInfo = new EmfTreeBeanAdvisorInfo(m_propertiesSupport);
        // prepare parent property
        advisorInfo.setEMFParentProperty(getArgumentReference(editor, arguments[0]));
        // prepare children property
        advisorInfo.setEMFChildrenProperty(getArgumentReference(editor, arguments[1]));
        // prepare hasChildren property
        advisorInfo.setEMFHasChildrenProperty(getArgumentReference(editor, arguments[2]));
        // 
        return advisorInfo;
    }
    // 
    if (AstNodeUtils.isSuccessorOf(binding, "org.eclipse.wb.rcp.databinding.EMFTreeObservableLabelProvider")) {
        Assert.isTrue(signature.endsWith("<init>(org.eclipse.core.databinding.observable.set.IObservableSet,org.eclipse.emf.ecore.EStructuralFeature,org.eclipse.emf.ecore.EStructuralFeature)"));
        // prepare allElements observable
        KnownElementsObservableInfo allElementsObservable = (KnownElementsObservableInfo) resolver.getModel(arguments[0]);
        if (allElementsObservable == null) {
            AbstractParser.addError(editor, MessageFormat.format(Messages.EmfObserveTypeContainer_argumentNotFound, arguments[0]), new Throwable());
            return null;
        }
        // create label provider
        EmfTreeObservableLabelProviderInfo labelProvider = new EmfTreeObservableLabelProviderInfo(AstNodeUtils.getFullyQualifiedName(binding, false), allElementsObservable, m_propertiesSupport);
        // prepare text property
        labelProvider.setEMFTextProperty(getArgumentReference(editor, arguments[1]));
        // prepare image property
        labelProvider.setEMFImageProperty(getArgumentReference(editor, arguments[2]));
        // 
        return labelProvider;
    }
    return null;
}
Also used : EmfTreeObservableLabelProviderInfo(org.eclipse.wb.internal.rcp.databinding.emf.model.observables.designer.EmfTreeObservableLabelProviderInfo) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) EmfTreeBeanAdvisorInfo(org.eclipse.wb.internal.rcp.databinding.emf.model.observables.designer.EmfTreeBeanAdvisorInfo)

Example 2 with KnownElementsObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo in project windowbuilder by eclipse.

the class MapsBeanObservableInfo method addSourceCode.

// //////////////////////////////////////////////////////////////////////////
// 
// Code generation
// 
// //////////////////////////////////////////////////////////////////////////
@Override
public void addSourceCode(List<String> lines, CodeGenerationSupport generationSupport) throws Exception {
    // prepare variable
    if (getVariableIdentifier() == null) {
        if (m_properties.length == 1) {
            setVariableIdentifier(generationSupport.generateLocalName("observeMap"));
        } else {
            setVariableIdentifier(generationSupport.generateLocalName("observeMaps"));
        }
    }
    // 
    KnownElementsObservableInfo domainObservable = (KnownElementsObservableInfo) m_domainObservable;
    // 
    if (m_properties.length == 1) {
        String observeMethod = isPojoBean(m_elementType) ? " = " + DataBindingsCodeUtils.getPojoObservablesClass() + ".observeMap(" : " = org.eclipse.core.databinding.beans.BeansObservables.observeMap(";
        // add code
        lines.add("org.eclipse.core.databinding.observable.map.IObservableMap " + getVariableIdentifier() + observeMethod + domainObservable.getSourceCode() + ", " + CoreUtils.getClassName(m_elementType) + ".class, \"" + m_properties[0] + "\");");
    } else {
        String observeMethod = isPojoBean(m_elementType) ? " = " + DataBindingsCodeUtils.getPojoObservablesClass() + ".observeMaps(" : " = org.eclipse.core.databinding.beans.BeansObservables.observeMaps(";
        // add code
        lines.add("org.eclipse.core.databinding.observable.map.IObservableMap[] " + getVariableIdentifier() + observeMethod + domainObservable.getSourceCode() + ", " + CoreUtils.getClassName(m_elementType) + ".class, new java.lang.String[]{\"" + StringUtils.join(m_properties, "\", \"") + "\"});");
    }
}
Also used : KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo)

Example 3 with KnownElementsObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo in project windowbuilder by eclipse.

the class TreeInputElementUiContentProvider method createDesignerProviders.

/**
 * Fill Designer page.
 */
private List<IUiContentProvider> createDesignerProviders() {
    List<IUiContentProvider> providers = Lists.newArrayList();
    providers.add(m_elementTypeDesignerUIProvider);
    // 
    if (m_binding.isDesignerMode()) {
        // add life objects
        createDefaultProviders(providers, true);
    } else {
        // create fake objects
        ObservableCollectionTreeContentProviderInfo contentProvider = m_binding.getContentProvider();
        // create factory
        boolean asList = contentProvider instanceof ObservableListTreeContentProviderInfo;
        BeansObservableFactoryInfo factory = null;
        try {
            factory = GlobalFactoryHelper.createTreeObservableFactory(m_binding.getInputObservable(), asList);
        } catch (Throwable e) {
            DesignerPlugin.log(e);
        }
        if (factory == null) {
            factory = asList ? new BeansListObservableFactoryInfo() : new BeansSetObservableFactoryInfo();
        }
        // 
        m_defaultObjects.add(factory);
        factory.createContentProviders(providers, m_provider);
        // create advisor
        TreeBeanAdvisorInfo advisor = null;
        try {
            advisor = GlobalFactoryHelper.createTreeBeanAdvisor(m_binding.getInputObservable());
        } catch (Throwable e) {
            DesignerPlugin.log(e);
        }
        if (advisor == null) {
            advisor = new TreeBeanAdvisorInfo();
        }
        m_defaultObjects.add(advisor);
        advisor.createContentProviders(providers, m_provider);
        // content provider always exist
        contentProvider.createContentProviders(providers, m_provider, true);
        // create label provider
        KnownElementsObservableInfo allElementsObservable = new KnownElementsObservableInfo(contentProvider);
        TreeObservableLabelProviderInfo labelProvider = null;
        try {
            labelProvider = GlobalFactoryHelper.createTreeLabelProvider(m_binding.getInputObservable(), allElementsObservable);
        } catch (Throwable e) {
            DesignerPlugin.log(e);
        }
        if (labelProvider == null) {
            labelProvider = new TreeObservableLabelProviderInfo(allElementsObservable);
        }
        m_defaultObjects.add(labelProvider);
        labelProvider.createContentProviders(providers, m_provider, true);
    }
    // content provider for properties: parent/children/has children/text/image
    m_contentLabelProvidersEditor = new TreeContentLabelProvidersUiContentProvider(m_binding);
    providers.add(m_contentLabelProvidersEditor);
    return providers;
}
Also used : ObservableCollectionTreeContentProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableCollectionTreeContentProviderInfo) BeansSetObservableFactoryInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansSetObservableFactoryInfo) TreeBeanAdvisorInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.TreeBeanAdvisorInfo) IUiContentProvider(org.eclipse.wb.internal.core.databinding.ui.editor.IUiContentProvider) BeansObservableFactoryInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansObservableFactoryInfo) BeansListObservableFactoryInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.BeansListObservableFactoryInfo) TreeObservableLabelProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.designer.TreeObservableLabelProviderInfo) KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) ObservableListTreeContentProviderInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableListTreeContentProviderInfo)

Example 4 with KnownElementsObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo in project windowbuilder by eclipse.

the class MapsEmfObservableInfo method addSourceCode.

// //////////////////////////////////////////////////////////////////////////
// 
// Code generation
// 
// //////////////////////////////////////////////////////////////////////////
@Override
public void addSourceCode(List<String> lines, CodeGenerationSupport generationSupport) throws Exception {
    // prepare variable
    if (getVariableIdentifier() == null) {
        setVariableIdentifier(generationSupport.generateLocalName("observeMaps"));
    }
    // prepare properties
    StringBuffer properties = new StringBuffer();
    for (Iterator<PropertyInfo> I = m_emfProperties.iterator(); I.hasNext(); ) {
        PropertyInfo property = I.next();
        properties.append(property.reference);
        if (I.hasNext()) {
            properties.append(", ");
        }
    }
    // add code
    KnownElementsObservableInfo domainObservable = (KnownElementsObservableInfo) getDomainObservable();
    // 
    lines.add("org.eclipse.core.databinding.observable.map.IObservableMap[] " + getVariableIdentifier() + m_propertiesSupport.getEMFObservablesCode("observeMaps(") + domainObservable.getSourceCode() + ", new org.eclipse.emf.ecore.EStructuralFeature[]{" + properties.toString() + "});");
}
Also used : KnownElementsObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo) PropertyInfo(org.eclipse.wb.internal.rcp.databinding.emf.model.bindables.PropertiesSupport.PropertyInfo)

Example 5 with KnownElementsObservableInfo

use of org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo 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

KnownElementsObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.KnownElementsObservableInfo)14 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)10 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)10 DatabindingsProvider (org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider)10 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 MapsBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.MapsBeanObservableInfo)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 TreeViewerInputBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.TreeViewerInputBindingInfo)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 ViewerObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.observables.ViewerObservableInfo)10 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)10 ObservableMapLabelProviderInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ObservableMapLabelProviderInfo)8 ViewerInputBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.widgets.input.ViewerInputBindingInfo)8