Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Adding custom JavaFX controls from a plugin
Adding custom JavaFX controls from a plugin [message #1734062] Fri, 03 June 2016 12:27 Go to next message
Kai Pervoelz is currently offline Kai PervoelzFriend
Messages: 14
Registered: August 2015
Junior Member
I am building an efxclipse based e4 application and I want to add some custom JavaFX controls to the application from a plugin.

The application is based on a MainFrame.fxml.
In the MainFrameController I add a HBox to the EclipseContext by

@Inject
IEclipseContext context;

@FXML
HBox myHBox;

@Override
public void initialize(final URL location, final ResourceBundle resources) {
      context.set("MyIDString", myHBox);
}


From a separate plugin I contribute an Addon to the Application.e4xmi by adding a ModelFragment to:

ExtendedElementID: org.eclipse.e4.application
Feature Name: addons

My idea was to inject the myHBox in this addon and add some custom JavaFX controls here but the problem is, the injection does not work.
The myInjectedHBox is always null.

@Inject
@Optional
@Named("MyIDString")
HBox myInjectedHBox;


It seems as if the MainFrameController and the Addon using different EclipseContexts. Any idea how this could work?

Kai
Re: Adding custom JavaFX controls from a plugin [message #1734063 is a reply to message #1734062] Fri, 03 June 2016 12:44 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Yes they do. Addon instances are created on the MApplication-Context and
your FXML is most likely an element inside the an MPart hence it is
created on the MPart instance.

I'm not sure but I think contributions should work in the opposite
directions. Addons are more a way to extend the e4 framework itself eg
by listening to model changes and reacting on them (see eg MinMax,
Cleanup,...).

If I'd model this think I'd use OSGi-Services let's say

MainFrameContributionService {
void apply(HBox box);
}

and in the controller I'd let the system inject them

class MainFrameController {
private List<MainFrameContributionService> list = new ArrayList<>();

@FXML
HBox myHBox;

@Inject
public void setServices(
@Service List<MainFrameContributionService> list) {
this.list = list;
}


public void initialize(final URL location, final ResourceBundle
resources) {
list.stream.foreach( s -> s.apply(box) );
}
}

Please note that @Service:
* allows you to retrieve a list of OSGi-Services
* is dynamic so if a services is coming and going you'll get an
reinjection

See
http://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Injection_of_OSGi-Services

Tom

On 03.06.16 14:27, Kai Pervoelz wrote:
> I am building an efxclipse based e4 application and I want to add some
> custom JavaFX controls to the application from a plugin.
>
> The application is based on a MainFrame.fxml. In the MainFrameController
> I add a HBox to the EclipseContext by
>
> @Inject
> IEclipseContext context;
>
> @FXML
> HBox myHBox;
>
> @Override
> public void initialize(final URL location, final ResourceBundle
> resources) {
> context.set("MyIDString", myHBox);
> }
>
>
> From a separate plugin I contribute an Addon to the Application.e4xmi by
> adding a ModelFragment to:
>
> ExtendedElementID: org.eclipse.e4.application
> Feature Name: addons
>
> My idea was to inject the myHBox in this addon and add some custom
> JavaFX controls here but the problem is, the injection does not work.
> The myInjectedHBox is always null.
>
> @Inject
> @Optional
> @Named("MyIDString")
> HBox myInjectedHBox;
>
>
> It seems as if the MainFrameController and the Addon using different
> EclipseContexts. Any idea how this could work?
>
> Kai
Re: Adding custom JavaFX controls from a plugin [message #1734080 is a reply to message #1734063] Fri, 03 June 2016 14:57 Go to previous messageGo to next message
Kai Pervoelz is currently offline Kai PervoelzFriend
Messages: 14
Registered: August 2015
Junior Member
Okay, thanks for the fast reply.
I will try the OSGi Service approach.

Kai
Re: Adding custom JavaFX controls from a plugin [message #1734084 is a reply to message #1734080] Fri, 03 June 2016 15:41 Go to previous messageGo to next message
Kai Pervoelz is currently offline Kai PervoelzFriend
Messages: 14
Registered: August 2015
Junior Member
Using an OSGi-Service works fine, but now there is another question:

What's the right/best location to inject the service and actually make the JavaFX contribution?

Since my plugin also contributes a part to the application, I could use this part to inject the service and add the JavaFX controls to the MainApplication. But then I am depending on this part, which might not be the best way. Another solution could be still using the Addon, inject the OSGi-Service there and add the JavaFX controls. But based ob your first answer, this might also not the best solution.

What would you suggest?

Kai
Re: Adding custom JavaFX controls from a plugin [message #1734194 is a reply to message #1734084] Mon, 06 June 2016 06:22 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I can not follow. What do you mean by injecting the service? You
register a service in the OSGi-Service registry (the best option is to
use Declarative-Services) and that's it.

Tom

On 03.06.16 17:41, Kai Pervoelz wrote:
> Using an OSGi-Service works fine, but now there is another question:
> What's the right/best location to inject the service and actually make
> the JavaFX contribution?
>
> Since my plugin also contributes a part to the application, I could use
> this part to inject the service and add the JavaFX controls to the
> MainApplication. But then I am depending on this part, which might not
> be the best way. Another solution could be still using the Addon, inject
> the OSGi-Service there and add the JavaFX controls. But based ob your
> first answer, this might also not the best solution.
>
> What would you suggest?
> Kai
Re: Adding custom JavaFX controls from a plugin [message #1734333 is a reply to message #1734194] Tue, 07 June 2016 09:06 Go to previous messageGo to next message
Kai Pervoelz is currently offline Kai PervoelzFriend
Messages: 14
Registered: August 2015
Junior Member
Yes, this part works fine. I used Declarative-Services and created the "MainFrameContributionService". And I use this service in the MainFrameController to add myHBox to the MainFrameContributionService.

Now I need to add my custom JavaFX Controls to this myHBox from another plugin. My plugins typically contributing views, handlers etc. via fragment.e4xmi, there is nothing which is instantiated at startup of the plugin, like the activator was in eclipse 3.x. Can/should I use an Activator for this here, too?

I want to add my JavaFX Controls to myHBox if a specific plugin exists in my application and I want it independent from instantiating any parts which are contributed by this plugin.

hope this describes my problem a little bit better.


Kai




Re: Adding custom JavaFX controls from a plugin [message #1734336 is a reply to message #1734333] Tue, 07 June 2016 09:21 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You could create a DS that makes your custom JavaFX control available. So if you plugin exists the control is contributed via DS, otherwise it doesn't exist.
Re: Adding custom JavaFX controls from a plugin [message #1734340 is a reply to message #1734333] Tue, 07 June 2016 09:31 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Any plugin can contribute to via DS so I don't get the problem

Tom

On 07.06.16 11:06, Kai Pervoelz wrote:
> Yes, this part works fine. I used Declarative-Services and created the
> "MainFrameContributionService". And I use this service in the
> MainFrameController to add myHBox to the MainFrameContributionService.
> Now I need to add my custom JavaFX Controls to this myHBox from another
> plugin. My plugins typically contributing views, handlers etc. via
> fragment.e4xmi, there is nothing which is instantiated at startup of the
> plugin, like the activator was in eclipse 3.x. Can/should I use an
> Activator for this here, too?
> I want to add my JavaFX Controls to myHBox if a specific plugin exists
> in my application and I want it independent from instantiating any parts
> which are contributed by this plugin.
> hope this describes my problem a little bit better.
>
> Kai
>
>
>
>
Previous Topic:Closing the Workbench causing Error
Next Topic:e(fx)clipse - The next release
Goto Forum:
  


Current Time: Fri Apr 19 13:53:23 GMT 2024

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

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

Back to the top