Drombler / drombler-fx

Drombler FX - the modular application framework for JavaFX.
https://www.drombler.org/drombler-fx
Other
60 stars 8 forks source link

[Feature] Make OSGI services available to actions and dockables. #119

Closed mainrs closed 8 years ago

mainrs commented 8 years ago

I have looked into the source code for acp and the fx part but I couldn't find any clue on how to retrieve OSGI services within my application. The fact that each bundle contains just definitions of actions (via the annotations) means that you normally do not get access to the OSGI layer because drombler-fx is hooking up those classes in the background. Even if you create a BundleActivator, you have no chance to pass any Service instance that you created/implemented/need to those actions or dockables.

A small example

I have an interface that is capable of storing my contacts and an implementation:

PersistenceStorage.java ``` public interface PersistenceStorage { void exporting(Contact contact); } ```
PersistenceStorageImpl.java ``` public class PersistenceStorageImpl extends PersistenceStorage { public void export(Contact contact) { System.out.println("exporting " + contact); } } ```

Let's assume that my editor pane somehow displays those contacts. After modifying them, I want to export them using the 'ExportAction' that extends AbstractFXAction. The export action would use the registered OSGI service 'PersistenceStorage' to export the data for each contact. This example is quite simple but imagine if you have some kind of service that resolves paths for you (if your data that is displayed contains scripts, properties, configurations and resources. Each 'profile' is made up of them and while displaying the content in the editor pane, some needs to constantly resolve paths to those resources to keep track if them. If you have a fixed folder structure, you could then easily realize this by implementing a service that needs the active profile and returns you information about the data that it contains. And this is where you need some service injection mechanism: You normally do not instantiate any objects yourself (at least not those that are automatically used by drombler-fx).

I hope you understand my idea. I think I didn't express myself well.

puce77 commented 8 years ago

I've provided a sample at StackOverflow how to solve this using a ServiceTracker: http://stackoverflow.com/a/35974498/506855

puce77 commented 8 years ago

I'm marking this as a duplicate of issue #38 "Provide CDI integration", as this is the current desired way how to pursue this further.

mainrs commented 8 years ago

Ah ok. Though that CDI means Java EE... That's why I opened another issue. Sorry :)