Bonjour

J'ai un Bean avec 2 variables le nom du pays et une référence à son parent (le continent)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
public class Country extends AbstractModelObject{
 
	private String countryName;// Nom du pays
	private Continent continentParent;// Le parent du pays -> le continent
 
............................	
}
et le Bean Parent (le continent) qui contient une liste de pays
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
public class Continent extends AbstractModelObject{
 
	private String continentName;// Nom du continent
	private List<Country> countries = new ArrayList<Country>(); //Liste des pays
 
........................	
}

J'ai créer un wizardPage (avec 2 champs parent et Nom) pour créer un pays.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
................
	@Override
	public void createControl(Composite parent) {
		final DataBindingContext dbc = new DataBindingContext();
 
		//ici mise en place des widgets		
 
		bind(dbc, parentText, country, "continent", new NotEmptyValidator(
		"le nom du continent"));
 
		bind(dbc, nameText, country, "countryName", new NotEmptyValidator(
				"le nom du pays"));
 
//fin de la méthode
	}
Et mon wizard qui contrôle ma page
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
 
public class AddCountryWizard extends Wizard implements INewWizard{
 
	/**
         * La page du wizard
         */
	private AddCountryWizardPage addCountryWizardPage;
 
 
	/**
         * Le pays
         */
	private Country country = new Country();
	/**
         * La continent parent
         */
	private Continent continentParent;
 
	/**
         * Constructeur du wizard
         * @param uiController
         */
	public AddStationWizard(){
		this.setWindowTitle("Nouveau pays");
	}
 
 
	/**
         * Ajoute les pages au wizard
         */
	@Override
	public void addPages() {
		super.addPages();
		if(addCountryWizardPage == null){
			country.setContinent(continentParent);
			addCountryWizardPage = new AddCountryWizardPage(country);
		}
		addPage(addCountryWizardPage);
	}
 
	@Override
	public boolean performFinish() {
                AddCountry(country);	
		return true;
	}
 
	/**
         * Initialisation du wizard
         */
	@Override
	public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
		// Si la selection est une instance de continent
		if(currentSelection.getFirstElement() instanceof Continent){
			continentParent = (Continent)currentSelection.getFirstElement();
		}
	}
 
 
	/**
         * Permet de lier un widgets de type "Text
         *  à la variable d'un Bean
         *  
         * @param dbc
         * @param textWidget
         * @param bean
         * @param property
         * @param validator
         */
	protected void bind(DataBindingContext dbc, Text textWidget, Object bean,
			String property, IValidator validator) {
		UpdateValueStrategy targetToModel = null;
		if (validator != null) {
			targetToModel = new UpdateValueStrategy()
					.setAfterConvertValidator(validator);
		}
		dbc.bindValue(SWTObservables.observeText(textWidget, SWT.Modify),
				BeansObservables.observeValue(bean, property), targetToModel,
				null);
	}
///////////////////////
//////////////////////////////
}

Je sélectionne un continent (ex: Asie), lorsque je lance mon wizard, mon champ texte parent ( = continent) contient une référence à l'objet
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
worlddatabinding.domain.Continent@51ef4970
Ce qui est logique vue que je lie directement l'objet parent au widget
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
bind(dbc, parentText, country, "continent", new NotEmptyValidator(
		"le nom du continent"));
Je souhaite avoir le nom du parent (Asie) dans mon widget hors quand je fais

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
bind(dbc, parentText, country.getContinent(), "continentName", new NotEmptyValidator(
		"le nom du continent"));
J'ai bien le nom de mon continent dans mon widget mais en faisant cela mon widget est lié au nom du continent

Donc si je souhaite par la suite changer le continent en tapant "Amerique" dans mon widget.... Je modifie le nom de mon objet parent Asie en Amerique.....

Bref.... Il est tard et je ne suis pas sur d'être explicite

Peut-on lier un Bean à un widget mais afficher dans celui-ci qu'une variable de ce Bean ?

D'avance merci