Tutoriel: retirer les rendez-vous
#
Ajouter une méthode RendezVous.siIdEst
#
public class RendezVous implements ModelValue {
private String idRendezVous;
// ...
public boolean siIdEst(String idRendezVous) {
return this.idRendezVous.equals(idRendezVous);
}
Ajouter une méthode ModeleFileAttente.retirerRendezVous
#
public class ModeleFileAttente implements Model, WatchJson, WriteObjectGraph {
// ...
// ajouter
private int indiceRendezVousParId(String idRendezVous) {
int indice = -1;
for(int i = 0; i < rendezVousDansOrdre.size(); i++) {
if(rendezVousDansOrdre.get(i).siIdEst(idRendezVous)) {
indice = i;
break;
}
}
return indice;
}
// ajouter
public void retirerRendezVous(String idRendezVous) {
int indiceRendezVous = indiceRendezVousParId(idRendezVous);
if(indiceRendezVous >= 0) {
rendezVousDansOrdre.remove(indiceRendezVous);
}
}
Ajouter le MsgRetirerRendezVous
#
public class MsgRetirerRendezVous extends Message<MsgRetirerRendezVous> {
private String idRendezVous;
public MsgRetirerRendezVous setIdRendezVous(String idRendezVous) {
this.idRendezVous = idRendezVous;
return this;
}
public void retirerDe(ModeleFileAttente fileAttente) {
fileAttente.retirerRendezVous(idRendezVous);
}
}
public class AppPong implements NtroAppFx {
// ...
@Override
public void registerMessages(MessageRegistrar registrar) {
//...
// ajouter
registrar.registerMessage(MsgRetirerRendezVous.class);
}
Modifier FragmentRendezVous
pour envoyer un MsgRetirerRendezVous
#
public class FragmentRendezVous extends ViewFragmentFx {
// ...
// ajouter
@FXML
private Button boutonRetirerRendezVous;
@Override
public void initialize() {
// ajouter
Ntro.assertNotNull(boutonRetirerRendezVous);
// ...
}
// ajouter
public void memoriserIdRendezVous(String idRendezVous) {
installerMsgRetirerRendezVous(idRendezVous);
}
// ajouter
protected void installerMsgRetirerRendezVous(String idRendezVous) {
boutonRetirerRendezVous.setOnAction(evtFx -> {
Ntro.newMessage(MsgRetirerRendezVous.class)
.setIdRendezVous(idRendezVous)
.send();
});
}
Modifier RendezVous
pour mémoriser le idRendezVous
#
public class RendezVous implements ModelValue {
// ...
public void afficherSur(FragmentRendezVous fragmentRendezVous) {
// ajouter
fragmentRendezVous.memoriserIdRendezVous(idRendezVous);
fragmentRendezVous.afficherNomPremierJoueur(premierJoueur.nomCourt());
}
Ajouter une tâche au dorsal dans le groupe ModifierFileAttente
#
public class ModifierFileAttente {
public static void creerTaches(BackendTasks tasks) {
tasks.taskGroup("ModifierFileAttente")
.waitsFor(model(ModeleFileAttente.class))
.contains(subTasks -> {
ajouterRendezVous(subTasks);
// ajouter
retirerRendezVous(subTasks);
});
}
// ...
// ajouter
private static void retirerRendezVous(BackendTasks subTasks) {
subTasks.task("retirerRendezVous")
.waitsFor(model(ModeleFileAttente.class))
.waitsFor(message(MsgRetirerRendezVous.class))
.executes(inputs -> {
MsgRetirerRendezVous msgRetirerRendezVous = inputs.get(message(MsgRetirerRendezVous.class));
ModeleFileAttente fileAttente = inputs.get(model(ModeleFileAttente.class));
msgRetirerRendezVous.retirerDe(fileAttente);
});
}
Vérifier que ça fonctionne
#