Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Convert a set of plugin projects to a minimal Eclipse 4 RCP
Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1695984] Wed, 20 May 2015 20:21 Go to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
Hello together!

I have a set of plugins that define their dependencies in their MANIFEST.MF files via the "Require-Bundle" or "Import-Package" headers. As a build system I use the Standart Java-Builder that is offered bei Eclipse by default - thus I have build.properties files that define source and output directories and the bin.includes of a plugin. Additionally I make use of the extension point mechanism to define views and menus.

It is my aim to move the application to a state where the user does not have to start it out of my IDE, but where the user can start an executable (.jar, .exe, .sh, ...). This lead me to consider moving to the Eclipse 4 RCP. Can anyone tell me if this is feasable? And if yes, could you point me to some documentation about getting up and running with E4? Or (even better) to documentation on converting a setup similar to mine to an E4 application.

Best Regards,
--
Alexander Baier
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1696182 is a reply to message #1695984] Fri, 22 May 2015 15:15 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,

you need to configure a product and a build. I would recommend to use
Tycho for building your application rather than the integrated PDE Build.

Best regards

Jonas

Am 21.05.2015 um 15:04 schrieb Alexander Baier:
> Hello together!
>
> I have a set of plugins that define their dependencies in their
> MANIFEST.MF files via the "Require-Bundle" or "Import-Package" headers.
> As a build system I use the Standart Java-Builder that is offered bei
> Eclipse by default - thus I have build.properties files that define
> source and output directories and the bin.includes of a plugin.
> Additionally I make use of the extension point mechanism to define views
> and menus.
>
> It is my aim to move the application to a state where the user does not
> have to start it out of my IDE, but where the user can start an
> executable (.jar, .exe, .sh, ...). This lead me to consider moving to
> the Eclipse 4 RCP. Can anyone tell me if this is feasable? And if yes,
> could you point me to some documentation about getting up and running
> with E4? Or (even better) to documentation on converting a setup similar
> to mine to an E4 application.
>
> Best Regards,


--
Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1696507 is a reply to message #1696182] Tue, 26 May 2015 21:03 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
Hi,

