Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SGWT.mobile - SC.showPrompt and Deferred command

    Hi,

    I have some panels that take a long time to load. I would like to prompt the user to wait with a modal message, basically to prevent the user from pushing multiple times on the same button thinking that the panel loading was not started. Here is the code that I thought would do the trick:

    Code:
        public void onRecordNavigationClick(RecordNavigationClickEvent event) {
        	SC.showPrompt("Please wait","Loading screen ...");
        	final TableMenuRecord tableMenuRecord = (TableMenuRecord)event.getRecord();
        	Scheduler.get().scheduleDeferred(new ScheduledCommand(){
    			public void execute() {
                	changeScreen((Screen)tableMenuRecord.getPanel());
                	SC.clearPrompt();
    			}
        	});
        }
    The slow command is tableMenuRecord.getPanel() which has to build the panel when called for the first time.

    The problem is that the prompt does not really pop up before the ScheduledCommand command starts, it actually pops up almost at the end and is therefore directly cleared and is useless.

    I have tried with DeferredCommand (which is deprecated and replaced by Scheduler stuffs) as suggested in the doc of showPrompt but with the same result.

    Thanks for your help, Ben
    Last edited by bda@n-side.com; 2 Mar 2013, 11:18.

    #2
    This is the right way to do it and is a known-working approach we use all the time. Your results basically suggest that there is some other code calling changeScreen() elsewhere, before the attempt to show the prompt.

    If you think there's something wrong with the technique in general, try putting together a test case we can run to see the effect.

    Comment


      #3
      ok, here is the test case

      Adjust the loop according to your machine such that it takes some seconds, you will see that the prompt does only pop once the loop is over.

      Thanks, Ben.

      Code:
          public void onDeviceReady() {
      
          	final NavStack navStack = new NavStack();
          	RootLayoutPanel.get().add(navStack);
          	ScrollablePanel panel1 = new ScrollablePanel("Panel 1");
      
          	panel1.setActions(new Action("Push"){
      			@SuppressWarnings("unchecked")
      			public void execute(ActionContext context) {
      				
      		    	SC.showPrompt("Please wait","Loading ...");
      		    	Scheduler.get().scheduleDeferred(new ScheduledCommand(){
      					public void execute() {
      
      						for (int i=0;i<100000000;i++) Math.random();
      				    	ScrollablePanel panel2 = new ScrollablePanel("Panel 2");
      				    	navStack.push(panel2);
      		            	SC.clearPrompt();
      					}
      		    	});
      
      			}
          	});
          	
          	navStack.push(panel1);
      
          	
      	}

      Comment


        #4
        The problem here turned out to be that CSS animations applied meant that it would not finish showing before your long drawing operation started. At that point, whether the animation showed at all during the long drawing operation is a matter of cross-browser inconsistency.

        The next nightly build includes an API that will allow you to disable the animations temporarily so you can get an instant prompt:

        SC.enablePromptAnimations(false);
        SC.showPrompt("Please wait", "Loading ...");

        //... your scheduler code ...

        SC.enablePromptAnimations(true);
        SC.clearPrompt();

        Comment


          #5
          Working fine now, many thanks for the solution!

          Comment


            #6
            SGWT SC.showPrompt and deferred command

            I perceive similar problem in Isomorphic SmartClient/SmartGWT Framework (v9.1p_2014-05-25/PowerEdition Deployment 2014-05-25) in Firefox 25.0:
            The prompt doesn't show before the deferred command as expected but rather later when this command execution dismisses it again.
            So far I try to postpone the command after prompt using fixed delay to give the browser some time to make it appear. Deferring it doesn't seem to have the desired effect at all.
            I don't like this solution because it is anyway not guaranteed to work for longer code execution.
            Code:
            Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
            	@Override
            	public boolean execute() {
            		...
            		return false;
            	}
            }, 20);
            I looked for something like SC.enablePromptAnimations but the API is not present.
            Is there any alternative in my SGWT release (newer than last post by Isomorphic here)?

            Comment


              #7
              Unrelated issue - what you need to do is show the prompt (or anything else that involves drawing), then use Scheduler to wait a negligible amount of time before kicking off a long-running action (like drawing a complex chart or doing a large export).

              Otherwise the browser does not refresh the screen while the long-running action takes place.

              This is not related to SmartGWT specifically or even to JavaScript - just a general programming technique.

              Comment

              Working...
              X