Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Newbie on Equinox and OSGI: Tutorial for swing based applications not using RCP and workbench?
Newbie on Equinox and OSGI: Tutorial for swing based applications not using RCP and workbench? [message #652316] Thu, 03 February 2011 14:56 Go to next message
Iñaki is currently offline IñakiFriend
Messages: 1
Registered: February 2011
Junior Member
Hello everyone,
Firstly, i have to say this is my first post in the forum and I am a newbie on Equinox.

I have been on the last weeks getting to know OSGi and its goodness. Our purpose is to migrate a JNLP Swing based application (prepared to be pluggable somehow) to a JNLP OSGi based framework where to plug applications.

The thing is that I have found extensive tutorials on building and executing eclipse RCP applications. They are fine, but as far as we are getting, we do not want to mount the workbench. We want to use our swing main application where other swing modules will be attached using osgi.

However, did not found ANY tutorial, reference, etc. on how to execute Swing applications over equinox. Can anyone point me in the right direction? Im pretty lost now.

Up to now, my objective is really simple:
- I want equinox to start a bundle which opens the application. Up to here everything is fine and have been able to do that (and consume OSGi services).

- I want that when I close the application, the equinox to be ended without executing system.exit stuff.

Ive read that if I implement iApplication interface, I can bootstrap on equinox so that my application is launched when the framework starts. And when it closes, the framework stops. Also, do not need to have "osgi.noShutdown=true" to be running equinox.

Am I going in the right direction?
Any help is appreciated,
Thanks,
Iñaki

PD: Later work goes on performing these steps:
- Make the environment web started (i think i will be able to do that without much effort).
- Prepare an OSGi OBR for extension modules.
- Build a module that enables to consult OBR extensions and install them (thinking on basing it on Felix OBR Implementation, could not find an OBR implementation in equinox).


Re: Newbie on Equinox and OSGI: Tutorial for swing based applications not using RCP and workbench? [message #664399 is a reply to message #652316] Fri, 08 April 2011 16:14 Go to previous messageGo to next message
Ronald So is currently offline Ronald SoFriend
Messages: 198
Registered: April 2011
Senior Member
I am facing the same issue and this is my 2nd week in OSGi. I was naive about creating a JFrame when I started the bundle and the exception stack trace said they cannot find javax.swing.JFrame.

Did you figure out how to bootstrap the SWING GUI in Eclipse Equinox?

Thanks.
Re: Newbie on Equinox and OSGI: Tutorial for swing based applications not using RCP and workbench? [message #666561 is a reply to message #652316] Thu, 21 April 2011 01:10 Go to previous messageGo to next message
Justin is currently offline JustinFriend
Messages: 7
Registered: September 2010
Junior Member
Sorry, I have no tutorial, but I think you are on the right path. Here is how I've handled it.

- Start with a regular headless RCP app
- SwingUtilities.invokeAndWait your code to start your GUI in the IApplication.start method
- Once your GUI is up, call context.applicationRunning() (don't think this is strictly necessary)
- Block the OSGi thread that started your application.start() on a latch or something
- When the frame is disposed, let the OSGi thread return the IApplication return code you desire.

Hope that helps some,
Justin
Re: Newbie on Equinox and OSGI: Tutorial for swing based applications not using RCP and workbench? [message #687635 is a reply to message #666561] Wed, 22 June 2011 22:14 Go to previous messageGo to next message
Ronald So is currently offline Ronald SoFriend
Messages: 198
Registered: April 2011
Senior Member
I figure this one out. Basically I launched the OSGi framework in console mode. Then I construct the main GUI JFrame in the activator class. You can skip the ComponentTracker class if you don't care about dynamic plug-ins.

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;

import com.company.ui.view.MainFrame;

public class MainUIActivator implements BundleActivator, Runnable {
	private BundleContext m_context = null;
	private MainFrame m_frame = null;
	private ComponentTracker m_ComponentTracker = null;

	/**
	 * Displays the applications window and starts extension tracking;
	 * everything is done on the Swing event thread to avoid synchronization and
	 * repainting issues.
	 * 
	 * @param context
	 *            The context of the bundle.
	 **/
	public void start(BundleContext context) {
		m_context = context;
		if (SwingUtilities.isEventDispatchThread()) {
			run();
		} else {
			try {
				SwingUtilities.invokeAndWait(this);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}

	/**
	 * Stops extension tracking and disposes of the application window.
	 * 
	 * @param context
	 *            The context of the bundle.
	 **/
	public void stop(BundleContext context) {
		m_ComponentTracker.close();
		final MainFrame frame = m_frame;
		
		System.out.println("Bundle State when stop is called: " + context.getBundle().getState());

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				frame.setVisible(false);
				frame.dispose();
			}
		});
	}

	/**
	 * This method actually performs the creation of the application window. It
	 * is intended to be called by the Swing event thread and should not be
	 * called directly.
	 **/
	public void run() {
		m_frame = new MainFrame();

		m_frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		m_frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
				try {
					m_context.getBundle(0).stop();
				} catch (BundleException ex) {
					ex.printStackTrace();
				}
			}
		});

		m_frame.setVisible(true);

		m_ComponentTracker = new ComponentTracker(m_context, m_frame);
		m_ComponentTracker.open();
	}
}
Re: Newbie on Equinox and OSGI: Tutorial for swing based applications not using RCP and workbench? [message #687905 is a reply to message #687635] Thu, 23 June 2011 13:42 Go to previous message
Ronald So is currently offline Ronald SoFriend
Messages: 198
Registered: April 2011
Senior Member
You need to import these two packages and define them in your bundle manifest too.

Import-Package: javax.swing,
 org.osgi.framework;version="1.3.0",

Previous Topic:can i run p2.process.artifacts from cmd line ant
Next Topic:No FrameworkStartLevel service in Indigo?
Goto Forum:
  


Current Time: Thu Apr 18 23:43:05 GMT 2024

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

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

Back to the top