Hi Janak

Cool. Thanks very much!

Regards, Etienne 



-----Original Message-----
From: Janak Mulani [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 07, 2006 2:00 AM
To: Etienne Studer
Cc: [email protected]
Subject: RE: [ULC-developer] long-running task on client with
blocking-UI

Hi Etienne,

You can make use of the InputBlocker class. However, this API is
internal to ULC and may change in future. But you can use it for now.

Please see the snippet below.

Thanks and regards,

Janak
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Etienne Studer
Sent: Saturday, November 04, 2006 12:37 AM
To: [email protected]
Subject: [ULC-developer] long-running task on client with blocking-UI


Hi

In the client-side part of an extension, I want to call a long-running
task (for example, the client connects to a local device, no request to
the ULC server-side is made). In order to keep the UI repainted, I need
to launch a separate task outside the AWT-Thread but I still want to
keep the UI blocked (just like one would do it in a pure Swing app). Is
there a hook in ULC core that allows me to block/unblock the UI? Any
suggestions?

Thanks for your feedback.

Regards, Etienne

--------------------


import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCCheckBox;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCTextField;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.client.InputBlocker;
import com.ulcjava.base.client.UIButton; import
com.ulcjava.base.client.UITextField;
import com.ulcjava.base.development.DevelopmentRunner;

public class LongTaskOnClientSnippet extends AbstractApplication {
        public void start() {
                final ULCTextField text = new ULCTextField(10);
                ULCCheckBox check = new ULCCheckBox("Check");
                final ULCMyButton but = new ULCMyButton();

                but.addActionListener(new IActionListener() {
                        public void actionPerformed(ActionEvent event) {
                                but.startClientTask(text);
                        }
                });

                ULCBoxPane content = new ULCBoxPane(true);
                content.add(check);
                content.add(text);
                content.add(but);
                ULCFrame frame = new
ULCFrame("LongTaskOnClientSnippet");
        
frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
                frame.add(content);
                frame.setSize(300, 300);
                frame.setVisible(true);

        }

        public static void main(String[] args) {
                DevelopmentRunner
        
.setApplicationClass(LongTaskOnClientSnippet.class);
                DevelopmentRunner.run();
        }

        public static class ULCMyButton extends ULCButton {
                public ULCMyButton() {
                        super("Action");
                }

                protected String typeString() {
                        return UIMyButton.class.getName();
                }

                public void startClientTask(ULCTextField fld) {
                        invokeUI("startClientTask", new Object[] { fld }
);
                }

        }

        public static class UIMyButton extends UIButton {
                public void startClientTask(final UITextField fld)
throws InterruptedException {
                        Thread task = new Thread() {
                                public void run() {
                                        try {
                                        Thread.sleep(5000);
        
System.out.println(Thread.currentThread().getId());
                                                for(int i = 0; i <
1000000000; i++) {
                                                        if (i % 1000000
== 0) {

        
System.out.print('.');
                                                        }
                                                }
                                        } catch (InterruptedException e)
{
                                                e.printStackTrace();
                                        }
                                }
                        };
        
System.out.println(Thread.currentThread().getId());
>>>                     InputBlocker.addBlockedSession(getSession());
>>>                     task.start();
>>>                     InputBlocker.removeBlockedSession(getSession());
                }
        }
}

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to