Hello Pascal,
We have done something similar. We needed to parse a large directory structure 
and we wanted to put a a progress bar that the user could cancel. I have 
provided a snippet. Basically, the long running task we executed in a Runnable 
in another Thread (so that Ulc could finish the roundtrip) and set up a 
ULCPollingTimer. There is lots of code that is specific to our company in here, 
but I believe you should be able to get the main idea. 

I hope this is enough.

public class LaunchButtonActionListener implements IActionListener {
                private AbsoluteDirectory currentChild;
                private int current = 0;
                private int total = 0;
                private ViewPaneModel model;
                private boolean done = false;

                public void actionPerformed(ActionEvent aEvent) {
                        model = new ViewPaneModel((String) 
branchesCombobox.getSelectedObject(), (String) 
twigsCombobox.getSelectedObject());
                        Runnable runnable = new Runnable() {
                                public void run() {
                                        model.setBranch(getCorrectBranch());  
                                        done = true; 
                                }

                                
                        };
                        Thread thread = new Thread(runnable);
                        thread.start();
                        initializeProgressBar(thread);
                }

                private void initializeProgressBar(Thread aThread) {
                        total = model.getProjectList().size();
                        final ProgressDialog progressDialog = new 
ProgressDialog(total, aThread);
                        final FccDialog dialog = 
progressDialog.getInDialogShell(null, true);
                        dialog.setSize(300, 100);
                        dialog.setVisible(true);
                        
                        final ULCPollingTimer timer = new ULCPollingTimer(100, 
null);
                        timer.setRepeats(false);
                        timer.addActionListener(new IActionListener() {
                                public void actionPerformed(ActionEvent event) {
                                        progressDialog.setText("Parsing project 
" + currentChild.getName());
                                        progressDialog.setCurrent(current);
                                        if ((current < total) && (!cancelled)) {
                                                timer.restart();
                                        } else if (cancelled) {
                                                dialog.setVisible(false);
                                                cancelled = false;
                                        } else {
                                
                                                //We are done here - you will 
need to decide how you know when you are done. Setting flag etc.
                                                        
dialog.setVisible(false);
                                                        Class<? extends 
IWorkbenchPane<? extends IModel>> classFromViewsCombobox = 
getClassFromViewsCombobox();
                                                                                
                                
WorkbenchFactory.getWorkbench().show(classFromViewsCombobox, model, model, 
model);
                                        }
                                }
                        });
                        timer.start();
                }

                public void parsingProject(AbsoluteDirectory 
anAbsoluteDirectory, int aCurrentCount, int aTotalCount) {
                        currentChild = anAbsoluteDirectory;
                        current = aCurrentCount;
                        total = aTotalCount;
                }

        }


Greg Hutchinson, B.Sc. 
Principal Application Developer /Développeur principal
Farm Credit Canada / Financement agricole Canada
1800 Hamilton Street, P.O. Box 4320
1800, rue Hamilton, C.P. 4320
Regina SK S4P 4L3
Tel/Tél. : (306) 780-3990 Cell : (306) 539-9060 Fax/Télec. : (306) 780-5655 
E-mail/Courriel : [email protected] 

Advancing the business of agriculture. Pour l'avenir de l'agroindustrie. 

Please consider the environment before printing this e-mail. Pensons à 
l'environnement avant d'imprimer ce courriel.

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Schäfer, Pascal
Sent: Wednesday, October 28, 2009 4:37 AM
To: [email protected]
Subject: [ULC-developer] Asynchronous method call

Hi all,

I have the following issue to implement:

I have a dialog where the user can press a button which starts to execute a 
database query that returns a list to fill a table. Because the query might 
take long the user should have another button to cancel the query. So this must 
be done asynchronously somehow.

So is there any support in the ULC API to support this asynchronous call? As 
far as I understand it would not be enough to do

queryButton.setEventDeliveryMode(UlcEventConstants.ASYNCHRONOUS_MODE)

because it is not asynchronous from the user's point of view, is it?

Thanks in advance. Any hint would be helpful.

Pascal


Disclaimer:
Aus Rechts- und Sicherheitsgründen ist die in dieser E-Mail gegebene 
Information nicht rechtsverbindlich.
Eine rechtsverbindliche Bestätigung reichen wir Ihnen gerne auf Anforderung in 
schriftlicher Form nach.
Beachten Sie bitte, dass jede Form der unautorisierten Nutzung, 
Veröffentlichung, Vervielfältigung oder Weitergabe des Inhalts dieser E-Mail 
nicht gestattet ist.
Diese Nachricht ist ausschließlich für den bezeichneten Adressaten oder dessen 
Vertreter bestimmt.
Sollten Sie nicht der vorgesehene Adressat dieser E-Mail oder dessen Vertreter 
sein, so bitten wir Sie, sich mit dem Absender der E-Mail in Verbindung zu 
setzen und/oder diese Nachricht mit allen Anhängen zu löschen.
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to