trouble getting Shell value during popup menu action [message #292460] |
Thu, 06 October 2005 14:28  |
Eclipse User |
|
|
|
I have a popup menu action which eventually calls code with an
IProgressMonitor to perform the operation.
I am having trouble getting a Shell value (required by the MessageDialog
call) in my operation.
a) getActiveWorkbenchWindow() returns null:
IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
b) If I use the Display from getDisplay() as follows, I get "invalid thread
access" when I try to call getActiveShell().
Display display = PlatformUI.getWorkbench().getDisplay();
shell = display.getActiveShell();
My code looks something like this:
public class DummyAction extends TeamAction {
public void run(IAction action) {
run(new WorkspaceModifyOperation(null) {
public void execute(IProgressMonitor monitor) throws
InterruptedException, InvocationTargetException {
try {
...
monitor.beginTask(null, 1000);
/* some work... */
/* would like to add message dialog here along with the
work */
...
} catch (TeamException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}, Policy.bind("DummyAction.problemMessage"), PROGRESS_DIALOG);
//$NON-NLS-1$
}
}
What approach should be taken to prompt for user input during the operation,
if it is possible?
I suspect, that the prompting may have to be done outside of the
WorkspaceModifyOperation.
Thanks,
Shaun M.
|
|
|
Re: trouble getting Shell value during popup menu action [message #292474 is a reply to message #292460] |
Thu, 06 October 2005 15:33  |
Eclipse User |
|
|
|
Originally posted by: douglas.pollock.magma.ca
Shaun M. wrote:
> a) getActiveWorkbenchWindow() returns null:
> b) If I use the Display from getDisplay() as follows, I get "invalid
> thread access" when I try to call getActiveShell().
You are calling from a non-UI thread. All calls to SWT must be made from
the UI thread. You can use Display.asyncExec and Display.syncExec to
execute code on the UI thread.
d.
|
|
|
Powered by
FUDForum. Page generated in 0.03350 seconds