1 11 package org.eclipse.jface.internal.databinding.provisional.beans; 12 13 import java.beans.BeanInfo ; 14 import java.beans.IntrospectionException ; 15 import java.beans.Introspector ; 16 import java.beans.PropertyDescriptor ; 17 18 import org.eclipse.jface.internal.databinding.internal.beans.JavaBeanObservableValue; 19 import org.eclipse.jface.internal.databinding.provisional.description.Property; 20 import org.eclipse.jface.internal.databinding.provisional.factories.IObservableFactory; 21 import org.eclipse.jface.internal.databinding.provisional.observable.IObservable; 22 import org.eclipse.jface.internal.databinding.provisional.observable.value.IObservableValue; 23 24 31 public class JavaBeansScalarObservableValueFactory extends Object implements 32 IObservableFactory { 33 34 37 public IObservable createObservable(Object description) { 38 if (! (description instanceof Property)) { 39 return null; 40 } 41 Property property = (Property) description; 42 Object collectionContainer = property.getObject(); 43 String propertyName = (String ) property.getPropertyID(); 44 45 BeanInfo beanInfo = null; 46 try { 47 beanInfo = Introspector.getBeanInfo(collectionContainer.getClass()); 48 } catch (IntrospectionException e) { 49 return null; 50 } 51 52 boolean found = false; 53 int position = 0; 54 PropertyDescriptor [] pds = beanInfo.getPropertyDescriptors(); 55 while (!found && position < pds.length) { 56 if (pds[position].getName().equals(propertyName)) { 57 found = true; 58 break; 59 } 60 ++position; 61 } 62 if (!found) { 63 return null; 64 } 65 IObservableValue updatable = new JavaBeanObservableValue(collectionContainer, pds[position]); 66 return updatable; 67 } 68 69 } 70 | Popular Tags |