Hi, forum followers
An screen controller class implements following ‘enabledRule’ handlers, for disabling edit and remove standard actions in a table depending on the situation:
@Install(to = "ubicacionsTable.edit", subject = "enabledRule")
private boolean ubicacionsTableEditEnabledRule(){
boolean swEditar;
MovimentUbicacio movimentUbicacio = ubicacionsTable.getSingleSelected();
Ubicacio ubicacio = movimentUbicacio.getUbicacio();
//Comprovació si aquesta instància de MovimentUbicacio està gravada a la BBDD:
MovimentUbicacio movubiBD = movimentUbicacioService.tornaRegistre(movimentUbicacio.getUuid());
//Si no està gravat a la BD no cal comprovar el darrer moviment en la ubicació, perquè vol dir que estàs editant un registre del qual encara no s'ha fet el commit.
if (movubiBD == null){
swEditar = true;
} else {
swEditar = ubicacioService.esDarrerMoviment(ubicacio, movimentUbicacio);
if (!swEditar){
//La ubicació té com a darrer moviment una altra instància de MovimentUbicacio diferent a la que volem editar. No permetre l'edició
notifications.create(Notifications.NotificationType.ERROR).withCaption("No es permet editar el moviment d'aquesta ubicació perqué s'hi ha fet algun moviment posterior").show();
}
}
return swEditar;
}
@Install(to = "ubicacionsTable.remove", subject = "enabledRule")
private boolean ubicacionsTableRemoveEnabledRule(){
boolean swEditar;
MovimentUbicacio movimentUbicacio = ubicacionsTable.getSingleSelected();
Ubicacio ubicacio = movimentUbicacio.getUbicacio();
//Comprovació si aquesta instància de MovimentUbicacio està gravada a la BBDD:
MovimentUbicacio movubiBD = movimentUbicacioService.tornaRegistre(movimentUbicacio.getUuid());
//Si no està gravat a la BD no cal comprovar el darrer moviment en la ubicació, perquè vol dir que estàs editant un registre que encara no s'ha fet el commit.
if (movubiBD == null){
swEditar = true;
} else {
swEditar = ubicacioService.esDarrerMoviment(ubicacio, movimentUbicacio);
if (!swEditar) {
//La ubicació té com a darrer moviment una altra instància de MovimentUbicacio diferent a la que volem editar. No permetre l'edició
notifications.create(Notifications.NotificationType.ERROR).withCaption("No es permet eliminar el moviment d'aquesta ubicació perqué s'hi ha fet algun moviment posterior").show();
}
}
return swEditar;
}
Those handlers include a notification message to inform the user why the action is disabled.
I notice that those handlers are triggered 3 times when item is selected and 8 times when all the transaction is commited, like you can see on the following video:
Is it normal this behaviour? Is there any solution to avoid multiple notifications?
Regards,
Xavier.