package org.eparapher.rcp; import java.net.URL; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; import org.eparapher.rcp.tools.RCPSingleton; /** * This class controls all aspects of the application's execution */ public class Application implements IApplication { public static final String PLUGIN_ID = "eParapher"; private static Logger log = Logger.getLogger(Activator.class); /* (non-Javadoc) * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext) */ public Object start(IApplicationContext context) { // Setup a simple configuration that logs on the console. URL log4JConfig= Platform.getBundle( Application.PLUGIN_ID ).getResource( "log4j.properties" ); //System.out.println(log4JConfig); PropertyConfigurator.configure( log4JConfig ); log.info( "Starting eParapher RCP Client." ); Display display = PlatformUI.createDisplay(); try { ApplicationWorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor(); //Manage single RCP instance and command line arguments of eParapher RCPSingleton rcps = new RCPSingleton(context,advisor); if (rcps.isAlreadystarted()) { log.info("Shutting down eParapher as it's already started."); return IApplication.EXIT_OK; } int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) { return IApplication.EXIT_RESTART; } return IApplication.EXIT_OK; } finally { display.dispose(); } } /* (non-Javadoc) * @see org.eclipse.equinox.app.IApplication#stop() */ public void stop() { final IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench == null) return; final Display display = workbench.getDisplay(); display.syncExec(new Runnable() { public void run() { if (!display.isDisposed()) workbench.close(); } }); } }