Mercurial > projects > dwt2
comparison org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/swt/TextObservableValue.d @ 85:6be48cf9f95c
Work on databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 18 Apr 2009 13:54:50 +0200 |
parents | 0a55d2d5a946 |
children |
comparison
equal
deleted
inserted
replaced
84:fcf926c91ca4 | 85:6be48cf9f95c |
---|---|
47 public class TextObservableValue : AbstractSWTVetoableValue { | 47 public class TextObservableValue : AbstractSWTVetoableValue { |
48 | 48 |
49 /** | 49 /** |
50 * {@link Text} widget that this is being observed. | 50 * {@link Text} widget that this is being observed. |
51 */ | 51 */ |
52 private final Text text; | 52 private const Text text; |
53 | 53 |
54 /** | 54 /** |
55 * Flag to track when the model is updating the widget. When | 55 * Flag to track when the model is updating the widget. When |
56 * <code>true</code> the handlers for the SWT events should not process | 56 * <code>true</code> the handlers for the SWT events should not process |
57 * the event as this would cause an infinite loop. | 57 * the event as this would cause an infinite loop. |
60 | 60 |
61 /** | 61 /** |
62 * SWT event that on firing this observable will fire change events to its | 62 * SWT event that on firing this observable will fire change events to its |
63 * listeners. | 63 * listeners. |
64 */ | 64 */ |
65 private final int updateEventType; | 65 private const int updateEventType; |
66 | 66 |
67 /** | 67 /** |
68 * Valid types for the {@link #updateEventType}. | 68 * Valid types for the {@link #updateEventType}. |
69 */ | 69 */ |
70 private static const int[] validUpdateEventTypes = [ SWT.Modify, | 70 private static const int[] validUpdateEventTypes = [ SWT.Modify, |
73 /** | 73 /** |
74 * Previous value of the Text. | 74 * Previous value of the Text. |
75 */ | 75 */ |
76 private String oldValue; | 76 private String oldValue; |
77 | 77 |
78 private Listener updateListener = new class() Listener { | 78 private Listener updateListener; |
79 class UpdateListener : Listener { | |
79 public void handleEvent(Event event) { | 80 public void handleEvent(Event event) { |
80 if (!updating) { | 81 if (!updating) { |
81 String newValue = text.getText(); | 82 String newValue = text.getText(); |
82 | 83 |
83 if (!newValue.equals(oldValue)) { | 84 if (!newValue.equals(oldValue)) { |
84 fireValueChange(Diffs.createValueDiff(oldValue, newValue)); | 85 fireValueChange(Diffs.createValueDiff(stringcast(oldValue), stringcast(newValue))); |
85 oldValue = newValue; | 86 oldValue = newValue; |
86 } | 87 } |
87 } | 88 } |
88 } | 89 } |
89 }; | 90 }; |
113 * @param realm can not be <code>null</code> | 114 * @param realm can not be <code>null</code> |
114 * @param text | 115 * @param text |
115 * @param updateEventType | 116 * @param updateEventType |
116 */ | 117 */ |
117 public this(Realm realm, Text text, int updateEventType) { | 118 public this(Realm realm, Text text, int updateEventType) { |
119 updateListener = new UpdateListener(); | |
118 super(realm, text); | 120 super(realm, text); |
119 | 121 |
120 bool eventValid = false; | 122 bool eventValid = false; |
121 for (int i = 0; !eventValid && i < validUpdateEventTypes.length; i++) { | 123 for (int i = 0; !eventValid && i < validUpdateEventTypes.length; i++) { |
122 eventValid = (updateEventType is validUpdateEventTypes[i]); | 124 eventValid = (updateEventType is validUpdateEventTypes[i]); |
123 } | 125 } |
124 if (!eventValid) { | 126 if (!eventValid) { |
125 throw new IllegalArgumentException( | 127 throw new IllegalArgumentException( |
126 "UpdateEventType [" + updateEventType + "] is not supported."); //$NON-NLS-1$//$NON-NLS-2$ | 128 Format("UpdateEventType [{}] is not supported.", updateEventType )); //$NON-NLS-1$//$NON-NLS-2$ |
127 } | 129 } |
128 this.text = text; | 130 this.text = text; |
129 this.updateEventType = updateEventType; | 131 this.updateEventType = updateEventType; |
130 if (updateEventType !is SWT.None) { | 132 if (updateEventType !is SWT.None) { |
131 text.addListener(updateEventType, updateListener); | 133 text.addListener(updateEventType, updateListener); |
136 verifyListener = new class() VerifyListener { | 138 verifyListener = new class() VerifyListener { |
137 public void verifyText(VerifyEvent e) { | 139 public void verifyText(VerifyEvent e) { |
138 if (!updating) { | 140 if (!updating) { |
139 String currentText = text | 141 String currentText = text |
140 .getText(); | 142 .getText(); |
141 String newText = currentText.substring(0, e.start) + e.text | 143 String newText = currentText.substring(0, e.start) ~ e.text |
142 + currentText.substring(e.end); | 144 ~ currentText.substring(e.end); |
143 if (!fireValueChanging(Diffs.createValueDiff(currentText, | 145 if (!fireValueChanging(Diffs.createValueDiff(stringcast(currentText), |
144 newText))) { | 146 stringcast(newText)))) { |
145 e.doit = false; | 147 e.doit = false; |
146 } | 148 } |
147 } | 149 } |
148 } | 150 } |
149 }; | 151 }; |
173 * Returns the current value of the {@link Text}. | 175 * Returns the current value of the {@link Text}. |
174 * | 176 * |
175 * @see org.eclipse.core.databinding.observable.value.AbstractVetoableValue#doGetValue() | 177 * @see org.eclipse.core.databinding.observable.value.AbstractVetoableValue#doGetValue() |
176 */ | 178 */ |
177 public Object doGetValue() { | 179 public Object doGetValue() { |
178 return oldValue = text.getText(); | 180 return stringcast(oldValue = text.getText()); |
179 } | 181 } |
180 | 182 |
181 /** | 183 /** |
182 * Returns the type of the value from {@link #doGetValue()}, i.e. | 184 * Returns the type of the value from {@link #doGetValue()}, i.e. |
183 * String.class | 185 * String.class |
184 * | 186 * |
185 * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() | 187 * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() |
186 */ | 188 */ |
187 public Object getValueType() { | 189 public Object getValueType() { |
188 return String.classinfo; | 190 return Class.fromType!(String); |
189 } | 191 } |
190 | 192 |
191 public void dispose() { | 193 public void dispose() { |
192 if (!text.isDisposed()) { | 194 if (!text.isDisposed()) { |
193 if (updateEventType !is SWT.None) { | 195 if (updateEventType !is SWT.None) { |