Search in sources :

Example 1 with IObservableFactory

use of org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory in project windowbuilder by eclipse.

the class AbstractViewerInputBindingInfo method createBinding.

// //////////////////////////////////////////////////////////////////////////
// 
// Creation
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * Create {@link IBindingInfo} for <code>JFace</code> viewer input.
 */
public static IBindingInfo createBinding(BindableInfo targetBindable, BindableInfo targetBindableProperty, BindableInfo modelBindable, BindableInfo modelBindableProperty, DatabindingsProvider provider) throws Exception {
    // prepare observable factories
    IObservableFactory targetFactory = targetBindableProperty.getObservableFactory();
    IObservableFactory modelFactory = modelBindableProperty.getObservableFactory();
    // check create over "target"
    if (targetFactory.getType() == Type.Input) {
        return createBinding(targetBindable, targetBindableProperty, modelBindable, modelBindableProperty, modelFactory, provider);
    }
    // create over "model"
    return createBinding(modelBindable, modelBindableProperty, targetBindable, targetBindableProperty, targetFactory, provider);
}
Also used : IObservableFactory(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory)

Example 2 with IObservableFactory

use of org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory in project windowbuilder by eclipse.

the class DatabindingsProvider method doValidate.

public static boolean doValidate(List<AbstractBindingInfo> bindings, IObserveInfo target, IObserveInfo targetProperty, IObserveInfo model, IObserveInfo modelProperty) throws Exception {
    // ignore itself
    if (target == model && targetProperty == modelProperty) {
        return false;
    }
    // prepare binable's
    BindableInfo targetBindable = (BindableInfo) target;
    BindableInfo targetPropertyBindable = (BindableInfo) targetProperty;
    IObservableFactory targetFactory = targetPropertyBindable.getObservableFactory();
    BindableInfo modelBindable = (BindableInfo) model;
    BindableInfo modelPropertyBindable = (BindableInfo) modelProperty;
    IObservableFactory modelFactory = modelPropertyBindable.getObservableFactory();
    // ignore null factories
    if (targetFactory == null || modelFactory == null) {
        return false;
    }
    // 
    Type targetType = targetFactory.getType();
    Type modelType = modelFactory.getType();
    // 
    if (targetType == Type.Input || targetType == Type.InputCollection || modelType == Type.Input || modelType == Type.InputCollection) {
        // ignore no collection type for input
        if (targetType == modelType) {
            return false;
        }
        if (targetType == Type.InputCollection) {
            if (modelType != Type.Input) {
                return false;
            }
        } else if (modelType == Type.InputCollection) {
            if (targetType != Type.Input) {
                return false;
            }
        } else if (targetType == Type.Input) {
            if (!validateInput(modelType)) {
                return false;
            }
        } else if (!validateInput(targetType)) {
            return false;
        }
        if (targetType == Type.Input) {
            if (findBinding(bindings, target, targetProperty)) {
                return false;
            }
        } else if (findBinding(bindings, model, modelProperty)) {
            return false;
        }
    } else if (targetType == modelType) {
        if (modelType == Type.Detail) {
            return false;
        }
    } else {
        if (targetType == Type.OnlyList) {
            if (!validateOnlyList(modelType)) {
                return false;
            }
        } else if (modelType == Type.OnlyList) {
            if (!validateOnlyList(targetType)) {
                return false;
            }
        } else if (targetType == Type.OnlySet) {
            if (!validateOnlySet(modelType)) {
                return false;
            }
        } else if (modelType == Type.OnlySet) {
            if (!validateOnlySet(targetType)) {
                return false;
            }
        } else if (targetType == Type.OnlyValue) {
            if (!validateOnlyValue(modelType)) {
                return false;
            }
        } else if (modelType == Type.OnlyValue) {
            if (!validateOnlyValue(targetType)) {
                return false;
            }
        } else if (targetType == Type.List) {
            if (!validateList(modelType)) {
                return false;
            }
        } else if (modelType == Type.List) {
            if (!validateList(targetType)) {
                return false;
            }
        } else if (targetType == Type.Set) {
            if (!validateSet(modelType)) {
                return false;
            }
        } else if (modelType == Type.Set) {
            if (!validateSet(targetType)) {
                return false;
            }
        } else if (targetType == Type.Any) {
            if (!validateAny(modelType)) {
                return false;
            }
        } else if (modelType == Type.Any) {
            if (!validateAny(targetType)) {
                return false;
            }
        } else if (targetType == Type.Detail) {
            if (!validateDetail(modelType)) {
                return false;
            }
        } else if (modelType == Type.Detail) {
            if (!validateDetail(targetType)) {
                return false;
            }
        }
    }
    // see http://www.eclipse.org/forums/index.php/t/262915/
    if (modelType == Type.List || modelType == Type.OnlyList || modelType == Type.Set || modelType == Type.OnlySet) {
        if (modelProperty.getParent() != null) {
            return false;
        }
    }
    // ignore itself
    return !targetBindable.getReference().equals(modelBindable.getReference()) || !targetPropertyBindable.getReference().equals(modelPropertyBindable.getReference());
}
Also used : ObserveType(org.eclipse.wb.internal.core.databinding.ui.ObserveType) Type(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory.Type) BindableInfo(org.eclipse.wb.internal.rcp.databinding.model.BindableInfo) IObservableFactory(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory)

