1 11 package org.eclipse.jface.internal.databinding.provisional.swt; 12 13 import org.eclipse.jface.internal.databinding.internal.swt.ButtonObservableValue; 14 import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableList; 15 import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue; 16 import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableList; 17 import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue; 18 import org.eclipse.jface.internal.databinding.internal.swt.ControlObservableValue; 19 import org.eclipse.jface.internal.databinding.internal.swt.LabelObservableValue; 20 import org.eclipse.jface.internal.databinding.internal.swt.ListObservableList; 21 import org.eclipse.jface.internal.databinding.internal.swt.ListObservableValue; 22 import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue; 23 import org.eclipse.jface.internal.databinding.internal.swt.TableObservableValue; 24 import org.eclipse.jface.internal.databinding.internal.swt.TextObservableValue; 25 import org.eclipse.jface.internal.databinding.provisional.DataBindingContext; 26 import org.eclipse.jface.internal.databinding.provisional.description.Property; 27 import org.eclipse.jface.internal.databinding.provisional.factories.IObservableFactory; 28 import org.eclipse.jface.internal.databinding.provisional.observable.IObservable; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.custom.CCombo; 31 import org.eclipse.swt.widgets.Button; 32 import org.eclipse.swt.widgets.Combo; 33 import org.eclipse.swt.widgets.Control; 34 import org.eclipse.swt.widgets.Label; 35 import org.eclipse.swt.widgets.List; 36 import org.eclipse.swt.widgets.Spinner; 37 import org.eclipse.swt.widgets.Table; 38 import org.eclipse.swt.widgets.Text; 39 40 68 final public class SWTObservableFactory implements IObservableFactory { 69 70 private int updateTime = DataBindingContext.TIME_LATE; 71 72 75 public SWTObservableFactory() { 76 } 77 78 85 public SWTObservableFactory(int updateTime) { 86 this.updateTime = updateTime; 87 } 88 89 public IObservable createObservable(Object description) { 90 if (description instanceof Property) { 91 Object object = ((Property) description).getObject(); 92 Object attribute = ((Property) description).getPropertyID(); 93 if (object instanceof Control 94 && SWTProperties.ENABLED.equals(attribute)) { 95 return new ControlObservableValue((Control) object, 96 (String ) attribute); 97 } 98 if (object instanceof Control 99 && SWTProperties.VISIBLE.equals(attribute)) { 100 return new ControlObservableValue((Control) object, 101 (String ) attribute); 102 } 103 if (object instanceof Spinner 104 && (SWTProperties.SELECTION.equals(attribute) 105 || SWTProperties.MIN.equals(attribute) || SWTProperties.MAX 106 .equals(attribute))) { 107 return new SpinnerObservableValue((Spinner) object, 108 (String ) attribute); 109 } 110 if (object instanceof Text && SWTProperties.TEXT.equals(attribute)) { 111 return new TextObservableValue((Text) object, SWT.Modify); 112 } 113 if (object instanceof Label && SWTProperties.TEXT.equals(attribute)) { 114 return new LabelObservableValue((Label) object); 115 } 116 if (object instanceof Button 117 && SWTProperties.SELECTION.equals(attribute)) { 118 return new ButtonObservableValue((Button) object); 119 } 120 if (object instanceof Combo 121 && (SWTProperties.TEXT.equals(attribute) || SWTProperties.SELECTION 122 .equals(attribute))) { 123 return new ComboObservableValue((Combo) object, 124 (String ) attribute); 125 } else if (object instanceof Combo 126 && SWTProperties.ITEMS.equals(attribute)) { 127 return new ComboObservableList((Combo) object); 128 } 129 if (object instanceof CCombo 130 && (SWTProperties.TEXT.equals(attribute) || SWTProperties.SELECTION 131 .equals(attribute))) { 132 return new CComboObservableValue((CCombo) object, 133 (String ) attribute); 134 } else if (object instanceof CCombo 135 && SWTProperties.ITEMS.equals(attribute)) { 136 return new CComboObservableList((CCombo) object); 137 } 138 if (object instanceof List 139 && SWTProperties.SELECTION.equals(attribute)) { 140 return new ListObservableValue((List) object); 142 } else if (object instanceof List 143 && SWTProperties.ITEMS.equals(attribute)) { 144 return new ListObservableList((List) object); 145 } 146 if (object instanceof Table) { 147 return new TableObservableValue((Table) object, 148 (String ) attribute); 149 } 150 } 151 if (description instanceof Text) { 152 int updatePolicy = new int[] { SWT.Modify, SWT.FocusOut, SWT.None }[updateTime]; 153 return new TextObservableValue((Text) description, updatePolicy); 154 } else if (description instanceof Button) { 155 return new ButtonObservableValue((Button) description); 157 } else if (description instanceof Label) { 158 return new LabelObservableValue((Label) description); 159 } else if (description instanceof Combo) { 160 return new ComboObservableList((Combo) description); 161 } else if (description instanceof Spinner) { 162 return new SpinnerObservableValue((Spinner) description, 163 SWTProperties.SELECTION); 164 } else if (description instanceof CCombo) { 165 return new CComboObservableList((CCombo) description); 166 } else if (description instanceof List) { 167 return new ListObservableList((List) description); 168 } 169 return null; 170 } 171 172 179 public void setUpdateTime(int time) { 180 updateTime = time; 181 } 182 } 183 | Popular Tags |