NF2.1 Ask Input Within Process
Caratteristica: Chiedere l'immissione all'interno del processo
Obiettivo: Sviluppo
Sviluppatore: Jan Thielemann
Info tecniche: IDEMPIERE-1773
Descrizione:
Nell'eseguire un processo dal GUI, hai ora due metodi per interagire con l'utente. Nella sottoclasse di SvrProcess puoi chiamare il processo UI per chiedere delle immissioni String o boolean. Ecco un esempio di come usare il metodo askForInput():
final StringBuffer string = new StringBuffer();
final StringBuffer stringcaptured = new StringBuffer();
processUI.askForInput("Please enter a String:", new Callback<String>() {
@Override public void onCallback(String result) { addLog("You entered: " + result); string.append(result); stringcaptured.append("true"); }
});
int timeoutInSeconds = 5;
int sleepms = 200;
int maxcycles = timeoutInSeconds * 1000 / sleepms;
int cycles = 0;
while (stringcaptured.length() == 0) {
try { Thread.sleep(sleepms); } catch (InterruptedException e) {} cycles++; if (cycles > maxcycles) throw new AdempiereUserError("Timeout waiting for user answer"); }
String userinput = string.toString();
Nota che dobbiamo usare oggetti finale così che possano essere usati nel callback. Usare un StringBuffer è una buona idea in questo caso. Nota inoltre che abbiamo implementato un timeout perchè un processo produce molti blocchi.



