Reputation: 349
So I'm making a eclipse plugin and I have a made my own dialog by extending the dialog class.
My dialog basically populates a treeview with data from a server. Sometimes the data cannot be populated (because the server is down) so my treeview is empty.
I have made another dialog appear reporting the error if I am unable to connect to the server. My problem is that I would like to close the initial dialog when I press ok in the error dialog.
I have not been able to find a good way to do this. I have tried setting setBlockOnOpen to false. I have tried calling cancelPressed. Neither of them have worked. I called them in the createDialogArea function.
Any Ideas on how I could get this to work?
Upvotes: 1
Views: 69
Reputation: 3085
It is basically user cancelling dialog. you need to invoke cancelPressed()
so it will be consistent handling if you have any code that depends on returnCode
if(noDataLoaded){
Display.getDefault().asyncExec(new Runnable() {
public void run() {
cancelPressed():
}
});
}
Upvotes: 2
Reputation: 111142
You need to do the close
call after the dialog creation has finished. You can do this by using this code:
parent.getDisplay().asyncExec(new Runnable()
{
@Override
public void run()
{
close();
}
});
in your createDialogArea
method. However the dialog may appear briefly. It would be better to do your check before creating the dialog.
Upvotes: 1