diff options
author | David Akehurst | 2014-05-15 17:29:21 +0000 |
---|---|---|
committer | David Akehurst | 2014-05-17 07:20:48 +0000 |
commit | ec345753c29cf2f9acf9b765be0a54b3e3f9a81f (patch) | |
tree | 7e29f174304c5e2c458f2b32c5f1945fe3d69799 /plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml | |
parent | e39e50efd845db6b228ec79e197cf0780506fce7 (diff) | |
download | org.eclipse.papyrus-ec345753c29cf2f9acf9b765be0a54b3e3f9a81f.tar.gz org.eclipse.papyrus-ec345753c29cf2f9acf9b765be0a54b3e3f9a81f.tar.xz org.eclipse.papyrus-ec345753c29cf2f9acf9b765be0a54b3e3f9a81f.zip |
[434594] Enable Model (Library/Metamodel/Profile) Registrations to be
added to via code
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=43459
Change-Id: Ib4eb7db3f1e82664a8c15a0c2ea2c06797d4b39e
Signed-off-by: David Akehurst <dave@akehurst.net>
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml')
11 files changed, 286 insertions, 94 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/IRegisteredItem.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/IRegisteredItem.java new file mode 100644 index 00000000000..a2911ab5f41 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/IRegisteredItem.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * 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: + * Dr. David H. Akehurst - enable programmatic registration + *******************************************************************************/ +package org.eclipse.papyrus.uml.extensionpoints; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.swt.graphics.Image; + +public interface IRegisteredItem { + + /** Name of the registered item */ + String getName(); + + /** URI to the file that is the registered item */ + URI getUri(); + + /** Path of the file that implements the registered element */ + String getPath(); + + /** Identifier for the provider of this item */ + String getProvider(); + + /** Long description of the registered item */ + String getDescription(); + + Image getImage(); +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/Registry.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/Registry.java new file mode 100644 index 00000000000..9120f04b8ca --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/Registry.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * 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: + * Dr. David H. Akehurst - enable programmatic registration + *****************************************************************************/ +package org.eclipse.papyrus.uml.extensionpoints; + +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.papyrus.uml.extensionpoints.library.IRegisteredLibrary; +import org.eclipse.papyrus.uml.extensionpoints.library.RegisteredLibrary; +import org.eclipse.papyrus.uml.extensionpoints.metamodel.IRegisteredMetamodel; +import org.eclipse.papyrus.uml.extensionpoints.metamodel.RegisteredMetamodel; +import org.eclipse.papyrus.uml.extensionpoints.profile.IRegisteredProfile; +import org.eclipse.papyrus.uml.extensionpoints.profile.RegisteredProfile; + +public class Registry { + + /** attribute that acts as a cache for the list of registered libraries */ + private static List<IRegisteredLibrary> registeredLibraries; + + public static List<IRegisteredLibrary> getRegisteredLibraries() { + if(null == registeredLibraries) { + registeredLibraries = RegisteredLibrary.getRegisteredLibraries(); + } + return registeredLibraries; + } + + public static void addRegisteredLibrary(IRegisteredLibrary lib) { + if(null == registeredLibraries) { + registeredLibraries = RegisteredLibrary.getRegisteredLibraries(); + } + registeredLibraries.add(lib); + } + + /** attribute that acts as a cache for the list of registered metamodels */ + private static List<IRegisteredMetamodel> registeredMetamodels; + + public static List<IRegisteredMetamodel> getRegisteredMetamodels() { + if(null == registeredMetamodels) { + registeredMetamodels = RegisteredMetamodel.getRegisteredMetamodels(); + } + return registeredMetamodels; + } + + public static void addRegisteredMetamodel(IRegisteredMetamodel lib) { + if(null == registeredMetamodels) { + registeredMetamodels = RegisteredMetamodel.getRegisteredMetamodels(); + } + registeredMetamodels.add(lib); + } + + /** attribute that acts as a cache for the list of registered profiles */ + private static List<IRegisteredProfile> registeredProfiles; + + public static List<IRegisteredProfile> getRegisteredProfiles() { + if(null == registeredProfiles) { + registeredProfiles = RegisteredProfile.getRegisteredProfiles(); + } + return registeredProfiles; + } + public static IRegisteredProfile getRegisteredProfile(String name, String path) { + Assert.isNotNull(name); + List<IRegisteredProfile> profiles = Registry.getRegisteredProfiles(); + for(int i = 0; i < profiles.size(); i++) { + IRegisteredProfile profile = profiles.get(i); + + // name corresponds. is path equal? + if(name.equals(profile.getName())) { + // no path indicated => first name that corresponds => profile returned + if(path == null) { + return profile; + } else if(path.equals(profile.getPath())) { + return profile; + } + } + } + return null; + } + public static void addRegisteredProfile(IRegisteredProfile lib) { + if(null == registeredProfiles) { + registeredProfiles = RegisteredProfile.getRegisteredProfiles(); + } + registeredProfiles.add(lib); + } +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/IRegisteredLibrary.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/IRegisteredLibrary.java new file mode 100644 index 00000000000..125ddccc6a5 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/IRegisteredLibrary.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * 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: + * Dr. David H. Akehurst + *******************************************************************************/ +package org.eclipse.papyrus.uml.extensionpoints.library; + +import org.eclipse.papyrus.uml.extensionpoints.IRegisteredItem; + +public interface IRegisteredLibrary extends IRegisteredItem { + +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredLibrary.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredLibrary.java index ad44c0da884..8b881e7f4ae 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredLibrary.java +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredLibrary.java @@ -7,6 +7,7 @@ * * Contributors: * CEA List - initial API and implementation + * Dr. David H. Akehurst - enable programmatic registration *******************************************************************************/ package org.eclipse.papyrus.uml.extensionpoints.library; @@ -15,6 +16,7 @@ import java.util.List; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.util.URI; import org.eclipse.papyrus.uml.extensionpoints.Activator; import org.eclipse.papyrus.uml.extensionpoints.standard.ExtensionIds; import org.eclipse.papyrus.uml.extensionpoints.standard.RegisteredElementExtensionPoint; @@ -22,14 +24,11 @@ import org.eclipse.papyrus.uml.extensionpoints.standard.RegisteredElementExtensi /** * Class that manages registered library extension point */ -public class RegisteredLibrary extends RegisteredElementExtensionPoint { +public class RegisteredLibrary extends RegisteredElementExtensionPoint implements IRegisteredLibrary { /** name of the extension point (main element name) in the DTD */ private static final String TAG_LIBRARY = "library"; - /** attribute that acts as a cache for the list of registered libraries */ - private static RegisteredLibrary[] RegisteredLibraries; - /** * Main constructor. * @@ -42,20 +41,22 @@ public class RegisteredLibrary extends RegisteredElementExtensionPoint { super(configElt, ordinal); } + public URI getUri() { + return super.uri; + } + + public String getPath() { + return super.path; + } + /** * Returns the list of registered libraries in the platform, using the Papyrus extension point. * * @return the list of registered libraries in the platform */ - public static RegisteredLibrary[] getRegisteredLibraries() { - - // if the list was already computed, returns it (like a cache) - if(RegisteredLibraries != null) { - return RegisteredLibraries; - } + public static List<IRegisteredLibrary> getRegisteredLibraries() { - // the list of libraries was not already computed. Read configuration elements - List<RegisteredLibrary> libraries = new ArrayList<RegisteredLibrary>(); + List<IRegisteredLibrary> libraries = new ArrayList<IRegisteredLibrary>(); // // Default elements : UML, Ecore, Java, XML PrimitiveTypes model library // RegisteredLibrary UmlPrimitiveTypes @@ -81,15 +82,14 @@ public class RegisteredLibrary extends RegisteredElementExtensionPoint { // Read configuration elements for the current extension for(int j = 0; j < configElements.length; j++) { - RegisteredLibrary proxy = parseLibraryExtension(configElements[j], libraries.size()); + IRegisteredLibrary proxy = parseLibraryExtension(configElements[j], libraries.size()); if(proxy != null) { libraries.add(proxy); } } // end of configElements loop - RegisteredLibraries = libraries.toArray(new RegisteredLibrary[libraries.size()]); - return RegisteredLibraries; + return libraries; } /** @@ -99,7 +99,7 @@ public class RegisteredLibrary extends RegisteredElementExtensionPoint { * @param configElt * @return */ - private static RegisteredLibrary parseLibraryExtension(IConfigurationElement configElt, int ordinal) { + private static IRegisteredLibrary parseLibraryExtension(IConfigurationElement configElt, int ordinal) { if(!TAG_LIBRARY.equals(configElt.getName())) { return null; } diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredLibrarySelectionDialog.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredLibrarySelectionDialog.java index 1483cc3c1f6..821b7244b17 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredLibrarySelectionDialog.java +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredLibrarySelectionDialog.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * CEA List - initial API and implementation - * Christian W. Damus (CEA) - bug 422257 - * + * CEA List - initial API and implementation + * Christian W. Damus (CEA) - bug 422257 + * Dr. David H. Akehurst - enable programmatic registration *******************************************************************************/ package org.eclipse.papyrus.uml.extensionpoints.library; @@ -22,6 +22,7 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.uml.extensionpoints.Activator; import org.eclipse.papyrus.uml.extensionpoints.standard.ExtensionLabelProvider; +import org.eclipse.papyrus.uml.extensionpoints.Registry; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.ElementListSelectionDialog; import org.eclipse.uml2.uml.Element; @@ -47,7 +48,7 @@ public class RegisteredLibrarySelectionDialog extends ElementListSelectionDialog /** * */ - private RegisteredLibrary[] regLibraries; + private IRegisteredLibrary[] regLibraries; /** * @@ -68,7 +69,7 @@ public class RegisteredLibrarySelectionDialog extends ElementListSelectionDialog importedLibrariesNames = getImportedLibraryNames(importedLibraries); // Retrieve registered Libraries - regLibraries = RegisteredLibrary.getRegisteredLibraries(); + regLibraries = Registry.getRegisteredLibraries().toArray(new IRegisteredLibrary[0]); // remove already applied Libraries from the list regLibraries = removeAlreadyImportededFromSelection(); @@ -110,20 +111,20 @@ public class RegisteredLibrarySelectionDialog extends ElementListSelectionDialog * * @return */ - private RegisteredLibrary[] removeAlreadyImportededFromSelection() { + private IRegisteredLibrary[] removeAlreadyImportededFromSelection() { - List<RegisteredLibrary> Libraries = new ArrayList<RegisteredLibrary>(); + List<IRegisteredLibrary> Libraries = new ArrayList<IRegisteredLibrary>(); for(int i = 0; i < regLibraries.length; i++) { - String currentName = regLibraries[i].name; + String currentName = regLibraries[i].getName(); if(!importedLibrariesNames.contains(currentName)) { Libraries.add(regLibraries[i]); } } - RegisteredLibrary[] cleandList; - cleandList = Libraries.toArray(new RegisteredLibrary[Libraries.size()]); + IRegisteredLibrary[] cleandList; + cleandList = Libraries.toArray(new IRegisteredLibrary[Libraries.size()]); return cleandList; } @@ -141,8 +142,8 @@ public class RegisteredLibrarySelectionDialog extends ElementListSelectionDialog } for(int i = 0; i < selection.length; i++) { - RegisteredLibrary currentLibrary = (RegisteredLibrary)(selection[i]); - URI modelUri = currentLibrary.uri; + IRegisteredLibrary currentLibrary = (IRegisteredLibrary)(selection[i]); + URI modelUri = currentLibrary.getUri(); addModelLibraryImportFromURI(currentModel, modelUri); } diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredProfileAsLibrarySelectionDialog.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredProfileAsLibrarySelectionDialog.java index bf210a947d1..a85148c1fec 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredProfileAsLibrarySelectionDialog.java +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/library/RegisteredProfileAsLibrarySelectionDialog.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * CEA List - initial API and implementation - * Christian W. Damus (CEA) - bug 422257 - * + * CEA List - initial API and implementation + * Christian W. Damus (CEA) - bug 422257 + * Dr. David H. Akehurst - enable programmatic registration *******************************************************************************/ package org.eclipse.papyrus.uml.extensionpoints.library; @@ -24,7 +24,8 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.uml.extensionpoints.Activator; -import org.eclipse.papyrus.uml.extensionpoints.profile.RegisteredProfile; +import org.eclipse.papyrus.uml.extensionpoints.Registry; +import org.eclipse.papyrus.uml.extensionpoints.profile.IRegisteredProfile; import org.eclipse.papyrus.uml.extensionpoints.standard.ExtensionLabelProvider; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.ElementListSelectionDialog; @@ -51,7 +52,7 @@ public class RegisteredProfileAsLibrarySelectionDialog extends ElementListSelect /** * */ - private RegisteredProfile[] regProfiles; + private IRegisteredProfile[] regProfiles; /** * @@ -72,7 +73,7 @@ public class RegisteredProfileAsLibrarySelectionDialog extends ElementListSelect importedProfilesNames = getImportedProfileNames(importedProfiles); // Retrieve registered profiles - regProfiles = RegisteredProfile.getRegisteredProfiles(); + regProfiles = Registry.getRegisteredProfiles().toArray(new IRegisteredProfile[0]); // remove already applied profiles from the list regProfiles = removeAlreadyImportedFromSelection(); @@ -116,20 +117,20 @@ public class RegisteredProfileAsLibrarySelectionDialog extends ElementListSelect * * @return */ - private RegisteredProfile[] removeAlreadyImportedFromSelection() { + private IRegisteredProfile[] removeAlreadyImportedFromSelection() { - List<RegisteredProfile> profiles = new ArrayList<RegisteredProfile>(); + List<IRegisteredProfile> profiles = new ArrayList<IRegisteredProfile>(); for(int i = 0; i < regProfiles.length; i++) { - String currentName = regProfiles[i].name; + String currentName = regProfiles[i].getName(); if(!importedProfilesNames.contains(currentName)) { profiles.add(regProfiles[i]); } } - RegisteredProfile[] cleandList; - cleandList = profiles.toArray(new RegisteredProfile[profiles.size()]); + IRegisteredProfile[] cleandList; + cleandList = profiles.toArray(new IRegisteredProfile[profiles.size()]); return cleandList; } @@ -151,8 +152,8 @@ public class RegisteredProfileAsLibrarySelectionDialog extends ElementListSelect for(int i = 0; i < selection.length; i++) { - RegisteredProfile currentProfile = (RegisteredProfile)(selection[i]); - URI modelUri = currentProfile.uri; + IRegisteredProfile currentProfile = (IRegisteredProfile)(selection[i]); + URI modelUri = currentProfile.getUri(); PackageImport pi = getModelLibraryImportFromURI(modelUri); diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/IRegisteredMetamodel.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/IRegisteredMetamodel.java new file mode 100644 index 00000000000..f5ee021a0a9 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/IRegisteredMetamodel.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * 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: + * Dr. David H. Akehurst - enable programmatic registration + *******************************************************************************/ +package org.eclipse.papyrus.uml.extensionpoints.metamodel; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.papyrus.uml.extensionpoints.IRegisteredItem; + +public interface IRegisteredMetamodel extends IRegisteredItem { + +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/RegisteredMetamodel.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/RegisteredMetamodel.java index 1fef4e11e76..bd78db7a9ba 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/RegisteredMetamodel.java +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/RegisteredMetamodel.java @@ -7,6 +7,7 @@ * * Contributors: * CEA List - initial API and implementation + * Dr. David H. Akehurst - enable programmatic registration *******************************************************************************/ package org.eclipse.papyrus.uml.extensionpoints.metamodel; @@ -16,6 +17,7 @@ import java.util.List; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.util.URI; import org.eclipse.papyrus.uml.extensionpoints.Activator; import org.eclipse.papyrus.uml.extensionpoints.standard.ExtensionIds; import org.eclipse.papyrus.uml.extensionpoints.standard.RegisteredElementExtensionPoint; @@ -23,14 +25,11 @@ import org.eclipse.papyrus.uml.extensionpoints.standard.RegisteredElementExtensi /** * Class that manages registered metamodel extension point */ -public class RegisteredMetamodel extends RegisteredElementExtensionPoint { +public class RegisteredMetamodel extends RegisteredElementExtensionPoint implements IRegisteredMetamodel { /** name of the extension point (main element name) in the DTD */ private static final String TAG_METAMODEL = "metamodel"; - /** list of registered metamodels (Cache) */ - private static RegisteredMetamodel[] RegisteredMetamodels; - /** * Creates a new RegisteredMetamodel. * @@ -41,23 +40,27 @@ public class RegisteredMetamodel extends RegisteredElementExtensionPoint { super(configElt, ordinal); } + public URI getUri() { + return super.uri; + } + + public String getPath() { + return super.path; + } + /** * Returns the list of registered metamodels in the platform, using the Papyrus extension point. * * @return the list of registered metamodels in the platform */ - public static RegisteredMetamodel[] getRegisteredMetamodels() { - // list was already computed, returns it. - if(RegisteredMetamodels != null) { - return RegisteredMetamodels; - } - List<RegisteredMetamodel> metamodels = new ArrayList<RegisteredMetamodel>(); + public static List<IRegisteredMetamodel> getRegisteredMetamodels() { + List<IRegisteredMetamodel> metamodels = new ArrayList<IRegisteredMetamodel>(); IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor( ExtensionIds.METAMODEL_EXTENSION_ID); // Read configuration elements for the current extension for(int j = 0; j < configElements.length; j++) { - RegisteredMetamodel proxy = parseMetamodelExtension(configElements[j], metamodels.size()); + IRegisteredMetamodel proxy = parseMetamodelExtension(configElements[j], metamodels.size()); if(proxy != null) { metamodels.add(proxy); @@ -71,8 +74,7 @@ public class RegisteredMetamodel extends RegisteredElementExtensionPoint { // = new RegisteredMetamodel("ecore", URI.createURI(UMLResource.ECORE_METAMODEL_URI)); // metamodels.add(EcoreMetamodel); - RegisteredMetamodels = metamodels.toArray(new RegisteredMetamodel[metamodels.size()]); - return RegisteredMetamodels; + return metamodels; } /** @@ -84,7 +86,7 @@ public class RegisteredMetamodel extends RegisteredElementExtensionPoint { * @return the RegisteredMetamodel with given name or <code>null</code> if no metamodel was * found. */ - public static RegisteredMetamodel getRegisteredMetamodel(String name) { + public static IRegisteredMetamodel getRegisteredMetamodel(String name) { return getRegisteredMetamodel(name, null); } @@ -99,18 +101,18 @@ public class RegisteredMetamodel extends RegisteredElementExtensionPoint { * @return the RegisteredMetamodel with given name or <code>null</code> if no metamodel was * found. */ - public static RegisteredMetamodel getRegisteredMetamodel(String name, String path) { + public static IRegisteredMetamodel getRegisteredMetamodel(String name, String path) { Assert.isNotNull(name); - RegisteredMetamodel[] metamodels = getRegisteredMetamodels(); + IRegisteredMetamodel[] metamodels = getRegisteredMetamodels().toArray(new IRegisteredMetamodel[0]); for(int i = 0; i < metamodels.length; i++) { - RegisteredMetamodel metamodel = metamodels[i]; + IRegisteredMetamodel metamodel = metamodels[i]; // name corresponds. is path equal? - if(name.equals(metamodel.name)) { + if(name.equals(metamodel.getName())) { // no path indicated => first name that corresponds => profile returned if(path == null) { return metamodel; - } else if(path.equals(metamodel.path)) { + } else if(path.equals(metamodel.getPath())) { return metamodel; } } @@ -127,7 +129,7 @@ public class RegisteredMetamodel extends RegisteredElementExtensionPoint { * the configuration element from which to retrieve the registered profile * @return the registered profile */ - private static RegisteredMetamodel parseMetamodelExtension(IConfigurationElement configElt, int ordinal) { + private static IRegisteredMetamodel parseMetamodelExtension(IConfigurationElement configElt, int ordinal) { if(!TAG_METAMODEL.equals(configElt.getName())) { return null; } diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/RegisteredMetamodelSelectionDialog.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/RegisteredMetamodelSelectionDialog.java index b659b3fe34f..5927d90ecaa 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/RegisteredMetamodelSelectionDialog.java +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/metamodel/RegisteredMetamodelSelectionDialog.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * CEA List - initial API and implementation - * Christian W. Damus (CEA) - bug 422257 - * + * CEA List - initial API and implementation + * Christian W. Damus (CEA) - bug 422257 + * Dr. David H. Akehurst - enable programmatic registration *******************************************************************************/ package org.eclipse.papyrus.uml.extensionpoints.metamodel; @@ -21,6 +21,7 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.uml.extensionpoints.Activator; +import org.eclipse.papyrus.uml.extensionpoints.Registry; import org.eclipse.papyrus.uml.extensionpoints.standard.ExtensionLabelProvider; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.ElementListSelectionDialog; @@ -47,7 +48,7 @@ public class RegisteredMetamodelSelectionDialog extends ElementListSelectionDial /** * */ - private RegisteredMetamodel[] regMetamodels; + private IRegisteredMetamodel[] regMetamodels; /** * @@ -68,7 +69,7 @@ public class RegisteredMetamodelSelectionDialog extends ElementListSelectionDial importedMetamodelsNames = getImportedMetamodelsNames(importedMetamodels); // Retrieve registered Libraries - regMetamodels = RegisteredMetamodel.getRegisteredMetamodels(); + regMetamodels = Registry.getRegisteredMetamodels().toArray(new IRegisteredMetamodel[0]); // remove already applied Libraries from the list regMetamodels = removeAlreadyImportedFromSelection(); @@ -110,20 +111,20 @@ public class RegisteredMetamodelSelectionDialog extends ElementListSelectionDial * * @return */ - private RegisteredMetamodel[] removeAlreadyImportedFromSelection() { + private IRegisteredMetamodel[] removeAlreadyImportedFromSelection() { - List<RegisteredMetamodel> Metamodels = new ArrayList<RegisteredMetamodel>(); + List<IRegisteredMetamodel> Metamodels = new ArrayList<IRegisteredMetamodel>(); for(int i = 0; i < regMetamodels.length; i++) { - String currentName = regMetamodels[i].name; + String currentName = regMetamodels[i].getName(); if(!importedMetamodelsNames.contains(currentName)) { Metamodels.add(regMetamodels[i]); } } - RegisteredMetamodel[] cleanedList; - cleanedList = Metamodels.toArray(new RegisteredMetamodel[Metamodels.size()]); + IRegisteredMetamodel[] cleanedList; + cleanedList = Metamodels.toArray(new IRegisteredMetamodel[Metamodels.size()]); return cleanedList; } @@ -141,8 +142,8 @@ public class RegisteredMetamodelSelectionDialog extends ElementListSelectionDial } for(int i = 0; i < selection.length; i++) { - RegisteredMetamodel currentLibrary = (RegisteredMetamodel)(selection[i]); - URI modelUri = currentLibrary.uri; + IRegisteredMetamodel currentLibrary = (IRegisteredMetamodel)(selection[i]); + URI modelUri = currentLibrary.getUri(); addModelImportFromURI(currentModel, modelUri); } diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/profile/IRegisteredProfile.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/profile/IRegisteredProfile.java new file mode 100644 index 00000000000..f7612319e40 --- /dev/null +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/profile/IRegisteredProfile.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2006 CEA List. + * 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: + * Dr. David H. Akehurst - enable programmatic registration + *******************************************************************************/ +package org.eclipse.papyrus.uml.extensionpoints.profile; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.papyrus.uml.extensionpoints.IRegisteredItem; + +public interface IRegisteredProfile extends IRegisteredItem { + String getQualifiedNames(); +} diff --git a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/profile/RegisteredProfile.java b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/profile/RegisteredProfile.java index 83998889dea..207388b894b 100644 --- a/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/profile/RegisteredProfile.java +++ b/plugins/uml/org.eclipse.papyrus.uml.extensionpoints/src/org/eclipse/papyrus/uml/extensionpoints/profile/RegisteredProfile.java @@ -7,6 +7,7 @@ * * Contributors: * CEA List - initial API and implementation + * Dr. David H. Akehurst - enable programmatic registration *******************************************************************************/ package org.eclipse.papyrus.uml.extensionpoints.profile; @@ -16,21 +17,21 @@ import java.util.List; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.util.URI; import org.eclipse.papyrus.uml.extensionpoints.Activator; +import org.eclipse.papyrus.uml.extensionpoints.Registry; import org.eclipse.papyrus.uml.extensionpoints.standard.ExtensionIds; import org.eclipse.papyrus.uml.extensionpoints.standard.RegisteredElementExtensionPoint; +import org.eclipse.swt.graphics.Image; /** * Class that manages registered profile extension point */ -public class RegisteredProfile extends RegisteredElementExtensionPoint { +public class RegisteredProfile extends RegisteredElementExtensionPoint implements IRegisteredProfile { /** name of the extension point (main element name) in the DTD */ private static final String TAG_PROFILE = "profile"; - /** List of registered profiles in the platform */ - private static RegisteredProfile[] registeredProfiles; - /** name of the <code>qualified name</code>attribute in the DTD */ private static final String ATT_QUALIFIED_NAMES = "qualifiednames"; @@ -45,6 +46,19 @@ public class RegisteredProfile extends RegisteredElementExtensionPoint { qualifiednames = getAttribute(configElt, ATT_QUALIFIED_NAMES, "", false); } + public URI getUri() { + return super.uri; + } + + public String getPath() { + return super.path; + } + + public String getQualifiedNames() { + //?should this field really be defined on the superclass? is it not specific to profiles? + return super.qualifiednames; + } + // /** // * Creates a new RegisteredProfile. // * @param name the name displayed to users @@ -87,7 +101,7 @@ public class RegisteredProfile extends RegisteredElementExtensionPoint { * the name of the profile to find * @return the RegistredProfile with given name or <code>null</code> if no profile was found. */ - public static RegisteredProfile getRegisteredProfile(String name) { + public static IRegisteredProfile getRegisteredProfile(String name) { return getRegisteredProfile(name, null); } @@ -101,18 +115,18 @@ public class RegisteredProfile extends RegisteredElementExtensionPoint { * the path of the profile file * @return the RegistredProfile with given name or <code>null</code> if no profile was found. */ - public static RegisteredProfile getRegisteredProfile(String name, String path) { + public static IRegisteredProfile getRegisteredProfile(String name, String path) { Assert.isNotNull(name); - RegisteredProfile[] profiles = getRegisteredProfiles(); + IRegisteredProfile[] profiles = Registry.getRegisteredProfiles().toArray(new IRegisteredProfile[0]); for(int i = 0; i < profiles.length; i++) { - RegisteredProfile profile = profiles[i]; + IRegisteredProfile profile = profiles[i]; // name corresponds. is path equal? - if(name.equals(profile.name)) { + if(name.equals(profile.getName())) { // no path indicated => first name that corresponds => profile returned if(path == null) { return profile; - } else if(path.equals(profile.path)) { + } else if(path.equals(profile.getPath())) { return profile; } } @@ -125,15 +139,10 @@ public class RegisteredProfile extends RegisteredElementExtensionPoint { * * @return the list of registred profiles in the platform */ - public static RegisteredProfile[] getRegisteredProfiles() { - - // if the list is already known, returns it (cache) - if(registeredProfiles != null) { - return registeredProfiles; - } + public static List<IRegisteredProfile> getRegisteredProfiles() { // the list has not been already built. Creates a new one and fill it. - List<RegisteredProfile> profiles = new ArrayList<RegisteredProfile>(); + List<IRegisteredProfile> profiles = new ArrayList<IRegisteredProfile>(); // // At least two element : Standard uml profile and Ecore uml profile // RegisteredProfile UmlStdProfile = new RegisteredProfile("Standard", @@ -151,15 +160,14 @@ public class RegisteredProfile extends RegisteredElementExtensionPoint { // Read configuration elements for the current extension for(int j = 0; j < configElements.length; j++) { - RegisteredProfile proxy = parseProfileExtension(configElements[j], profiles.size()); + IRegisteredProfile proxy = parseProfileExtension(configElements[j], profiles.size()); if(proxy != null) { profiles.add(proxy); } } // end of configElements loop - registeredProfiles = profiles.toArray(new RegisteredProfile[profiles.size()]); - return registeredProfiles; + return profiles; } /** @@ -171,7 +179,7 @@ public class RegisteredProfile extends RegisteredElementExtensionPoint { * the configuration element from which to retrieve the registered profile * @return the registered profile */ - private static RegisteredProfile parseProfileExtension(IConfigurationElement configElt, int ordinal) { + private static IRegisteredProfile parseProfileExtension(IConfigurationElement configElt, int ordinal) { if(!TAG_PROFILE.equals(configElt.getName())) { return null; } |