Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » [NEON] Refresh Ui Component instantly
[NEON] Refresh Ui Component instantly [message #1746653] Wed, 02 November 2016 13:45 Go to next message
A N is currently offline A NFriend
Messages: 25
Registered: July 2014
Junior Member
Hi,

I implemented a menu to load data asynchronously as following:

public abstract class AbstractLoadingMenu extends AbstractMenu {
	
	@Override
	protected String getConfiguredText() {
		return TEXTS.get("AbstractLoadingMenu");
	}

	@Override
	protected Set<? extends IMenuType> getConfiguredMenuTypes() {
		return CollectionUtility.hashSet(TableMenuType.EmptySpace);
	}

	@Override
	protected void execAction() {
		setEnabled(false);
		Jobs.schedule(new IRunnable() {
			@Override
			public void run() throws Exception {
				try {
					setText(getConfiguredLoadingMessage());
					load();
				} catch (Throwable t) {
					t.printStackTrace();
					setText(getConfiguredErrorMessage());
				} finally {
					setText(getConfiguredText());
					setEnabled(true);
				}

			}
			
		}, Jobs.newInput().withName(getConfiguredText()).withRunContext(ClientRunContexts.copyCurrent()));
	}

	protected abstract void load();
}


Sometimes it takes rather long until the menu becomes enabled again despite setEnabled(true); being called almost instantly. I suspect it maybe has something todo with it being called out of a job. Is there a method to force the ui to refresh instantly after setEnabled(true); has been called?

Other than that I am generally interested in any feedback about this implementation.
Re: [NEON] Refresh Ui Component instantly [message #1747376 is a reply to message #1746653] Mon, 14 November 2016 07:32 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
Your guess is almost right. The UI change doesn't happen immediately because you call setText/setEnabled outside of a model job. All changes on the Scout (UI) model must happen inside of a model job. So when you do something in the background by starting an arbitrary Thread you must make sure, that this Thread starts a model thread again, when you call a method on the Scout model (like you do). Instead of the Jobs class, simply use the ModelJobs class. A small example:

   // this is executed by a thread != Scout model thread
   loadALotOfDataInTheBackground();

   // when you're done...
    ModelJobs.schedule(new IRunnable() {
      @Override
      public void run() throws Exception {
         m_stringField.setText("I'm done");
      }
    }, ModelJobs.newInput(ClientRunContexts.copyCurrent()));


You should also check the technical guide for more details about the Scout jobs framework:

https://eclipsescout.github.io/6.0/technical-guide.html#modeljobs


Eclipse Scout Homepage | Documentation | GitHub
Re: [NEON] Refresh Ui Component instantly [message #1747378 is a reply to message #1747376] Mon, 14 November 2016 07:54 Go to previous message
A N is currently offline A NFriend
Messages: 25
Registered: July 2014
Junior Member
Andre Wegmueller wrote on Mon, 14 November 2016 07:32


You should also check the technical guide for more details about the Scout jobs framework:

https://eclipsescout.github.io/6.0/technical-guide.html#modeljobs


Thats what I should have done in the first place. Thank you!
Previous Topic:Issues with Hello World example for beginners
Next Topic:[neon] Login with http works, but not https
Goto Forum:
  


Current Time: Fri Apr 26 06:28:14 GMT 2024

Powered by FUDForum. Page generated in 0.03344 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top