New file |
0,0 → 1,179 |
package org.tela_botanica.client.vues; |
|
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.List; |
|
import org.tela_botanica.client.ComposantClass; |
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.Information; |
import org.tela_botanica.client.modeles.Personne; |
import org.tela_botanica.client.modeles.PersonneListe; |
|
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.Scroll; |
import com.extjs.gxt.ui.client.Style.SelectionMode; |
import com.extjs.gxt.ui.client.Style.SortDir; |
import com.extjs.gxt.ui.client.binder.TableBinder; |
import com.extjs.gxt.ui.client.event.ComponentEvent; |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent; |
import com.extjs.gxt.ui.client.event.SelectionChangedListener; |
import com.extjs.gxt.ui.client.event.SelectionListener; |
import com.extjs.gxt.ui.client.store.ListStore; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Info; |
import com.extjs.gxt.ui.client.widget.LayoutContainer; |
import com.extjs.gxt.ui.client.widget.form.LabelField; |
import com.extjs.gxt.ui.client.widget.layout.FitLayout; |
import com.extjs.gxt.ui.client.widget.layout.FormLayout; |
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.table.TableItem; |
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem; |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; |
import com.google.gwt.core.client.GWT; |
import com.google.gwt.user.client.Window; |
|
public class PersonneListeVue extends ContentPanel implements Rafraichissable { |
|
private Mediateur mediateur = null ; |
private Table table = null; |
private ListStore<Personne> store = null; |
private TableBinder<Personne> binder = null; |
private Personne personneSelectionnee = null; |
|
public PersonneListeVue() { |
mediateur = Registry.get(RegistreId.MEDIATEUR); |
|
//Définition de la barre d'outil |
ToolBar toolBar = new ToolBar(); |
TextToolItem ajouter = new TextToolItem("Ajouter"); |
ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER); |
ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
mediateur.clicAjouterPersonne(); |
} |
}); |
toolBar.add(ajouter); |
|
|
final Rafraichissable r = this ; |
|
// TODO : ajouter btn mod & supp |
final TextToolItem modifier = new TextToolItem("Modifier"); |
modifier.setIconStyle(ComposantClass.ICONE_MODIFIER); |
modifier.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
mediateur.clicModifierPersonne(personneSelectionnee); |
} |
}); |
toolBar.add(modifier); |
|
final TextToolItem supprimer = new TextToolItem("Supprimer"); |
supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
|
mediateur.clicSupprimerPersonne(r, binder.getSelection()); |
} |
}); |
|
supprimer.setIconStyle(ComposantClass.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("fmt_nom_complet", "Nom Complet", .20f)); |
columns.add(new TableColumn("nom", "Nom", .20f)); |
columns.add(new TableColumn("code_postal", "Code Postal", .10f)); |
columns.add(new TableColumn("ville", "Ville", .20f)); |
columns.add(new TableColumn("courriel_princ", "Courriel", .25f)); |
|
TableColumnModel cm = new TableColumnModel(columns); |
|
table = new Table(cm); |
table.setSelectionMode(SelectionMode.MULTI); |
table.setBorders(false); |
|
table.setHorizontalScroll(true); |
|
add(table); |
|
store = new ListStore<Personne>(); |
|
binder = new TableBinder<Personne>(table, store); |
binder.setAutoSelect(true); |
|
binder.addSelectionChangedListener(new SelectionChangedListener<Personne>() { |
public void selectionChanged(SelectionChangedEvent<Personne> event) { |
Personne p = (Personne) event.getSelectedItem(); |
personneSelectionnee = p; |
clicListe(p); |
} |
}); |
|
setLayout(new FitLayout()); |
} |
|
private void clicListe(Personne personne) { |
mediateur.clicListePersonne(personne); |
} |
|
public void rafraichir(Object nouvellesDonnees) { |
|
if (nouvellesDonnees instanceof PersonneListe) { |
|
setHeading("Personnes"); |
PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees; |
|
List<Personne> liste = new ArrayList<Personne>(); |
for (Iterator<String> it = listePersonnes.keySet().iterator(); it.hasNext();) { |
liste.add(listePersonnes.get(it.next())); |
} |
|
store.removeAll(); |
store.add(liste); |
|
mediateur.actualiserPanneauCentral(); |
|
table.sort(0, SortDir.ASC); |
if (store.getCount() > 0) { |
table.getSelectionModel().select(0); |
} |
|
|
|
} else if (nouvellesDonnees instanceof Information) { |
|
Information info = (Information) nouvellesDonnees; |
Info.display("Erreur", info.getMessages().toString()); |
|
if (info.getType().equals("suppression_personne")) { |
|
List<TableItem> selectionPersonnes = table.getSelectedItems(); |
final int taille = selectionPersonnes.size(); |
for (int i = 0; i < taille; i++) { |
//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null); |
table.remove(selectionPersonnes.get(i)); |
} |
} |
|
|
|
} else { |
GWT.log("Pas de correspondance" + nouvellesDonnees.getClass() + " dans la méthode rafraichir() de la classe "+this.getClass(), null); |
} |
layout(); |
} |
} |
|
|
|
|
|
|