1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
|
package webpage.client;
import java.util.Vector;
import webpage.client.GeoLocRemoteService;
import webpage.client.GeoLocRemoteServiceAsync;
import webpage.client.SelectBDD;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SourcesTableEvents;
import com.google.gwt.user.client.ui.TableListener;
import com.google.gwt.user.client.ui.Widget;
import com.gwtext.client.widgets.MessageBox;
public class FenListe extends DialogBox
implements ClickListener, TableListener {
/**
* Hauteur des boutons de la fenêtre
*/
final int hautButton = 30;
/**
* Longueur des boutons de la fenêtre
*/
final int longButton = 100;
/**
* Position horizontale des boutons
*/
final int horiButton = 745 - longButton;
/**
* Largeur de la liste
*/
final int largList = 735 - longButton;
/**
* Hauteur de la liste
*/
final int hautList = 420;
/**
* Conteneur de la fenêtre
*/
private GeoLocRemoteServiceAsync service = null;
private ServiceDefTarget endpoint = null;
private AbsolutePanel conteneur = null;
/**
* Bouton "Fermer"
*/
private Button closeButton = null;
/**
* Bouton ajouter
*/
private Button addButton = null;
/**
* Bouton modifier
*/
private Button editButton = null;
/**
* Bouton supprimer
*/
private Button deleteButton = null;
/**
* Panel de la liste
*/
private FlowPanel tableFlowPanel = null;
/**
* Entete de la liste
*/
private FlexTable headerTable = null;
/**
* ScrollPanel
*/
private ScrollPanel scroll = null;
/**
* Liste
*/
private FlexTable table = null;
/**
* Nombre d'enregistrement dans la table
*/
private int lastTableRow = 0;
/**
* Table cible dans la BDD
*/
private String tableBDD = null;
/**
* Ligne selectionée
*/
private int selectedRow = 0;
/**
* identifiant BDD de la ligne sélectionnée
*/
private int selected = -1;
/**
* titre de la fenêtre
*/
private String titre=null;
// CONSTRUCTEUR
/**
* Constructeur
*/
public FenListe(String entite) {
super(false, true);
tableBDD = entite;
this.init();
}
//INITIALISATION DE LA FENETRE
/**
* Fonction d'initialisation de la fenêtre
*/
private void init() {
// Création et init du proxy client
service = (GeoLocRemoteServiceAsync) GWT.create(GeoLocRemoteService.class);
// Définition de l'URL
endpoint = (ServiceDefTarget) service;
String moduleRelativeURL = GWT.getModuleBaseURL() + "SelectBDD";
endpoint.setServiceEntryPoint(moduleRelativeURL);
// fin init proxy client
this.setSize("750px", "450px");
this.setWidget(this.getConteneur());
this.recup();
this.changerLargColonne(0, 0);// On cache l'index de la BDD
this.center();
}
// CREATION DES PANEL
/**
* Fonction de création du Conteneur de la fenêtre
* @return conteneur Le conteneur
*/
private AbsolutePanel getConteneur() {
if (conteneur == null) {
conteneur = new AbsolutePanel();
conteneur.setSize("750px", "450px");
conteneur.add(this.getCloseButton(), horiButton, 415);
conteneur.add(this.getAddButton(), horiButton, 5);
conteneur.add(this.getEditButton(), horiButton, 36);
conteneur.add(this.getDeleteButton(), horiButton, 67);
conteneur.add(this.getTableFlowPanel(), 5, 5);
}
return conteneur;
}
/**
* Création du panel qui contiendra la liste des véhicules
* @return tableFlowPanel
*/
private FlowPanel getTableFlowPanel() {
if (tableFlowPanel == null) {
tableFlowPanel = new FlowPanel();
tableFlowPanel.setHeight("100%");
tableFlowPanel.setWidth(largList + "px");
tableFlowPanel.add(this.getHeaderTable());
tableFlowPanel.add(this.getScroll());
}
return tableFlowPanel;
}
/**
* Création de l'entete de la liste
* @return headerTable
*/
private FlexTable getHeaderTable() {
if (headerTable == null) {
headerTable = new FlexTable();
headerTable.addStyleName("Table-ListeHeader");
headerTable.setCellSpacing(0);
headerTable.setCellPadding(0);
headerTable.setWidth(largList + "px");
}
return headerTable;
}
/**
* Création du ScrollPane
* @return scroll
*/
private ScrollPanel getScroll() {
if (scroll == null) {
scroll = new ScrollPanel(this.getTable());
scroll.addStyleName("Table-ListePanel");
scroll.setHeight(hautList + "px");
scroll.setWidth(largList + "px");
}
return scroll;
}
/**
* Création de la liste
* @return table
*/
private FlexTable getTable() {
if (table == null) {
table = new FlexTable();
table.setCellSpacing(0);
table.setCellPadding(0);
table.setWidth(largList + "px");
table.setStyleName("Table-List");
table.addTableListener(this);
}
return table;
}
// CREATION DES BOUTONS
/**
* Fonction de création du bouton "supprimer"
* @return deleteButton
*/
private Button getDeleteButton() {
if (deleteButton == null) {
deleteButton = new Button("Supprimer", this);
deleteButton.setPixelSize(longButton, hautButton);
deleteButton.setEnabled(false);
}
return deleteButton;
}
/**
* Fonction de création du bouton "Modifier"
* @return editButton Le bouton "Modifier"
*/
private Button getEditButton() {
if (editButton == null) {
editButton = new Button("Modifier", this);
editButton.setPixelSize(longButton, hautButton);
editButton.setEnabled(false);
}
return editButton;
}
/**
* Fonction de création du bouton Ajouter
* @return
*/
private Button getAddButton() {
if (addButton == null) {
addButton = new Button("Ajouter", this);
addButton.setPixelSize(longButton, hautButton);
}
return addButton;
}
/**
* Fonction de création du bouton Fermer
* @return Button Le bouton Fermer
*/
private Button getCloseButton() {
if (closeButton == null) {
closeButton = new Button("Fermer", this);
closeButton.setPixelSize(longButton, hautButton);
}
return closeButton;
}
// FONCTION OUTILS
/**
* Insertion d'enregistrement visuellement dans la liste
* @param String La chaîne de charactères à ajouter au tableau
*/
public void insertInList(String col1) {
int i = lastTableRow++;
table.setText(i + 1, 0, col1);
}
/**
* Fonction pour recupérer les enregistrement dans la BDD et les inserer dans la liste
*/
private void recup() {
String query = "Select * from " + tableBDD + ";";
service.getSelectBDD(query, new AsyncCallback<SelectBDD>() {
public void onFailure(Throwable caught) {
}
public void onSuccess(SelectBDD result) {
Vector<Vector<String>> list = null;
int tailleList = 0;
int tailleLigne = 0;
list = result.getList();
tailleList = list.size();
tailleLigne = list.elementAt(0).size();
for (int i = 0; i < tailleList; i++) {
for (int j = 1; j < tailleLigne; j++) {
insertInList(list.elementAt(i).elementAt(j));
}
}
}
});
}
/**
* Fonction pour changer la taille d'une colonne
* @param int col L'index de la colonne
* @param int larg La nouvelle largeur
*/
public void changerLargColonne(int col, int larg) {
headerTable.getColumnFormatter().setWidth(col, larg + "px");
table.getColumnFormatter().setWidth(col, larg + "px");
}
/**
* Fonction de selection des lignes
* @param row int La ligne clickée
*/
private void selectRow(int row) {
styleRow(selectedRow, false);
styleRow(row, true);
selectedRow = row;
}
/**
* Fonction pour changer le style de la selection
* @param row int La ligne clickée
* @param selected boolean
*/
private void styleRow(int row, boolean selected) {
if (row != -1) {
// Activation des boutons
this.activeBouton(true);
if (selected) {
table.getRowFormatter().addStyleName(row + 1,"Table-SelectedRow");
} else {
table.getRowFormatter().removeStyleName(row + 1,"Table-SelectedRow");
}
}
}
/**
* Fonction pour l'activation des boutons modifier et supprimer
* @param boolean Etat: activation/désactivation
*/
private void activeBouton(boolean etat) {
this.getEditButton().setEnabled(etat);
this.getDeleteButton().setEnabled(etat);
}
/**
* Fonction pour récuperer la ligne selectionnée
* @return int La ligne visuellement selectionnée
*/
public int getSelectedRow() {
return selectedRow;
}
/**
* Fonction pour modifier une cellule
*/
public void modifLigne(int row, int col, String text) {
table.setText(row + 1, col, text);
}
/**
* Fonction supprimer
*/
private void supprimer() {
String query = "Delete from " + tableBDD + " where immatriculation='"
+ selected + "';";
service.setBDD(query, new AsyncCallback<Object>() {
public void onFailure(Throwable caught) {
}
public void onSuccess(Object result) {
styleRow(selectedRow, false);
table.removeRow(selectedRow);
activeBouton(false);
}
});
}
/**
* Fonction pour editer le titre de la fenetre
* @param newTitre
*/
public void editTitre(String newTitre)
{
this.titre=newTitre;
this.setText(titre);
}
/**
* Fonction pour afficher le detail de la ligne selectio
* @param fenDetail
*/
public void afficherDetail(DialogBox fenDetail){
fenDetail.show();
}
// LISTENER DE LA FENETRE
/**
* Listener de click
* @param sender La source du click
*/
public void onClick(Widget sender) {
// Gestion des click sur les boutons
if (sender.getClass() == Button.class) {
// Bouton Ajouter
if (sender.equals(this.getAddButton())) {
}
// Bouton Fermer
else if (sender.equals(this.getCloseButton())) {
this.hide();
}
// Bouton Supprimer
else if (sender.equals(this.getDeleteButton())) {
MessageBox.confirm("Suppression " + titre, "Confirmer?",
new MessageBox.ConfirmCallback() {
public void execute(String btnID) {
if (btnID.toLowerCase().equals("yes")) {
supprimer();
}
}
});
}
// Bouton Modifier
else if (sender.equals(this.getEditButton())) {
}
}
}
/**
* Listener de la table
* @param sender SourcesTableEvents L'évenement
* @param row int La ligne
* @param cell int La cellule
*/
public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
if (row > 0) {
selectRow(row - 1);
selected = Integer.parseInt(table.getText(row, 0));
}
}
} |
Partager