New file |
0,0 → 1,169 |
package org.tela_botanica.client.vues; |
|
import java.util.ArrayList; |
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.i18n.Constantes; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.Information; |
import org.tela_botanica.client.modeles.Structure; |
import org.tela_botanica.client.modeles.StructureListe; |
import org.tela_botanica.client.modeles.Utilisateur; |
|
import com.extjs.gxt.ui.client.Registry; |
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.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.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; |
|
public class StructureListeVue extends ContentPanel implements Rafraichissable { |
|
private Mediateur mediateur = null ; |
private Constantes i18nC = null ; |
private Rafraichissable structureListePanneauVue = null ; |
private Table table = null; |
private ListStore<Structure> store = null; |
private TableBinder<Structure> binder = null; |
private TextToolItem modifier; |
private TextToolItem supprimer; |
private TextToolItem ajouter; |
|
public StructureListeVue(Mediateur mediateurCourant) { |
mediateur = mediateurCourant; |
i18nC = mediateur.i18nC; |
|
Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT); |
structureListePanneauVue = this; |
|
ToolBar toolBar = new ToolBar(); |
ajouter = new TextToolItem(i18nC.ajouter()); |
ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER); |
ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
mediateur.clicAjouterStructure(); |
} |
}); |
toolBar.add(ajouter); |
|
modifier = new TextToolItem(i18nC.modifier()); |
modifier.setIconStyle(ComposantClass.ICONE_MODIFIER); |
modifier.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
mediateur.clicModifierStructure(binder.getSelection()); |
} |
}); |
toolBar.add(modifier); |
|
supprimer = new TextToolItem(i18nC.supprimer()); |
supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER); |
supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() { |
public void componentSelected(ComponentEvent ce) { |
mediateur.clicSupprimerStructure(structureListePanneauVue, binder.getSelection()); |
} |
}); |
if (!utilisateur.isIdentifie()) { |
supprimer.disable(); |
} |
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", i18nC.ville(), .3f)); |
columns.add(new TableColumn("nom", i18nC.nom(), .7f)); |
|
TableColumnModel cm = new TableColumnModel(columns); |
table = new Table(cm); |
table.setSelectionMode(SelectionMode.MULTI); |
table.setBorders(false); |
table.setStripeRows(true); |
add(table); |
|
|
store = new ListStore<Structure>(); |
store.sort("ville", SortDir.ASC); |
|
binder = new TableBinder<Structure>(table, store); |
binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() { |
public void selectionChanged(SelectionChangedEvent<Structure> event) { |
Structure m = (Structure) event.getSelectedItem(); |
clicListe(m); |
} |
}); |
|
setLayout(new FitLayout()); |
} |
|
private void clicListe(Structure structure) { |
if (store.getCount() > 0) { |
mediateur.clicListeStructure(structure); |
} |
} |
|
public void rafraichir(Object nouvelleDonnees) { |
if (nouvelleDonnees instanceof StructureListe) { |
StructureListe structures = (StructureListe) nouvelleDonnees; |
setHeading(i18nC.titreStructureListe()); |
|
List<Structure> liste = (List<Structure>) structures.toList(); |
store.removeAll(); |
store.add(liste); |
|
mediateur.actualiserPanneauCentral(); |
|
if (store.getCount() > 0) { |
table.getSelectionModel().select(0); |
} |
} else if (nouvelleDonnees instanceof Information) { |
Information info = (Information) nouvelleDonnees; |
if (info.getType().equals("suppression_structure")) { |
// Affichage d'un message d'information |
//GWT.log(info.toString(), null); |
Info.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />")); |
|
// Suppression des structures sélectionnées |
List<TableItem> selectionStructure = table.getSelectedItems(); |
final int taille = selectionStructure.size(); |
for (int i = 0; i < taille; i++) { |
//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null); |
table.remove(selectionStructure.get(i)); |
} |
|
// Désactivation des boutons si la liste est vide |
if (table.getItemCount() == 0) { |
supprimer.disable(); |
modifier.disable(); |
} |
} else if (info.getType().equals("maj_utilisateur")) { |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) { |
if (table.getItemCount() != 0) { |
supprimer.enable(); |
} |
} else { |
supprimer.disable(); |
} |
} |
} else { |
GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null); |
} |
layout(); |
} |
} |