1 11 12 package org.eclipse.jface.internal.databinding.provisional.factories; 13 14 import org.eclipse.jface.internal.databinding.internal.ListBinding; 15 import org.eclipse.jface.internal.databinding.internal.ValueBinding; 16 import org.eclipse.jface.internal.databinding.provisional.BindSpec; 17 import org.eclipse.jface.internal.databinding.provisional.Binding; 18 import org.eclipse.jface.internal.databinding.provisional.BindingException; 19 import org.eclipse.jface.internal.databinding.provisional.DataBindingContext; 20 import org.eclipse.jface.internal.databinding.provisional.observable.IObservable; 21 import org.eclipse.jface.internal.databinding.provisional.observable.list.IObservableList; 22 import org.eclipse.jface.internal.databinding.provisional.observable.value.IObservableValue; 23 24 28 public class DefaultBindingFactory implements IBindingFactory { 29 30 37 public Binding createBinding(DataBindingContext dataBindingContext, 38 IObservable targetObservable, IObservable modelObservable, 39 BindSpec bindSpec) { 40 Binding binding; 41 if (bindSpec == null) { 42 bindSpec = new BindSpec(null, null, null, null); 43 } 44 if (targetObservable instanceof IObservableValue) { 45 if (modelObservable instanceof IObservableValue) { 46 IObservableValue target = (IObservableValue) targetObservable; 47 IObservableValue model = (IObservableValue) modelObservable; 48 dataBindingContext.fillBindSpecDefaults(dataBindingContext, 49 bindSpec, target.getValueType(), model.getValueType()); 50 binding = new ValueBinding(dataBindingContext, target, model, 51 bindSpec); 52 return binding; 53 } 54 throw new BindingException( 55 "incompatible observables: target is value, model is " + modelObservable.getClass().getName()); } else if (targetObservable instanceof IObservableList) { 57 if (modelObservable instanceof IObservableList) { 58 IObservableList target = (IObservableList) targetObservable; 59 IObservableList model = (IObservableList) modelObservable; 60 dataBindingContext.fillBindSpecDefaults(dataBindingContext, 61 bindSpec, target.getElementType(), model 62 .getElementType()); 63 binding = new ListBinding(dataBindingContext, target, model, 64 bindSpec); 65 return binding; 66 } 67 throw new BindingException( 68 "incompatible observable: target is list, model is " + modelObservable.getClass().getName()); } 70 return null; 71 } 72 73 } 74 | Popular Tags |