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);
}
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());
}
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;
}
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;
}
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();
}
}
Aggregations