|
45 | 45 | import org.eclipse.core.databinding.conversion.Converter; |
46 | 46 | import org.eclipse.core.databinding.observable.Observables; |
47 | 47 | import org.eclipse.core.databinding.observable.list.IObservableList; |
| 48 | +import org.eclipse.core.databinding.observable.value.ComputedValue; |
48 | 49 | import org.eclipse.core.databinding.observable.value.IObservableValue; |
49 | 50 | import org.eclipse.core.databinding.observable.value.WritableValue; |
50 | 51 | import org.eclipse.core.databinding.validation.IValidator; |
@@ -213,24 +214,53 @@ private void setupProjectVersionDataBinding(DataBindingContext context) { |
213 | 214 | } |
214 | 215 |
|
215 | 216 | private void setupAutoPromoteDataBinding(DataBindingContext context) { |
216 | | - ISWTObservableValue promoteButton = WidgetProperties.selection().observe(autoPromoteButton); |
217 | | - ISWTObservableValue stopPreviousVersion = |
| 217 | + ISWTObservableValue promoteButton = |
| 218 | + WidgetProperties.selection().observe(autoPromoteButton); |
| 219 | + final ISWTObservableValue stopPreviousVersion = |
218 | 220 | WidgetProperties.selection().observe(stopPreviousVersionButton); |
219 | | - ISWTObservableValue stopPreviousVersionEnablement = |
| 221 | + final ISWTObservableValue stopPreviousVersionEnablement = |
220 | 222 | WidgetProperties.enabled().observe(stopPreviousVersionButton); |
221 | 223 |
|
222 | | - // use an intermediary value to control the enabled state of stopPreviousVersionButton |
223 | | - // based on the promote checkbox's state |
224 | | - WritableValue enablement = new WritableValue(); |
225 | | - context.bindValue(promoteButton, enablement); |
226 | | - context.bindValue(stopPreviousVersionEnablement, enablement); |
| 224 | + context.bindValue(stopPreviousVersionEnablement, promoteButton); |
227 | 225 |
|
228 | 226 | IObservableValue promoteModel = PojoProperties.value("autoPromote").observe(model); |
229 | 227 | IObservableValue stopPreviousVersionModel = |
230 | 228 | PojoProperties.value("stopPreviousVersion").observe(model); |
231 | 229 |
|
232 | 230 | context.bindValue(promoteButton, promoteModel); |
233 | | - context.bindValue(stopPreviousVersion, stopPreviousVersionModel); |
| 231 | + |
| 232 | + // Intermediary model necessary for "Restore Defaults" to work. |
| 233 | + final IObservableValue currentStopPreviousVersionChoice = new WritableValue(); |
| 234 | + context.bindValue(currentStopPreviousVersionChoice, stopPreviousVersionModel); |
| 235 | + |
| 236 | + // One-way update: button selection <-- latest user choice |
| 237 | + // Update the button (to match the user choice), if enabled; if not, force unchecking. |
| 238 | + context.bindValue(stopPreviousVersion, new ComputedValue() { |
| 239 | + @Override |
| 240 | + protected Object calculate() { |
| 241 | + boolean buttonEnabled = (boolean) stopPreviousVersionEnablement.getValue(); |
| 242 | + boolean currentValue = (boolean) currentStopPreviousVersionChoice.getValue(); |
| 243 | + if (!buttonEnabled) { |
| 244 | + return Boolean.FALSE; // Force unchecking the stop previous button if it is disabled. |
| 245 | + } |
| 246 | + return currentValue; // Otherwise, check the button according to the latest user choice. |
| 247 | + } |
| 248 | + }, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null); |
| 249 | + |
| 250 | + // One-way update: button selection --> latest user choice |
| 251 | + // Update the user choice (to match the button selection), only when the button is enabled. |
| 252 | + context.bindValue(new ComputedValue() { |
| 253 | + @Override |
| 254 | + protected Object calculate() { |
| 255 | + boolean buttonEnabled = (boolean) stopPreviousVersionEnablement.getValue(); |
| 256 | + boolean buttonValue = (boolean) stopPreviousVersion.getValue(); |
| 257 | + boolean currentValue = (boolean) currentStopPreviousVersionChoice.getValue(); |
| 258 | + if (buttonEnabled) { |
| 259 | + return buttonValue; // Remember the button state as the latest choice if it is enabled. |
| 260 | + } |
| 261 | + return currentValue; // Otherwise, retain the latest (current) user choice. |
| 262 | + } |
| 263 | + }, stopPreviousVersionModel, null, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER)); |
234 | 264 | } |
235 | 265 |
|
236 | 266 | private void setupBucketDataBinding(DataBindingContext context) { |
|
0 commit comments