Example 3 with IObservableFactory

use of org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory in project windowbuilder by eclipse.

the class DatabindingsProvider method createBinding.

// //////////////////////////////////////////////////////////////////////////
// 
// Creation/Editing
// 
// //////////////////////////////////////////////////////////////////////////
@Override
public IBindingInfo createBinding(IObserveInfo target, IObserveInfo targetProperty, IObserveInfo model, IObserveInfo modelProperty) throws Exception {
    // prepare target
    BindableInfo targetBindable = (BindableInfo) target;
    BindableInfo targetBindableProperty = (BindableInfo) targetProperty;
    IObservableFactory targetFactory = targetBindableProperty.getObservableFactory();
    // prepare model
    BindableInfo modelBindable = (BindableInfo) model;
    BindableInfo modelBindableProperty = (BindableInfo) modelProperty;
    IObservableFactory modelFactory = modelBindableProperty.getObservableFactory();
    // 
    // calculate type
    Type type = calculateObserveType(targetFactory, modelFactory);
    // handle input type
    if (type == Type.Input) {
        return AbstractViewerInputBindingInfo.createBinding(targetBindable, targetBindableProperty, modelBindable, modelBindableProperty, this);
    }
    // create observable's
    ObservableInfo targetObservable = createObservable(targetFactory, targetBindable, targetBindableProperty, type);
    ObservableInfo modelObservable = createObservable(modelFactory, modelBindable, modelBindableProperty, type);
    // create binding
    switch(type) {
        case OnlyValue:
            return new ValueBindingInfo(targetObservable, modelObservable);
        case OnlyList:
            return new ListBindingInfo(targetObservable, modelObservable);
        case OnlySet:
            return new SetBindingInfo(targetObservable, modelObservable);
    }
    // 
    Assert.fail("");
    return null;
}
Also used : ObserveType(org.eclipse.wb.internal.core.databinding.ui.ObserveType) Type(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory.Type) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) BindableInfo(org.eclipse.wb.internal.rcp.databinding.model.BindableInfo) ValueBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.ValueBindingInfo) IObservableFactory(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory) SetBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.SetBindingInfo) ListBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.context.ListBindingInfo)

Example 4 with IObservableFactory

use of org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory in project windowbuilder by eclipse.

the class DatabindingsProvider method createBinding.

// //////////////////////////////////////////////////////////////////////////
// 
// Creation/Editing
// 
// //////////////////////////////////////////////////////////////////////////
@Override
public IBindingInfo createBinding(IObserveInfo target, IObserveInfo targetProperty, IObserveInfo model, IObserveInfo modelProperty) throws Exception {
    // prepare target
    BindableInfo targetBindable = (BindableInfo) target;
    BindableInfo targetBindableProperty = (BindableInfo) targetProperty;
    IObservableFactory targetFactory = targetBindableProperty.getObservableFactory();
    // prepare model
    BindableInfo modelBindable = (BindableInfo) model;
    BindableInfo modelBindableProperty = (BindableInfo) modelProperty;
    IObservableFactory modelFactory = modelBindableProperty.getObservableFactory();
    // calculate type
    Type type = org.eclipse.wb.internal.rcp.databinding.DatabindingsProvider.calculateObserveType(targetFactory, modelFactory);
    // handle input type
    if (type == Type.Input) {
        // XXX
        throw new UnsupportedOperationException();
    }
    // create binding
    BindingInfo binding = new BindingInfo(targetBindable, targetBindableProperty, modelBindable, modelBindableProperty);
    binding.setDocumentEditor(new AttributeDocumentEditor(binding));
    // 
    return binding;
}
Also used : ObserveType(org.eclipse.wb.internal.core.databinding.ui.ObserveType) Type(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory.Type) BindableInfo(org.eclipse.wb.internal.rcp.databinding.model.BindableInfo) WidgetBindableInfo(org.eclipse.wb.internal.rcp.databinding.xwt.model.widgets.WidgetBindableInfo) BindingInfo(org.eclipse.wb.internal.rcp.databinding.xwt.model.BindingInfo) IBindingInfo(org.eclipse.wb.internal.core.databinding.model.IBindingInfo) AbstractBindingInfo(org.eclipse.wb.internal.rcp.databinding.model.AbstractBindingInfo) AttributeDocumentEditor(org.eclipse.wb.internal.rcp.databinding.xwt.model.AttributeDocumentEditor) IObservableFactory(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory)

