From 9cf37f13e2a0a4214bfebd1f82d631bf478c0aee Mon Sep 17 00:00:00 2001 From: eperico Date: Thu, 21 Jan 2010 16:10:31 +0000 Subject: NEW - bug 297816: [SysML] Provide a Parametric diagram https://bugs.eclipse.org/bugs/show_bug.cgi?id=297816 -Manage diagram initialization through the papyrus wizard --- .../diagramprofile/utils/StereotypeUtils.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'plugins/profile-tool') diff --git a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/StereotypeUtils.java b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/StereotypeUtils.java index b8cf28d84d9..c1ed8a3510c 100644 --- a/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/StereotypeUtils.java +++ b/plugins/profile-tool/org.eclipse.papyrus.diagramprofile/src/org/eclipse/papyrus/diagramprofile/utils/StereotypeUtils.java @@ -13,8 +13,13 @@ *****************************************************************************/ package org.eclipse.papyrus.diagramprofile.utils; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Package; import org.eclipse.uml2.uml.Profile; @@ -25,6 +30,18 @@ import org.eclipse.uml2.uml.Stereotype; */ public class StereotypeUtils { + /** extension point ID to load profile */ + public static final String extensionPointIdForProfile = "org.eclipse.uml2.uml.generated_package"; + + /** URI for profile */ + public static final String uriExtensionPointIdForProfile = "uri"; + + /** location for profile */ + public static final String locationExtensionPointIdForProfile = "location"; + + /** URI for SysML profile */ + public static final String SYSML_URI = "http://www.eclipse.org/papyrus/0.7.0/SysML"; + /** * Get the base Element from a stereotype application. * @@ -88,4 +105,53 @@ public class StereotypeUtils { return s != null; } + /** + * Load a profile from an URI + * + * @return the profile + */ + public static Profile loadProfile(String uri, ResourceSet set) { + String locationURI = ""; + Profile profile = null; + IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor( + extensionPointIdForProfile); + for (IConfigurationElement e : extensions) { + String extensionURI = e.getAttribute(uriExtensionPointIdForProfile); + if (extensionURI.equals(uri)) { + locationURI = e.getAttribute(locationExtensionPointIdForProfile); + URI profileURI = URI.createURI(locationURI); + if (set != null) { + Resource resource = set.getResource(profileURI, true); + for (EObject obj : resource.getContents()) { + if (obj instanceof Profile) { + profile = (Profile) obj; + return profile; + } + } + } + } + } + return profile; + } + + /** + * Apply a profile on a package, from an URI + */ + public static void applyProfile(String uri, Package element) { + Profile profile = loadProfile(uri, element.eResource().getResourceSet()); + if (profile != null) { + element.applyProfile(profile); + } + } + + /** + * Apply the SysML profile on the specified element + */ + public static void applySysMLProfile(Package element) { + Profile profile = loadProfile(SYSML_URI, element.eResource().getResourceSet()); + if (profile != null) { + element.applyProfile(profile); + } + } + } -- cgit v1.2.3