tags:

views:

393

answers:

1

I'm writing a graphic application, with java, swt and osgi. The bundle A holds the application main window. Depending on the selection of the user, a different user interface must be loaded. That is, the different GUI are in different bundles. So the main bundle A calls the bundle B to draw the new graphic interface. The bundle B contains many classes, SWT controls that extend the Composite class. This controls need a parent to draw to. The problem here is, the bundle B needs to draw on the bundle A. I tried to sends the parent composite that will hold the new interface from A to B, but when B creates the new control, it crashes.

Any idea? How to solve this problem?

+1  A: 

Sounds like you're trying to setup some complicated cross dependency thing that isn't working out too well.

Are you aware of the Whiteboard pattern? You can read more here: http://www.osgi.org/wiki/uploads/Links/whiteboard.pdf

So based on that pattern let's say A is your 'main' bundle which loads the main UI. To keep things simple, let's say bundle A also exports the following interface:

public interface UIExtensionService {

    Control createExtension(Composite parent);

}

Bundle B (and C, D, E, F, etc) then registers appropriate implementations of this interface. You can use properties when you register the service to help your main bundle narrow down on a particular implementation for instance, if you want to show something specific based on a given user input.

Bundle A then uses the BundleContext to find an appropriate implementation of UIExtensionService and calls the createExtension method passing in the parent you want to use.

Hope that helps.

brindy