Creating simple dialogs from inside SvrProcess doit () method - "Components can be accessed only in event listeners"

328 views
Skip to first unread message

Neil Gordon

unread,
Jun 24, 2014, 3:03:46 PM6/24/14
to idem...@googlegroups.com
Please can I ask for assistance with the following.

We are using iDempiere Release-2.0:

1. How do I get the currently selected tab (that is, the tab which invoked the process), and requery the data in the tab, from within the doIt() method of a SvrProcess?

2. How do I implement the following code, from within the doIt() method of a SvrProcess, which used to work in Release-1.0c:

    boolean continueSubmit = FDialog.ask(0, null, "Do you want to continue?");

I now receive the error: "Components can be accessed only in event listeners".

I implemented a static helper method which provides a callback (please see the method a little further down). The problem is , that in my SvrProcess, if I update the record which is referenced by the window, then the window is not also updated (it needs to be refreshed manually), because of the asynchronous nature of the operation. Hence my question no. 1 above.

I also wonder, if there isn't a simpler way to do this, as there was in version 1?

Your assistance would be highly appreciated.

Here is the static helper method, which uses AEnv.executeAsyncDesktopTask:

public static void showDialogAsk(final String msg, final Callback<Boolean> callback) {
     
      Runnable runnable = new Runnable() {
     
      @Override
      public void run() {
          FDialog.ask(0, null, msg, callback);
      }
    };
    AEnv.executeAsyncDesktopTask(runnable);   
}

References:

https://groups.google.com/forum/#!searchin/idempiere/Components$20can$20be$20accessed$20only$20in$20event$20listeners/idempiere/BZmV94A2FbQ/k1JYzQwIsh8J
https://groups.google.com/forum/#!searchin/idempiere/Components$20can$20be$20accessed$20only$20in$20event$20listeners/idempiere/HBoEo2Yx1dc/g3bd9t3w4NEJ

-----
Neil Gordon
nTier Software Services


Edwin Ang

unread,
Jun 24, 2014, 11:26:55 PM6/24/14
to idem...@googlegroups.com
Hi Neil,

Jan Thielemann has written this nice tutorial here. I think this is what you are looking for.



Regards,

Edwin Ang



--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/faa81e36-7941-4185-8750-85c84c010650%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Neil Gordon

unread,
Jun 25, 2014, 4:13:14 AM6/25/14
to idem...@googlegroups.com
Edwin,

Thank you very much, that was a great help indeed.

The answer is to be found in the comments which are found in IProcessUI.ask, which I found after reading your reply. I am repeating it here in case it helps anyone:

final StringBuffer answer = new StringBuffer();
aProcessMonitor.ask(adMessage, new Callback<String>() {              
    @Override
    public void onCallback(String result) {
        answer.append(result != null ? result : "-");
    }
});


-----
Neil Gordon
nTier Software Services


Neil Gordon

unread,
Jun 25, 2014, 4:14:58 AM6/25/14
to idem...@googlegroups.com
Sorry, I missed out the most important part of the code:


final StringBuffer answer = new StringBuffer();
aProcessMonitor.ask(adMessage, new Callback<String>() {               
    @Override
    public void onCallback(String result) {
        answer.append(result != null ? result : "-");
    }
});

//wait for answer       
while (answer.length() == 0) {
    try {
        Thread.sleep(200);
    } catch (InterruptedException e) {}

}

On Tuesday, June 24, 2014 9:03:46 PM UTC+2, Neil Gordon wrote:

Jan Thielemann

unread,
Jun 25, 2014, 7:14:54 AM6/25/14
to idem...@googlegroups.com
Added it to the wiki. Good that you mentioned it again.

Neil Gordon

unread,
Jun 25, 2014, 10:29:48 AM6/25/14
to idem...@googlegroups.com

Thanks Jan, the Wiki article looks good.


-----
Neil Gordon
nTier Software Services

Reply all
Reply to author
Forward
0 new messages