Search in sources :

Example 1 with SingleInstanceManager

use of org.freeplane.main.application.SingleInstanceManager in project freeplane by freeplane.

the class ActivatorImpl method startFramework.

private void startFramework(final BundleContext context) {
    registerClasspathUrlHandler(context);
    if (null == System.getProperty("org.freeplane.core.dir.lib", null)) {
        final File root = new File(FreeplaneGUIStarter.getResourceBaseDir()).getAbsoluteFile().getParentFile();
        try {
            String rootUrl = root.toURI().toURL().toString();
            if (!rootUrl.endsWith("/")) {
                rootUrl = rootUrl + "/";
            }
            final String libUrl = rootUrl + "core/org.freeplane.core/lib/";
            System.setProperty("org.freeplane.core.dir.lib", libUrl);
        } catch (final MalformedURLException e) {
        }
    }
    // initialize ApplicationController - SingleInstanceManager needs the configuration
    starter = createStarter();
    final SingleInstanceManager singleInstanceManager = new SingleInstanceManager(starter);
    singleInstanceManager.start(getCallParameters());
    if (singleInstanceManager.isSlave()) {
        LogUtils.info("opened files in master - exiting now");
        System.exit(0);
    } else if (singleInstanceManager.isMasterPresent()) {
        starter.setDontLoadLastMaps();
    }
    loadPlugins(context);
    final Controller controller = starter.createController();
    starter.createModeControllers(controller);
    try {
        final ServiceReference[] controllerProviders = context.getServiceReferences(IControllerExtensionProvider.class.getName(), null);
        if (controllerProviders != null) {
            for (int i = 0; i < controllerProviders.length; i++) {
                final ServiceReference controllerProvider = controllerProviders[i];
                final IControllerExtensionProvider service = (IControllerExtensionProvider) context.getService(controllerProvider);
                service.installExtension(controller);
                context.ungetService(controllerProvider);
            }
        }
    } catch (final InvalidSyntaxException e) {
        e.printStackTrace();
    }
    try {
        final Set<String> modes = controller.getModes();
        for (final String modeName : modes) {
            final ServiceReference[] modeControllerProviders = context.getServiceReferences(IModeControllerExtensionProvider.class.getName(), "(mode=" + modeName + ")");
            if (modeControllerProviders != null) {
                final ModeController modeController = controller.getModeController(modeName);
                Controller.getCurrentController().selectModeForBuild(modeController);
                for (int i = 0; i < modeControllerProviders.length; i++) {
                    final ServiceReference modeControllerProvider = modeControllerProviders[i];
                    final IModeControllerExtensionProvider service = (IModeControllerExtensionProvider) context.getService(modeControllerProvider);
                    service.installExtension(modeController);
                    context.ungetService(modeControllerProvider);
                }
            }
        }
    } catch (final InvalidSyntaxException e) {
        e.printStackTrace();
    }
    if ("true".equals(System.getProperty("org.freeplane.exit_on_start", null))) {
        controller.getViewController().invokeLater(new Runnable() {

            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (final InterruptedException e) {
                }
                System.exit(0);
            }
        });
        return;
    }
    controller.getViewController().invokeLater(new Runnable() {

        public void run() {
            final Bundle[] bundles = context.getBundles();
            final HashSet<String> plugins = new HashSet<String>();
            for (Bundle bundle : bundles) {
                plugins.add(bundle.getSymbolicName());
            }
            FilterController.getController(controller).loadDefaultConditions();
            starter.buildMenus(controller, plugins);
            starter.createFrame(getCallParameters());
        }
    });
}
Also used : MalformedURLException(java.net.MalformedURLException) SingleInstanceManager(org.freeplane.main.application.SingleInstanceManager) Bundle(org.osgi.framework.Bundle) ModeController(org.freeplane.features.mode.ModeController) ResourceController(org.freeplane.core.resources.ResourceController) FilterController(org.freeplane.features.filter.FilterController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) ServiceReference(org.osgi.framework.ServiceReference) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 HashSet (java.util.HashSet)1 ResourceController (org.freeplane.core.resources.ResourceController)1 FilterController (org.freeplane.features.filter.FilterController)1 Controller (org.freeplane.features.mode.Controller)1 ModeController (org.freeplane.features.mode.ModeController)1 SingleInstanceManager (org.freeplane.main.application.SingleInstanceManager)1 Bundle (org.osgi.framework.Bundle)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1