public void stop() { String renderId = getRendererServiceId(); context.unregisterService(focusListener, renderId); context.unregisterService(this, renderId); cluster.stop(); String editorId = cluster.getClusterConfig().getString("editor.id"); context.unregisterService(editorContext.getEditorManager(), editorId); context.unregisterService(this, editorId); if (baseService != null) { baseService.destroy(); baseService = null; } if (modelService != null) { modelService.destroy(); modelService = null; } cluster = null; focusListener = null; }
public void start() throws EditorException { String clusterName; switch (mode) { case EDIT: clusterName = "cms-editor"; break; case COMPARE: clusterName = "cms-compare"; break; case VIEW: default: clusterName = "cms-preview"; break; } JavaPluginConfig editorConfig = new JavaPluginConfig(parameters); editorConfig.put("wicket.id", editorId); IPluginConfigService pluginConfigService = context.getService(IPluginConfigService.class.getName(), IPluginConfigService.class); IClusterConfig clusterConfig = pluginConfigService.getCluster(clusterName); if (clusterConfig == null) { throw new EditorException("No cluster found with name " + clusterName); } cluster = context.newCluster(clusterConfig, editorConfig); IClusterConfig decorated = cluster.getClusterConfig(); String modelId = decorated.getString(RenderService.MODEL_ID); modelService = new ModelReference<T>(modelId, getEditorModel()); modelService.init(context); if (mode == Mode.COMPARE) { String baseId = decorated.getString("model.compareTo"); baseService = new ModelReference<T>(baseId, getBaseModel()); baseService.init(context); } String editorId = decorated.getString("editor.id"); context.registerService(this, editorId); context.registerService(editorContext.getEditorManager(), editorId); cluster.start(); IRenderService renderer = context.getService(decorated.getString(RenderService.WICKET_ID), IRenderService.class); if (renderer == null) { cluster.stop(); context.unregisterService(this, editorId); context.unregisterService(editorContext.getEditorManager(), editorId); modelService.destroy(); throw new EditorException("No IRenderService found"); } String renderId = getRendererServiceId(); // attach self to renderer, so that other plugins can close us context.registerService(this, renderId); // observe focus events, those need to be synchronized with the active model of the editor // manager focusListener = new IFocusListener() { private static final long serialVersionUID = 1L; public void onFocus(IRenderService renderService) { editorContext.onFocus(); } }; context.registerService(focusListener, renderId); }