3,7 → 3,6 |
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; |
15,11 → 14,8 |
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.ButtonEvent; |
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; |
27,22 → 23,21 |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Info; |
import com.extjs.gxt.ui.client.widget.button.Button; |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel; |
import com.extjs.gxt.ui.client.widget.grid.Grid; |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel; |
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.ToolBar; |
import com.google.gwt.core.client.GWT; |
|
public class CollectionListeVue extends ContentPanel implements Rafraichissable { |
|
private Mediateur mediateur = null ; |
private Constantes i18nC = null ; |
private Mediateur mediateur = null; |
private Constantes i18nC = null; |
|
private Table table = null; |
private Grid<Collection> grille = null; |
private ListStore<Collection> store = null; |
private TableBinder<Collection> binder = null; |
|
private Button modifier; |
private Button supprimer; |
52,7 → 47,8 |
mediateur = mediateurCourant; |
i18nC = mediateur.i18nC; |
|
Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT); |
setLayout(new FitLayout()); |
setHeading(i18nC.collectionListeTitre()); |
|
ToolBar toolBar = new ToolBar(); |
ajouter = new Button(i18nC.ajouter()); |
68,7 → 64,7 |
modifier.setIcon(Images.ICONES.formModifier()); |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent ce) { |
mediateur.clicModifierCollection(binder.getSelection()); |
mediateur.clicModifierCollection(grille.getSelectionModel().getSelectedItems()); |
} |
}); |
toolBar.add(modifier); |
77,44 → 73,36 |
supprimer.setIcon(Images.ICONES.supprimer()); |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent ce) { |
clicSupprimerCollection(binder.getSelection()); |
clicSupprimerCollection(grille.getSelectionModel().getSelectedItems()); |
} |
}); |
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("nom", i18nC.nom(), .5f)); |
columns.add(new TableColumn("structure_nom", i18nC.structure(), .3f)); |
columns.add(new TableColumn("structure_ville", i18nC.ville(), .2f)); |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>(); |
colonnes.add(new ColumnConfig("nom", i18nC.nom(), 300)); |
colonnes.add(new ColumnConfig("structure_nom", i18nC.structure(), 200)); |
colonnes.add(new ColumnConfig("structure_ville", i18nC.ville(), 150)); |
colonnes.get(1).setHidden(true); |
ColumnModel modeleDeColonne = new ColumnModel(colonnes); |
|
columns.get(1).setHidden(true); |
GridSelectionModel<Collection> modeleDeSelection = new GridSelectionModel<Collection>(); |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Collection>() { |
public void selectionChanged(SelectionChangedEvent<Collection> event) { |
Collection collectionSelectionnee = (Collection) event.getSelectedItem(); |
clicListe(collectionSelectionnee); |
} |
}); |
|
TableColumnModel cm = new TableColumnModel(columns); |
table = new Table(cm); |
table.setSelectionMode(SelectionMode.MULTI); |
table.setBorders(false); |
table.setStripeRows(true); |
add(table); |
|
|
store = new ListStore<Collection>(); |
store.sort("nom", SortDir.ASC); |
|
binder = new TableBinder<Collection>(table, store); |
binder.addSelectionChangedListener(new SelectionChangedListener<Collection>() { |
public void selectionChanged(SelectionChangedEvent<Collection> event) { |
Collection m = (Collection) event.getSelectedItem(); |
clicListe(m); |
} |
}); |
|
setLayout(new FitLayout()); |
grille = new Grid<Collection>(store, modeleDeColonne); |
grille.setWidth("100%"); |
grille.setAutoExpandColumn("nom"); |
grille.setSelectionModel(modeleDeSelection); |
add(grille); |
} |
|
private void clicListe(Collection m) { |
128,49 → 116,52 |
mediateur.clicSupprimerCollection(this, collectionsASupprimer); |
} |
} |
|
private void gererEtatActivationBouton() { |
int nbreElementDuMagazin = store.getCount(); |
if (nbreElementDuMagazin == 0) { |
supprimer.disable(); |
modifier.disable(); |
} else if (nbreElementDuMagazin > 0) { |
modifier.enable(); |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) { |
supprimer.enable(); |
} |
} |
} |
|
public void rafraichir(Object nouvelleDonnees) { |
if (nouvelleDonnees instanceof CollectionListe) { |
CollectionListe collections = (CollectionListe) nouvelleDonnees; |
setHeading(i18nC.collectionListeTitre()); |
|
List<Collection> liste = (List<Collection>) collections.toList(); |
store.removeAll(); |
store.add(liste); |
|
mediateur.actualiserPanneauCentral(); |
|
if (store.getCount() > 0) { |
table.getSelectionModel().select(0, 0, true); |
if (collections != null) { |
List<Collection> liste = (List<Collection>) collections.toList(); |
store.removeAll(); |
store.add(liste); |
|
mediateur.actualiserPanneauCentral(); |
|
if (store.getCount() > 0) { |
grille.getSelectionModel().select(0, false); |
} |
} |
} else if (nouvelleDonnees instanceof Information) { |
Information info = (Information) nouvelleDonnees; |
if (info.getType().equals("suppression_collection")) { |
// Affichage d'un message d'information |
//GWT.log(info.toString(), null); |
Info.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />")); |
|
// Suppression des structures sélectionnées |
List<TableItem> selectionCollection = table.getSelectedItems(); |
List<Collection> selectionCollection = grille.getSelectionModel().getSelectedItems(); |
final int taille = selectionCollection.size(); |
for (int i = 0; i < taille; i++) { |
//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null); |
table.remove(selectionCollection.get(i)); |
store.remove(selectionCollection.get(i)); |
} |
|
// Désactivation des boutons si la liste est vide |
if (table.getItemCount() == 0) { |
supprimer.disable(); |
modifier.disable(); |
} |
gererEtatActivationBouton(); |
} else if (info.getType().equals("maj_utilisateur")) { |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) { |
if (table.getItemCount() != 0) { |
supprimer.enable(); |
} |
} else { |
supprimer.disable(); |
} |
gererEtatActivationBouton(); |
} |
} else { |
GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null); |