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());
}
});
}
Aggregations