Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » UI jobs on wizard pages
UI jobs on wizard pages [message #808856] Tue, 28 February 2012 08:19 Go to next message
Arthur Gurov is currently offline Arthur GurovFriend
Messages: 7
Registered: November 2011
Location: Ukraine
Junior Member
Hi guys,

I faced with following problem:
I'm developing rcp applications and decided to use wizards as they are part of rcp. Everything is nice, but I can't find how I can run job on wizard page. I know that I can use "getContainer().run()" on "performFinish()" in wizard, but I have few pages and I want to load some data when I press "Next" button. It seems that such functionality exist (when I creating new projects I sometimes see progress bar when I switching from one page to another), but all my attempts didn't gave a result Sad

Does anybody know how I can use jobs exactly inside of a page?

p.s. Sorry for my english Smile

Best regards, Arthur.
Re: UI jobs on wizard pages [message #808952 is a reply to message #808856] Tue, 28 February 2012 10:17 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi,
i don't know why you would use an UI Job to accomplish this. But using simple threads u can do the following:

1. Tell your wizard that a progress monitor is beeing needed
wizard.setNeedsProgressMonitor(true);

2. Overload the getNextPage(IWizardPage page) method of Wizard with code similar to this:

@Override
public IWizardPage getNextPage(IWizardPage page) {

	try {
		getContainer().run(true, true, new IRunnableWithProgress() {
			
			@Override
			public void run(final IProgressMonitor monitor) throws InvocationTargetException,
					InterruptedException {
				final int steps = 10;
				monitor.beginTask("Starting load task...", steps);

				// Have another thread do the work.  
				Thread loadThread = new Thread() {
					boolean cancelled = false;
					
					@Override
					public void run() {
						for (int i=0;i<steps;i++)
						{
							try {
								// do something here
								Thread.sleep(1000);
							} catch (InterruptedException e) {
								cancelled = true;
								e.printStackTrace();
							}
							monitor.internalWorked(1);
						}
					}
				};
				
				loadThread.start();
				
				// Enable cancellation by frequently checking the canceled state.
				while (!monitor.isCanceled() && loadThread.isAlive())
				{
					Thread.sleep(1000);
				}
				
				if (monitor.isCanceled())
				{
					// actually we would have to veto the page switch here, which is not possible by this approach  
				}
			}
		});
	} catch (InvocationTargetException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	return super.getNextPage(page);
}


3. Be aware that if u load the data while switching to the next page u cannot veto the page switch in case your load fails. So I am not sure whether this is a good approach.
Re: UI jobs on wizard pages [message #809974 is a reply to message #808952] Wed, 29 February 2012 14:16 Go to previous messageGo to next message
Arthur Gurov is currently offline Arthur GurovFriend
Messages: 7
Registered: November 2011
Location: Ukraine
Junior Member
Thank you a lot. It seems that this may help Smile

One more question. Can I launch such task when first page opens? In some cases I have few combo controls on first page and unfortunately this controls should have dinamical values, which should be loaded from database.

Best regards, Arthur.
Re: UI jobs on wizard pages [message #809986 is a reply to message #809974] Wed, 29 February 2012 14:33 Go to previous message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
You can also put such code in a WizardPage. The page also provides a getContainer() method. In your case in might be possible to overload the setVisible() method of DialogPage and place the code there.
Previous Topic:RCP Editor
Next Topic:Difference between RCP and E4
Goto Forum:
  


Current Time: Fri Mar 29 12:25:16 GMT 2024

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

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

Back to the top