Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » extension passing messages to e4 UI, how to?(How does a Extension callback to the extension point, a e4 UI?)
extension passing messages to e4 UI, how to? [message #540197] Tue, 15 June 2010 11:05 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Now that I have the extension mechanism working Smile I would like to add the ability for my extension to call back to the e4 UI that provides the extension point with messages for display in the e4 UI. The extension I have will run long running processes and I would like to have status messages passed back into a scrolling window in the e4 UI.

It looks like I can add a handler in the e4 UI I have, but cannot see a way to call this from the extension and could not find any example of calls in the this direction. The e4 UI uses Runnable to call the extension, is there a preferred way of setting up a callback to exercise the handler in the e4 UI?

Thx.

David
Re: extension passing messages to e4 UI, how to? [message #540227 is a reply to message #540197] Tue, 15 June 2010 12:41 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Usually you would create a Job for your long running operation. It gets
passed an IProgressMonitor which your job can use to update the work
completed. By default it will update the progress monitor.

There is also the equivalent IRunnableWithProgress, where you can run
against a container.

In general, you can spawn a Job (preferred) or Thread and use
display.syncExec(*) or display.asyncExec(*) to update something in the
UI (a label, a colour, etc).

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: extension passing messages to e4 UI, how to? [message #541568 is a reply to message #540227] Mon, 21 June 2010 15:01 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Paul,

Trying to make the jump from 3.5 to e4 is proving a little difficult. I found this example for 3.5

public class DialogProgressProvider extends ProgressProvider {
  public IProgressMonitor createMonitor(final Job job) {
    final IProgressMonitor[] m = new IProgressMonitor[]{
      new NullProgressMonitor()};
    Display.getDefault().syncExec(new Runnable() {
      public void run() {
        final ProgressMonitorDialog dialog =
            new NonBlockingProgressMonitorDialog(
                Display.getDefault().getActiveShell());
        dialog.setBlockOnOpen(false);
        dialog.setCancelable(true);
        dialog.open();
        job.addJobChangeListener(new JobChangeAdapter() {
          public void done(IJobChangeEvent event) {
            // what if the job returned an error?
            close(dialog);
          }
        });
        m[0] = new AccumulatingProgressMonitor(
          dialog.getProgressMonitor(), Display.getDefault());
      }
    });
    return m[0];
  }


I do not want a dialog, I want to use one of the views where e4 injects the composite parent in. AccumulatingProgressMonitor is no longer available and since the view is already in the UI thread I imagine this is not a problem. Not clear to me how you pass the reference to the e4 view as the equivalent of the AccumulatingProgressMonitor?

The other hook up I do not get is that the 'job' is actually run in an extension. I cannot see how the extension can callback to the IProgressMonitor in order for it to display the progress strings produced by the extension? Here is the run code for the extension.

	public void doRun(@Optional IProgressMonitor monitor) throws IOException,
	InterruptedException {
		if(monitor == null)  {
			monitor = new NullProgressMonitor();
		}
		Display display = parent.getDisplay();
		if (!(display==null || display.isDisposed())) {
			display.asyncExec(new Runnable () {
				public void run() {
					// Use OSGi extension to invoke test engine 
					// Use the unchanged version, i.e. original
					TestCase original = testCaseComposite.getOriginalTestCase();
					final String[] testToRun = new String[6];
					if(!original.isValid()) {
						// Output to status window and return
					}
					// Hmmm smells a bit
					testToRun[0] = original.getInboundMetaFile();
					testToRun[1] = original.getOutboundMetaFile();
					testToRun[2] = original.getInboundDataFile();
					testToRun[3] = original.getOutboundDataFile();
					testToRun[4] = original.getMappingMetaFile();

					IConfigurationElement[] config = Platform.getExtensionRegistry()
							.getConfigurationElementsFor(ITESTER_ID);
					try {
						for (IConfigurationElement e : config) {
							System.out.println("Evaluating extension");
							final Object o = e.createExecutableExtension("class");
							if (o instanceof IFlatFileTester) {
								ISafeRunnable runnable = new ISafeRunnable() {
									@Override
									public void handleException(Throwable exception) {
										System.out.println("Exception in Test engine");
									}
		
									@Override
									public void run() throws Exception {
										((IFlatFileTester) o).run(testToRun);
									}
								};
								SafeRunner.run(runnable);
							}
						}
					} catch (CoreException ex) {
						System.out.println(ex.getMessage());
					}
				}
			});
		}
	}


Can you help with these two questions?

Thx.

David
Re: extension passing messages to e4 UI, how to? [message #577734 is a reply to message #540197] Tue, 15 June 2010 12:41 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Usually you would create a Job for your long running operation. It gets
passed an IProgressMonitor which your job can use to update the work
completed. By default it will update the progress monitor.

There is also the equivalent IRunnableWithProgress, where you can run
against a container.

In general, you can spawn a Job (preferred) or Thread and use
display.syncExec(*) or display.asyncExec(*) to update something in the
UI (a label, a colour, etc).

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: extension passing messages to e4 UI, how to? [message #578052 is a reply to message #540227] Mon, 21 June 2010 15:01 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Paul,

Trying to make the jump from 3.5 to e4 is proving a little difficult. I found this example for 3.5


public class DialogProgressProvider extends ProgressProvider {
public IProgressMonitor createMonitor(final Job job) {
final IProgressMonitor[] m = new IProgressMonitor[]{
new NullProgressMonitor()};
Display.getDefault().syncExec(new Runnable() {
public void run() {
final ProgressMonitorDialog dialog =
new NonBlockingProgressMonitorDialog(
Display.getDefault().getActiveShell());
dialog.setBlockOnOpen(false);
dialog.setCancelable(true);
dialog.open();
job.addJobChangeListener(new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
// what if the job returned an error?
close(dialog);
}
});
m[0] = new AccumulatingProgressMonitor(
dialog.getProgressMonitor(), Display.getDefault());
}
});
return m[0];
}


I do not want a dialog, I want to use one of the views where e4 injects the composite parent in. AccumulatingProgressMonitor is no longer available and since the view is already in the UI thread I imagine this is not a problem. Not clear to me how you pass the reference to the e4 view as the equivalent of the AccumulatingProgressMonitor?

The other hook up I do not get is that the 'job' is actually run in an extension. I cannot see how the extension can callback to the IProgressMonitor in order for it to display the progress strings produced by the extension? Here is the run code for the extension.


public void doRun(@Optional IProgressMonitor monitor) throws IOException,
InterruptedException {
if(monitor == null) {
monitor = new NullProgressMonitor();
}
Display display = parent.getDisplay();
if (!(display==null || display.isDisposed())) {
display.asyncExec(new Runnable () {
public void run() {
// Use OSGi extension to invoke test engine
// Use the unchanged version, i.e. original
TestCase original = testCaseComposite.getOriginalTestCase();
final String[] testToRun = new String[6];
if(!original.isValid()) {
// Output to status window and return
}
// Hmmm smells a bit
testToRun[0] = original.getInboundMetaFile();
testToRun[1] = original.getOutboundMetaFile();
testToRun[2] = original.getInboundDataFile();
testToRun[3] = original.getOutboundDataFile();
testToRun[4] = original.getMappingMetaFile();

IConfigurationElement[] config = Platform.getExtensionRegistry()
.getConfigurationElementsFor(ITESTER_ID);
try {
for (IConfigurationElement e : config) {
System.out.println("Evaluating extension");
final Object o = e.createExecutableExtension("class");
if (o instanceof IFlatFileTester) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void handleException(Throwable exception) {
System.out.println("Exception in Test engine");
}

@Override
public void run() throws Exception {
((IFlatFileTester) o).run(testToRun);
}
};
SafeRunner.run(runnable);
}
}
} catch (CoreException ex) {
System.out.println(ex.getMessage());
}
}
});
}
}


Can you help with these two questions?

Thx.

David
Re: extension passing messages to e4 UI, how to? [message #741051 is a reply to message #540197] Wed, 19 October 2011 06:14 Go to previous message
Parvez Ahmad Ahmad is currently offline Parvez Ahmad AhmadFriend
Messages: 31
Registered: May 2010
Member
Hi
Below link is a good reply
http://wiki.eclipse.org/E4/EAS/Progress_Service
I am unable to figure out what imports are needed

Inject Provider<StatusHandler> statusHandler;
@Inject Provider<RunnableContext> runnableContext;
IRunnable runnable = new Runnable("My long-running operation...") {
protected IStatus run() {
IProgressMonitor monitor = runnableContext.get().getProgressMonitor();
monitor.beginTask("foo", 100);
try {
doFirstHalfFoo();
monitor.worked(50);
doSecondHalfFoo();
} catch (FooException e) {
statusHandler.get().handle(e, "foo failure message", runnableContext.get().getStatusReportingService());
} finally {
monitor.done();
}
}
};
runnableContext.get().run(runnable);


Parvez Ahmad hakim
www.abobjects.com
Previous Topic:Problem updating 4.1.1
Next Topic:HowTo Display Validaton Status ICONS in a Form
Goto Forum:
  


Current Time: Wed Apr 24 20:38:25 GMT 2024

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

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

Back to the top