|
Lines 7-23
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Ovidio Mallo - initial API and implementation (bug 235195) |
9 |
* Ovidio Mallo - initial API and implementation (bug 235195) |
|
|
10 |
* Ovidio Mallo - bug 237856 |
| 10 |
******************************************************************************/ |
11 |
******************************************************************************/ |
| 11 |
|
12 |
|
| 12 |
package org.eclipse.jface.tests.databinding.wizard; |
13 |
package org.eclipse.jface.tests.databinding.wizard; |
| 13 |
|
14 |
|
| 14 |
import org.eclipse.core.databinding.DataBindingContext; |
15 |
import org.eclipse.core.databinding.DataBindingContext; |
| 15 |
import org.eclipse.core.databinding.ValidationStatusProvider; |
16 |
import org.eclipse.core.databinding.ValidationStatusProvider; |
|
|
17 |
import org.eclipse.core.databinding.observable.Diffs; |
| 18 |
import org.eclipse.core.databinding.observable.ObservableTracker; |
| 16 |
import org.eclipse.core.databinding.observable.Observables; |
19 |
import org.eclipse.core.databinding.observable.Observables; |
|
|
20 |
import org.eclipse.core.databinding.observable.Realm; |
| 17 |
import org.eclipse.core.databinding.observable.list.IObservableList; |
21 |
import org.eclipse.core.databinding.observable.list.IObservableList; |
|
|
22 |
import org.eclipse.core.databinding.observable.value.AbstractObservableValue; |
| 18 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
23 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
| 19 |
import org.eclipse.core.databinding.observable.value.WritableValue; |
24 |
import org.eclipse.core.databinding.observable.value.WritableValue; |
| 20 |
import org.eclipse.core.databinding.validation.ValidationStatus; |
25 |
import org.eclipse.core.databinding.validation.ValidationStatus; |
|
|
26 |
import org.eclipse.core.internal.commands.util.Util; |
| 21 |
import org.eclipse.core.runtime.IStatus; |
27 |
import org.eclipse.core.runtime.IStatus; |
| 22 |
import org.eclipse.jface.databinding.wizard.WizardPageSupport; |
28 |
import org.eclipse.jface.databinding.wizard.WizardPageSupport; |
| 23 |
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; |
29 |
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; |
|
Lines 69-74
Link Here
|
| 69 |
loadWizardPage(page); |
75 |
loadWizardPage(page); |
| 70 |
} |
76 |
} |
| 71 |
|
77 |
|
|
|
78 |
public void testPageCompleteOnValidationStaleness() { |
| 79 |
IWizardPage page = new WizardPage("Page") { |
| 80 |
public void createControl(Composite parent) { |
| 81 |
setControl(parent); |
| 82 |
|
| 83 |
ValidationObservable validation = new ValidationObservable(); |
| 84 |
|
| 85 |
DataBindingContext dbc = new DataBindingContext(); |
| 86 |
dbc.addValidationStatusProvider(new ValidationProvider( |
| 87 |
validation)); |
| 88 |
|
| 89 |
WizardPageSupport.create(this, dbc); |
| 90 |
|
| 91 |
assertTrue(isPageComplete()); |
| 92 |
|
| 93 |
validation.setStale(true); |
| 94 |
assertFalse(isPageComplete()); |
| 95 |
|
| 96 |
validation.setStale(false); |
| 97 |
assertTrue(isPageComplete()); |
| 98 |
} |
| 99 |
}; |
| 100 |
|
| 101 |
loadWizardPage(page); |
| 102 |
} |
| 103 |
|
| 72 |
private void loadWizardPage(IWizardPage page) { |
104 |
private void loadWizardPage(IWizardPage page) { |
| 73 |
Wizard wizard = new Wizard() { |
105 |
Wizard wizard = new Wizard() { |
| 74 |
public boolean performFinish() { |
106 |
public boolean performFinish() { |
|
Lines 81-87
Link Here
|
| 81 |
dialog.create(); |
113 |
dialog.create(); |
| 82 |
} |
114 |
} |
| 83 |
|
115 |
|
| 84 |
private class ValidationProvider extends ValidationStatusProvider { |
116 |
private static class ValidationObservable extends AbstractObservableValue { |
|
|
117 |
|
| 118 |
private Object value = ValidationStatus.ok(); |
| 119 |
|
| 120 |
private boolean stale = false; |
| 121 |
|
| 122 |
public ValidationObservable() { |
| 123 |
super(Realm.getDefault()); |
| 124 |
} |
| 125 |
|
| 126 |
protected Object doGetValue() { |
| 127 |
return value; |
| 128 |
} |
| 129 |
|
| 130 |
protected void doSetValue(Object value) { |
| 131 |
Object oldValue = this.value; |
| 132 |
this.value = value; |
| 133 |
if (!Util.equals(oldValue, value)) { |
| 134 |
fireValueChange(Diffs.createValueDiff(oldValue, value)); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
public boolean isStale() { |
| 139 |
ObservableTracker.getterCalled(this); |
| 140 |
return stale; |
| 141 |
} |
| 142 |
|
| 143 |
public void setStale(boolean stale) { |
| 144 |
if (this.stale != stale) { |
| 145 |
this.stale = stale; |
| 146 |
if (stale) { |
| 147 |
fireStale(); |
| 148 |
} else { |
| 149 |
fireValueChange(Diffs.createValueDiff(value, value)); |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
public Object getValueType() { |
| 155 |
return IStatus.class; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
private static class ValidationProvider extends ValidationStatusProvider { |
| 85 |
|
160 |
|
| 86 |
private final IObservableValue validation; |
161 |
private final IObservableValue validation; |
| 87 |
|
162 |
|