Example 5 with IObservableFactory

use of org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory in project windowbuilder by eclipse.

the class BeanSupport method getProperties.

// //////////////////////////////////////////////////////////////////////////
// 
// Properties
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * @return {@link PropertyBindableInfo} properties for given bean {@link Class}.
 */
public List<PropertyBindableInfo> getProperties(BeanBindableInfo beanObjectInfo) {
    try {
        boolean topLevel = beanObjectInfo instanceof FieldBeanBindableInfo || beanObjectInfo instanceof MethodBeanBindableInfo || beanObjectInfo instanceof LocalVariableBindableInfo;
        IObserveInfo parent = topLevel ? null : beanObjectInfo;
        Class<?> beanClass = beanObjectInfo.getObjectType();
        // load properties
        List<PropertyBindableInfo> properties = Lists.newArrayList();
        boolean version_1_3 = Activator.getStore().getBoolean(IPreferenceConstants.GENERATE_CODE_FOR_VERSION_1_3);
        // load properties
        for (PropertyDescriptor descriptor : getPropertyDescriptors(beanClass)) {
            Class<?> propertyType = descriptor.getPropertyType();
            // 
            if (topLevel && propertyType != null && CoreUtils.isAssignableFrom(m_IObservable, propertyType) && isGetter(descriptor)) {
                // property with observable (direct) type
                // 
                // calculate type
                IObservableFactory.Type directType = getDirectType(propertyType);
                // 
                if (directType == null) {
                    // unknown observable type
                    properties.add(new DirectPropertyBindableInfo(this, parent, descriptor));
                } else {
                    // create direct factory
                    IObservableFactory observableFactory = DirectObservableFactory.forProperty(directType);
                    // create direct property
                    DirectPropertyBindableInfo property = new DirectPropertyBindableInfo(this, parent, descriptor, observableFactory);
                    properties.add(property);
                    // add direct observable
                    if (m_resolver != null) {
                        ObservableInfo directObservable = observableFactory.createObservable(beanObjectInfo, property, directType, version_1_3);
                        m_resolver.addModelSupport(new DirectModelSupport(directObservable));
                    }
                }
            } else {
                // simple property
                properties.add(new BeanPropertyDescriptorBindableInfo(this, parent, descriptor));
            }
        }
        // sort properties
        Collections.sort(properties, ObserveComparator.INSTANCE);
        // 
        if (topLevel) {
            if (CoreUtils.isAssignableFrom(m_IObservable, beanClass)) {
                // bean class is observable
                // 
                // calculate type
                IObservableFactory.Type directType = getDirectType(beanClass);
                // 
                if (directType == null) {
                    // unknown observable type
                    properties.clear();
                } else {
                    // create direct factory
                    IObservableFactory observableFactory = DirectObservableFactory.forBean(directType);
                    // create fake direct property
                    DirectPropertyBindableInfo property = new DirectPropertyBindableInfo(this, parent, getDirectName(directType), beanClass, StringReferenceProvider.EMPTY, observableFactory);
                    // 
                    properties.add(0, property);
                    // add direct observable
                    if (m_resolver != null) {
                        ObservableInfo directObservable = observableFactory.createObservable(beanObjectInfo, property, directType, version_1_3);
                        m_resolver.addModelSupport(new DirectFieldModelSupport(directObservable));
                    }
                    // 
                    if (directType == IObservableFactory.Type.OnlyValue) {
                        // add fake direct detail property
                        properties.add(1, new DirectPropertyBindableInfo(this, parent, DirectObservableInfo.DETAIL_PROPERTY_NAME, beanClass, StringReferenceProvider.EMPTY, DirectObservableFactory.forDetailBean()));
                    }
                }
            } else if (List.class.isAssignableFrom(beanClass)) {
                // bean class is List
                properties.add(0, new CollectionPropertyBindableInfo(this, parent, "Collection as WritableList/Properties.selfList()", beanClass, beanObjectInfo.getReferenceProvider()));
            } else if (Set.class.isAssignableFrom(beanClass)) {
                // bean class is Set
                properties.add(0, new CollectionPropertyBindableInfo(this, parent, "Collection as WritableSet/Properties.selfSet()", beanClass, beanObjectInfo.getReferenceProvider()));
            } else if (!CoreUtils.isAssignableFrom(m_Viewer, beanClass)) {
                boolean selection = false;
                if (CoreUtils.isAssignableFrom(m_ISelectionProvider, beanClass)) {
                    selection = true;
                    properties.add(0, new ViewerObservablePropertyBindableInfo(this, parent, "single selection", TypeImageProvider.OBJECT_IMAGE, Object.class, "observeSingleSelection", ViewerObservableFactory.SINGLE_SELECTION, IObserveDecorator.BOLD));
                    properties.add(1, new ViewerObservablePropertyBindableInfo(this, parent, PropertiesSupport.DETAIL_SINGLE_SELECTION_NAME, TypeImageProvider.OBJECT_IMAGE, Object.class, "observeSingleSelection", ViewerObservableFactory.DETAIL_SINGLE_SELECTION, IObserveDecorator.BOLD));
                    properties.add(2, new ViewerObservablePropertyBindableInfo(this, parent, "multi selection", TypeImageProvider.COLLECTION_IMAGE, Object.class, "observeMultiSelection", ViewerObservableFactory.MULTI_SELECTION, IObserveDecorator.BOLD));
                }
                if (CoreUtils.isAssignableFrom(m_ICheckable, beanClass)) {
                    properties.add(selection ? 3 : 0, new ViewerObservablePropertyBindableInfo(this, parent, "checked elements", TypeImageProvider.COLLECTION_IMAGE, Object.class, "observeCheckedElements", ViewerObservableFactory.CHECKED_ELEMENTS, IObserveDecorator.BOLD));
                }
            }
        }
        // 
        return properties;
    } catch (Throwable e) {
        DesignerPlugin.log(e);
        return Collections.emptyList();
    }
}
Also used : IObserveInfo(org.eclipse.wb.internal.core.databinding.model.IObserveInfo) DirectObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectObservableInfo) ObservableInfo(org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo) PropertyDescriptor(java.beans.PropertyDescriptor) DirectModelSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectModelSupport) DirectPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectPropertyBindableInfo) DirectFieldModelSupport(org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectFieldModelSupport) IObservableFactory(org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory) List(java.util.List) DirectPropertyBindableInfo(org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectPropertyBindableInfo)

