Subversion Repositories eFlore/Applications.coel

Rev

Rev 60 | Rev 133 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 60 Rev 69
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
import java.util.Iterator;
4
import java.util.Iterator;
5
import java.util.List;
5
import java.util.List;
-
 
6
 
6
 
7
import org.tela_botanica.client.ComposantClass;
7
import org.tela_botanica.client.Mediateur;
8
import org.tela_botanica.client.Mediateur;
8
import org.tela_botanica.client.RegistreId;
9
import org.tela_botanica.client.RegistreId;
9
import org.tela_botanica.client.interfaces.Rafraichissable;
10
import org.tela_botanica.client.interfaces.Rafraichissable;
10
import org.tela_botanica.client.modeles.Structure;
11
import org.tela_botanica.client.modeles.Structure;
11
import org.tela_botanica.client.modeles.ListeStructure;
12
import org.tela_botanica.client.modeles.StructureListe;
12
 
13
 
13
import com.extjs.gxt.ui.client.Registry;
14
import com.extjs.gxt.ui.client.Registry;
14
import com.extjs.gxt.ui.client.Style.SelectionMode;
15
import com.extjs.gxt.ui.client.Style.SelectionMode;
15
import com.extjs.gxt.ui.client.binder.TableBinder;
16
import com.extjs.gxt.ui.client.binder.TableBinder;
-
 
17
import com.extjs.gxt.ui.client.event.ComponentEvent;
16
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
18
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
17
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
19
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
-
 
20
import com.extjs.gxt.ui.client.event.SelectionListener;
18
import com.extjs.gxt.ui.client.store.ListStore;
21
import com.extjs.gxt.ui.client.store.ListStore;
19
import com.extjs.gxt.ui.client.widget.ContentPanel;
22
import com.extjs.gxt.ui.client.widget.ContentPanel;
20
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
23
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
21
import com.extjs.gxt.ui.client.widget.table.Table;
24
import com.extjs.gxt.ui.client.widget.table.Table;
22
import com.extjs.gxt.ui.client.widget.table.TableColumn;
25
import com.extjs.gxt.ui.client.widget.table.TableColumn;
23
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
26
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
24
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
27
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
25
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
28
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
26
import com.google.gwt.user.client.Window;
29
import com.google.gwt.user.client.Window;
27
 
30
 
28
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
31
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
29
	
32
	
30
	private Mediateur coelMediateur = null ;
33
	private Mediateur coelMediateur = null ;
31
	private Table table = null;
34
	private Table table = null;
32
	private ListStore<Structure> store = null;
35
	private ListStore<Structure> store = null;
33
	private TableBinder<Structure> binder = null;
36
	private TableBinder<Structure> binder = null;
34
 
37
 
