Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Using asyncExec in TitleAreaDialog
Using asyncExec in TitleAreaDialog [message #507702] Thu, 14 January 2010 12:15 Go to next message
Fabian Dankof is currently offline Fabian DankofFriend
Messages: 9
Registered: July 2009
Junior Member
Hello!

I created a TitleAreaDialog that does some background processing in
a non-ui thread. The non-ui thread is run in method okPressed().

Now I'm trying to manipulate the UI from the non-ui thread by the
use of Display.asyncExec(). Unfortunately my runnable doesn't get
executed.

There are no exceptions. The dialog is opend in
ApplicationWorkbenchAdvisor.postStartup()

Here's the code of the dialog:

------------------------- SNIP -----------------------------


import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.swtdesigner.SWTResourceManager;

public class LoginDialog extends TitleAreaDialog {

private Text text_2;
private Text text_1;
private Text text;

private Label label;


/**
* Create the dialog
*
* @param parentShell
*/
public LoginDialog(Shell parentShell) {
super(parentShell);
}

/**
* Create contents of the dialog
*
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
[...]

label = new Label(container, SWT.NONE);
label.setVisible(false);
label.setText("Prüfen...");
new Label(container, SWT.NONE);
[...]
//
return area;
}



@Override
protected void okPressed() {

final Display display = Display.getDefault();



Thread t = new Thread() {
@Override
public void run() {
try {
// some background processing
Thread.sleep(2000);
display.syncExec(new Runnable(){
@Override
public void run() {

label.setText("Finished");
LoginDialog.super.okPressed();
}});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
t.start();
}
[...]

}


------------------------------ SNAP -----------------------------


Hope there is someone who can help me with this.

Greetings,

Fabian
Re: Using asyncExec in TitleAreaDialog [message #508202 is a reply to message #507702] Sun, 17 January 2010 15:43 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi Fabian,

I don't get the Logindialog.super.okPressed();

What's with the super?

Best regards,

Wim


> Hello!
>
> I created a TitleAreaDialog that does some background processing in
> a non-ui thread. The non-ui thread is run in method okPressed().
>
> Now I'm trying to manipulate the UI from the non-ui thread by the
> use of Display.asyncExec(). Unfortunately my runnable doesn't get
> executed.
>
> There are no exceptions. The dialog is opend in
> ApplicationWorkbenchAdvisor.postStartup()
>
> Here's the code of the dialog:
>
> ------------------------- SNIP -----------------------------
>
>
> import org.eclipse.core.runtime.jobs.JobChangeAdapter;
> import org.eclipse.jface.dialogs.IDialogConstants;
> import org.eclipse.jface.dialogs.TitleAreaDialog;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.Point;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Label;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
>
> import com.swtdesigner.SWTResourceManager;
>
> public class LoginDialog extends TitleAreaDialog {
>
> private Text text_2;
> private Text text_1;
> private Text text;
>
> private Label label;
>
>
> /**
> * Create the dialog
> *
> * @param parentShell
> */
> public LoginDialog(Shell parentShell) {
> super(parentShell);
> }
>
> /**
> * Create contents of the dialog
> *
> * @param parent
> */
> @Override
> protected Control createDialogArea(Composite parent) {
> [...]
>
> label = new Label(container, SWT.NONE);
> label.setVisible(false);
> label.setText("Pr
Re: Using asyncExec in TitleAreaDialog [message #508255 is a reply to message #508202] Mon, 18 January 2010 07:14 Go to previous messageGo to next message
Fabian Dankof is currently offline Fabian DankofFriend
Messages: 9
Registered: July 2009
Junior Member
Hi Wim,

By callign LoginDialog.super.okPressed() I intended to refer to
TitleAreaDialog's okPressed() method.

Best regards, Fabian
Re: Using asyncExec in TitleAreaDialog [message #508697 is a reply to message #508255] Tue, 19 January 2010 21:42 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi Fabian,

But that does not contain the asyn call...

--

Best Regards,
Wim Jongman
-- All wiyht. Rho sritched mg kegtops awound?
(Eclipse Old Skool Quote Service)

> Hi Wim,
>
> By callign LoginDialog.super.okPressed() I intended to refer to
> TitleAreaDialog's okPressed() method.
>
> Best regards, Fabian
Re: Using asyncExec in TitleAreaDialog [message #508698 is a reply to message #508697] Tue, 19 January 2010 21:44 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
I mean: the super does not contain the call to the synexec.

--

Best Regards,
Wim Jongman
-- "640K ought to be enough for anybody." - Bill Gates, 1981
(Eclipse Old Skool Quote Service)

> Hi Fabian,
>
> But that does not contain the asyn call...
>
> --
>
> Best Regards,
> Wim Jongman
> -- All wiyht. Rho sritched mg kegtops awound?
> (Eclipse Old Skool Quote Service)
>
>> Hi Wim,
>>
>> By callign LoginDialog.super.okPressed() I intended to refer to
>> TitleAreaDialog's okPressed() method.
>>
>> Best regards, Fabian
Re: Using asyncExec in TitleAreaDialog [message #508829 is a reply to message #508698] Wed, 20 January 2010 08:54 Go to previous messageGo to next message
Fabian Dankof is currently offline Fabian DankofFriend
Messages: 9
Registered: July 2009
Junior Member
Yeah that's right but I don't think that this is the cause.
Using the Eclipse debugger, I can verify that the Runnable
isn't even called by the platform.

Am 19.01.2010 22:44, schrieb Wim Jongman:
> I mean: the super does not contain the call to the synexec.
>
Re: Using asyncExec in TitleAreaDialog [message #509497 is a reply to message #508829] Fri, 22 January 2010 16:01 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

I've changed your code to a runnable snippet and the Runnable does get run.
Which platform and eclipse version are you using? Does the snippet below
work for you? Do you see any obvious differences between the snippet and
the code in your app?

public class LoginDialog extends TitleAreaDialog {
private Label label;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setBounds(10,10,200,200);
shell.open();
new LoginDialog(shell).open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
public LoginDialog(Shell parentShell) {
super(parentShell);
}
protected Control createDialogArea(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new FillLayout());
label = new Label(container, SWT.NONE);
//label.setVisible(false);
label.setText("Pr
Re: Using asyncExec in TitleAreaDialog [message #509712 is a reply to message #509497] Mon, 25 January 2010 07:35 Go to previous messageGo to next message
Fabian Dankof is currently offline Fabian DankofFriend
Messages: 9
Registered: July 2009
Junior Member
Hello Grant,

your snippet works nicely as I would expect it. I'm using Eclipse RCP
3.4 and Java 1.6.0_17

Do you have any idea why it doesn't work in a rich client app? Maybe
it is because the class is called in
ApplicationWorkbenchAdvisor.postStartup() ???
Re: Using asyncExec in TitleAreaDialog [message #509837 is a reply to message #509712] Mon, 25 January 2010 15:00 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
I think that your best bet is to put a breakpoint at your
"display.syncExec(new Runnable(){" line and debug into the syncExec() call
to see if anything happens that prevents your Runnable from being run.
Since syncExec() is supposed to execute the Runnable immediately you should
not have to trace too far to see what's happening.

Grant


"Fabian Dankof" <dankof@abis-reicom.de> wrote in message
news:hjjhh7$8fl$1@build.eclipse.org...
> Hello Grant,
>
> your snippet works nicely as I would expect it. I'm using Eclipse RCP
> 3.4 and Java 1.6.0_17
>
> Do you have any idea why it doesn't work in a rich client app? Maybe
> it is because the class is called in
> ApplicationWorkbenchAdvisor.postStartup() ???
>
>
Previous Topic:When is the RCP complete and the rest is done using plug-ins
Next Topic:Activities based on source variables
Goto Forum:
  


Current Time: Fri Apr 19 02:50:28 GMT 2024

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

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

Back to the top