How to get workspace location in Eclipse 4.x - eclipse-rcp

I need to get workspace a location using API in Eclipse 4.x platform. I know that I can use
ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
but I'm wondering if there is another way to do that without static reference to ResourcesPlugin? For example using Dependency Injection..
Thanks in advance
Qinto.

From Eclipse Wiki:
#Inject
#Named(E4Workbench.INSTANCE_LOCATION)
private Location instanceLocation;
This didn't work for me in my LifeCycleManager, though, throwing an exception that the Location object was not available to be injected. I removed the #Named annotation and a valid Location object was injected:
#Inject
private Location instanceLocation;

Related

JBoss Seam cannot create Java Persistence Entity Manager

I am at a complete loss with this one. I am scouring the Internet via Google to try and find a solution for this problem. I haven't used JBoss in a very long time, and we use Seam version 2 ... not sure what exact version. I've never used Seam before, so I don't know anything about this framework. My boss wrote most of this code, but he has moved beyond looking at this code, and has tasked me to fix this problem.
So, the problem is ... A user is logged into our Seam app, everything is fine, but when we try to load users from a CSV file, it's as if Seam forgets who we are, and then we get an error.
We have a UserIdentity class starts off like:
#Name("org.jboss.seam.security.identity")
#Scope(ScopeType.SESSION)
#Install(precedence = Install.APPLICATION)
#BypassInterceptors
#Startup
public class UserIdentity extends Identity {
In this class, we have one line of code:
EntityManager entityManager = (EntityManager)Component.getInstance("entityManager",true);
That is returning null, and hence we get an NullPointerException (NPE).
I presume that "Component.getInstance" fails, and it would be nice if we could refresh this and get it back again. It would be great if I could update to a newer seam jar and fix this.
I will continue to scour the Internet for a fix, but in the meantime, if someone has seen this issue, and knows how to fix it, that would be great.
Thanks!
When you use Component.getInstance method is used to get a reference to a Seam session bean component.
True end your context and creates again. As it is not finding that context It is returning null.
As the EntityManager is used in Session Scope, You don't have to Create it again.
Simple you can inject entity manager as,
EntityManager entityManager = (EntityManager)Component.getInstance("entityManager");
or
#In
EntityManager entityManager;

How do Service / SourceProviders work in Eclipse 4 RCP 2.0?

I've been busily getting with the future and migrating an old eclipse 3.7 application over to Eclipse 4 and whilst I'm happy with the application model for porting all the views I have a number of source providers that I am unsure about porting wise. I've been using a few tutorials on Eclipse 4 including this Tutorial from good old Lars but none seem to cover this particular element.
For a small amount of Context my existing application has a few classes extending AbstractSourceProvider that are registered in the org.eclipse.ui.services extension point. My views register themselves as listeners to these services using the ISourceProviderService.getSourceProvider(key) function from the workbench and update themselves if that source fires a sourced changed event. I also have a few providers that reference each other some times too so I'm wondering if this will still work with injection.
What sort of model is used in Eclipse 4?, should I just use the same old extension point? Can these extension point services be injected in to the views in the new cool anotationy way?
What gives?
You can create a service in a number of ways:
Create an instance of your service class and put it in the IEclipseContext. This is often done in an 'Addon':
public class MyAddon
{
#PostConstruct
void postConstruct(IEclipseContext context)
{
MyService myService = ContextInjectionFactory.make(MyService.class, context);
context.put(MyService.class, myService);
}
}
The 'Addon' is declared in the application.e4xmi file.
You could also create the service like this in the LifeCycle class for the RCP.
An OSGi service will automatically be added to the Eclipse context.
You can use a Context Function which uses an OSGi service but doesn't create the actual service until it is needed.
In all cases you reference the service by injection:
#Inject
MyService myService;
Note that injection is only done on objects created by Eclipse from objects described in the application.e4xmi. It is possible to do injection on other objects using ContextInjectionFactory.

Where to find the Wicket Stuff annotation package?

Where I can find wicketstuff-annotation.jar? It's used to be available at least in a Maven repo at http://wicketstuff.org/maven/repository but that doesn't exist anymore, and the Wicket Stuff homepage is not very helpful either.
Specifically, I need org.wicketstuff.annotation.mount.MountPath because I want readable URLs in my Wicket app and find annotations an elegant way to mount pages. (I wonder why this kind of stuff isn't included in core Wicket distribution...)
(Any place to download the jar from would be fine; I don't use Maven in current project.)
You can just mount your pages anywhere in your application, typically in your Application's init() method, like:
#Override
protected void init() {
mountBookmarkablePage("/users", UsersPage.class);
}
That said, if you want to use the annotations package, it is available from Maven Central
Update from Wicket 1.5:
You should use the method mountPage() instead of mountBookmarkablePage() as that method has been removed from Wicket 1.5.
#Override
protected void init() {
mountPage("/users", UsersPage.class);
}
https://cwiki.apache.org/WICKET/migration-to-wicket-15.html
This is the URL. You can click on Binary link to download the required jar.
A community user today contributed an upgrade of the library to Wicket 1.5, so it will be available for next release (1.5-RC6). Until then the users of 1.5 can use it from Github repo.

Where is the jar file for EJB3 annotations for JBoss 5?

This should be simple, but I'm at a complete loss.
I'm working through a tutorial for setting up some MBeans in JBoss 5.0. It has an example like this:
#Remote
public interface Calculator {
public double getInterestRate();
public double calculateTotalInterest(double presentValue, int years);
public double calculateFutureValue(double presentValue, int years);
}
I'm trying to find the jar file that contains the data for the #Remote annotation, and I cannot seem to find which jar file I need. A google search gives me little to nothing that seems to apply to JBoss 5.0. Any help would be much appreciated.
It's smuggled away inside common/lib/jboss-javaee.jar, along with the rest of the JavaEE API. This JAR is for use by the JBoss server.
Another copy is kept inside client/jboss-javaee.jar, for use by clients.
Both are copies of the same classes.
And if you are in a similar situation in future, go to www.findjar.com, type in the name of the class, and the search engine would find the jar for you. That website has served me countless times.

How to get classloader for a bundle in equinox?

I have read a lot of equinox code for this, but still can't figure out a non-hacky way of getting the classloader for a osgi bundle in eclipse equinox setup. Is there one?
In OSGi 4.3 you can use:
bundle.adapt(BundleWiring.class).getClassLoader()
The short answer (certainly for OSGi 4.1, not sure of 4.2) is you can't get a bundle's classloader. However the Bundle interface exposes a loadClass() method and this would allow you to write a classloader that wraps the bundle API and delegates to that loadClass() method. Or you can save some time and use Spring DM's BundleDelegatingClassLoader class instead.
The class loader of a bundle can be obtained through the BundleWiring interface. Here a short example:
Bundle bundle = bundleContext.getBundle();
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
ClassLoader classLoader = bundleWiring.getClassLoader();
In normal java code, you can get the class loader that loaded a given object with
object.getClass().getClassLoader();
Or even just
SomeType.class.getClassLoader();
The same applies to Equinox, just use an object or type that comes from the bundle you are interested in.