35
	public StructureListePanneauVue() {
38
	public StructureListePanneauVue() {
36
		coelMediateur = Registry.get(RegistreId.MEDIATEUR);
39
		coelMediateur = Registry.get(RegistreId.MEDIATEUR);
37
		
40
		
38
		ToolBar toolBar = new ToolBar();
41
		ToolBar toolBar = new ToolBar();
39
		TextToolItem ajouter = new TextToolItem("Ajouter");
42
		TextToolItem ajouter = new TextToolItem("Ajouter");
40
		ajouter.setIconStyle("icone-ajouter");
43
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
-
 
44
		ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {  
-
 
45
			public void componentSelected(ComponentEvent ce) {  
-
 
46
				coelMediateur.clicAjouterStructure();
-
 
47
			}  
-
 
48
		});
41
		toolBar.add(ajouter);
49
		toolBar.add(ajouter);
42
 
50
 
43
		TextToolItem modifier = new TextToolItem("Modifier");
51
		TextToolItem modifier = new TextToolItem("Modifier");
44
		modifier.setIconStyle("icone-modifier");
52
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
45
		toolBar.add(modifier);
53
		toolBar.add(modifier);
46
		
54
		
47
		TextToolItem supprimer = new TextToolItem("Supprimer");
55
		TextToolItem supprimer = new TextToolItem("Supprimer");
48
		supprimer.setIconStyle("icone-supprimer");
56
		supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
49
		toolBar.add(supprimer);
57
		toolBar.add(supprimer);
50
 
58
 
51
		setTopComponent(toolBar);
59
		setTopComponent(toolBar);
52
 
60
 
53
		List<TableColumn> columns = new ArrayList<TableColumn>();
61
		List<TableColumn> columns = new ArrayList<TableColumn>();
54
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
62
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
55
		columns.add(new TableColumn("ville", "Ville", .3f));
63
		columns.add(new TableColumn("ville", "Ville", .3f));
56
		columns.add(new TableColumn("nom", "Nom", .7f));
64
		columns.add(new TableColumn("nom", "Nom", .7f));
57
		
65
		
58
		TableColumnModel cm = new TableColumnModel(columns);
66
		TableColumnModel cm = new TableColumnModel(columns);
59
 
67
 
60
		table = new Table(cm);
68
		table = new Table(cm);
61
		table.setSelectionMode(SelectionMode.MULTI);
69
		table.setSelectionMode(SelectionMode.MULTI);
62
		table.setBorders(false);
70
		table.setBorders(false);
63
 
71
 
64
		add(table);
72
		add(table);
65
 
73
 
66
		store = new ListStore<Structure>();
74
		store = new ListStore<Structure>();
67
 
75
 
68
		binder = new TableBinder<Structure>(table, store);
76
		binder = new TableBinder<Structure>(table, store);
69
		binder.setAutoSelect(true);
77
		binder.setAutoSelect(true);
70
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
78
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
71
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
79
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
72
				Structure m = (Structure) event.getSelectedItem();
80
				Structure m = (Structure) event.getSelectedItem();
73
				clicListe(m);
81
				clicListe(m);
74
			}
82
			}
75
		});
83
		});
76
 
84
 
77
		setLayout(new FitLayout());
85
		setLayout(new FitLayout());
78
	}
86
	}
79
 
87
 
80
	public ListStore<Structure> getStore() {
88
	public ListStore<Structure> getStore() {
81
		return store;
89
		return store;
82
	}
90
	}
83
 
91
 
84
	public TableBinder<Structure> getBinder() {
92
	public TableBinder<Structure> getBinder() {
85
		return binder;
93
		return binder;
86
	}
94
	}
87
 
95
 
88
	private void clicListe(Structure institution) {
96
	private void clicListe(Structure institution) {
89
		coelMediateur.clicListeInstitution(institution);
97
		coelMediateur.clicListeInstitution(institution);
90
	}
98
	}
91
 
99
 
92
	public void rafraichir(Object nouvelleDonnees) {
100
	public void rafraichir(Object nouvelleDonnees) {
93
		if (nouvelleDonnees instanceof ListeStructure) {
101
		if (nouvelleDonnees instanceof StructureListe) {
94
			ListeStructure listeInstitutions = (ListeStructure) nouvelleDonnees;
102
			StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
95
			setHeading("Institutions");
103
			setHeading("Institutions");
96
 
104
 
97
			List<Structure> liste = new ArrayList<Structure>();
105
			List<Structure> liste = new ArrayList<Structure>();
98
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
106
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
99
				liste.add(listeInstitutions.get(it.next()));
107
				liste.add(listeInstitutions.get(it.next()));
100
			}
108
			}
101
			
109
			
102
			store.removeAll();
110
			store.removeAll();
103
			store.add((List<Structure>) liste);
111
			store.add((List<Structure>) liste);
104
			
112
			
105
			// Test pour savoir si la liste contient des éléments
113
			// Test pour savoir si la liste contient des éléments
106
			if (listeInstitutions.size() > 0) {
114
			if (listeInstitutions.size() > 0) {
107
				binder.setSelection((Structure) listeInstitutions.get(0));
115
				binder.setSelection((Structure) listeInstitutions.get(0));
108
			}
116
			}
109
		}
117
		}
110
		
118
		
111
	}
119
	}
112
}
120
}