|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008 Ovidio Mallo and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Ovidio Mallo - initial API and implementation (bug 237856) |
| 10 |
******************************************************************************/ |
| 11 |
|
| 12 |
package org.eclipse.jface.tests.databinding.wizard; |
| 13 |
|
| 14 |
import org.eclipse.core.databinding.DataBindingContext; |
| 15 |
import org.eclipse.core.databinding.ValidationStatusProvider; |
| 16 |
import org.eclipse.core.databinding.observable.Diffs; |
| 17 |
import org.eclipse.core.databinding.observable.ObservableTracker; |
| 18 |
import org.eclipse.core.databinding.observable.Observables; |
| 19 |
import org.eclipse.core.databinding.observable.Realm; |
| 20 |
import org.eclipse.core.databinding.observable.list.IObservableList; |
| 21 |
import org.eclipse.core.databinding.observable.value.AbstractObservableValue; |
| 22 |
import org.eclipse.core.databinding.observable.value.IObservableValue; |
| 23 |
import org.eclipse.core.databinding.validation.ValidationStatus; |
| 24 |
import org.eclipse.core.internal.commands.util.Util; |
| 25 |
import org.eclipse.core.runtime.IStatus; |
| 26 |
import org.eclipse.jface.databinding.wizard.WizardPageSupport; |
| 27 |
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase; |
| 28 |
import org.eclipse.jface.wizard.IWizardPage; |
| 29 |
import org.eclipse.jface.wizard.Wizard; |
| 30 |
import org.eclipse.jface.wizard.WizardDialog; |
| 31 |
import org.eclipse.jface.wizard.WizardPage; |
| 32 |
import org.eclipse.swt.widgets.Composite; |
| 33 |
|
| 34 |
/** |
| 35 |
* @since 1.2 |
| 36 |
*/ |
| 37 |
public class WizardPageSupportTest extends AbstractSWTTestCase { |
| 38 |
|
| 39 |
public void testPageCompleteOnValidationStaleness() { |
| 40 |
IWizardPage page = new WizardPage("Page") { |
| 41 |
public void createControl(Composite parent) { |
| 42 |
setControl(parent); |
| 43 |
|
| 44 |
ValidationObservable validation = new ValidationObservable(); |
| 45 |
|
| 46 |
DataBindingContext dbc = new DataBindingContext(); |
| 47 |
dbc.addValidationStatusProvider(new ValidationProvider( |
| 48 |
validation)); |
| 49 |
|
| 50 |
WizardPageSupport.create(this, dbc); |
| 51 |
|
| 52 |
assertTrue(isPageComplete()); |
| 53 |
|
| 54 |
validation.setStale(true); |
| 55 |
assertFalse(isPageComplete()); |
| 56 |
|
| 57 |
validation.setStale(false); |
| 58 |
assertTrue(isPageComplete()); |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
loadWizardPage(page); |
| 63 |
} |
| 64 |
|
| 65 |
private void loadWizardPage(IWizardPage page) { |
| 66 |
Wizard wizard = new Wizard() { |
| 67 |
public boolean performFinish() { |
| 68 |
return true; |
| 69 |
} |
| 70 |
}; |
| 71 |
wizard.addPage(page); |
| 72 |
|
| 73 |
WizardDialog dialog = new WizardDialog(getShell(), wizard); |
| 74 |
dialog.create(); |
| 75 |
} |
| 76 |
|
| 77 |
private static class ValidationObservable extends AbstractObservableValue { |
| 78 |
|
| 79 |
private Object value = ValidationStatus.ok(); |
| 80 |
|
| 81 |
private boolean stale = false; |
| 82 |
|
| 83 |
public ValidationObservable() { |
| 84 |
super(Realm.getDefault()); |
| 85 |
} |
| 86 |
|
| 87 |
protected Object doGetValue() { |
| 88 |
return value; |
| 89 |
} |
| 90 |
|
| 91 |
protected void doSetValue(Object value) { |
| 92 |
Object oldValue = this.value; |
| 93 |
this.value = value; |
| 94 |
if (!Util.equals(oldValue, value)) { |
| 95 |
fireValueChange(Diffs.createValueDiff(oldValue, value)); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
public boolean isStale() { |
| 100 |
ObservableTracker.getterCalled(this); |
| 101 |
return stale; |
| 102 |
} |
| 103 |
|
| 104 |
public void setStale(boolean stale) { |
| 105 |
if (this.stale != stale) { |
| 106 |
this.stale = stale; |
| 107 |
if (stale) { |
| 108 |
fireStale(); |
| 109 |
} else { |
| 110 |
fireValueChange(Diffs.createValueDiff(value, value)); |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
public Object getValueType() { |
| 116 |
return IStatus.class; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
private static class ValidationProvider extends ValidationStatusProvider { |
| 121 |
|
| 122 |
private final IObservableValue validation; |
| 123 |
|
| 124 |
public ValidationProvider(IObservableValue validation) { |
| 125 |
this.validation = validation; |
| 126 |
} |
| 127 |
|
| 128 |
public IObservableValue getValidationStatus() { |
| 129 |
return validation; |
| 130 |
} |
| 131 |
|
| 132 |
public IObservableList getTargets() { |
| 133 |
return Observables.emptyObservableList(); |
| 134 |
} |
| 135 |
|
| 136 |
public IObservableList getModels() { |
| 137 |
return Observables.emptyObservableList(); |
| 138 |
} |
| 139 |
} |
| 140 |
} |