Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 59 → Rev 60

/trunk/src/org/tela_botanica/client/vues/StructureListePanneauVue.java
New file
0,0 → 1,112
package org.tela_botanica.client.vues;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Structure;
import org.tela_botanica.client.modeles.ListeStructure;
 
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binder.TableBinder;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.table.Table;
import com.extjs.gxt.ui.client.widget.table.TableColumn;
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.user.client.Window;
 
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
private Mediateur coelMediateur = null ;
private Table table = null;
private ListStore<Structure> store = null;
private TableBinder<Structure> binder = null;
 
public StructureListePanneauVue() {
coelMediateur = Registry.get(RegistreId.MEDIATEUR);
ToolBar toolBar = new ToolBar();
TextToolItem ajouter = new TextToolItem("Ajouter");
ajouter.setIconStyle("icone-ajouter");
toolBar.add(ajouter);
 
TextToolItem modifier = new TextToolItem("Modifier");
modifier.setIconStyle("icone-modifier");
toolBar.add(modifier);
TextToolItem supprimer = new TextToolItem("Supprimer");
supprimer.setIconStyle("icone-supprimer");
toolBar.add(supprimer);
 
setTopComponent(toolBar);
 
List<TableColumn> columns = new ArrayList<TableColumn>();
// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
columns.add(new TableColumn("ville", "Ville", .3f));
columns.add(new TableColumn("nom", "Nom", .7f));
TableColumnModel cm = new TableColumnModel(columns);
 
table = new Table(cm);
table.setSelectionMode(SelectionMode.MULTI);
table.setBorders(false);
 
add(table);
 
store = new ListStore<Structure>();
 
binder = new TableBinder<Structure>(table, store);
binder.setAutoSelect(true);
binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
public void selectionChanged(SelectionChangedEvent<Structure> event) {
Structure m = (Structure) event.getSelectedItem();
clicListe(m);
}
});
 
setLayout(new FitLayout());
}
 
public ListStore<Structure> getStore() {
return store;
}
 
public TableBinder<Structure> getBinder() {
return binder;
}
 
private void clicListe(Structure institution) {
coelMediateur.clicListeInstitution(institution);
}
 
public void rafraichir(Object nouvelleDonnees) {
if (nouvelleDonnees instanceof ListeStructure) {
ListeStructure listeInstitutions = (ListeStructure) nouvelleDonnees;
setHeading("Institutions");
 
List<Structure> liste = new ArrayList<Structure>();
for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
liste.add(listeInstitutions.get(it.next()));
}
store.removeAll();
store.add((List<Structure>) liste);
// Test pour savoir si la liste contient des éléments
if (listeInstitutions.size() > 0) {
binder.setSelection((Structure) listeInstitutions.get(0));
}
}
}
}