Aggregations

IObservableFactory (org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory)6 BindableInfo (org.eclipse.wb.internal.rcp.databinding.model.BindableInfo)4 ObserveType (org.eclipse.wb.internal.core.databinding.ui.ObserveType)3 Type (org.eclipse.wb.internal.rcp.databinding.model.IObservableFactory.Type)3 ObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.ObservableInfo)2 PropertyDescriptor (java.beans.PropertyDescriptor)1 List (java.util.List)1 IBindingInfo (org.eclipse.wb.internal.core.databinding.model.IBindingInfo)1 IObserveInfo (org.eclipse.wb.internal.core.databinding.model.IObserveInfo)1 AbstractBindingInfo (org.eclipse.wb.internal.rcp.databinding.model.AbstractBindingInfo)1 DirectFieldModelSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectFieldModelSupport)1 DirectModelSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectModelSupport)1 DirectObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectObservableInfo)1 DirectPropertyBindableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.direct.DirectPropertyBindableInfo)1 WritableListBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableListBeanObservableInfo)1 WritableSetBeanObservableInfo (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.WritableSetBeanObservableInfo)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 WritableListCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableListCodeSupport)1 WritableSetCodeSupport (org.eclipse.wb.internal.rcp.databinding.model.beans.observables.standard.WritableSetCodeSupport)1