| 12
 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
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 
 | package fr.jl2tho.gwt.tutorial.client;
 
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.NumberFormat;
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.Label;
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.TextBox;
import com.google.gwt.user.client.ui.Widget;
 
import fr.jl2tho.gwt.tutorial.client.common.NumberText;
import fr.jl2tho.gwt.tutorial.server.ListeCompteServiceImpl;
 
@SuppressWarnings("deprecation")
public class AcListBox extends DialogBox {
 
private AbsolutePanel posContainer; // AbsolutePanel qui contient tous les
 
// controles
 
private FlexTable table;
 
private int lastTableRow = 0;
 
private int selectedRow = -1;
 
private NumberText soldeIT;
 
private TextBox prenomIT;
 
private TextBox nomIT;
 
private Button modifierPB;
 
private Button ajouterPB;
 
private Button supprimerPB;
 
ServiceDefTarget endpoint;
 
ListeCompteServiceAsync compteService;
 
private TextBox lineIT;
 
public AcListBox() {
 
super();
 
setText("Academical test for list");
 
this.setSize("800px", "600px");
 
posContainer = new AbsolutePanel();
 
posContainer.setSize("800px", "600px");
 
setWidget(posContainer);
 
 
 
 
 
Button closeButton = new Button("Close");
 
closeButton.addClickListener(new ClickListener() {
 
public void onClick(Widget sender) {
 
AcListBox.this.hide();
 
}
 
});
 
 
// Ce paneau n'accepte qu'un seul widget : il faut donc utiliser
 
// setWidget et non pas add.
 
posContainer.add(closeButton, 730, 530);
 
// **************** Debut du code fonctionnel
 
// ****************************
 
// 1) Creation de la FlexTable qui contiendra le titre
 
FlexTable tableH = new FlexTable();
 
// Setup the table.
 
tableH.setCellSpacing(0);
 
tableH.setCellPadding(0);
 
tableH.setWidth("100%");
 
tableH.setStyleName("Jl2tho-ListHeader");
 
// Creation de la ligne de titre et de la definition des colonnes.
 
tableH.setText(0, 0, "Nom");
 
tableH.getColumnFormatter().setWidth(0, "300px");
 
tableH.setText(0, 1, "Prénom");
 
tableH.getColumnFormatter().setWidth(1, "300px");
 
tableH.setText(0, 2, "Solde Compte");
 
tableH.getColumnFormatter().setWidth(2, "149px");
 
// La 3eme colonne doit afficher des nombres allignes a droite
 
tableH.getColumnFormatter().addStyleName(2, "Jl2tho-NumberColumn");
 
// 2) Creation de la FlexTable qui contiendra la liste
 
table = new FlexTable();
 
// Setup the table.
 
table.setCellSpacing(0);
 
table.setCellPadding(0);
 
table.setWidth("100%");
 
table.setStyleName("Jl2tho-List");
 
// Definit les colonnes de la liste
 
table.getColumnFormatter().setWidth(0, "300px");
 
table.getColumnFormatter().setWidth(1, "300px");
 
table.getColumnFormatter().setWidth(2, "149px");
 
table.getColumnFormatter().addStyleName(2, "Jl2tho-NumberColumn");
 
 
// 3) Creation du ScrollPanel qui contient la liste precedente.
 
// cest le scollpanel qui assure lapparition de lascenseur.
 
ScrollPanel listPanel = new ScrollPanel(table);
 
listPanel.addStyleName("Jl2tho-listePanel");
 
// Le panneau occupe tout lespace disponible
 
listPanel.setHeight("100%");
 
listPanel.setWidth("100%");
 
// 4) Creation du FlowPanel qui contient :
 
// - la table contenant le titre
 
// - le ScrollPanel contenant la liste.
 
FlowPanel listFlowPanel = new FlowPanel();
 
// Il est impératif de définir la taille du FlowPanel
 
listFlowPanel.setSize("770px", "220px");
 
// On ne donne pas de position, chaque widget prend tout lespace
 
// disponible.
 
listFlowPanel.add(tableH);
 
listFlowPanel.add(listPanel);
 
// 5) On ajoute la liste a la fenetre :
 
posContainer.add(listFlowPanel, 10, 31);
 
insertInList("Durand", "Arthur", 1232.30);
 
insertInList("Dupond", "Daniel", 50000);
 
insertInList("Dupont", "Thierry", -50.30);
 
table.addTableListener(new TableListener() {
 
public void onCellClicked(SourcesTableEvents sender, int row,
 
int cell) {
 
// Select the row that was clicked (-1 to account for header
 
// row).
 
if (row > 0) {
 
selectRow(row - 1);
 
// Ajout pour la copie
 
nomIT.setText(table.getText(row, 0));
 
prenomIT.setText(table.getText(row, 1));
 
if (table.getCellFormatter().getStyleName(row, 2).equals(
 
"redText")) {
 
soldeIT.setText("-" + table.getText(row, 2));
 
} else {
 
soldeIT.setText(table.getText(row, 2));
 
}
 
}
 
}
 
});
 
// Ajout des controles textes :
 
Label simpleLabel = new Label("Nom");
 
posContainer.add(simpleLabel, 10, 283);
 
simpleLabel = new Label("Prénom");
 
posContainer.add(simpleLabel, 10, 319);
 
simpleLabel = new Label("Solde compte");
 
posContainer.add(simpleLabel, 10, 355);
 
soldeIT = new NumberText();
 
posContainer.add(soldeIT, 115, 353);
 
prenomIT = new TextBox();
 
posContainer.add(prenomIT, 115, 317);
 
nomIT = new TextBox();
 
posContainer.add(nomIT, 115, 281);
 
modifierPB = new Button("Modifier");
 
modifierPB.setWidth("90px");
 
posContainer.add(modifierPB, 408, 528);
 
ajouterPB = new Button("Ajouter");
 
ajouterPB.setWidth("90px");
 
posContainer.add(ajouterPB, 506, 528);
 
supprimerPB = new Button("Supprimer");
 
supprimerPB.setWidth("90px");
 
posContainer.add(supprimerPB, 604, 528);
 
supprimerPB.addClickListener(new ClickListener() {
 
public void onClick(Widget sender) {
 
if (selectedRow > 0) {
 
// Deselectionner l'affichage
 
styleRow(selectedRow, false);
 
// supprimer la ligne
 
table.removeRow(selectedRow);
 
// effacer les champs de saisi
 
nomIT.setText("");
 
prenomIT.setText("");
 
soldeIT.setText("");
 
selectedRow = -1;
 
}
 
}
 
});
 
modifierPB.addClickListener(new ClickListener() {
 
public void onClick(Widget sender) {
 
if (table.getCellFormatter().getStyleName(selectedRow + 1, 2)
 
.equals("redText")) {
 
table.getCellFormatter().removeStyleName(selectedRow + 1,
 
2, "redText");
 
}
 
table.setText(selectedRow + 1, 0, nomIT.getText());
 
table.setText(selectedRow + 1, 1, prenomIT.getText());
 
double newValue = soldeIT.getValuee();
 
if (newValue < 0) {
 
table.getCellFormatter().addStyleName(selectedRow + 1, 2,
 
"redText");
 
newValue = -newValue;
 
NumberFormat.getDecimalFormat().format(selectedRow);
 
}
 
table.setText(selectedRow + 1, 2, NumberFormat.getFormat(
 
"#,##0.00").format(newValue));
 
}
 
});
 
 
ajouterPB.addClickListener(new ClickListener() {
 
 
	public void onClick(Widget sender) {
 
		System.out.println("Je suis cool avant inser");
	insertInList(nomIT.getText(),prenomIT.getText(), soldeIT.getValuee());
 
	// (3) Create an asynchronous callback to handle the result.
	System.out.println("Je suis cool apres insert");
 
 
	// (4) Make the call. Control flow will continue immediately and later
 
	// 'callback' will be invoked when the RPC completes.
 
	lineIT.setText("Avant");
	System.out.println("Je suis cool avant");
	getService().addCompte(nomIT.getText(),prenomIT.getText(), soldeIT.getValuee(), 
 
			 new AsyncCallback<Object>() {
 
		public void onSuccess(Object result) {
			System.out.println("Je suis cool reussi");
		lineIT.setText(lineIT.getText()+"Reussi");
 
		}
 
		public void onFailure(Throwable caught) {
 
			lineIT.setText(lineIT.getText()+"échoué");
 
		}
 
		});
 
	lineIT.setText(lineIT.getText()+"Apres");
	System.out.println("Je suis cool apres");
	}
 
	});
}
 
public void insertInList(String col1, String col2, double col3) {
 
int i = lastTableRow++;
 
table.setText(i + 1, 0, col1);
 
table.setText(i + 1, 1, col2);
 
setColonneNombre(i, col3);
 
}
 
public void setColonneNombre(int row, double colValue) {
 
if (colValue < 0) {
 
table.getCellFormatter().addStyleName(row + 1, 2, "redText");
 
colValue = -colValue;
 
}
 
table.setText(row + 1, 2, NumberFormat.getFormat("#,##0.00").format(
 
colValue));
 
}
 
private void selectRow(int row) {
 
styleRow(selectedRow, false);
 
styleRow(row, true);
 
selectedRow = row;
 
}
 
private void styleRow(int row, boolean selected) {
 
if (row != -1) {
 
if (selected) {
 
table.getRowFormatter().addStyleName(row + 1,
 
"jl2tho-SelectedRow");
 
} else {
 
table.getRowFormatter().removeStyleName(row + 1,
 
"jl2tho-SelectedRow");
 
}
 
}
 
}
 
 
 
 
 
public ListeCompteServiceAsync getService(){
 
//Creation et initialisation du proxy client permettant lappel du service : compte
 
//1) Creation du stub
 
compteService = (ListeCompteServiceAsync) GWT.create(ListeCompteService.class);
 
//2) Definir lURL : elle doit appartenir au meme domaine que la page html Host
 
endpoint = (ServiceDefTarget) compteService;
 
String moduleRelativeURL = GWT.getModuleBaseURL() + "/compte";
 
endpoint.setServiceEntryPoint(moduleRelativeURL);
 
//Fin initialisation du proxy client.
 
return compteService;
}
} | 
Partager