| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.authoring.ui; |
| |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.emf.ecore.EAttribute; |
| import org.eclipse.emf.ecore.EReference; |
| import org.eclipse.epf.authoring.gef.util.DiagramEditorUtil; |
| import org.eclipse.epf.authoring.ui.editors.EditorChooser; |
| import org.eclipse.epf.authoring.ui.providers.MethodEditorPageProvider; |
| import org.eclipse.epf.authoring.ui.providers.ProcessEditorPageProvider; |
| import org.eclipse.epf.diagram.model.util.GraphicalDataManager; |
| import org.eclipse.epf.library.ILibraryServiceListener; |
| import org.eclipse.epf.library.LibraryPlugin; |
| import org.eclipse.epf.library.LibraryService; |
| import org.eclipse.epf.library.configuration.ConfigurationApplicator; |
| import org.eclipse.epf.library.configuration.ConfigurationHelper; |
| import org.eclipse.epf.library.configuration.DefaultElementRealizer; |
| import org.eclipse.epf.library.configuration.ProcessAuthoringConfigurator; |
| import org.eclipse.epf.library.configuration.ProcessConfigurator; |
| import org.eclipse.epf.library.edit.ICommandListener; |
| import org.eclipse.epf.library.edit.IConfigurationApplicator; |
| import org.eclipse.epf.library.edit.IConfigurator; |
| import org.eclipse.epf.library.edit.IConfiguratorFactory; |
| import org.eclipse.epf.library.edit.Providers; |
| import org.eclipse.epf.library.edit.command.MethodElementAddCommand; |
| import org.eclipse.epf.library.util.CopyAttachmentsToNewLocation; |
| import org.eclipse.epf.persistence.refresh.RefreshJob; |
| import org.eclipse.epf.uma.ContentDescription; |
| import org.eclipse.epf.uma.MethodConfiguration; |
| import org.eclipse.epf.uma.MethodElement; |
| import org.eclipse.epf.uma.MethodLibrary; |
| import org.eclipse.epf.uma.VariabilityElement; |
| import org.eclipse.epf.uma.ecore.util.OppositeFeature; |
| |
| /** |
| * The Authoring UI service. |
| * |
| * @author Kelvin Low |
| * @since 1.0 |
| */ |
| public class AuthoringUIService { |
| |
| // The shared instance. |
| private static AuthoringUIService instance = new AuthoringUIService(); |
| |
| // The status flag. |
| private boolean started = false; |
| |
| /** |
| * Creates a new instance. |
| */ |
| private AuthoringUIService() { |
| LibraryService.getInstance().addListener(new ILibraryServiceListener() { |
| public void libraryCreated(MethodLibrary library) { |
| } |
| |
| public void libraryOpened(MethodLibrary library) { |
| } |
| |
| public void libraryReopened(MethodLibrary library) { |
| } |
| |
| public void libraryClosed(MethodLibrary library) { |
| } |
| |
| public void librarySet(MethodLibrary library) { |
| if (library != null) { |
| start(); |
| } |
| } |
| |
| public void configurationSet(MethodConfiguration config) { |
| } |
| }); |
| } |
| |
| /** |
| * Returns the shared instance. |
| */ |
| public static AuthoringUIService getInstance() { |
| return instance; |
| } |
| |
| /** |
| * Starts the Authoring UI service. |
| */ |
| public synchronized void start() { |
| if (!started) { |
| // Initialize ProcessAuthoringConfigurator |
| ProcessAuthoringConfigurator.INSTANCE.getClass(); |
| |
| // Initialize the move/paste command. |
| MethodElementAddCommand |
| .setResourceManager(new CopyAttachmentsToNewLocation()); |
| |
| // Initialize the EditorChooser. |
| EditorChooser.getInstance(); |
| |
| // Load EditorPage Providers |
| MethodEditorPageProvider.getInstance().loadProviders(); |
| ProcessEditorPageProvider.getInstance().loadProviders(); |
| |
| // Set providers for library edit. |
| Providers.setConfiguratorFactory(new IConfiguratorFactory() { |
| public IConfigurator createConfigurator( |
| MethodConfiguration config) { |
| return new ProcessConfigurator(config, null, true); |
| } |
| }); |
| |
| Providers |
| .setConfigurationApplicator(new ConfigurationApplicator()); |
| |
| Providers.setPreferenceStore(LibraryPlugin.getDefault() |
| .getPreferenceStore()); |
| |
| Providers.setAuthoringPlugin(AuthoringUIPlugin.getDefault()); |
| |
| List cmdListeners = GraphicalDataManager.getInstance() |
| .getCommandListeners(); |
| cmdListeners.addAll(DiagramEditorUtil.getInstance() |
| .getVaryCommandListeners()); |
| for (Iterator iter = cmdListeners.iterator(); iter.hasNext();) { |
| ICommandListener listener = (ICommandListener) iter.next(); |
| Providers.registerCommandListener(listener); |
| } |
| |
| RefreshJob.getInstance().start(); |
| |
| started = true; |
| } |
| } |
| |
| /** |
| * Stops the Authoring UI service. |
| */ |
| public synchronized void stop() { |
| if (started) { |
| RefreshJob.getInstance().stop(); |
| started = false; |
| } |
| } |
| |
| } |