Thank you for your answer! Unfortunately using Tycho is not an option
for me at the moment.
I googled around for "product" and found the RCP4 Tutorial from Lars
Vogel (can't link to it, as I have to few posts).
With the help of that tutorial I set up a Eclipse 4 RCP project and I am
now "porting" my plugins over to the RCP4 architecture.

Here I hang at one point where I want to show a part to the user. I used
to do it like this:

MyPart part = null; // this class extends org.eclipse.ui.part.ViewPart
part = (MyPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
    .getActivePage().showView("id");


But this threw a "org.eclipse.e4.core.di.InjectionException:
java.lang.IllegalStateException: Workbench has not been created yet.",
so I tried the following snippet:

MPart part = partService.findPart("id");
part.setVisible(true);
MyPart myPart = (MyPart) part.getWidget();
myPart.setSomething(/*...*/)


I defined a Part in my Application.e4xmi with id "id" whose classURI
points to the MyPart class. MyPart extends org.eclipse.ui.part.ViewPart,
as stated above. This whole code is contained in a handler that defines
an execute(EPartService partService) method annotated with @Execute.

This does not work, as part.getWidget() does not return an instance of
MyPart but rather something named
org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer$2.

How do I get a reference to my part?

Regards,

Alexander Baier
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1696532 is a reply to message #1696507] Wed, 27 May 2015 07:03 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
You need to migrate your view to an Eclipse 4 view. That means it should be a POJO and not extend ViewPart. Since you seem to have a mixed mode you need to register it in your plugin.xml as e4view.
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1698027 is a reply to message #1696532] Wed, 10 June 2015 13:15 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
I missed your answer at first, sorry about that and thank you fo the quick response!

Dirk Fauth wrote on Wed, 27 May 2015 07:03
You need to migrate your view to an Eclipse 4 view. That means it should be a POJO and not extend ViewPart. Since you seem to have a mixed mode you need to register it in your plugin.xml as e4view.


I am not quite clear on the terminology. What exactly does "mixed mode" mean? And do you have an example of registering a view as an e4view in the plugin.xml? Is there an overview of migrating views extending ViewPart to Eclipse 4 views?

Regards,
--
Alexander Baier
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1698111 is a reply to message #1698027] Thu, 11 June 2015 11:48 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
http://www.vogella.com/tutorials/Eclipse4MigrationGuide/article.html
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699227 is a reply to message #1698111] Mon, 22 June 2015 17:59 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
It seems like I do not get email notification, when someone answers my posts :/

Thanks for responding this quickly! I started to convert my Views into POJOs and link them (if that's the right term) in the Application Model. This works very well and I can display my inital view Smile

But I am stuck regarding a view that registeres a mouse listener on a tree. This listener starts/shows other views based on the tree's current selection. To make those other views visible I need an EPartService. Now, what is the recommended way to get hold of an EPartService instance? Can I just do a constructor injection on my view, hold said instance in a field and use it when the mouse listener activates?

EDIT: Is a listener even the right approach here? Or is there something I should do on the Application Model level?

Regards,
--
Alexander Baier

[Updated on: Mon, 22 June 2015 18:04]

Report message to a moderator

Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699262 is a reply to message #1699227] Tue, 23 June 2015 06:57 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
I'm not sure about the question.

First, in E4 you do almost everything via injection. For the EPartService it is typically fine to do a field injection.

Second, if you need to programmatically perform actions on the application model, you need to use the eclipse 4 services. Since you want to show different views dependent on your selection, IMHO using the EPartService is the correct way. If you only need to change the content of a view, you could give the ESelectionService a try.
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699501 is a reply to message #1699262] Wed, 24 June 2015 15:48 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
Dirk Fauth wrote on Tue, 23 June 2015 06:57
I'm not sure about the question.

First, in E4 you do almost everything via injection. For the EPartService it is typically fine to do a field injection.

Ok, I will go down this route then. I was wondering, if there is some kind of lifecycle I have to be careful about, when working with the EPartService. E.g. does the service injected at object creation time (constructor, field) behave different than one, that is injected on a method call. Or, more to the point of my example, is it safe to use a PartService injected via the constructor after the constructor has finished executing.

Quote:
Second, if you need to programmatically perform actions on the application model, you need to use the eclipse 4 services. Since you want to show different views dependent on your selection, IMHO using the EPartService is the correct way. If you only need to change the content of a view, you could give the ESelectionService a try.


I actually want to use multiple instances of the same view. How do I do that? Can I just call EPartService.createPart(String) multiple times? If yes, is there a build-in mechanism allowing me to differentiate between these multiple instances, or do I have to do my own book keeping?

Regards,
--
Alexander Baier
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699516 is a reply to message #1699501] Wed, 24 June 2015 17:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
Unless you are providing your own EPartService on a lower level, there should be only one instance per application. And within a part it shouldn't make a difference when it is injected.

Multiple instances of one part is done via part descriptors.
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699542 is a reply to message #1699516] Wed, 24 June 2015 22:12 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6363
Registered: July 2009
Senior Member
Sorry to correct you but this is NOT correct! There are multiple
EPartService-Instances and even worse they can change overtime if you
reparent your UI to another top-level window!

So it is important that:
* EPartService is retrieved via field/method injection
* in Mars there's a bug that causes IEclipseContext#get(EPartService)
to retrieve the wrong EPartService instance

Tom

On 24.06.15 19:37, Dirk Fauth wrote:
> Unless you are providing your own EPartService on a lower level, there
> should be only one instance per application. And within a part it
> shouldn't make a difference when it is injected.
> Multiple instances of one part is done via part descriptors.
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699543 is a reply to message #1699542] Wed, 24 June 2015 22:30 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
Dirk Fauth wrote on Wed, 24 June 2015 17:37

Multiple instances of one part is done via part descriptors.


I will look into that, haven't heard about those until now.

Thomas Schindl wrote on Wed, 24 June 2015 22:12

[...]
So it is important that:
* EPartService is retrieved via field/method injection
[...]


Regarding field injection: When is this executed? Each time the EPartService I am referencing with my field changes? So does the field always hold the "correct" (what exactly that means, I don't know) EPartService?

Regards,
--
Alexander Baier
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699550 is a reply to message #1699543] Thu, 25 June 2015 04:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6363
Registered: July 2009
Senior Member
On 25.06.15 00:30, Alexander Baier wrote:
> Dirk Fauth wrote on Wed, 24 June 2015 17:37
>> Multiple instances of one part is done via part descriptors.
>
>
> I will look into that, haven't heard about those until now.
>
> Thomas Schindl wrote on Wed, 24 June 2015 22:12
>> [...]
>> So it is important that:
>> * EPartService is retrieved via field/method injection
>> [...]
>
>
> Regarding field injection: When is this executed? Each time the
> EPartService I am referencing with my field changes? So does the field
> always hold the "correct" (what exactly that means, I don't know)
> EPartService?

Yes! DI will update the field when ever the value changes because of
whatever reason. You don't have to care about it.

Tom
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699557 is a reply to message #1699550] Thu, 25 June 2015 06:27 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
Quote:
Sorry to correct you but this is NOT correct! There are multiple
EPartService-Instances and even worse they can change overtime if you
reparent your UI to another top-level window!


No need for excuses! Thanks for correcting me. Looks like I'm not that familiar with the internals as I thought. Smile

Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699683 is a reply to message #1699543] Thu, 25 June 2015 19:23 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
Regarding the part descriptors: How do I use them? I currently have a POJO that implements my view and an MPart in my Application.e4xmi. This only allows me to display one instance of said view. I, however, want to programatically create multiple instances of the same view.

I googled around, but did not find any comprehensive explanation. Is there documentation available that talks about the E4 "stuff" in more detail than "click here and here and copy paste these things and then run it"? Tutorials are great to get started but usually lack the depth to keep you going beyond that initial step. This leads to me coming back here with every little question that pops up.

Regards,
--
Alexander Baier
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1699708 is a reply to message #1699683] Fri, 26 June 2015 04:15 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
The tutorials by Lars Vogel are really good IMHO: http://www.vogella.com/tutorials/EclipseRCP/article.html

His book contains almost every information you need to get started with e4 and beyond.

Regarding part descriptors, there is also a tutorial http://www.vogella.com/tutorials/Eclipse4Services/article.html#selectedservices_partservice5
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1705580 is a reply to message #1699708] Mon, 17 August 2015 15:32 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
I went ahead and bought the Eclipse 4 RCP book from Lars Vogel. This is indeed a great resource to get startet with E4. With your and his help I got my Application completely ported to E4, thank you! Smile
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1706763 is a reply to message #1705580] Sun, 30 August 2015 16:55 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
I am now trying to make use of E4's dependency injection to properly declare the dependencies of my classes instead of pulling those out of
public static <Dependency> INSTANCE
fields all over the place.

I have a Part that I create and show via PartService#createPart(String) and PartService#showPart(Part, PartState). This Part's class has a dependency on Interface A which is to be set via the constructor of said class:
@Inject
public SomeClass(A dependency) { ... }


I want to bind A.class to an implementation before I create SomeClass, so it gets properly injected into the constructor. To do this, I try (and fail) to get a reference to the appropriate IEclipseContext:
EModelService modelService;
IEclipseContext ctx = modelService.getContainingContext(somePart);
ctx.set(A.class, new AImpl()); // NPE
part.setContext(ctx);


This, however, does not work. It throws an NPE because ctx is null.

What is the intended way of injecting dependencies into a class that is created by a Part?

Regards,
--
Alex

[Updated on: Sun, 30 August 2015 16:56]

Report message to a moderator

Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1706767 is a reply to message #1706763] Sun, 30 August 2015 20:21 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
Typically you use the ContextInjectionFactory. And you should be able to get the IEclipseContext injected.
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1706818 is a reply to message #1706767] Mon, 31 August 2015 11:37 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
Dirk Fauth wrote on Sun, 30 August 2015 22:21
Typically you use the ContextInjectionFactory. And you should be able to get the IEclipseContext injected.


The problem is not really with injecting itself, but with getting a context that is not null to put dependencies into. Your Factory suggestion lead me to find EclipseContextFactory, which indeed lets me create a new Context I can use to inject dependencies with.

For further reference, this is the code I ended up with:
MPart part = partService.createPart(viewId);
IEclipseContext ctx = EclipseContextFactory.create();
ctx.set(A.class, new AImpl());
part.setContext(ctx);        
partService.showPart(part, PartState.VISIBLE);
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1706821 is a reply to message #1706818] Mon, 31 August 2015 11:57 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
Well, modelService.getContainingContext(somePart) is returning null because you just created the model element. You haven't added it to the application model yourself. Since you haven't posted WHERE you are trying to create your MPart, I can't tell you a better way.

Dependent on the use case and the location, I create a new IEclipseContext using the current IEclipseContext#createChild(). And then I put my dependencies in there if I need a local instance that should not be accessible in other contexts. If the created instance needs to be accessible in other locations too, you need to use the IEclipseContext in the hierarchy that fits your needs the best.
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1706928 is a reply to message #1706821] Mon, 31 August 2015 22:19 Go to previous messageGo to next message
Alexander Baier is currently offline Alexander BaierFriend
Messages: 16
Registered: May 2015
Junior Member
Dirk Fauth wrote on Mon, 31 August 2015 13:57
Well, modelService.getContainingContext(somePart) is returning null because you just created the model element. You haven't added it to the application model yourself. Since you haven't posted WHERE you are trying to create your MPart, I can't tell you a better way.


I am creating my MPart inside a class which I instantiate via ContextInjectionFactory#make. It gets the partService injected.

Dirk Fauth wrote on Mon, 31 August 2015 13:57

Dependent on the use case and the location, I create a new IEclipseContext using the current IEclipseContext#createChild(). And then I put my dependencies in there if I need a local instance that should not be accessible in other contexts. If the created instance needs to be accessible in other locations too, you need to use the IEclipseContext in the hierarchy that fits your needs the best.


So I should pass an EclipseContext down into my class and create a child context from that? Is it important for my child to have such a parent context when setting it as the context of a part?
Re: Convert a set of plugin projects to a minimal Eclipse 4 RCP [message #1706943 is a reply to message #1706928] Tue, 01 September 2015 06:50 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2526
Registered: July 2012
Senior Member
Quote:
I am creating my MPart inside a class which I instantiate via ContextInjectionFactory#make. It gets the partService injected.


I guess that is ok, but still just creating it doesn't mean to add it to the model. IIRC partService#showPart() will add the MPart to the model hierarchy. So afterwards you will have the IEclipseContext. If you need it before you might want to try to add the MPart to the part stack manually before. Not sure if that is a "better" way. Just another one.

The contexts are designed to be hierarchical. This way you for example have access to the elements put in application level. That doesn't happen if you create a new one without the hierarchy. If you don't need other values from the context it is fine, otherwise it will fail when trying to access such values.
Previous Topic:"No repository found containing" error while generating P2
Next Topic:Composite overlapping a part?
Goto Forum:
  


Current Time: Fri Nov 24 16:54:01 GMT 2017

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

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