Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Custom StatusReporter (or how to override WorkbenchStatusReporter)
Custom StatusReporter (or how to override WorkbenchStatusReporter) [message #915747] Mon, 17 September 2012 22:23 Go to next message
Justin Unterreiner is currently offline Justin UnterreinerFriend
Messages: 10
Registered: August 2012
Junior Member
I need to change some of the behavior in WorkbenchStatusReporter.

Ideally I would like to extend WorkbenchStatusReporter and override the report method.

In PartRenderingEngine I can see where the status reporter is pulled from the context:

public void eventLoopException(Throwable exception) {
	StatusReporter statusReporter = (StatusReporter) appContext
			.get(StatusReporter.class.getName());
	if (statusReporter != null) {
		statusReporter.show(StatusReporter.ERROR,
				"Internal Error", exception);
	} else {
		if (logger != null) {
			logger.error(exception);
		}
	}
}


I thought I would be able to add my own with the following:

lContext.set(StatusReporter.class.getName(), new MyCustomStatusReporter());


But my custom one is never used; the code that gets the status reporter in PartRenderingEngine always ends up invoking StatusReporterCreationFunction (which creates an instance of WorkbenchStatusReporter).

How can I specify my own implementation of StatusReporter to replace/extend the WorkbenchStatusReporter?
Re: Custom StatusReporter (or how to override WorkbenchStatusReporter) [message #915756 is a reply to message #915747] Mon, 17 September 2012 22:49 Go to previous messageGo to next message
Eclipse UserFriend
Since StatusReporter is a core service you would need a bit extra work to get it done .

You would need to provide your context function as in http://www.vogella.com/articles/EclipseRCP/article.html#icontextfunction

Part of your component definition (create a {projectRoot}/OSGI-INF/component.xml)would look like this:
<implementation class="org.eclipse.e4.paho.client.OtherCF"/>
   
 <service>
   <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
 </service>
 
 <property name="service.context.key" type="String" 
   value="org.eclipse.e4.core.services.statusreporter.StatusReporter"/>


where *.OtherCF is something like:
public class OtherCF extends ContextFunction {

	@Override
	public Object compute(IEclipseContext context) {
		return ContextInjectionFactory.make(MyWorkbenchStatusReporter.class,
				context);
	}

}


where the MyWorkbenchStatusReporter is your StatusReporter extending and implementing anything you like.
Re: Custom StatusReporter (or how to override WorkbenchStatusReporter) [message #981758 is a reply to message #915756] Mon, 12 November 2012 17:15 Go to previous messageGo to next message
Justin Unterreiner is currently offline Justin UnterreinerFriend
Messages: 10
Registered: August 2012
Junior Member
Sorry to bump this old thread, but I'm noticing something weird here.

Using your example I was able to register my custom status reporter and everything works fine when launching from Eclipse.

However, we've noticed that the component is not registered when running from a standalone build that was built from Eclipse.

My MANIFEST.MF has this line:
Service-Component: OSGI-INF/StatusReporter.xml


StatusReporter.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="hxxp://www.osgi.org/xmlns/scr/v1.1.0" 
  name="com.company.blah.productname.StatusReporter">

<implementation class="com.company.blah.productname.StatusReporterContextFunction"/>

 <service>
   <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
 </service>

 <property name="service.context.key" type="String" 
   value="org.eclipse.e4.core.services.statusreporter.StatusReporter"/>

</scr:component>


StatusReporterContextFunction.java:
package com.company.blah.productname;

import org.eclipse.e4.core.contexts.ContextFunction;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;

public class StatusReporterContextFunction extends ContextFunction {
	@Override public Object compute(IEclipseContext pContext) {
		return ContextInjectionFactory.make(StatusReporter.class, pContext);
	}
}


Is there some additional step I'm missing to get this to work for a build running outside of Eclipse?
Re: Custom StatusReporter (or how to override WorkbenchStatusReporter) [message #981882 is a reply to message #981758] Mon, 12 November 2012 19:28 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Did you check that the build.properties is correct? Also make sure the
bundle is activate lazy.

Tom

Am 12.11.12 18:15, schrieb Justin Unterreiner:
> Sorry to bump this old thread, but I'm noticing something weird here.
>
> Using your example I was able to register my custom status reporter and
> everything works fine when launching from Eclipse.
>
> However, we've noticed that the component is not registered when running
> from a standalone build that was built from Eclipse.
>
> My MANIFEST.MF has this line:
>
> Service-Component: OSGI-INF/StatusReporter.xml
>
>
> StatusReporter.xml looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <scr:component xmlns:scr="hxxp://www.osgi.org/xmlns/scr/v1.1.0"
> name="com.company.blah.productname.StatusReporter">
>
> <implementation
> class="com.company.blah.productname.StatusReporterContextFunction"/>
>
> <service>
> <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
> </service>
>
> <property name="service.context.key" type="String"
> value="org.eclipse.e4.core.services.statusreporter.StatusReporter"/>
>
> </scr:component>
>
>
> StatusReporterContextFunction.java:
>
> package com.company.blah.productname;
>
> import org.eclipse.e4.core.contexts.ContextFunction;
> import org.eclipse.e4.core.contexts.ContextInjectionFactory;
> import org.eclipse.e4.core.contexts.IEclipseContext;
>
> public class StatusReporterContextFunction extends ContextFunction {
> @Override public Object compute(IEclipseContext pContext) {
> return ContextInjectionFactory.make(StatusReporter.class,
> pContext);
> }
> }
>
>
> Is there some additional step I'm missing to get this to work for a
> build running outside of Eclipse?
Re: Custom StatusReporter (or how to override WorkbenchStatusReporter) [message #981916 is a reply to message #981882] Mon, 12 November 2012 20:06 Go to previous messageGo to next message
Justin Unterreiner is currently offline Justin UnterreinerFriend
Messages: 10
Registered: August 2012
Junior Member
The build.properties includes the OSGI-INF directory:

output.. = bin/
bin.includes = META-INF/,\
               .,\
               plugin.xml,\
               css/default.css,\
               Application.e4xmi,\
               conf/,\
               com.company.blah.productname.product,\
               images/,\
               OSGI-INF/
source.. = src/,\
           conf/
src.includes = images/



And the MANIFEST.MF contains the lazy activation policy:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.company.blah.productname
Bundle-SymbolicName: com.company.blah.productname; singleton:=true
Bundle-Version: 2.0.4
Bundle-Activator: com.company.blah.productname.Activator
Bundle-Vendor: company
Bundle-ActivationPolicy: lazy
Eclipse-RegisterBuddy: com.company.framework,
 com.company.blah.lib
Require-Bundle: javax.inject;bundle-version="1.0.0",
 org.eclipse.core.runtime;bundle-version="3.8.0",
 org.eclipse.swt;bundle-version="3.100.0",
 org.eclipse.core.databinding;bundle-version="1.4.1",
 org.eclipse.core.databinding.beans;bundle-version="1.2.200",
 org.eclipse.jface;bundle-version="3.8.0",
 org.eclipse.jface.databinding;bundle-version="1.6.0",
 org.eclipse.e4.ui.services;bundle-version="0.10.1",
 org.eclipse.e4.ui.workbench;bundle-version="0.10.2",
 org.eclipse.e4.core.services;bundle-version="1.0.0",
 org.eclipse.e4.core.di;bundle-version="1.1.0",
 org.eclipse.e4.core.contexts;bundle-version="1.1.0",
 org.eclipse.e4.ui.workbench.swt;bundle-version="0.10.1",
 org.eclipse.core.databinding.property;bundle-version="1.4.100",
 org.eclipse.e4.ui.css.core;bundle-version="0.10.1",
 org.w3c.css.sac;bundle-version="1.3.1",
 org.eclipse.e4.core.commands;bundle-version="0.10.1",
 org.eclipse.e4.ui.bindings;bundle-version="0.10.1",
 org.eclipse.ui;bundle-version="3.103.0",
 org.eclipse.ui.forms;bundle-version="3.5.200",
 com.company.blah.lib,
 com.company.productname2.model,
 com.company.framework,
 com.company.productname2.business,
 com.company.productname2.model;bundle-version="1.6.0",
 org.eclipse.osgi.services;bundle-version="3.3.100",
 org.eclipse.nebula.widgets.datechooser;bundle-version="1.0.0",
 javax.annotation;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: com.company.common.model.reporting,
 com.company.lassen.reporting,
 com.company.lib,
 com.company.blah.lib.swt,
 org.eclipse.e4.core.di.extensions,
 org.eclipse.e4.ui.di,
 org.osgi.framework;version="1.3.0",
 org.osgi.service.event;version="1.3.0"
Service-Component: OSGI-INF/StatusReporter.xml

Re: Custom StatusReporter (or how to override WorkbenchStatusReporter) [message #982046 is a reply to message #981916] Mon, 12 November 2012 22:36 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

@Justin: Properly you miss some flags. If you want create a small example (service plus small application) and send it to Lars.Vogel@gmail.com, I have a look.
Re: Custom StatusReporter (or how to override WorkbenchStatusReporter) [message #985691 is a reply to message #982046] Thu, 15 November 2012 17:28 Go to previous messageGo to next message
Justin Unterreiner is currently offline Justin UnterreinerFriend
Messages: 10
Registered: August 2012
Junior Member
I've created a standalone project and everything works as expected.

What really bugs me is that it works in my regular project when running from Eclipse, but not from the build that Eclipse produces. If it works when running from Eclipse, wouldn't that indicate that the configuration is correct and something is not created right for the build?

Is there a way I can turn on verbose or trace level logging in OSGI so I can see what is going on and/or why it is failing to load my component?

I tried adding the following to my launcher ini, but it didn't seem to make a difference.

-Dosgi.debug.verbose=true
-Dosgi.tracefile=C:/tmp/osgitrace.txt
Re: Custom StatusReporter (or how to override WorkbenchStatusReporter) [message #985707 is a reply to message #915747] Thu, 15 November 2012 18:13 Go to previous message
Justin Unterreiner is currently offline Justin UnterreinerFriend
Messages: 10
Registered: August 2012
Junior Member
I ended up removing the XML file and reference in the manifest and did it programmatically via my Activator:

public void start(BundleContext bundleContext) throws Exception {
	Dictionary<String, Object> properties = new Hashtable<String, Object>();
	
	properties.put("service.context.key", "org.eclipse.e4.core.services.statusreporter.StatusReporter");
	
	StatusReporterContextFunction implementation = new StatusReporterContextFunction();
	bundleContext.registerService("org.eclipse.e4.core.contexts.IContextFunction", implementation, properties);
	
	Activator.context = bundleContext;
}
Previous Topic:Making a fixed perspective in an e4 model?
Next Topic:Injecting doesn't work - eModelService.find works - why?
Goto Forum:
  


Current Time: Thu Apr 25 22:46:46 GMT 2024

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

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

Back to the top