Subversion Repositories eFlore/Applications.coel

Rev

Rev 69 | Rev 153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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