Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Dumoulin2014-12-01 21:57:59 +0000
committerCedric Dumoulin2014-12-01 22:08:31 +0000
commitbce24eb9d107d561e5f761e28fd04a3bbe74236f (patch)
treefbdfda128cd72c8a404a7d59ee887a238373a18e /plugins/uml/profile
parent9aeaa15880324bffa4e85297b6a35590f74bad1a (diff)
downloadorg.eclipse.papyrus-bce24eb9d107d561e5f761e28fd04a3bbe74236f.tar.gz
org.eclipse.papyrus-bce24eb9d107d561e5f761e28fd04a3bbe74236f.tar.xz
org.eclipse.papyrus-bce24eb9d107d561e5f761e28fd04a3bbe74236f.zip
432802 [profile] - Remove Syserr, sysout. Adjust plugin.xml
Diffstat (limited to 'plugins/uml/profile')
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/META-INF/MANIFEST.MF5
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/EclipseProject.java434
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/META-INF/MANIFEST.MF2
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/build.properties26
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ProfileApplicator.java2255
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/commands/CreateProfileAndProfileResourceCommand.java372
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/services/ProfileCatalogService.java168
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/PropertiesEditorWidget.java1273
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/StereotypeNameToProfileSynchronizer.java424
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TaggedValuesEditorWidget.java488
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AbstractBaseHandler.java3
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AddProfileHandler.java466
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/CreateProfileHandler.java431
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/UpdateProfileHandler.java573
-rw-r--r--plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/StereotypeURL.java837
15 files changed, 3875 insertions, 3882 deletions
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/META-INF/MANIFEST.MF b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/META-INF/MANIFEST.MF
index ac2ebc35629..8ea29d4e976 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/META-INF/MANIFEST.MF
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/META-INF/MANIFEST.MF
@@ -1,10 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Tests
+Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.papyrus.uml.profile.drafter.tests
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.1.0.qualifier
Fragment-Host: org.eclipse.papyrus.uml.profile.drafter;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.papyrus.infra.gmfdiag.common
Export-Package: org.eclipse.papyrus.uml.profile.drafter.tests,
org.eclipse.papyrus.uml.profile.drafter.tests.exception
+Bundle-Vendor: %providerName
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/EclipseProject.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/EclipseProject.java
index 3a5ec1ef0b3..4b5340d7211 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/EclipseProject.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter.tests/src/org/eclipse/papyrus/uml/profile/drafter/tests/EclipseProject.java
@@ -1,217 +1,217 @@
-package org.eclipse.papyrus.uml.profile.drafter.tests;
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-
-import java.net.URL;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.uml.profile.drafter.tests.exception.ExecutionException;
-
-
-/**
- * This class allows to create or load an Eclipse Project.
- * This is the projects found in the project explorer.
- * This class is mainly used in tests.
- *
- * @author cedric dumoulin
- *
- */
-public class EclipseProject {
-
- /**
- * The underlying Eclipse project.
- *
- */
- protected IProject project;
-
- protected IProgressMonitor monitor = new NullProgressMonitor();
-
- /**
- * Constructor.
- * Create or load the specified project.
- * @throws ExecutionException
- */
- public EclipseProject( String projectName ) throws ExecutionException {
- // Create the project
- initProject(projectName);
- }
-
- /**
- * Create or load the project.
- *
- * @param projectName
- * @throws ExecutionException
- */
- protected void initProject(String projectName ) throws ExecutionException {
- project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
-
- if( project == null) {
- throw new ExecutionException("Can't get project '" + projectName + "' from workspace.");
- }
-
- if(project != null && !project.exists()) {
-// IProgressMonitor monitor = new NullProgressMonitor();
- try {
- project.create(monitor);
- } catch (CoreException e) {
- throw new ExecutionException("Can't create project '" + projectName + "'.", e);
- }
- }
-
- if(!project.isOpen()) {
- try {
- project.open(null);
- } catch (CoreException e) {
- throw new ExecutionException("Can't open project '" + projectName + "'.", e);
- }
- }
-
-
-
- }
-
-
- /**
- * @return the project
- */
- public IProject getProject() {
- return project;
- }
-
- /**
- *
- * @param fromBundle
- * @param fromResourceName
- * @param toResourceName
- * @return
- * @throws ExecutionException
- */
- public IFile copyResource( String fromBundle, String fromResourceName, String toResourceName) throws ExecutionException {
-
- try {
- Path toURL = new Path(toResourceName);
- System.out.println(toURL);
-
- IFile file = project.getFile(toResourceName);
- // link all the models resources
- if(!file.exists()) {
- // Create intermediate folders
- ensureFolders(file);
-
- URL url = FileLocator.find(Platform.getBundle(fromBundle), new Path(fromResourceName), null);
- URL newFile = FileLocator.resolve(url);
-
- // encode the URI for spaces in the path
- // And then create a link to the file
- file.createLink(new URL(newFile.toString().replaceAll(" ", "%20")).toURI(), IResource.REPLACE, monitor);
- }
- return file;
- } catch (Exception e) {
- throw new ExecutionException("Can't copy resource '" + toResourceName + "'.", e);
- }
- }
-
- /**
- * Copy the specified resource from the specified bundle to this project.
- * Use the same path in src and target.
- *
- * @param fromBundle
- * @param fromResourceName
- * @return
- * @throws ExecutionException
- */
- public IFile copyResource( String fromBundle, String fromResourceName) throws ExecutionException {
-
- return copyResource(fromBundle, fromResourceName, fromResourceName);
- }
-
- /**
- *
- * @param fromBundle
- * @param fromResourceNames
- * @throws ExecutionException
- */
- public void copyResources(String fromBundle, String ...fromResourceNames) throws ExecutionException {
-
- for(String fromResourceName : fromResourceNames) {
- copyResource(fromBundle, fromResourceName);
- }
- }
-
- /**
- * Ensure that the intermediates folders exist in the project.
- *
- * @param project
- * @param name
- * @throws CoreException
- */
- protected void ensureFolders(IFile file) throws CoreException {
-
- IPath path = file.getProjectRelativePath();
- IPath folderPath = path.removeLastSegments(1);
-
- String[] segments = folderPath.segments();
-
- for( int i = segments.length-1; i>=0; i--) {
- IPath curFolderPath = folderPath.removeLastSegments(i);
- createFolder(curFolderPath);
- }
-
-
- }
-
- /**
- *
- * @param folderPath
- * @throws CoreException
- */
- private void createFolder(IPath folderPath) throws CoreException {
- IFolder parent = project.getFolder(folderPath);
- if(!parent.exists()) {
- parent.create(true, true, monitor);
- }
- assert (parent.exists()); }
-
- /**
- * Creates all the folders that are needed to contains the resource.
- *
- * @param modelName
- * @throws ExecutionException
- */
- public void createFolders(String modelName) throws ExecutionException {
- try {
- IFile file = project.getFile(modelName);
- // link all the models resources
- if(!file.exists()) {
- // Create intermediate folders
- ensureFolders(file);
- }
- } catch (CoreException e) {
- throw new ExecutionException("Can't create intermediate folders for '" + modelName + ". ", e);
- }
- }
-
-}
+package org.eclipse.papyrus.uml.profile.drafter.tests;
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+
+import java.net.URL;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.uml.profile.drafter.tests.exception.ExecutionException;
+
+
+/**
+ * This class allows to create or load an Eclipse Project.
+ * This is the projects found in the project explorer.
+ * This class is mainly used in tests.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class EclipseProject {
+
+ /**
+ * The underlying Eclipse project.
+ *
+ */
+ protected IProject project;
+
+ protected IProgressMonitor monitor = new NullProgressMonitor();
+
+ /**
+ * Constructor.
+ * Create or load the specified project.
+ * @throws ExecutionException
+ */
+ public EclipseProject( String projectName ) throws ExecutionException {
+ // Create the project
+ initProject(projectName);
+ }
+
+ /**
+ * Create or load the project.
+ *
+ * @param projectName
+ * @throws ExecutionException
+ */
+ protected void initProject(String projectName ) throws ExecutionException {
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+
+ if( project == null) {
+ throw new ExecutionException("Can't get project '" + projectName + "' from workspace.");
+ }
+
+ if(project != null && !project.exists()) {
+// IProgressMonitor monitor = new NullProgressMonitor();
+ try {
+ project.create(monitor);
+ } catch (CoreException e) {
+ throw new ExecutionException("Can't create project '" + projectName + "'.", e);
+ }
+ }
+
+ if(!project.isOpen()) {
+ try {
+ project.open(null);
+ } catch (CoreException e) {
+ throw new ExecutionException("Can't open project '" + projectName + "'.", e);
+ }
+ }
+
+
+
+ }
+
+
+ /**
+ * @return the project
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /**
+ *
+ * @param fromBundle
+ * @param fromResourceName
+ * @param toResourceName
+ * @return
+ * @throws ExecutionException
+ */
+ public IFile copyResource( String fromBundle, String fromResourceName, String toResourceName) throws ExecutionException {
+
+ try {
+ Path toURL = new Path(toResourceName);
+// System.out.println(toURL);
+
+ IFile file = project.getFile(toResourceName);
+ // link all the models resources
+ if(!file.exists()) {
+ // Create intermediate folders
+ ensureFolders(file);
+
+ URL url = FileLocator.find(Platform.getBundle(fromBundle), new Path(fromResourceName), null);
+ URL newFile = FileLocator.resolve(url);
+
+ // encode the URI for spaces in the path
+ // And then create a link to the file
+ file.createLink(new URL(newFile.toString().replaceAll(" ", "%20")).toURI(), IResource.REPLACE, monitor);
+ }
+ return file;
+ } catch (Exception e) {
+ throw new ExecutionException("Can't copy resource '" + toResourceName + "'.", e);
+ }
+ }
+
+ /**
+ * Copy the specified resource from the specified bundle to this project.
+ * Use the same path in src and target.
+ *
+ * @param fromBundle
+ * @param fromResourceName
+ * @return
+ * @throws ExecutionException
+ */
+ public IFile copyResource( String fromBundle, String fromResourceName) throws ExecutionException {
+
+ return copyResource(fromBundle, fromResourceName, fromResourceName);
+ }
+
+ /**
+ *
+ * @param fromBundle
+ * @param fromResourceNames
+ * @throws ExecutionException
+ */
+ public void copyResources(String fromBundle, String ...fromResourceNames) throws ExecutionException {
+
+ for(String fromResourceName : fromResourceNames) {
+ copyResource(fromBundle, fromResourceName);
+ }
+ }
+
+ /**
+ * Ensure that the intermediates folders exist in the project.
+ *
+ * @param project
+ * @param name
+ * @throws CoreException
+ */
+ protected void ensureFolders(IFile file) throws CoreException {
+
+ IPath path = file.getProjectRelativePath();
+ IPath folderPath = path.removeLastSegments(1);
+
+ String[] segments = folderPath.segments();
+
+ for( int i = segments.length-1; i>=0; i--) {
+ IPath curFolderPath = folderPath.removeLastSegments(i);
+ createFolder(curFolderPath);
+ }
+
+
+ }
+
+ /**
+ *
+ * @param folderPath
+ * @throws CoreException
+ */
+ private void createFolder(IPath folderPath) throws CoreException {
+ IFolder parent = project.getFolder(folderPath);
+ if(!parent.exists()) {
+ parent.create(true, true, monitor);
+ }
+ assert (parent.exists()); }
+
+ /**
+ * Creates all the folders that are needed to contains the resource.
+ *
+ * @param modelName
+ * @throws ExecutionException
+ */
+ public void createFolders(String modelName) throws ExecutionException {
+ try {
+ IFile file = project.getFile(modelName);
+ // link all the models resources
+ if(!file.exists()) {
+ // Create intermediate folders
+ ensureFolders(file);
+ }
+ } catch (CoreException e) {
+ throw new ExecutionException("Can't create intermediate folders for '" + modelName + ". ", e);
+ }
+ }
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/META-INF/MANIFEST.MF b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/META-INF/MANIFEST.MF
index d61493cb530..d2b445605d5 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/META-INF/MANIFEST.MF
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.papyrus.uml.profile.drafter;singleton:=true
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.eclipse.papyrus.uml.profile.drafter.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/build.properties b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/build.properties
index 40a73c400e8..d6f4e721fa8 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/build.properties
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/build.properties
@@ -1,14 +1,12 @@
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .,\
- plugin.xml,\
- plugin.properties,\
- about.html
-src.includes = about.html,\
- src/,\
- plugin.xml,\
- icons/,\
- build.properties,\
- plugin.properties,\
- META-INF/
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties,\
+ about.html,\
+ icons/
+src.includes = about.html,\
+ icons/,\
+ src/,\
+ test/
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ProfileApplicator.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ProfileApplicator.java
index d9cc58a2952..e38a5e07e53 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ProfileApplicator.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ProfileApplicator.java
@@ -1,1128 +1,1127 @@
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.profile.drafter;
-
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.util.BasicDiagnostic;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.emf.common.util.DiagnosticChain;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.util.Diagnostician;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.uml.profile.Activator;
-import org.eclipse.papyrus.uml.profile.drafter.commands.CreateProfileAndProfileResourceCommand;
-import org.eclipse.papyrus.uml.profile.drafter.exceptions.DraftProfileException;
-import org.eclipse.papyrus.uml.profile.drafter.exceptions.NotFoundException;
-import org.eclipse.papyrus.uml.profile.drafter.ui.dialog.IStereotypeUpdateArgs;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.MetaclassesModel;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.PropertyModel;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.StereoptypeModel;
-import org.eclipse.papyrus.uml.profile.utils.Util;
-import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
-import org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition;
-import org.eclipse.papyrus.uml.tools.profile.definition.Version;
-import org.eclipse.papyrus.uml.tools.utils.ElementUtil;
-import org.eclipse.uml2.uml.AggregationKind;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.ElementImport;
-import org.eclipse.uml2.uml.Extension;
-import org.eclipse.uml2.uml.ExtensionEnd;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.ProfileApplication;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLFactory;
-import org.eclipse.uml2.uml.util.UMLUtil;
-import org.eclipse.uml2.uml.util.UMLUtil.Profile2EPackageConverter;
-import org.eclipse.uml2.uml.util.UMLUtil.UML2EcoreConverter;
-
-/**
- * This class hold a {@link NamedElement} and provides utility methods to manage {@link Stereotype} on this
- * element.
- *
- * @author cedric dumoulin
- *
- */
-public class ProfileApplicator {
-
- /**
- * Uml Element target of the applicator.
- * This is the element for which we create/update a Profile ans stereotype
- */
- protected NamedElement umlElement;
-
- /**
- * Constructor.
- *
- * @param umlElement
- */
- public ProfileApplicator(NamedElement umlElement) {
- super();
- this.umlElement = umlElement;
- }
-
- /**
- * @return the umlElement
- */
- public NamedElement getUmlElement() {
- return umlElement;
- }
-
-
- /**
- * Return the Profiles applied to the nearest package of the umlElement.
- * @return A list of profiles applied to the nearest package of the umlElement.
- *
- * @unused
- */
- public List<Profile> getAppliedProfiles() {
- return umlElement.getNearestPackage().getAppliedProfiles();
- }
-
- /**
- * Update or create the specified stereotype according to the provided {@link IStereotypeUpdateArgs}.
- *
- * @param updateArgs Arguments used to update or create a Stereotype.
- *
- * @throws DraftProfileException If an error occur during update.
- */
- public void updateStereotype(IStereotypeUpdateArgs updateArgs) throws DraftProfileException {
-
- String profileName = updateArgs.getProfileName();
- String stereotypeName = updateArgs.getStereotypeName();
-
- boolean isProfileModified = false;
- // The package to which the corresponding Profile is attached
- Package applicantPackage = null;
-
- PapyrusDefinitionAnnotation annotations = null;
- Stereotype stereotype = null;
- // lookup profile
- Profile profile = umlElement.getNearestPackage().getAppliedProfile(profileName, true);
- if( profile == null ) {
- // ask creation confirmation
- profile = createProfile(profileName);
- // Create the stereotype
- stereotype = createStereotype(profile, stereotypeName);
-
-// applyProfileToUmlElement( profile);
- // TODO change next behavior
-// throw new DraftProfileException("Profile '" + profileName + "' not applied on nesting packages. Apply profile first.");
-
- // We will apply profile in nearest PAckage
- // TODO let choose between nearest, root or choosen
- applicantPackage = umlElement.getNearestPackage();
- annotations = createPapyrusDefinitionAnnotation(0, 0, 1);
- isProfileModified = true;
- }
- else {
- // Profile already exist
- // Lookup for the stereotype
- stereotype = profile.getOwnedStereotype(stereotypeName, true);
- applicantPackage = getApplicantPackage(profile);
- if( stereotype == null ) {
- // We need to create the stereotype
- // ask creation confirmation
- // TODO change next behavior
- stereotype = createStereotype(profile, stereotypeName);
- annotations = createUpdatedPapyrusDefinitionAnnotation(profile, 0, 0, 1);
- isProfileModified = true;
- }
- }
-
- // update metaclasses by adding missing metaclasses
- if( ! updateArgs.getExtendedMetaclasses().isEmpty() ) {
- isProfileModified = updateStereotypeMetaclasses( stereotype, updateArgs.getExtendedMetaclasses()) || isProfileModified ;
- }
-
- // Do we need to reapply the profile ?
- // We do it only if the profile is modified
- if( isProfileModified) {
- definesAllProfiles( profile );
- redefineAllProfiles( profile, annotations );
- cleanAllProfiles( profile );
-// validateAllProfiles(profile, Arrays.asList((EPackage)profile) );
- applyProfile( applicantPackage, profile);
- }
-
- // Apply stereotype to element
- applyStereotype( stereotype );
-
- }
-
- /**
- * Add metaclasses to the specified {@link Stereotype}. Only add metaclasses that are not alread attached.
- * Also create any required {@link ElementImport}
- *
- * @param stereotype
- * @param extendedMetaclasses
- * @return True if the Stereotype is updated by adding one of the specified metaclass, false if the stereotype is not modified (the metaclass was already attached).
- */
- private boolean updateStereotypeMetaclasses(Stereotype stereotype, List<Class> extendedMetaclasses) {
-
- boolean updated = false;
- for( Class metaclass : extendedMetaclasses ) {
- // add the metaclass to stereotype
- updated = updateMetaclassToStereotype( stereotype, metaclass) || updated;
- }
- return updated;
- }
-
- /**
- * Add the specified metaclass to the stereotype. Do nothing if the metaclass already exist.
- * This implies creating an {@link Extension} between the {@link Stereotype} and the Metaclass.
- * Also create any required {@link ElementImport}.
- *
- * @param stereotype The stereotype to which the metaclass should be added
- * @param metaclass The metaclass to add.
- * @return True if the Stereotype is modified by adding the specified metaclass, false if the stereotype is not modified (the metaclass was already attached).
- *
- */
- @SuppressWarnings("unused")
- private boolean updateMetaclassToStereotype(Stereotype stereotype, Class metaclass) {
-
- if( stereotype.getExtendedMetaclasses().contains(metaclass) ) {
- return false;
- }
-
- // Ensure that a corresponding ElementImport exists in one of te
- // stereotype container.
- ElementImport target = stereotype.getProfile().getMetaclassReference(metaclass, true);
-// ElementImport target = getMetaclassElementImport(stereotype, metaclass);
-
- // Create extension
- Extension extension = stereotype.createExtension(metaclass, false);
-// Extension extension = createExtension(stereotype, (Type)target.getImportedElement());
-// extension.setName("Ext_" + stereotype.getName() + "_" + metaclass.getName());
- // Add the extension to the profile package owning this stereotype
- stereotype.getNearestPackage().getPackagedElements().add(extension);
-// stereotype.getProfile().getPackagedElements().add(extension);
- return true;
- }
-
- /**
- * Apply the specified stereotype from the specified profile to the umlElement.
- * Create any missing element.
- *
- * @param profileName
- * @param stereotypeName
- * @throws DraftProfileException
- *
- * @{@link Deprecated} use {@link #updateStereotype(IStereotypeUpdateArgs)} or {@link #applyStereotype2(String, String)}
- */
- public void applyStereotype( String profileName, String stereotypeName) throws DraftProfileException {
-
- // lookup profile
- Profile profile = umlElement.getNearestPackage().getAppliedProfile(profileName, true);
- if( profile == null ) {
- // ask creation confirmation
- profile = createProfile(profileName);
- applyProfileToUmlElement( profile);
- // TODO change next behavior
-// throw new DraftProfileException("Profile '" + profileName + "' not applied on nesting packages. Apply profile first.");
- }
-
- // Lookup stereotype
- Stereotype stereotype = profile.getApplicableStereotype(stereotypeName);
- if( stereotype == null ) {
- // ask creation confirmation
- // TODO change next behavior
- stereotype = createStereotypeAndRedefineProfile(profile, stereotypeName);
-// throw new DraftProfileException("Profile '" + stereotypeName + "' do not exist in Profile 'profileName'.");
- }
-
- // Apply stereotype to element
- applyStereotype( stereotype);
- }
-
- /**
- * Apply the specified stereotype from the specified profile to the umlElement.
- * Create any missing elements ( {@link Profile}, {@link ElementImport} ...).
- *
- * @param profileName
- * @param stereotypeName
- * @throws DraftProfileException
- */
- public void applyStereotype2( String profileName, String stereotypeName) throws DraftProfileException {
-
- boolean isProfileModified = false;
- Package applicantPackage = null;
-
- PapyrusDefinitionAnnotation annotations = null;
- Stereotype stereotype = null;
- // lookup profile
- Profile profile = umlElement.getNearestPackage().getAppliedProfile(profileName, true);
- if( profile == null ) {
- // ask creation confirmation
- profile = createProfile(profileName);
- // Create the stereotype
- stereotype = createStereotype(profile, stereotypeName, "Class");
-
-// applyProfileToUmlElement( profile);
- // TODO change next behavior
-// throw new DraftProfileException("Profile '" + profileName + "' not applied on nesting packages. Apply profile first.");
-
- // We will apply profile in nearest PAckage
- // TODO let choose between nearest, root or choosen
- applicantPackage = umlElement.getNearestPackage();
- annotations = createPapyrusDefinitionAnnotation(0, 0, 1);
- isProfileModified = true;
- }
- else {
- // Profile already exist
- // Lookup for the stereotype
- stereotype = profile.getOwnedStereotype(stereotypeName, true);
- if( stereotype == null ) {
- // We need to create the stereotype
- // ask creation confirmation
- // TODO change next behavior
- stereotype = createStereotype(profile, stereotypeName, "Class");
- applicantPackage = getApplicantPackage(profile);
- annotations = createUpdatedPapyrusDefinitionAnnotation(profile, 0, 0, 1);
- isProfileModified = true;
- }
- }
-
- // Do we need to reapply the profile ?
- if( isProfileModified) {
- definesAllProfiles( profile );
- redefineAllProfiles( profile, annotations );
- cleanAllProfiles( profile );
-// validateAllProfiles(profile, Arrays.asList((EPackage)profile) );
- applyProfile( applicantPackage, profile);
- }
-
- // Apply stereotype to element
- applyStereotype( stereotype );
- }
-
- /**
- * Apply the specified profile to the specified package.
- * see {@link Package#applyProfile(Profile)};
- *
- * @param applicantPackage
- * @param profile
- */
- private void applyProfile(Package applicantPackage, Profile profile) {
- applicantPackage.applyProfile(profile);
- }
-
- /**
- * Validate specified profiles.
- * Copied from org.eclipse.papyrus.uml.diagram.profile.custom.commands.DefineProfileCommand
- *
- * @param rootObject The object used as a root of object to validate. This is usually the Profile containing object to validate.
- *
- * @param objectsToValidate List of objects (here Profile) to validate.
- * @return The status of the validation.
- */
- private IStatus validateAllProfiles(EObject rootObject, List<EPackage> objectsToValidate) {
-
- EditingDomain domain = EMFHelper.resolveEditingDomain(rootObject);
- AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
- Diagnostician diagnostician = createDiagnostician(adapterFactory, new NullProgressMonitor());
- BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(rootObject);
- Map<Object, Object> context = diagnostician.createDefaultContext();
-
- for(EPackage ePackage : objectsToValidate) {
- diagnostician.validate(ePackage, diagnostic, context);
- }
-
- if(diagnostic.getSeverity() == Diagnostic.ERROR) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The defined profile is invalid");
- }
-
- if(diagnostic.getSeverity() == Diagnostic.WARNING) {
- return new Status(IStatus.WARNING, Activator.PLUGIN_ID, "The profile has been successfully defined");
- }
-
- return Status.OK_STATUS;
- }
-
- /**
- * Call {@link Profile#define()} to all Profile nested in the specified Package.
- * If the Package is a Profile, define it also.
- *
- * @param container
- */
- private void definesAllProfiles(Package container) {
-
- defineAllProfiles(container, true);
- }
-
- /**
- * Perform changes in Profile definition, in order to meet Papyrus requirements. Add also
- * Profile versions and annotations.
- *
- * @param profile
- * @param annotations
- */
- private void redefineAllProfiles(Profile profile, PapyrusDefinitionAnnotation annotations) {
- ProfileRedefinition.redefineProfile(profile, annotations);
- }
-
- /**
- * Clean indirect EClass from the provided profile.
- * Required by Papyrus.
- *
- * @param profile
- */
- private void cleanAllProfiles(Profile profile) {
- ProfileRedefinition.cleanProfile(profile);
- }
-
- /**
- * Apply the Profile to the nearest Package of the umlElement.
- *
- * @param profile
- * @throws DraftProfileException
- * @deprecated Only used by deprecated methods.
- */
- private void applyProfileToUmlElement(Profile profile) throws DraftProfileException {
-
-
- Package nearestPackage = umlElement.getNearestPackage();
- if( nearestPackage == null) {
- throw new DraftProfileException("Can't get nearest Package for element '" + umlElement.getName() +"'");
-
- }
-
- nearestPackage.applyProfile(profile);
- }
-
- /**
- * Create the specified Profile
- * @param profileName The name of the Profile to create.
- *
- */
- private Profile createProfile(String profileName) {
-// Profile profile = UMLFactory.eINSTANCE.createProfile();
-// profile.setName(profileName);
-//
-// return profile;
-
- CreateProfileAndProfileResourceCommand createCmd = new CreateProfileAndProfileResourceCommand(profileName, getModelSet());
-
- createCmd.execute();
-
- return createCmd.getResultProfile();
- }
-
- /**
- * Get the modelSet owning the uml model owning the umlElement.
- *
- * @return
- */
- private ModelSet getModelSet() {
-
- ResourceSet rs = umlElement.eResource().getResourceSet();
- // In Papyrus, The ResourceSet is an ModelSet.
- return (ModelSet)rs;
-
- }
-
- /**
- * Apply the specified stereotype to the umlElement.
- * @param stereotype
- */
- public void applyStereotype(Stereotype stereotype) {
- // Check application
- if (umlElement.getStereotypeApplication(stereotype) != null) {
- return;
- }
- // not applied : do it !
- umlElement.applyStereotype(stereotype);
- }
-
- /**
- * Create a new Stereotype in the provided Profile.
- *
- * @param profile
- * @param stereotypeName
- * @return
- */
- protected Stereotype createStereotype( Profile profile, String stereotypeName) {
-
- // Create a new stereotype
- Stereotype stereotype = UMLFactory.eINSTANCE.createStereotype();
- stereotype.setName(stereotypeName);
- // Add the stereotype to the profile
- profile.getPackagedElements().add(stereotype);
-
- return stereotype;
- }
-
- /**
- * Create a new Stereotype in the provided Profile
- *
- * @param profile
- * @param stereotypeName
- * @return
- * @throws NotFoundException If the uml::metaclass can't be found.
- */
- protected Stereotype createStereotype( Profile profile, String stereotypeName, String metaclassName) throws NotFoundException {
-
- // Create a new stereotype
- Stereotype stereotype = createStereotype(profile, stereotypeName);
-
- // If a metaclass name is specified, create an extension to its import.
- if( metaclassName != null) {
- ElementImport target = getElementImportByName(umlElement, metaclassName);
- Extension extension = createExtension(stereotype, (Type)target.getImportedElement());
- extension.setName("E_" + stereotype.getName());
- profile.getPackagedElements().add(extension);
- }
-
- return stereotype;
- }
-
- /**
- * Create a new Stereotype in the provided Profile
- *
- * @param profile
- * @param stereotypeName
- * @return
- * @deprecated
- */
- protected Stereotype createStereotypeAndRedefineProfile( Profile profile, String stereotypeName) {
-
- System.err.println("Try to create stereotype");
- // Remember which package apply the profile
- Package applicantPackage = getApplicantPackage(profile);
-
- // Create a new stereotype
- Stereotype stereotype = UMLFactory.eINSTANCE.createStereotype();
- stereotype.setName(stereotypeName);
- profile.getPackagedElements().add(stereotype);
-
- // TODO : set application
- ElementImport target = lookupElementImportByName(profile, "Class");
- Extension extension = createExtension(stereotype, (Type)target.getImportedElement());
- extension.setName("E_" + stereotype.getName());
- profile.getPackagedElements().add(extension);
-
- // Define the profile
- profile.define();
-
- // Define the profile annotation (from Papyrus)
- // == adapt to Papyrus
- Version curVersion = Util.getProfileDefinitionVersion(profile);
- Version version = new Version(curVersion.getMajor(), curVersion.getMinor(), curVersion.getMicro()+4);
- PapyrusDefinitionAnnotation papyrusAnnotation = new PapyrusDefinitionAnnotation(version, "", "", "", "");
- // define the profile
- ProfileRedefinition.redefineProfile(profile, papyrusAnnotation);
- ProfileRedefinition.cleanProfile(profile);
-
-
-// // Reapply to main package
-// ServicesRegistry servicesRegistry = lookupServicesRegistry(context);
-//
-//// ModelSet modelSet = ServiceUtilsForIEvaluationContext.getInstance().getModelSet(context);
-// UmlModel umlModel = UmlUtils.getUmlModelChecked(servicesRegistry);
-// Package rootPackage = (Package)umlModel.lookupRoot();
-//
-// rootPackage.applyProfile(profile);
-
- // Re-Apply profile to its package
- applicantPackage.applyProfile(profile);
-
- return stereotype;
- }
-
- /**
- * Create a {@link PapyrusDefinitionAnnotation} based on the actual definition found in the profile, and
- * with updated versions.
- *
- * @param profile
- * @param majorInc
- * @param minorInc
- * @param microInc
- * @return a new {@link PapyrusDefinitionAnnotation}
- */
- protected PapyrusDefinitionAnnotation createUpdatedPapyrusDefinitionAnnotation(Profile profile, int majorInc, int minorInc, int microInc) {
- Version curVersion = Util.getProfileDefinitionVersion(profile);
- Version version = new Version(curVersion.getMajor() + majorInc, curVersion.getMinor()+minorInc, curVersion.getMicro()+microInc);
- PapyrusDefinitionAnnotation papyrusAnnotation = new PapyrusDefinitionAnnotation(version, "", "", "", "");
- return papyrusAnnotation;
- }
-
- /**
- * Create a new {@link PapyrusDefinitionAnnotation} with the specified values.
- *
- * @param stereotype
- * @param majorInc
- * @param minorInc
- * @param microInc
- * @return a new {@link PapyrusDefinitionAnnotation}
- */
- protected PapyrusDefinitionAnnotation createPapyrusDefinitionAnnotation( int majorInc, int minorInc, int microInc) {
- Version version = new Version(majorInc, minorInc, microInc);
- Date date = new Date();
- PapyrusDefinitionAnnotation papyrusAnnotation = new PapyrusDefinitionAnnotation(version, "", "", DateFormat.getInstance().format(date), "");
- return papyrusAnnotation;
- }
-
- /**
- * Lookup the {@link Package} applying the specified profile. Start lookup from the umlElement.
- *
- * @param profile
- * @return
- */
- private Package getApplicantPackage(Profile profile) {
- ProfileApplication profileApplication = null;
-
- Package container = umlElement.getNearestPackage();
- while(profileApplication == null && container != null) {
- profileApplication = container.getProfileApplication(profile);
- if( profileApplication != null) {
- return container;
- }
- container = container.getNestingPackage();
- }
- return null;
- }
-
- /**
- * Lookup the nearest {@link ProfileApplication} declaring the {@link Profile}.
- *
- * @param stereotype
- * @return
- * the nearest profile application owning the stereotype
- */
- public ProfileApplication getNearestProfileApplication(Profile profile) {
- ProfileApplication profileApplication = null;
-
- Package container = umlElement.getNearestPackage();
- while(profileApplication == null && container != null) {
- profileApplication = container.getProfileApplication(profile);
- container = container.getNestingPackage();
- }
- return profileApplication;
- }
-
- /**
- * Get the metaclass {@link ElementImport} for requested type. Lookup if the import already exist in Profile. Return it if found.
- * Create it otherwise, by using the aliasName as a hint for the imported metaclass (ie: name ='Class'==> type=Class).
- *
- * @param fromElement Uml:Element used as a starting point to lookup for the {@link ElementImport}. This element
- * is also used to lookup the rootContainer where the ElementImport will be created
- * @return The requested metaclass
- * @throws NotFoundException If the uml::metaclass can't be found
- */
- private ElementImport getElementImportByName(Element fromElement, String aliasName) throws NotFoundException {
-
- ElementImport elementImport = lookupElementImportByName(fromElement, aliasName);
- if(elementImport == null) {
- elementImport = createMetaclassElementImport(fromElement, aliasName);
- }
-
- return elementImport;
- }
-
- /**
- * Get the metaclass {@link ElementImport} for requested type. Lookup if the import already exist in Profile. Return it if found.
- * Create it otherwise.
- *
- * @param fromElement Uml:Element used as a starting point to lookup for the {@link ElementImport}. This element
- * is also used to lookup the rootContainer where the ElementImport will be created
- * @return The Metaclass for which an element import is requested.
- *
- * @throws NotFoundException If the uml::metaclass can't be found
- */
- private ElementImport getMetaclassElementImport(Element fromElement, Class metaclass) {
-
- ElementImport elementImport = lookupElementImportByName(fromElement, metaclass.getName());
- if(elementImport == null) {
- elementImport = createMetaclassElementImport(fromElement, metaclass);
- }
-
- return elementImport;
- }
-
- /**
- * Create the {@link ElementImport} for the specified uml:metaClass name.
- *
- * @param umlMetamodelLocator An uml Element used to locate the uml:metamodel throw the ResourceSet.
- * @param aliasName
- * @return
- * @throws NotFoundException If the metaclass can't be found
- */
- private ElementImport createMetaclassElementImport(Element fromElement, String aliasName) throws NotFoundException {
-
- // Get the corresponding metaclass
- Class metaclass = getUmlMetaClass(aliasName, fromElement);
- // Create the elementImport
- return createMetaclassElementImport(fromElement, metaclass);
- }
-
- /**
- * Create the {@link ElementImport} for the specified uml:metaClass name.
- *
- * @param umlMetamodelLocator An uml Element used to locate the uml:metamodel throw the ResourceSet.
- * @param aliasName
- * @return
- * @throws NotFoundException If the metaclass can't be found
- */
- private ElementImport createMetaclassElementImport(Element fromElement, Class metaclass) {
-// ElementImport elementImport = UMLFactory.eINSTANCE.createElementImport();
-// elementImport.setAlias(metaclass.getName());
-// elementImport.setImportedElement(metaclass);
-// // Add it to the root of the Profile model
-// getResourceRoot().creategetImportedElements().add(elementImport);
-
- ElementImport elementImport = getRootPackageContainer(fromElement).createElementImport(metaclass);
- elementImport.setAlias(metaclass.getName());
- return elementImport;
- }
-
- /**
- * Get the {@link Package} root container to which the specified element belong.
- *
- * @return
- */
- private Package getRootPackageContainer(Element element) {
- // This is the root container
- return (Package)EcoreUtil.getRootContainer(element);
- }
-
- /**
- * Get the metaclass with specified name in UML metamodel.
- * Throw an exception if not found.
- *
- * @param metaclassName
- * @param ressourceLocator Any uml::Element allowing to get the ResourceSet for uml.
- * @return
- * @throws NotFoundException
- */
- protected Class getUmlMetaClass( String metaclassName, Element ressourceLocator) throws NotFoundException {
- // TODO Use a cache for the previous result instead of computing it.
- List<Class> metaclasses = ElementUtil.getPossibleMetaclasses(ressourceLocator);
-
- for( Class curClass : metaclasses) {
- if( curClass.getName().equals(metaclassName)) {
- return curClass;
- }
- }
-
- // Not found
- throw new NotFoundException("No uml metaclass found with name '" + metaclassName + "'");
- }
-
- /**
- * Lookup the {@link ElementImport} for the specified aliasName. Start lookup from the specified fromelement.
- *
- * @param fromElement Uml:Element used as a starting point to lookup for the {@link ElementImport}. This element
- * is also used to lookup the rootContainer where the ElementImport will be created
- * @param aliasName The name of the requested {@link ElementImport}.
- * @return the {@link ElementImport} or null if not found.
- */
- private ElementImport lookupElementImportByName(Element fromElement, String aliasName) {
-
- if( fromElement == null) {
- return null;
- }
-
- //
- if( fromElement instanceof Package ) {
- Package container = (Package)fromElement;
- for( ElementImport ele : container.getElementImports() ) {
- if(aliasName.equals(ele.getAlias() ) ) {
- return ele;
- }
- }
- // Not found in package, search nesting packages
- return lookupElementImportByName(container.getNestingPackage(), aliasName );
- }
- // Lookup from the nearest package of the element.
- return lookupElementImportByName(fromElement.getNearestPackage(), aliasName );
- }
-
- /**
- * Create an extension between the specified {@link Stereotype} and the specified {@link Type}.
- *
- * @param source
- * @param target
- * @return
- */
- protected Extension createExtension( Stereotype source, Type target) {
- //create the extension
- Extension newExtension = UMLFactory.eINSTANCE.createExtension();
-
- //create the endSource
- ExtensionEnd endSource = UMLFactory.eINSTANCE.createExtensionEnd();
-
- //initialize the endSource
- endSource.setName("extension_" + source.getName()); //$NON-NLS-1$ //$NON-NLS-2$
- endSource.setType(source);
- endSource.setAggregation(AggregationKind.COMPOSITE_LITERAL);
-
- //add the endSource to the extension
- newExtension.getOwnedEnds().add(endSource); // add extension end to extension
-
-
- //create source_property
- Property property = UMLFactory.eINSTANCE.createProperty();
- property.setName("base_" + target.getName());
- // property.setIsDerived(true);
- property.setType(target); // set the type
- property.setAssociation(newExtension); // Set the association link
- property.setAggregation(AggregationKind.NONE_LITERAL);
-
- newExtension.getMemberEnds().add(property);
-
- source.getOwnedAttributes().add(property);
-
- return newExtension;
- }
-
- /**
- * Define all Profiles found from the container, including the provided package (if it is a profile)
- * and nested Profile.
- *
- * @param container
- * the package from which to define {@link Profile}
- */
- protected List<EPackage> defineAllProfiles(Package container, boolean saveConstraintInDef) {
-
- List<EPackage> result = new ArrayList<EPackage>();
-
- // we wants to define
- if(container instanceof Profile) {
- Map<String, String> options = createProfileDefinitionOptions(saveConstraintInDef);
- EPackage profileDefinition = ((Profile)container).define(options, null, null);
- result.add(profileDefinition);
- }
-
- for( Package nestedPackage : container.getNestedPackages() ) {
- List<EPackage> profileDefinitions = defineAllProfiles(nestedPackage, saveConstraintInDef);
- result.addAll(profileDefinitions);
- }
-
- return result;
- }
-
- /**
- * @param saveConstraintInDef
- * @return
- */
- private Map<String, String> createProfileDefinitionOptions(
- boolean saveConstraintInDef) {
- Map<String, String> options = new HashMap<String, String>();
-
- options.put(Profile2EPackageConverter.OPTION__ECORE_TAGGED_VALUES, UMLUtil.OPTION__PROCESS);
- options.put(Profile2EPackageConverter.OPTION__DERIVED_FEATURES, UMLUtil.OPTION__REPORT);
- options.put(Profile2EPackageConverter.OPTION__DUPLICATE_FEATURE_INHERITANCE, UMLUtil.OPTION__PROCESS);
- options.put(Profile2EPackageConverter.OPTION__DUPLICATE_FEATURES, UMLUtil.OPTION__PROCESS);
- options.put(Profile2EPackageConverter.OPTION__DUPLICATE_OPERATIONS, UMLUtil.OPTION__REPORT);
- options.put(Profile2EPackageConverter.OPTION__DUPLICATE_OPERATION_INHERITANCE, UMLUtil.OPTION__REPORT);
- options.put(Profile2EPackageConverter.OPTION__REDEFINING_OPERATIONS, UMLUtil.OPTION__REPORT);
- options.put(Profile2EPackageConverter.OPTION__REDEFINING_PROPERTIES, UMLUtil.OPTION__REPORT);
- options.put(Profile2EPackageConverter.OPTION__SUBSETTING_PROPERTIES, UMLUtil.OPTION__REPORT);
- options.put(Profile2EPackageConverter.OPTION__UNION_PROPERTIES, UMLUtil.OPTION__PROCESS);
- options.put(UML2EcoreConverter.OPTION__SUPER_CLASS_ORDER, UMLUtil.OPTION__REPORT);
- options.put(Profile2EPackageConverter.OPTION__ANNOTATION_DETAILS, UMLUtil.OPTION__REPORT);
-
- //Generate constraints for the validation
- String handleConstraints = saveConstraintInDef ? UMLUtil.OPTION__PROCESS : UMLUtil.OPTION__IGNORE;
- options.put(Profile2EPackageConverter.OPTION__INVARIANT_CONSTRAINTS, handleConstraints);
- options.put(Profile2EPackageConverter.OPTION__VALIDATION_DELEGATES, handleConstraints);
- options.put(Profile2EPackageConverter.OPTION__INVOCATION_DELEGATES, handleConstraints);
- options.put(UML2EcoreConverter.OPTION__OPERATION_BODIES, handleConstraints);
- //
-
- options.put(Profile2EPackageConverter.OPTION__COMMENTS, UMLUtil.OPTION__IGNORE);
- options.put(Profile2EPackageConverter.OPTION__FOREIGN_DEFINITIONS, UMLUtil.OPTION__IGNORE);
-
- options.put(Profile2EPackageConverter.OPTION__UNTYPED_PROPERTIES, UMLUtil.OPTION__PROCESS); //Closer to the UML semantics of untyped properties
-
- return options;
- }
-
-
- /**
- * Create a {@link Diagnostician} to validate profile.
- * Copied from org.eclipse.papyrus.uml.diagram.profile.custom.commands.DefineProfileCommand
- * @param adapterFactory
- * @param progressMonitor
- * @return
- */
- protected Diagnostician createDiagnostician(final AdapterFactory adapterFactory, final IProgressMonitor progressMonitor) {
- return new Diagnostician() {
-
- @Override
- public String getObjectLabel(EObject eObject) {
- if(adapterFactory != null && !eObject.eIsProxy()) {
- IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(eObject, IItemLabelProvider.class);
- if(itemLabelProvider != null) {
- return itemLabelProvider.getText(eObject);
- }
- }
- return super.getObjectLabel(eObject);
- }
-
- @Override
- public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
- progressMonitor.worked(1);
- return super.validate(eClass, eObject, diagnostics, context);
- }
- };
- }
-
- /**
- * Update or create the specified stereotype according to the provided {@link IStereotypeUpdateArgs}.
- *
- * @param updateArgs Arguments used to update or create a Stereotype.
- *
- * @throws DraftProfileException If an error occur during update.
- */
- public void updateStereotype(StereoptypeModel stereoptypeModel) throws DraftProfileException {
-
- String profileName = stereoptypeModel.getProfileName();
- String stereotypeName = stereoptypeModel.getStereotypeName();
-
- boolean isProfileModified = false;
- // The package to which the corresponding Profile is attached
- Package applicantPackage = null;
-
- PapyrusDefinitionAnnotation annotations = null;
- Stereotype stereotype = null;
- // lookup profile
- Profile profile = umlElement.getNearestPackage().getAppliedProfile(profileName, true);
- if( profile == null ) {
- // ask creation confirmation
- profile = createProfile(profileName);
- // Create the stereotype
- stereotype = createStereotype(profile, stereotypeName);
-
-// applyProfileToUmlElement( profile);
- // TODO change next behavior
-// throw new DraftProfileException("Profile '" + profileName + "' not applied on nesting packages. Apply profile first.");
-
- // We will apply profile in nearest PAckage
- // TODO let choose between nearest, root or choosen
- applicantPackage = umlElement.getNearestPackage();
- annotations = createPapyrusDefinitionAnnotation(0, 0, 1);
- isProfileModified = true;
- }
- else {
- // Profile already exist
- // Lookup for the stereotype
- stereotype = profile.getOwnedStereotype(stereotypeName, true);
- applicantPackage = getApplicantPackage(profile);
- if( stereotype == null ) {
- // We need to create the stereotype
- // ask creation confirmation
- // TODO change next behavior
- stereotype = createStereotype(profile, stereotypeName);
- annotations = createUpdatedPapyrusDefinitionAnnotation(profile, 0, 0, 1);
- isProfileModified = true;
- }
- }
-
- // update metaclasses by adding missing metaclasses
- MetaclassesModel metaclassesModel = stereoptypeModel.getMetaclassesCollection();
- if( ! metaclassesModel.getSelectedMetaclasses().isEmpty() ) {
- isProfileModified = updateStereotypeMetaclasses( stereotype, metaclassesModel.getSelectedMetaclasses()) || isProfileModified ;
- }
-
- // Update property definitions
- if( !stereoptypeModel.getProperties().isEmpty()) {
- isProfileModified = createOrUpdateProperties( stereotype, stereoptypeModel.getProperties()) || isProfileModified;
- }
-
-
- // Do we need to reapply the profile ?
- // We do it only if the profile is modified
- if( isProfileModified) {
- definesAllProfiles( profile );
- redefineAllProfiles( profile, annotations );
- cleanAllProfiles( profile );
-// validateAllProfiles(profile, Arrays.asList((EPackage)profile) );
- applyProfile( applicantPackage, profile);
- }
-
- // Apply stereotype to element
- applyStereotype( stereotype );
- // Update or set property values
- // This should be done once the profile is applied
- if( !stereoptypeModel.getProperties().isEmpty()) {
- updatePropertyValues( stereotype, stereoptypeModel.getProperties()) ;
- }
-
-
-
- }
-
- /**
- * Update any values associated to properties.
- * Check if a value need to be modified, and modify it accordingly.
- *
- * @param stereotype
- * @param properties
- */
- private void updatePropertyValues(Stereotype stereotype, List<PropertyModel> properties) {
-
-// System.err.println("uml.profile.drafter.ProfileApplicator.updatePropertyValues() is disabled - values are not updated.");
-
- for( PropertyModel propertyModel : properties) {
- updatePropertyValue( stereotype, propertyModel);
- }
-
- }
-
- /**
- * Update the value of the property if needed.
- *
- * @param stereotype
- * @param propertyModel
- */
- private void updatePropertyValue(Stereotype stereotype, PropertyModel propertyModel) {
-
- // Get the actual value
- Object actualValue = getUmlElement().getValue(stereotype, propertyModel.getProposedName());
-
-// org.eclipse.papyrus.uml.profile.utils.Util.getValueObjectFromString(String, Type)
- // Need to check if the Property value is modified
- if(propertyModel.isValueModified() ) {
- String valueAsStr = propertyModel.getValue();
- if( valueAsStr == null || valueAsStr.length() == 0 ) {
- getUmlElement().setValue(stereotype, propertyModel.getProposedName(), null);
- return;
- }
-
- Object newValue = org.eclipse.papyrus.uml.profile.utils.Util.getValueObjectFromString(valueAsStr, propertyModel.getType());
- getUmlElement().setValue(stereotype, propertyModel.getProposedName(), newValue);
- }
-
- }
-
- /**
- * Check if the property definitions need to be updated or created, accordingly to
- * {@link PropertyModel}s.
- * Create missing property, and update modified ones.
- *
- * @param stereotype The stereotype that own the properties.
- *
- * @param properties models used to update the properties
- * @return
- */
- private boolean createOrUpdateProperties(Stereotype stereotype, List<PropertyModel> properties) {
-
- boolean isUpdated = false;
- for( PropertyModel propertyModel : properties) {
- isUpdated = createOrUpdateProperty( stereotype, propertyModel) || isUpdated;
- }
-
- return isUpdated;
- }
-
- /**
- * Check if the property associated to {@link PropertyModel} need to be updated or created.
- *
- * Update the specified {@link Property} of the {@link Stereotype}
- * @param stereotype The {@link Stereotype} owning the property.
- * @param propertyModel The {@link PropertyModel} to use to update stereotype's corresponding property.
- *
- */
-
- private boolean createOrUpdateProperty(Stereotype stereotype, PropertyModel propertyModel) {
-
- boolean isUpdated = false;
- boolean isPropertyExistIn = propertyModel.isPropertyExistIn(stereotype);
-
- switch(propertyModel.getStateKind()) {
- case modified:
- if( isPropertyExistIn) {
- isUpdated = updateProperty( stereotype, propertyModel);
- }
- break;
-
- case created:
- if( ! isPropertyExistIn) {
- isUpdated = createProperty( stereotype, propertyModel);
- }
-
- break;
-
- default:
- break;
- }
-
- return isUpdated;
- }
-
- /**
- * Update the specified {@link Property} of the {@link Stereotype}.
- *
- * @param stereotype The {@link Stereotype} owning the property.
- * @param propertyModel The {@link PropertyModel} to use to update stereotype's corresponding property.
- *
- */
- private boolean updateProperty(Stereotype stereotype, PropertyModel propertyModel) {
-
- boolean isUpdated = false;
- String newName = propertyModel.getProposedName();
- System.err.println("updateProperty(" + stereotype.getName() + "." + propertyModel.getProposedName() );
- if( newName!=null && (! newName.equals( stereotype.getName() ) ) ) {
- stereotype.setName(newName);
- isUpdated = true;
- }
-
- return isUpdated;
-
- }
-
- /**
- * Create the specified {@link Property} of the {@link Stereotype}.
- *
- * @param stereotype The {@link Stereotype} owning the property.
- * @param propertyModel The {@link PropertyModel} to use to update stereotype's corresponding property.
- *
- */
- private boolean createProperty(Stereotype stereotype, PropertyModel propertyModel) {
-
- boolean isUpdated = true;
-
-// System.err.println("createProperty(" + stereotype.getName() + "." + propertyModel.getProposedName() );
- stereotype.createOwnedAttribute(propertyModel.getProposedName(), propertyModel.getType());
-
- return isUpdated;
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter;
+
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.BasicDiagnostic;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.DiagnosticChain;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.papyrus.uml.profile.drafter.commands.CreateProfileAndProfileResourceCommand;
+import org.eclipse.papyrus.uml.profile.drafter.exceptions.DraftProfileException;
+import org.eclipse.papyrus.uml.profile.drafter.exceptions.NotFoundException;
+import org.eclipse.papyrus.uml.profile.drafter.ui.dialog.IStereotypeUpdateArgs;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.MetaclassesModel;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.PropertyModel;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.StereoptypeModel;
+import org.eclipse.papyrus.uml.profile.utils.Util;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition;
+import org.eclipse.papyrus.uml.tools.profile.definition.Version;
+import org.eclipse.papyrus.uml.tools.utils.ElementUtil;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.ElementImport;
+import org.eclipse.uml2.uml.Extension;
+import org.eclipse.uml2.uml.ExtensionEnd;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.util.UMLUtil;
+import org.eclipse.uml2.uml.util.UMLUtil.Profile2EPackageConverter;
+import org.eclipse.uml2.uml.util.UMLUtil.UML2EcoreConverter;
+
+/**
+ * This class hold a {@link NamedElement} and provides utility methods to manage {@link Stereotype} on this
+ * element.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ProfileApplicator {
+
+ /**
+ * Uml Element target of the applicator.
+ * This is the element for which we create/update a Profile ans stereotype
+ */
+ protected NamedElement umlElement;
+
+ /**
+ * Constructor.
+ *
+ * @param umlElement
+ */
+ public ProfileApplicator(NamedElement umlElement) {
+ super();
+ this.umlElement = umlElement;
+ }
+
+ /**
+ * @return the umlElement
+ */
+ public NamedElement getUmlElement() {
+ return umlElement;
+ }
+
+
+ /**
+ * Return the Profiles applied to the nearest package of the umlElement.
+ * @return A list of profiles applied to the nearest package of the umlElement.
+ *
+ * @unused
+ */
+ public List<Profile> getAppliedProfiles() {
+ return umlElement.getNearestPackage().getAppliedProfiles();
+ }
+
+ /**
+ * Update or create the specified stereotype according to the provided {@link IStereotypeUpdateArgs}.
+ *
+ * @param updateArgs Arguments used to update or create a Stereotype.
+ *
+ * @throws DraftProfileException If an error occur during update.
+ */
+ public void updateStereotype(IStereotypeUpdateArgs updateArgs) throws DraftProfileException {
+
+ String profileName = updateArgs.getProfileName();
+ String stereotypeName = updateArgs.getStereotypeName();
+
+ boolean isProfileModified = false;
+ // The package to which the corresponding Profile is attached
+ Package applicantPackage = null;
+
+ PapyrusDefinitionAnnotation annotations = null;
+ Stereotype stereotype = null;
+ // lookup profile
+ Profile profile = umlElement.getNearestPackage().getAppliedProfile(profileName, true);
+ if( profile == null ) {
+ // ask creation confirmation
+ profile = createProfile(profileName);
+ // Create the stereotype
+ stereotype = createStereotype(profile, stereotypeName);
+
+// applyProfileToUmlElement( profile);
+ // TODO change next behavior
+// throw new DraftProfileException("Profile '" + profileName + "' not applied on nesting packages. Apply profile first.");
+
+ // We will apply profile in nearest PAckage
+ // TODO let choose between nearest, root or choosen
+ applicantPackage = umlElement.getNearestPackage();
+ annotations = createPapyrusDefinitionAnnotation(0, 0, 1);
+ isProfileModified = true;
+ }
+ else {
+ // Profile already exist
+ // Lookup for the stereotype
+ stereotype = profile.getOwnedStereotype(stereotypeName, true);
+ applicantPackage = getApplicantPackage(profile);
+ if( stereotype == null ) {
+ // We need to create the stereotype
+ // ask creation confirmation
+ // TODO change next behavior
+ stereotype = createStereotype(profile, stereotypeName);
+ annotations = createUpdatedPapyrusDefinitionAnnotation(profile, 0, 0, 1);
+ isProfileModified = true;
+ }
+ }
+
+ // update metaclasses by adding missing metaclasses
+ if( ! updateArgs.getExtendedMetaclasses().isEmpty() ) {
+ isProfileModified = updateStereotypeMetaclasses( stereotype, updateArgs.getExtendedMetaclasses()) || isProfileModified ;
+ }
+
+ // Do we need to reapply the profile ?
+ // We do it only if the profile is modified
+ if( isProfileModified) {
+ definesAllProfiles( profile );
+ redefineAllProfiles( profile, annotations );
+ cleanAllProfiles( profile );
+// validateAllProfiles(profile, Arrays.asList((EPackage)profile) );
+ applyProfile( applicantPackage, profile);
+ }
+
+ // Apply stereotype to element
+ applyStereotype( stereotype );
+
+ }
+
+ /**
+ * Add metaclasses to the specified {@link Stereotype}. Only add metaclasses that are not alread attached.
+ * Also create any required {@link ElementImport}
+ *
+ * @param stereotype
+ * @param extendedMetaclasses
+ * @return True if the Stereotype is updated by adding one of the specified metaclass, false if the stereotype is not modified (the metaclass was already attached).
+ */
+ private boolean updateStereotypeMetaclasses(Stereotype stereotype, List<Class> extendedMetaclasses) {
+
+ boolean updated = false;
+ for( Class metaclass : extendedMetaclasses ) {
+ // add the metaclass to stereotype
+ updated = updateMetaclassToStereotype( stereotype, metaclass) || updated;
+ }
+ return updated;
+ }
+
+ /**
+ * Add the specified metaclass to the stereotype. Do nothing if the metaclass already exist.
+ * This implies creating an {@link Extension} between the {@link Stereotype} and the Metaclass.
+ * Also create any required {@link ElementImport}.
+ *
+ * @param stereotype The stereotype to which the metaclass should be added
+ * @param metaclass The metaclass to add.
+ * @return True if the Stereotype is modified by adding the specified metaclass, false if the stereotype is not modified (the metaclass was already attached).
+ *
+ */
+ @SuppressWarnings("unused")
+ private boolean updateMetaclassToStereotype(Stereotype stereotype, Class metaclass) {
+
+ if( stereotype.getExtendedMetaclasses().contains(metaclass) ) {
+ return false;
+ }
+
+ // Ensure that a corresponding ElementImport exists in one of te
+ // stereotype container.
+ ElementImport target = stereotype.getProfile().getMetaclassReference(metaclass, true);
+// ElementImport target = getMetaclassElementImport(stereotype, metaclass);
+
+ // Create extension
+ Extension extension = stereotype.createExtension(metaclass, false);
+// Extension extension = createExtension(stereotype, (Type)target.getImportedElement());
+// extension.setName("Ext_" + stereotype.getName() + "_" + metaclass.getName());
+ // Add the extension to the profile package owning this stereotype
+ stereotype.getNearestPackage().getPackagedElements().add(extension);
+// stereotype.getProfile().getPackagedElements().add(extension);
+ return true;
+ }
+
+ /**
+ * Apply the specified stereotype from the specified profile to the umlElement.
+ * Create any missing element.
+ *
+ * @param profileName
+ * @param stereotypeName
+ * @throws DraftProfileException
+ *
+ * @{@link Deprecated} use {@link #updateStereotype(IStereotypeUpdateArgs)} or {@link #applyStereotype2(String, String)}
+ */
+ public void applyStereotype( String profileName, String stereotypeName) throws DraftProfileException {
+
+ // lookup profile
+ Profile profile = umlElement.getNearestPackage().getAppliedProfile(profileName, true);
+ if( profile == null ) {
+ // ask creation confirmation
+ profile = createProfile(profileName);
+ applyProfileToUmlElement( profile);
+ // TODO change next behavior
+// throw new DraftProfileException("Profile '" + profileName + "' not applied on nesting packages. Apply profile first.");
+ }
+
+ // Lookup stereotype
+ Stereotype stereotype = profile.getApplicableStereotype(stereotypeName);
+ if( stereotype == null ) {
+ // ask creation confirmation
+ // TODO change next behavior
+ stereotype = createStereotypeAndRedefineProfile(profile, stereotypeName);
+// throw new DraftProfileException("Profile '" + stereotypeName + "' do not exist in Profile 'profileName'.");
+ }
+
+ // Apply stereotype to element
+ applyStereotype( stereotype);
+ }
+
+ /**
+ * Apply the specified stereotype from the specified profile to the umlElement.
+ * Create any missing elements ( {@link Profile}, {@link ElementImport} ...).
+ *
+ * @param profileName
+ * @param stereotypeName
+ * @throws DraftProfileException
+ */
+ public void applyStereotype2( String profileName, String stereotypeName) throws DraftProfileException {
+
+ boolean isProfileModified = false;
+ Package applicantPackage = null;
+
+ PapyrusDefinitionAnnotation annotations = null;
+ Stereotype stereotype = null;
+ // lookup profile
+ Profile profile = umlElement.getNearestPackage().getAppliedProfile(profileName, true);
+ if( profile == null ) {
+ // ask creation confirmation
+ profile = createProfile(profileName);
+ // Create the stereotype
+ stereotype = createStereotype(profile, stereotypeName, "Class");
+
+// applyProfileToUmlElement( profile);
+ // TODO change next behavior
+// throw new DraftProfileException("Profile '" + profileName + "' not applied on nesting packages. Apply profile first.");
+
+ // We will apply profile in nearest PAckage
+ // TODO let choose between nearest, root or choosen
+ applicantPackage = umlElement.getNearestPackage();
+ annotations = createPapyrusDefinitionAnnotation(0, 0, 1);
+ isProfileModified = true;
+ }
+ else {
+ // Profile already exist
+ // Lookup for the stereotype
+ stereotype = profile.getOwnedStereotype(stereotypeName, true);
+ if( stereotype == null ) {
+ // We need to create the stereotype
+ // ask creation confirmation
+ // TODO change next behavior
+ stereotype = createStereotype(profile, stereotypeName, "Class");
+ applicantPackage = getApplicantPackage(profile);
+ annotations = createUpdatedPapyrusDefinitionAnnotation(profile, 0, 0, 1);
+ isProfileModified = true;
+ }
+ }
+
+ // Do we need to reapply the profile ?
+ if( isProfileModified) {
+ definesAllProfiles( profile );
+ redefineAllProfiles( profile, annotations );
+ cleanAllProfiles( profile );
+// validateAllProfiles(profile, Arrays.asList((EPackage)profile) );
+ applyProfile( applicantPackage, profile);
+ }
+
+ // Apply stereotype to element
+ applyStereotype( stereotype );
+ }
+
+ /**
+ * Apply the specified profile to the specified package.
+ * see {@link Package#applyProfile(Profile)};
+ *
+ * @param applicantPackage
+ * @param profile
+ */
+ private void applyProfile(Package applicantPackage, Profile profile) {
+ applicantPackage.applyProfile(profile);
+ }
+
+ /**
+ * Validate specified profiles.
+ * Copied from org.eclipse.papyrus.uml.diagram.profile.custom.commands.DefineProfileCommand
+ *
+ * @param rootObject The object used as a root of object to validate. This is usually the Profile containing object to validate.
+ *
+ * @param objectsToValidate List of objects (here Profile) to validate.
+ * @return The status of the validation.
+ */
+ private IStatus validateAllProfiles(EObject rootObject, List<EPackage> objectsToValidate) {
+
+ EditingDomain domain = EMFHelper.resolveEditingDomain(rootObject);
+ AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
+ Diagnostician diagnostician = createDiagnostician(adapterFactory, new NullProgressMonitor());
+ BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(rootObject);
+ Map<Object, Object> context = diagnostician.createDefaultContext();
+
+ for(EPackage ePackage : objectsToValidate) {
+ diagnostician.validate(ePackage, diagnostic, context);
+ }
+
+ if(diagnostic.getSeverity() == Diagnostic.ERROR) {
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The defined profile is invalid");
+ }
+
+ if(diagnostic.getSeverity() == Diagnostic.WARNING) {
+ return new Status(IStatus.WARNING, Activator.PLUGIN_ID, "The profile has been successfully defined");
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Call {@link Profile#define()} to all Profile nested in the specified Package.
+ * If the Package is a Profile, define it also.
+ *
+ * @param container
+ */
+ private void definesAllProfiles(Package container) {
+
+ defineAllProfiles(container, true);
+ }
+
+ /**
+ * Perform changes in Profile definition, in order to meet Papyrus requirements. Add also
+ * Profile versions and annotations.
+ *
+ * @param profile
+ * @param annotations
+ */
+ private void redefineAllProfiles(Profile profile, PapyrusDefinitionAnnotation annotations) {
+ ProfileRedefinition.redefineProfile(profile, annotations);
+ }
+
+ /**
+ * Clean indirect EClass from the provided profile.
+ * Required by Papyrus.
+ *
+ * @param profile
+ */
+ private void cleanAllProfiles(Profile profile) {
+ ProfileRedefinition.cleanProfile(profile);
+ }
+
+ /**
+ * Apply the Profile to the nearest Package of the umlElement.
+ *
+ * @param profile
+ * @throws DraftProfileException
+ * @deprecated Only used by deprecated methods.
+ */
+ private void applyProfileToUmlElement(Profile profile) throws DraftProfileException {
+
+
+ Package nearestPackage = umlElement.getNearestPackage();
+ if( nearestPackage == null) {
+ throw new DraftProfileException("Can't get nearest Package for element '" + umlElement.getName() +"'");
+
+ }
+
+ nearestPackage.applyProfile(profile);
+ }
+
+ /**
+ * Create the specified Profile
+ * @param profileName The name of the Profile to create.
+ *
+ */
+ private Profile createProfile(String profileName) {
+// Profile profile = UMLFactory.eINSTANCE.createProfile();
+// profile.setName(profileName);
+//
+// return profile;
+
+ CreateProfileAndProfileResourceCommand createCmd = new CreateProfileAndProfileResourceCommand(profileName, getModelSet());
+
+ createCmd.execute();
+
+ return createCmd.getResultProfile();
+ }
+
+ /**
+ * Get the modelSet owning the uml model owning the umlElement.
+ *
+ * @return
+ */
+ private ModelSet getModelSet() {
+
+ ResourceSet rs = umlElement.eResource().getResourceSet();
+ // In Papyrus, The ResourceSet is an ModelSet.
+ return (ModelSet)rs;
+
+ }
+
+ /**
+ * Apply the specified stereotype to the umlElement.
+ * @param stereotype
+ */
+ public void applyStereotype(Stereotype stereotype) {
+ // Check application
+ if (umlElement.getStereotypeApplication(stereotype) != null) {
+ return;
+ }
+ // not applied : do it !
+ umlElement.applyStereotype(stereotype);
+ }
+
+ /**
+ * Create a new Stereotype in the provided Profile.
+ *
+ * @param profile
+ * @param stereotypeName
+ * @return
+ */
+ protected Stereotype createStereotype( Profile profile, String stereotypeName) {
+
+ // Create a new stereotype
+ Stereotype stereotype = UMLFactory.eINSTANCE.createStereotype();
+ stereotype.setName(stereotypeName);
+ // Add the stereotype to the profile
+ profile.getPackagedElements().add(stereotype);
+
+ return stereotype;
+ }
+
+ /**
+ * Create a new Stereotype in the provided Profile
+ *
+ * @param profile
+ * @param stereotypeName
+ * @return
+ * @throws NotFoundException If the uml::metaclass can't be found.
+ */
+ protected Stereotype createStereotype( Profile profile, String stereotypeName, String metaclassName) throws NotFoundException {
+
+ // Create a new stereotype
+ Stereotype stereotype = createStereotype(profile, stereotypeName);
+
+ // If a metaclass name is specified, create an extension to its import.
+ if( metaclassName != null) {
+ ElementImport target = getElementImportByName(umlElement, metaclassName);
+ Extension extension = createExtension(stereotype, (Type)target.getImportedElement());
+ extension.setName("E_" + stereotype.getName());
+ profile.getPackagedElements().add(extension);
+ }
+
+ return stereotype;
+ }
+
+ /**
+ * Create a new Stereotype in the provided Profile
+ *
+ * @param profile
+ * @param stereotypeName
+ * @return
+ * @deprecated
+ */
+ protected Stereotype createStereotypeAndRedefineProfile( Profile profile, String stereotypeName) {
+
+ // Remember which package apply the profile
+ Package applicantPackage = getApplicantPackage(profile);
+
+ // Create a new stereotype
+ Stereotype stereotype = UMLFactory.eINSTANCE.createStereotype();
+ stereotype.setName(stereotypeName);
+ profile.getPackagedElements().add(stereotype);
+
+ // TODO : set application
+ ElementImport target = lookupElementImportByName(profile, "Class");
+ Extension extension = createExtension(stereotype, (Type)target.getImportedElement());
+ extension.setName("E_" + stereotype.getName());
+ profile.getPackagedElements().add(extension);
+
+ // Define the profile
+ profile.define();
+
+ // Define the profile annotation (from Papyrus)
+ // == adapt to Papyrus
+ Version curVersion = Util.getProfileDefinitionVersion(profile);
+ Version version = new Version(curVersion.getMajor(), curVersion.getMinor(), curVersion.getMicro()+4);
+ PapyrusDefinitionAnnotation papyrusAnnotation = new PapyrusDefinitionAnnotation(version, "", "", "", "");
+ // define the profile
+ ProfileRedefinition.redefineProfile(profile, papyrusAnnotation);
+ ProfileRedefinition.cleanProfile(profile);
+
+
+// // Reapply to main package
+// ServicesRegistry servicesRegistry = lookupServicesRegistry(context);
+//
+//// ModelSet modelSet = ServiceUtilsForIEvaluationContext.getInstance().getModelSet(context);
+// UmlModel umlModel = UmlUtils.getUmlModelChecked(servicesRegistry);
+// Package rootPackage = (Package)umlModel.lookupRoot();
+//
+// rootPackage.applyProfile(profile);
+
+ // Re-Apply profile to its package
+ applicantPackage.applyProfile(profile);
+
+ return stereotype;
+ }
+
+ /**
+ * Create a {@link PapyrusDefinitionAnnotation} based on the actual definition found in the profile, and
+ * with updated versions.
+ *
+ * @param profile
+ * @param majorInc
+ * @param minorInc
+ * @param microInc
+ * @return a new {@link PapyrusDefinitionAnnotation}
+ */
+ protected PapyrusDefinitionAnnotation createUpdatedPapyrusDefinitionAnnotation(Profile profile, int majorInc, int minorInc, int microInc) {
+ Version curVersion = Util.getProfileDefinitionVersion(profile);
+ Version version = new Version(curVersion.getMajor() + majorInc, curVersion.getMinor()+minorInc, curVersion.getMicro()+microInc);
+ PapyrusDefinitionAnnotation papyrusAnnotation = new PapyrusDefinitionAnnotation(version, "", "", "", "");
+ return papyrusAnnotation;
+ }
+
+ /**
+ * Create a new {@link PapyrusDefinitionAnnotation} with the specified values.
+ *
+ * @param stereotype
+ * @param majorInc
+ * @param minorInc
+ * @param microInc
+ * @return a new {@link PapyrusDefinitionAnnotation}
+ */
+ protected PapyrusDefinitionAnnotation createPapyrusDefinitionAnnotation( int majorInc, int minorInc, int microInc) {
+ Version version = new Version(majorInc, minorInc, microInc);
+ Date date = new Date();
+ PapyrusDefinitionAnnotation papyrusAnnotation = new PapyrusDefinitionAnnotation(version, "", "", DateFormat.getInstance().format(date), "");
+ return papyrusAnnotation;
+ }
+
+ /**
+ * Lookup the {@link Package} applying the specified profile. Start lookup from the umlElement.
+ *
+ * @param profile
+ * @return
+ */
+ private Package getApplicantPackage(Profile profile) {
+ ProfileApplication profileApplication = null;
+
+ Package container = umlElement.getNearestPackage();
+ while(profileApplication == null && container != null) {
+ profileApplication = container.getProfileApplication(profile);
+ if( profileApplication != null) {
+ return container;
+ }
+ container = container.getNestingPackage();
+ }
+ return null;
+ }
+
+ /**
+ * Lookup the nearest {@link ProfileApplication} declaring the {@link Profile}.
+ *
+ * @param stereotype
+ * @return
+ * the nearest profile application owning the stereotype
+ */
+ public ProfileApplication getNearestProfileApplication(Profile profile) {
+ ProfileApplication profileApplication = null;
+
+ Package container = umlElement.getNearestPackage();
+ while(profileApplication == null && container != null) {
+ profileApplication = container.getProfileApplication(profile);
+ container = container.getNestingPackage();
+ }
+ return profileApplication;
+ }
+
+ /**
+ * Get the metaclass {@link ElementImport} for requested type. Lookup if the import already exist in Profile. Return it if found.
+ * Create it otherwise, by using the aliasName as a hint for the imported metaclass (ie: name ='Class'==> type=Class).
+ *
+ * @param fromElement Uml:Element used as a starting point to lookup for the {@link ElementImport}. This element
+ * is also used to lookup the rootContainer where the ElementImport will be created
+ * @return The requested metaclass
+ * @throws NotFoundException If the uml::metaclass can't be found
+ */
+ private ElementImport getElementImportByName(Element fromElement, String aliasName) throws NotFoundException {
+
+ ElementImport elementImport = lookupElementImportByName(fromElement, aliasName);
+ if(elementImport == null) {
+ elementImport = createMetaclassElementImport(fromElement, aliasName);
+ }
+
+ return elementImport;
+ }
+
+ /**
+ * Get the metaclass {@link ElementImport} for requested type. Lookup if the import already exist in Profile. Return it if found.
+ * Create it otherwise.
+ *
+ * @param fromElement Uml:Element used as a starting point to lookup for the {@link ElementImport}. This element
+ * is also used to lookup the rootContainer where the ElementImport will be created
+ * @return The Metaclass for which an element import is requested.
+ *
+ * @throws NotFoundException If the uml::metaclass can't be found
+ */
+ private ElementImport getMetaclassElementImport(Element fromElement, Class metaclass) {
+
+ ElementImport elementImport = lookupElementImportByName(fromElement, metaclass.getName());
+ if(elementImport == null) {
+ elementImport = createMetaclassElementImport(fromElement, metaclass);
+ }
+
+ return elementImport;
+ }
+
+ /**
+ * Create the {@link ElementImport} for the specified uml:metaClass name.
+ *
+ * @param umlMetamodelLocator An uml Element used to locate the uml:metamodel throw the ResourceSet.
+ * @param aliasName
+ * @return
+ * @throws NotFoundException If the metaclass can't be found
+ */
+ private ElementImport createMetaclassElementImport(Element fromElement, String aliasName) throws NotFoundException {
+
+ // Get the corresponding metaclass
+ Class metaclass = getUmlMetaClass(aliasName, fromElement);
+ // Create the elementImport
+ return createMetaclassElementImport(fromElement, metaclass);
+ }
+
+ /**
+ * Create the {@link ElementImport} for the specified uml:metaClass name.
+ *
+ * @param umlMetamodelLocator An uml Element used to locate the uml:metamodel throw the ResourceSet.
+ * @param aliasName
+ * @return
+ * @throws NotFoundException If the metaclass can't be found
+ */
+ private ElementImport createMetaclassElementImport(Element fromElement, Class metaclass) {
+// ElementImport elementImport = UMLFactory.eINSTANCE.createElementImport();
+// elementImport.setAlias(metaclass.getName());
+// elementImport.setImportedElement(metaclass);
+// // Add it to the root of the Profile model
+// getResourceRoot().creategetImportedElements().add(elementImport);
+
+ ElementImport elementImport = getRootPackageContainer(fromElement).createElementImport(metaclass);
+ elementImport.setAlias(metaclass.getName());
+ return elementImport;
+ }
+
+ /**
+ * Get the {@link Package} root container to which the specified element belong.
+ *
+ * @return
+ */
+ private Package getRootPackageContainer(Element element) {
+ // This is the root container
+ return (Package)EcoreUtil.getRootContainer(element);
+ }
+
+ /**
+ * Get the metaclass with specified name in UML metamodel.
+ * Throw an exception if not found.
+ *
+ * @param metaclassName
+ * @param ressourceLocator Any uml::Element allowing to get the ResourceSet for uml.
+ * @return
+ * @throws NotFoundException
+ */
+ protected Class getUmlMetaClass( String metaclassName, Element ressourceLocator) throws NotFoundException {
+ // TODO Use a cache for the previous result instead of computing it.
+ List<Class> metaclasses = ElementUtil.getPossibleMetaclasses(ressourceLocator);
+
+ for( Class curClass : metaclasses) {
+ if( curClass.getName().equals(metaclassName)) {
+ return curClass;
+ }
+ }
+
+ // Not found
+ throw new NotFoundException("No uml metaclass found with name '" + metaclassName + "'");
+ }
+
+ /**
+ * Lookup the {@link ElementImport} for the specified aliasName. Start lookup from the specified fromelement.
+ *
+ * @param fromElement Uml:Element used as a starting point to lookup for the {@link ElementImport}. This element
+ * is also used to lookup the rootContainer where the ElementImport will be created
+ * @param aliasName The name of the requested {@link ElementImport}.
+ * @return the {@link ElementImport} or null if not found.
+ */
+ private ElementImport lookupElementImportByName(Element fromElement, String aliasName) {
+
+ if( fromElement == null) {
+ return null;
+ }
+
+ //
+ if( fromElement instanceof Package ) {
+ Package container = (Package)fromElement;
+ for( ElementImport ele : container.getElementImports() ) {
+ if(aliasName.equals(ele.getAlias() ) ) {
+ return ele;
+ }
+ }
+ // Not found in package, search nesting packages
+ return lookupElementImportByName(container.getNestingPackage(), aliasName );
+ }
+ // Lookup from the nearest package of the element.
+ return lookupElementImportByName(fromElement.getNearestPackage(), aliasName );
+ }
+
+ /**
+ * Create an extension between the specified {@link Stereotype} and the specified {@link Type}.
+ *
+ * @param source
+ * @param target
+ * @return
+ */
+ protected Extension createExtension( Stereotype source, Type target) {
+ //create the extension
+ Extension newExtension = UMLFactory.eINSTANCE.createExtension();
+
+ //create the endSource
+ ExtensionEnd endSource = UMLFactory.eINSTANCE.createExtensionEnd();
+
+ //initialize the endSource
+ endSource.setName("extension_" + source.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ endSource.setType(source);
+ endSource.setAggregation(AggregationKind.COMPOSITE_LITERAL);
+
+ //add the endSource to the extension
+ newExtension.getOwnedEnds().add(endSource); // add extension end to extension
+
+
+ //create source_property
+ Property property = UMLFactory.eINSTANCE.createProperty();
+ property.setName("base_" + target.getName());
+ // property.setIsDerived(true);
+ property.setType(target); // set the type
+ property.setAssociation(newExtension); // Set the association link
+ property.setAggregation(AggregationKind.NONE_LITERAL);
+
+ newExtension.getMemberEnds().add(property);
+
+ source.getOwnedAttributes().add(property);
+
+ return newExtension;
+ }
+
+ /**
+ * Define all Profiles found from the container, including the provided package (if it is a profile)
+ * and nested Profile.
+ *
+ * @param container
+ * the package from which to define {@link Profile}
+ */
+ protected List<EPackage> defineAllProfiles(Package container, boolean saveConstraintInDef) {
+
+ List<EPackage> result = new ArrayList<EPackage>();
+
+ // we wants to define
+ if(container instanceof Profile) {
+ Map<String, String> options = createProfileDefinitionOptions(saveConstraintInDef);
+ EPackage profileDefinition = ((Profile)container).define(options, null, null);
+ result.add(profileDefinition);
+ }
+
+ for( Package nestedPackage : container.getNestedPackages() ) {
+ List<EPackage> profileDefinitions = defineAllProfiles(nestedPackage, saveConstraintInDef);
+ result.addAll(profileDefinitions);
+ }
+
+ return result;
+ }
+
+ /**
+ * @param saveConstraintInDef
+ * @return
+ */
+ private Map<String, String> createProfileDefinitionOptions(
+ boolean saveConstraintInDef) {
+ Map<String, String> options = new HashMap<String, String>();
+
+ options.put(Profile2EPackageConverter.OPTION__ECORE_TAGGED_VALUES, UMLUtil.OPTION__PROCESS);
+ options.put(Profile2EPackageConverter.OPTION__DERIVED_FEATURES, UMLUtil.OPTION__REPORT);
+ options.put(Profile2EPackageConverter.OPTION__DUPLICATE_FEATURE_INHERITANCE, UMLUtil.OPTION__PROCESS);
+ options.put(Profile2EPackageConverter.OPTION__DUPLICATE_FEATURES, UMLUtil.OPTION__PROCESS);
+ options.put(Profile2EPackageConverter.OPTION__DUPLICATE_OPERATIONS, UMLUtil.OPTION__REPORT);
+ options.put(Profile2EPackageConverter.OPTION__DUPLICATE_OPERATION_INHERITANCE, UMLUtil.OPTION__REPORT);
+ options.put(Profile2EPackageConverter.OPTION__REDEFINING_OPERATIONS, UMLUtil.OPTION__REPORT);
+ options.put(Profile2EPackageConverter.OPTION__REDEFINING_PROPERTIES, UMLUtil.OPTION__REPORT);
+ options.put(Profile2EPackageConverter.OPTION__SUBSETTING_PROPERTIES, UMLUtil.OPTION__REPORT);
+ options.put(Profile2EPackageConverter.OPTION__UNION_PROPERTIES, UMLUtil.OPTION__PROCESS);
+ options.put(UML2EcoreConverter.OPTION__SUPER_CLASS_ORDER, UMLUtil.OPTION__REPORT);
+ options.put(Profile2EPackageConverter.OPTION__ANNOTATION_DETAILS, UMLUtil.OPTION__REPORT);
+
+ //Generate constraints for the validation
+ String handleConstraints = saveConstraintInDef ? UMLUtil.OPTION__PROCESS : UMLUtil.OPTION__IGNORE;
+ options.put(Profile2EPackageConverter.OPTION__INVARIANT_CONSTRAINTS, handleConstraints);
+ options.put(Profile2EPackageConverter.OPTION__VALIDATION_DELEGATES, handleConstraints);
+ options.put(Profile2EPackageConverter.OPTION__INVOCATION_DELEGATES, handleConstraints);
+ options.put(UML2EcoreConverter.OPTION__OPERATION_BODIES, handleConstraints);
+ //
+
+ options.put(Profile2EPackageConverter.OPTION__COMMENTS, UMLUtil.OPTION__IGNORE);
+ options.put(Profile2EPackageConverter.OPTION__FOREIGN_DEFINITIONS, UMLUtil.OPTION__IGNORE);
+
+ options.put(Profile2EPackageConverter.OPTION__UNTYPED_PROPERTIES, UMLUtil.OPTION__PROCESS); //Closer to the UML semantics of untyped properties
+
+ return options;
+ }
+
+
+ /**
+ * Create a {@link Diagnostician} to validate profile.
+ * Copied from org.eclipse.papyrus.uml.diagram.profile.custom.commands.DefineProfileCommand
+ * @param adapterFactory
+ * @param progressMonitor
+ * @return
+ */
+ protected Diagnostician createDiagnostician(final AdapterFactory adapterFactory, final IProgressMonitor progressMonitor) {
+ return new Diagnostician() {
+
+ @Override
+ public String getObjectLabel(EObject eObject) {
+ if(adapterFactory != null && !eObject.eIsProxy()) {
+ IItemLabelProvider itemLabelProvider = (IItemLabelProvider)adapterFactory.adapt(eObject, IItemLabelProvider.class);
+ if(itemLabelProvider != null) {
+ return itemLabelProvider.getText(eObject);
+ }
+ }
+ return super.getObjectLabel(eObject);
+ }
+
+ @Override
+ public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
+ progressMonitor.worked(1);
+ return super.validate(eClass, eObject, diagnostics, context);
+ }
+ };
+ }
+
+ /**
+ * Update or create the specified stereotype according to the provided {@link IStereotypeUpdateArgs}.
+ *
+ * @param updateArgs Arguments used to update or create a Stereotype.
+ *
+ * @throws DraftProfileException If an error occur during update.
+ */
+ public void updateStereotype(StereoptypeModel stereoptypeModel) throws DraftProfileException {
+
+ String profileName = stereoptypeModel.getProfileName();
+ String stereotypeName = stereoptypeModel.getStereotypeName();
+
+ boolean isProfileModified = false;
+ // The package to which the corresponding Profile is attached
+ Package applicantPackage = null;
+
+ PapyrusDefinitionAnnotation annotations = null;
+ Stereotype stereotype = null;
+ // lookup profile
+ Profile profile = umlElement.getNearestPackage().getAppliedProfile(profileName, true);
+ if( profile == null ) {
+ // ask creation confirmation
+ profile = createProfile(profileName);
+ // Create the stereotype
+ stereotype = createStereotype(profile, stereotypeName);
+
+// applyProfileToUmlElement( profile);
+ // TODO change next behavior
+// throw new DraftProfileException("Profile '" + profileName + "' not applied on nesting packages. Apply profile first.");
+
+ // We will apply profile in nearest PAckage
+ // TODO let choose between nearest, root or choosen
+ applicantPackage = umlElement.getNearestPackage();
+ annotations = createPapyrusDefinitionAnnotation(0, 0, 1);
+ isProfileModified = true;
+ }
+ else {
+ // Profile already exist
+ // Lookup for the stereotype
+ stereotype = profile.getOwnedStereotype(stereotypeName, true);
+ applicantPackage = getApplicantPackage(profile);
+ if( stereotype == null ) {
+ // We need to create the stereotype
+ // ask creation confirmation
+ // TODO change next behavior
+ stereotype = createStereotype(profile, stereotypeName);
+ annotations = createUpdatedPapyrusDefinitionAnnotation(profile, 0, 0, 1);
+ isProfileModified = true;
+ }
+ }
+
+ // update metaclasses by adding missing metaclasses
+ MetaclassesModel metaclassesModel = stereoptypeModel.getMetaclassesCollection();
+ if( ! metaclassesModel.getSelectedMetaclasses().isEmpty() ) {
+ isProfileModified = updateStereotypeMetaclasses( stereotype, metaclassesModel.getSelectedMetaclasses()) || isProfileModified ;
+ }
+
+ // Update property definitions
+ if( !stereoptypeModel.getProperties().isEmpty()) {
+ isProfileModified = createOrUpdateProperties( stereotype, stereoptypeModel.getProperties()) || isProfileModified;
+ }
+
+
+ // Do we need to reapply the profile ?
+ // We do it only if the profile is modified
+ if( isProfileModified) {
+ definesAllProfiles( profile );
+ redefineAllProfiles( profile, annotations );
+ cleanAllProfiles( profile );
+// validateAllProfiles(profile, Arrays.asList((EPackage)profile) );
+ applyProfile( applicantPackage, profile);
+ }
+
+ // Apply stereotype to element
+ applyStereotype( stereotype );
+ // Update or set property values
+ // This should be done once the profile is applied
+ if( !stereoptypeModel.getProperties().isEmpty()) {
+ updatePropertyValues( stereotype, stereoptypeModel.getProperties()) ;
+ }
+
+
+
+ }
+
+ /**
+ * Update any values associated to properties.
+ * Check if a value need to be modified, and modify it accordingly.
+ *
+ * @param stereotype
+ * @param properties
+ */
+ private void updatePropertyValues(Stereotype stereotype, List<PropertyModel> properties) {
+
+// System.err.println("uml.profile.drafter.ProfileApplicator.updatePropertyValues() is disabled - values are not updated.");
+
+ for( PropertyModel propertyModel : properties) {
+ updatePropertyValue( stereotype, propertyModel);
+ }
+
+ }
+
+ /**
+ * Update the value of the property if needed.
+ *
+ * @param stereotype
+ * @param propertyModel
+ */
+ private void updatePropertyValue(Stereotype stereotype, PropertyModel propertyModel) {
+
+ // Get the actual value
+ Object actualValue = getUmlElement().getValue(stereotype, propertyModel.getProposedName());
+
+// org.eclipse.papyrus.uml.profile.utils.Util.getValueObjectFromString(String, Type)
+ // Need to check if the Property value is modified
+ if(propertyModel.isValueModified() ) {
+ String valueAsStr = propertyModel.getValue();
+ if( valueAsStr == null || valueAsStr.length() == 0 ) {
+ getUmlElement().setValue(stereotype, propertyModel.getProposedName(), null);
+ return;
+ }
+
+ Object newValue = org.eclipse.papyrus.uml.profile.utils.Util.getValueObjectFromString(valueAsStr, propertyModel.getType());
+ getUmlElement().setValue(stereotype, propertyModel.getProposedName(), newValue);
+ }
+
+ }
+
+ /**
+ * Check if the property definitions need to be updated or created, accordingly to
+ * {@link PropertyModel}s.
+ * Create missing property, and update modified ones.
+ *
+ * @param stereotype The stereotype that own the properties.
+ *
+ * @param properties models used to update the properties
+ * @return
+ */
+ private boolean createOrUpdateProperties(Stereotype stereotype, List<PropertyModel> properties) {
+
+ boolean isUpdated = false;
+ for( PropertyModel propertyModel : properties) {
+ isUpdated = createOrUpdateProperty( stereotype, propertyModel) || isUpdated;
+ }
+
+ return isUpdated;
+ }
+
+ /**
+ * Check if the property associated to {@link PropertyModel} need to be updated or created.
+ *
+ * Update the specified {@link Property} of the {@link Stereotype}
+ * @param stereotype The {@link Stereotype} owning the property.
+ * @param propertyModel The {@link PropertyModel} to use to update stereotype's corresponding property.
+ *
+ */
+
+ private boolean createOrUpdateProperty(Stereotype stereotype, PropertyModel propertyModel) {
+
+ boolean isUpdated = false;
+ boolean isPropertyExistIn = propertyModel.isPropertyExistIn(stereotype);
+
+ switch(propertyModel.getStateKind()) {
+ case modified:
+ if( isPropertyExistIn) {
+ isUpdated = updateProperty( stereotype, propertyModel);
+ }
+ break;
+
+ case created:
+ if( ! isPropertyExistIn) {
+ isUpdated = createProperty( stereotype, propertyModel);
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ return isUpdated;
+ }
+
+ /**
+ * Update the specified {@link Property} of the {@link Stereotype}.
+ *
+ * @param stereotype The {@link Stereotype} owning the property.
+ * @param propertyModel The {@link PropertyModel} to use to update stereotype's corresponding property.
+ *
+ */
+ private boolean updateProperty(Stereotype stereotype, PropertyModel propertyModel) {
+
+ boolean isUpdated = false;
+ String newName = propertyModel.getProposedName();
+ System.err.println("updateProperty(" + stereotype.getName() + "." + propertyModel.getProposedName() );
+ if( newName!=null && (! newName.equals( stereotype.getName() ) ) ) {
+ stereotype.setName(newName);
+ isUpdated = true;
+ }
+
+ return isUpdated;
+
+ }
+
+ /**
+ * Create the specified {@link Property} of the {@link Stereotype}.
+ *
+ * @param stereotype The {@link Stereotype} owning the property.
+ * @param propertyModel The {@link PropertyModel} to use to update stereotype's corresponding property.
+ *
+ */
+ private boolean createProperty(Stereotype stereotype, PropertyModel propertyModel) {
+
+ boolean isUpdated = true;
+
+// System.err.println("createProperty(" + stereotype.getName() + "." + propertyModel.getProposedName() );
+ stereotype.createOwnedAttribute(propertyModel.getProposedName(), propertyModel.getType());
+
+ return isUpdated;
+ }
+
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/commands/CreateProfileAndProfileResourceCommand.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/commands/CreateProfileAndProfileResourceCommand.java
index e185335ea8d..1170305bbc7 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/commands/CreateProfileAndProfileResourceCommand.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/commands/CreateProfileAndProfileResourceCommand.java
@@ -1,187 +1,185 @@
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.profile.drafter.commands;
-
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.uml.profile.drafter.model.CreatedPapyrusProfileModel;
-import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.papyrus.uml.tools.model.UmlUtils;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.UMLFactory;
-
-/**
- * A pseudo-command used to create a {@link Profile} and its associated Resource.
- *
- * <br>
- * This class use the command pattern, but do not implement any existing interface. This can be changed in
- * the future.
- * The methods signature follow the emf commands (org.eclipse.emf.common.command.Command).
- *
- * @author cedric dumoulin
- *
- */
-public class CreateProfileAndProfileResourceCommand {
-
- protected String profileName;
- protected URI resourceURI;
- /**
- * {@link ModelSet} containing the model to which the Profile should be applied.
- */
- protected ModelSet modelSet;
-
- protected Resource resultResource;
- protected Profile resultProfile;
-
-
- /**
- * Constructor.
- *
- * @param profileName
- * @param modelSet
- */
- public CreateProfileAndProfileResourceCommand(String profileName, ModelSet modelSet) {
- super();
- this.profileName = profileName;
- this.modelSet = modelSet;
- // Create the uri
- this.resourceURI = getResourceURIFromProfileName(profileName);
- }
-
- /**
- * Constructor.
- *
- * @param profileName
- * @param resourceURI
- * @param modelSet
- */
- public CreateProfileAndProfileResourceCommand(String profileName, URI resourceURI, ModelSet modelSet) {
- super();
- this.profileName = profileName;
- this.resourceURI = resourceURI;
- this.modelSet = modelSet;
- }
-
- /**
- * @return the resultResource
- */
- public Resource getResultResource() {
- return resultResource;
- }
-
- /**
- * @return the resultProfile
- */
- public Profile getResultProfile() {
- return resultProfile;
- }
-
- /**
- * Compute the {@link Resource} {@link URI} from the profileName.
- * Use the name associated in {@link ModelSet}, and replace the last segment with the name of the profile. Then
- * append '.profile.uml'.
- *
- *
- * @param profileName
- * @return
- */
- private URI getResourceURIFromProfileName(String profileName) {
-
- URI baseURI = modelSet.getURIWithoutExtension().trimSegments(1);
- System.err.println("baseURI =" + baseURI.toString());
-
- baseURI = baseURI.appendSegment(profileName).appendFileExtension("profile");
- System.err.println("baseURI =" + baseURI.toString());
-
- return baseURI;
- }
-
- /**
- * Check if a resource already exist for the specified resourceURI.
- * Do not load the corresponding resource.
- *
- * @return Return true if a resource already exist for the specified resourceURI, false otherwise.
- */
- private boolean isResourceAlreadyExist() {
- // TODO
-
-// resourceURI.toPlatformString(true);
- return false;
- }
-
- /**
- * Returns whether the command is valid to <code>execute</code>.
- * The command is valid to execute if a Resource with the same name do not already exists, and if the
- * requested resource can be created.
- *
- *
- * @return whether the command is valid to <code>execute</code>.
- */
- public boolean canExecute() {
- return !isResourceAlreadyExist();
- }
-
- /**
- * Execute the command.
- */
- public void execute() {
-
- CreatedPapyrusProfileModel profileModel = new CreatedPapyrusProfileModel(modelSet, resourceURI, true);
-
- resultProfile = profileModel.getProfile();
- resultProfile.setName(profileName);
- resultResource = profileModel.getProfileResource();
-
-// createProfile();
-// createResource();
-//
-// resultResource.getContents().add(resultProfile);
-
-// try {
-// resultResource.save(null);
-// } catch (IOException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
- }
-
- /**
- * Create the specified Profile
- * @param profileName The name of the Profile to create.
- *
- */
- private Profile createProfile() {
- resultProfile = UMLFactory.eINSTANCE.createProfile();
- resultProfile.setName(profileName);
-
- return resultProfile;
- }
-
- /**
- * Create the {@link Resource} that will hold the Profile.
- */
- private Resource createResource() {
-
- resultResource = modelSet.createResource(resourceURI.appendFileExtension("uml"), null);
- // Register the resource with UML model
- UmlModel umlModel = UmlUtils.getUmlModel(modelSet);
- umlModel.handle(resultResource);
- return resultResource;
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.commands;
+
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.uml.profile.drafter.model.CreatedPapyrusProfileModel;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.model.UmlUtils;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.UMLFactory;
+
+/**
+ * A pseudo-command used to create a {@link Profile} and its associated Resource.
+ *
+ * <br>
+ * This class use the command pattern, but do not implement any existing interface. This can be changed in
+ * the future.
+ * The methods signature follow the emf commands (org.eclipse.emf.common.command.Command).
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class CreateProfileAndProfileResourceCommand {
+
+ protected String profileName;
+ protected URI resourceURI;
+ /**
+ * {@link ModelSet} containing the model to which the Profile should be applied.
+ */
+ protected ModelSet modelSet;
+
+ protected Resource resultResource;
+ protected Profile resultProfile;
+
+
+ /**
+ * Constructor.
+ *
+ * @param profileName
+ * @param modelSet
+ */
+ public CreateProfileAndProfileResourceCommand(String profileName, ModelSet modelSet) {
+ super();
+ this.profileName = profileName;
+ this.modelSet = modelSet;
+ // Create the uri
+ this.resourceURI = getResourceURIFromProfileName(profileName);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param profileName
+ * @param resourceURI
+ * @param modelSet
+ */
+ public CreateProfileAndProfileResourceCommand(String profileName, URI resourceURI, ModelSet modelSet) {
+ super();
+ this.profileName = profileName;
+ this.resourceURI = resourceURI;
+ this.modelSet = modelSet;
+ }
+
+ /**
+ * @return the resultResource
+ */
+ public Resource getResultResource() {
+ return resultResource;
+ }
+
+ /**
+ * @return the resultProfile
+ */
+ public Profile getResultProfile() {
+ return resultProfile;
+ }
+
+ /**
+ * Compute the {@link Resource} {@link URI} from the profileName.
+ * Use the name associated in {@link ModelSet}, and replace the last segment with the name of the profile. Then
+ * append '.profile.uml'.
+ *
+ *
+ * @param profileName
+ * @return
+ */
+ private URI getResourceURIFromProfileName(String profileName) {
+
+ URI baseURI = modelSet.getURIWithoutExtension().trimSegments(1);
+
+ baseURI = baseURI.appendSegment(profileName).appendFileExtension("profile");
+
+ return baseURI;
+ }
+
+ /**
+ * Check if a resource already exist for the specified resourceURI.
+ * Do not load the corresponding resource.
+ *
+ * @return Return true if a resource already exist for the specified resourceURI, false otherwise.
+ */
+ private boolean isResourceAlreadyExist() {
+ // TODO
+
+// resourceURI.toPlatformString(true);
+ return false;
+ }
+
+ /**
+ * Returns whether the command is valid to <code>execute</code>.
+ * The command is valid to execute if a Resource with the same name do not already exists, and if the
+ * requested resource can be created.
+ *
+ *
+ * @return whether the command is valid to <code>execute</code>.
+ */
+ public boolean canExecute() {
+ return !isResourceAlreadyExist();
+ }
+
+ /**
+ * Execute the command.
+ */
+ public void execute() {
+
+ CreatedPapyrusProfileModel profileModel = new CreatedPapyrusProfileModel(modelSet, resourceURI, true);
+
+ resultProfile = profileModel.getProfile();
+ resultProfile.setName(profileName);
+ resultResource = profileModel.getProfileResource();
+
+// createProfile();
+// createResource();
+//
+// resultResource.getContents().add(resultProfile);
+
+// try {
+// resultResource.save(null);
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+ }
+
+ /**
+ * Create the specified Profile
+ * @param profileName The name of the Profile to create.
+ *
+ */
+ private Profile createProfile() {
+ resultProfile = UMLFactory.eINSTANCE.createProfile();
+ resultProfile.setName(profileName);
+
+ return resultProfile;
+ }
+
+ /**
+ * Create the {@link Resource} that will hold the Profile.
+ */
+ private Resource createResource() {
+
+ resultResource = modelSet.createResource(resourceURI.appendFileExtension("uml"), null);
+ // Register the resource with UML model
+ UmlModel umlModel = UmlUtils.getUmlModel(modelSet);
+ umlModel.handle(resultResource);
+ return resultResource;
+ }
+
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/services/ProfileCatalogService.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/services/ProfileCatalogService.java
index 7eb9e125885..a02ec6450e7 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/services/ProfileCatalogService.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/services/ProfileCatalogService.java
@@ -1,82 +1,86 @@
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.profile.drafter.services;
-
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.services.IService;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.uml.profile.drafter.UserProfileCatalog;
-
-/**
- * @author dumoulin
- *
- */
-public class ProfileCatalogService implements IService {
-
- /**
- * ModelSet to retrieve models
- */
- protected ModelSet modelSet;
-
- /**
- * The associated ProfileCatalog.
- */
- protected UserProfileCatalog profileCatalog;
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- @Override
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
- // Retrieve required services.
- modelSet = servicesRegistry.getService(ModelSet.class);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#startService()
- *
- * @throws ServiceException
- */
- @Override
- public void startService() throws ServiceException {
- System.err.println("Service started:" + this.getClass().getSimpleName());
-
- }
-
- /**
- * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
- *
- * @throws ServiceException
- */
- @Override
- public void disposeService() throws ServiceException {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Get the ProfileCatalog owned by the service.
- * @return
- */
- public UserProfileCatalog getProfileCatalog() {
- // TODO Auto-generated method stub
- return profileCatalog;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.services;
+
+import static org.eclipse.papyrus.uml.profile.drafter.Activator.log;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.IService;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.uml.profile.drafter.ProfileCatalog;
+import org.eclipse.papyrus.uml.profile.drafter.UserProfileCatalog;
+
+/**
+ * A service used to access a singleton {@link ProfileCatalog}.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ProfileCatalogService implements IService {
+
+ /**
+ * ModelSet to retrieve models
+ */
+ protected ModelSet modelSet;
+
+ /**
+ * The associated ProfileCatalog.
+ */
+ protected UserProfileCatalog profileCatalog;
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ @Override
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ // Retrieve required services.
+ modelSet = servicesRegistry.getService(ModelSet.class);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void startService() throws ServiceException {
+ log.info("Service started:" + this.getClass().getSimpleName());
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void disposeService() throws ServiceException {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Get the ProfileCatalog owned by the service.
+ * @return
+ */
+ public UserProfileCatalog getProfileCatalog() {
+ // TODO Auto-generated method stub
+ return profileCatalog;
+ }
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/PropertiesEditorWidget.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/PropertiesEditorWidget.java
index cf347f7a395..762c1bbce9d 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/PropertiesEditorWidget.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/PropertiesEditorWidget.java
@@ -1,637 +1,636 @@
-package org.eclipse.papyrus.uml.profile.drafter.ui.dialog;
-
-import java.util.List;
-
-import org.eclipse.core.databinding.DataBindingContext;
-import org.eclipse.core.databinding.beans.BeanProperties;
-import org.eclipse.core.databinding.beans.BeansObservables;
-import org.eclipse.core.databinding.beans.IBeanValueProperty;
-import org.eclipse.core.databinding.observable.list.WritableList;
-import org.eclipse.core.databinding.observable.map.IObservableMap;
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.core.databinding.property.value.IValueProperty;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.jface.databinding.swt.WidgetProperties;
-import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
-import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
-import org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport;
-import org.eclipse.jface.databinding.viewers.ViewerProperties;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ColumnViewer;
-import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.AccessibleTypeCatalog;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.MemberKind;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.PropertyModel;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.StateKind;
-import org.eclipse.papyrus.uml.profile.drafter.ui.providers.TypeLabelProvider;
-import org.eclipse.papyrus.uml.profile.drafter.utils.UMLPrimitiveTypesModel;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.Type;
-
-/**
- * A widget used to edit a list of {@link PropertyModel}.
- * @author dumoulin
- *
- */
-public class PropertiesEditorWidget {
- private DataBindingContext m_bindingContext;
-
- private Composite contentArea;
-// private List<PropertyModel> properties;
- private WritableList properties;
- private NamedElement selectedElement;
-
- private TableViewer treeViewer;
- private TableViewerColumn nameViewerColumn;
- private TableViewerColumn typeViewerColumn;
- private TableViewerColumn statusViewerColumn;
- private TableViewerColumn valueViewerColumn;
-
- private TableViewerColumn memberViewerColumn;
-
- private TableViewerColumn deletedViewerColumn;
-
- /**
- * Label provider associated to this class. Lazy creation.
- */
- private ILabelProvider typeLabelProvider;
-
- /**
- * The catalog of type associated to this class. Lazy creation.
- */
- private ITypeCatalog typeCatalog;
-
- /**
- * Library of UML Primitive types. Lazy loading.
- */
- private UMLPrimitiveTypesModel umlPrimitiveTypesLibrary;
-
- /**
- * Create the composite.
- * @param parent
- * @param stereotype The stereotype defining the taggedValues
- * @param selectedElement The uml {@link NamedElement} for which taggedValue are edited
- *
- * @wbp.parser.entryPoint
- */
- public PropertiesEditorWidget(Composite parent, List<PropertyModel> properties, NamedElement selectedElement) {
-
-// this.properties = Properties.selfList(PropertyModel.class).observe(properties);
- if( properties instanceof WritableList) {
- this.properties = (WritableList)properties;
- }
- else {
- this.properties = new WritableList(properties, PropertyModel.class);
- }
- this.selectedElement = selectedElement;
- createContent(parent);
- }
-
-
- /**
- * @param stereotype the stereotype to set
- */
- public void setProperties( List<PropertyModel> properties) {
-// this.properties = Properties.selfList(PropertyModel.class).observe(properties);
- if( properties instanceof WritableList) {
- this.properties = (WritableList)properties;
- }
- else {
- this.properties = new WritableList(properties, PropertyModel.class);
- }
-// treeViewer.setInput(properties);
- }
-
-
- /**
- * Create the overall component.
- * @param parent
- */
- protected void createContent(Composite parent) {
-
- contentArea = createContentArea(parent);
-
- // now lets bind the values
- // No extra label provider / content provider / setInput required
-// WritableList input;
-// if( properties instanceof WritableList ) {
-// input = (WritableList)properties;
-// }
-// else {
-// input = new WritableList(properties, PropertyModel.class);
-// }
-// ViewerSupport.bind(treeViewer,
-// input,
-// BeanProperties.values(new String[] { "proposedName", "type", "modelStatus", "value" }));
-
-
-// fillContentArea();
-// createDialogContents();
-
- }
-
- /**
- * Create the content area.
- *
- * @param parent
- * @return
- */
- protected Composite createContentArea(Composite parent) {
- // create a composite with standard margins and spacing
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.makeColumnsEqualWidth = true;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- Composite tableTitle = new Composite(composite, SWT.NONE);
- tableTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
- tableTitle.setLayout(new FillLayout(SWT.HORIZONTAL));
-
- Label label = new Label(tableTitle, SWT.NONE);
- label.setText("Properties");
-
- Button addPropertyButton = new Button(tableTitle, SWT.NONE);
- addPropertyButton.setText("+");
- addPropertyButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- addPropertyPressed(e);
- }
-
- });
-
-
- Button removePropertyButton = new Button(tableTitle, SWT.NONE);
- removePropertyButton.setText("-");
- removePropertyButton.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- removePropertyPressed(e);
- }
-
- });
-
- treeViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION );
- Table tree = treeViewer.getTable();
- GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
- gd_tree.minimumHeight = 100;
- tree.setLayoutData(gd_tree);
-
- nameViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
- TableColumn NameTableColumn = nameViewerColumn.getColumn();
- NameTableColumn.setWidth(100);
- NameTableColumn.setText("name");
-// treeViewerColumn.setLabelProvider( new TaggedValueNameColumnLabelProvider() );
-
- // Type column
- typeViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
- TableColumn typeTableColumn = typeViewerColumn.getColumn();
- typeTableColumn.setWidth(100);
- typeTableColumn.setText("type");
-
- statusViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
- TableColumn statusTableColumn = statusViewerColumn.getColumn();
- statusTableColumn.setWidth(67);
- statusTableColumn.setText("status");
-
- memberViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
- TableColumn memberTableColumn = memberViewerColumn.getColumn();
- memberTableColumn.setWidth(64);
- memberTableColumn.setText("member");
-
- deletedViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
- TableColumn deletedTableColumn = deletedViewerColumn.getColumn();
- deletedTableColumn.setWidth(37);
- deletedTableColumn.setText("deleted");
-// treeViewerColumn_1.setLabelProvider( new TaggedValueNameColumnLabelProvider() );
-
- valueViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
- TableColumn valueTableColumn = valueViewerColumn.getColumn();
- valueTableColumn.setWidth(100);
- valueTableColumn.setText("value");
-// treeViewerColumn_2.setLabelProvider( new TaggedValueValueColumnLabelProvider() );
-
- tree.setHeaderVisible(true);
- m_bindingContext = initDataBindings();
-// initManualDataBindings(m_bindingContext);
-
- return composite;
-
- }
-
- /**
- * The add button has been pressed.
- * @param e
- */
- private void addPropertyPressed(SelectionEvent e) {
- System.err.println("addPropertyPressed()");
- // Create PropertyModem
- PropertyModel model;
- try {
- model = new PropertyModel(MemberKind.owned, "newProperty", getUMLPrimitiveTypeLibrary().getDefaultType());
- } catch (NullPointerException e1) {
- // Provide a Property with no type.
- model = new PropertyModel(MemberKind.owned, "newProperty");
- }
-
- properties.add(model);
- }
-
- /**
- * The remove button has been pressed.
- * @param e
- */
- private void removePropertyPressed(SelectionEvent e) {
- ISelection selection = treeViewer.getSelection();
- if( selection instanceof IStructuredSelection ) {
- IStructuredSelection structSelection = (IStructuredSelection)selection;
- removeProperty((PropertyModel)structSelection.getFirstElement());
- }
- }
-
- /**
- * remove the specified property from the property list.
- *
- * @param propertyModel model to remove. Can be null.
- */
- private void removeProperty(PropertyModel propertyModel) {
- if(propertyModel == null) {
- return;
- }
-
- if(propertyModel.getStateKind() == StateKind.created) {
- // We just created it. So we can safely remove
- properties.remove(propertyModel);
- }
- else if( propertyModel.getMemberKind() == MemberKind.owned) {
- // We just change the status of the model.
- // This is done by sending the delete event
- propertyModel.deleteModelEvent();
- }
- else {
- // We do not allow removal of other MemberKind
- }
-
- }
-
-
- private void createDialogContents() {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Fill the content area with values found in stereotype.
- */
- private void fillContentArea() {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Get the name of the taggedValue
- * @author dumoulin
- *
- */
- public class TaggedValueNameColumnLabelProvider extends ColumnLabelProvider {
-
- @Override
- public String getText(Object element) {
-
- Property property = (Property)element;
- return property.getName();
- }
- }
-
- /**
- * Get the value of the taggedValue
- *
- */
- public class TaggedValueValueColumnLabelProvider extends ColumnLabelProvider {
-
- @Override
- public String getText(Object element) {
-
- Property property = (Property)element;
- Object value = selectedElement.getValue((Stereotype)property.getOwner(), property.getName());
-
- if(value instanceof NamedElement) {
- return ((NamedElement)value).getName();
- }
- // TODO
- // collections and arrays
- // dynamic objects
- return value.toString();
- }
- }
-
- /**
- * Content Provider for TaggedValues hierarchy
- *
- */
- private class MyContentProvider implements ITreeContentProvider {
-
- private Object[] EMPTY_ARRAY = new Object[]{};
-
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
- *
- * @param inputElement
- * @return
- */
- @Override
- public Object[] getElements(Object inputElement) {
-
-
- Stereotype stereotype = (Stereotype)inputElement;
- // Return the stereotype's Properties
- return stereotype.getAllAttributes().toArray();
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- *
- * @param parentElement
- * @return
- */
- @Override
- public Object[] getChildren(Object parentElement) {
- return EMPTY_ARRAY;
- }
-
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Object getParent(Object element) {
- Property property = (Property)element;
- return property.getOwner();
- }
-
- @Override
- public boolean hasChildren(Object element) {
- return false;
- }
-
- }
-
- /**
- * Returns an ObservableValueEditingSupport instance which binds the given
- * cell editor property to the given element property.
- *
- * @param viewer
- * the column viewer
- * @param dbc
- * the DataBindingContext used for binding between the cell
- * editor and the viewer element.
- * @param cellEditor
- * the cell editor
- * @param cellEditorProperty
- * the cell editor property to be bound to the element.
- * @param elementProperty
- * the element property to be bound to the cell editor.
- * @return an ObservableValueEditingSupport instance using the given
- * arguments.
- * copied from org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport.create(ColumnViewer, DataBindingContext, CellEditor, IValueProperty, IValueProperty)
- */
- protected static EditingSupport create(ColumnViewer viewer, DataBindingContext dbc, final CellEditor cellEditor,
- final IValueProperty cellEditorProperty,
- final IValueProperty elementProperty) {
-
- return new ObservableValueEditingSupport(viewer, dbc) {
- protected IObservableValue doCreateCellEditorObservable( CellEditor cellEditor) {
- //WidgetProperties.text(SWT.Modify).observe(cellEditor.getControl());
- if( cellEditor instanceof ComboBoxViewerCellEditor) {
- return cellEditorProperty.observe(((ComboBoxViewerCellEditor)cellEditor).getViewer() );
- }
-
- return cellEditorProperty.observe(cellEditor.getControl());
- }
-
- protected IObservableValue doCreateElementObservable( Object element, ViewerCell cell) {
- return elementProperty.observe(element);
- }
-
- protected CellEditor getCellEditor(Object element) {
- return cellEditor;
- }
-
-
- };
- }
-
- protected DataBindingContext initDataBindings() {
- DataBindingContext bindingContext = new DataBindingContext();
- //
- ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
- IObservableMap[] observeMaps = BeansObservables.observeMaps(listContentProvider.getKnownElements(), PropertyModel.class, new String[]{"proposedName", "type", "stateKind", "memberKind", "lifeStatusKind", "value"});
- treeViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps) {
- /**
- * Handle Type
- * @see org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider#getColumnText(java.lang.Object, int)
- *
- * @param element
- * @param columnIndex
- * @return
- */
- @Override
- public String getColumnText(Object element, int columnIndex) {
-
- if (columnIndex < attributeMaps.length) {
- Object result = attributeMaps[columnIndex].get(element);
- if(result instanceof Type) {
- return getTypeLabelProvider().getText(result);
- }
- return result == null ? "" : result.toString(); //$NON-NLS-1$
- }
- return null;
- }
- });
-
-
-
-
-
-
- treeViewer.setContentProvider(listContentProvider);
- //
- treeViewer.setInput(properties);
-
- // Set Cell Editors
- //
- CellEditor cellEditor_0 = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorProperty_0 = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valueProperty_0 = BeanProperties.value("proposedName");
- nameViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_0, cellEditorProperty_0, valueProperty_0));
- //
- // Type column
-// CellEditor cellEditor_1 = new TextCellEditor(treeViewer.getTable());
-// IValueProperty cellEditorProperty = WidgetProperties.text(SWT.Modify);
-// IBeanValueProperty valueProperty_1 = BeanProperties.value("type");
-// treeViewerColumn_1.setEditingSupport(create(treeViewer, bindingContext, cellEditor_1, cellEditorProperty, valueProperty_1));
- // Use a dedicated ComboBox CellEditor for type
- ComboBoxViewerCellEditor typeCellEditor = new ComboBoxViewerCellEditor(treeViewer.getTable());
- typeCellEditor.setContentProvider(ArrayContentProvider.getInstance());
- typeCellEditor.setLabelProvider(getTypeLabelProvider());
- typeCellEditor.setInput(getTypeCatalog().getTypes());
- // Use a special label provider
-
- IValueProperty typeCellEditorBindAnchor = ViewerProperties.singleSelection();
- WidgetProperties.text(SWT.Modify);
- IBeanValueProperty typeModelPropertyBindAnchor = BeanProperties.value("type");
- typeViewerColumn.setEditingSupport(create(treeViewer, bindingContext, typeCellEditor, typeCellEditorBindAnchor, typeModelPropertyBindAnchor));
-
- //
- CellEditor cellEditor_2 = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorProperty_1 = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valueProperty_2 = BeanProperties.value("stateKind");
- statusViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_2, cellEditorProperty_1, valueProperty_2));
- //
- CellEditor cellEditor_3 = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorProperty_2 = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valueProperty_3 = BeanProperties.value("value");
- valueViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_3, cellEditorProperty_2, valueProperty_3));
- //
- //
- CellEditor cellEditor_member = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorPropertyMember = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valuePropertyMember = BeanProperties.value("memberKind");
- memberViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_member, cellEditorPropertyMember, valuePropertyMember));
- //
- CellEditor cellEditor_del = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorPropertyDel = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valuePropertyDel = BeanProperties.value("lifeStatusKind");
- memberViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_del, cellEditorPropertyDel, valuePropertyDel));
-
-
-
-
- return bindingContext;
- }
-
- /**
- * Return the {@link TypeLabelProvider} associated to this class.
- *
- * @return
- */
- private ILabelProvider getTypeLabelProvider() {
- if( typeLabelProvider == null) {
- typeLabelProvider = new TypeLabelProvider();
- }
- return typeLabelProvider;
- }
-
- /**
- * Return the {@link ITypeCatalog} associated to this class.
- *
- * @return
- */
- private ITypeCatalog getTypeCatalog() {
- if( typeCatalog == null) {
- typeCatalog = new AccessibleTypeCatalog(selectedElement, getUMLPrimitiveTypeLibrary());
- }
- return typeCatalog;
- }
-
- /**
- * Get the Library of UML Primitive types. Lookup in the {@link ResourceSet} associated to the selected NamedElement.
- *
- * @return the library found.
- *
- * @throws UnsupportedOperationException If the Library can't be found in the associated {@link ResourceSet}.
- */
- private UMLPrimitiveTypesModel getUMLPrimitiveTypeLibrary() {
- if( umlPrimitiveTypesLibrary == null) {
- // Create primitiveTypeModel from the ResourceSet associated to the element.
- // It will be used to add such types.
- try {
- umlPrimitiveTypesLibrary = new UMLPrimitiveTypesModel(selectedElement.eResource().getResourceSet());
- } catch (UnsupportedOperationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
- return umlPrimitiveTypesLibrary;
- }
-
-
- /**
- * Additional databinding done manually.
- * @param bindingContext
- * @return
- */
- protected DataBindingContext initManualDataBindings(DataBindingContext bindingContext) {
- //
- //
- CellEditor cellEditor_0 = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorProperty_0 = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valueProperty_0 = BeanProperties.value("proposedName");
- nameViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_0, cellEditorProperty_0, valueProperty_0));
- //
- CellEditor cellEditor_1 = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorProperty = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valueProperty_1 = BeanProperties.value("type");
- typeViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_1, cellEditorProperty, valueProperty_1));
- //
- CellEditor cellEditor_2 = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorProperty_1 = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valueProperty_2 = BeanProperties.value("modelStatus");
- statusViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_2, cellEditorProperty_1, valueProperty_2));
- //
- CellEditor cellEditor_3 = new TextCellEditor(treeViewer.getTable());
- IValueProperty cellEditorProperty_2 = WidgetProperties.text(SWT.Modify);
- IBeanValueProperty valueProperty_3 = BeanProperties.value("value");
- valueViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_3, cellEditorProperty_2, valueProperty_3));
- //
- return bindingContext;
- }
-}
+package org.eclipse.papyrus.uml.profile.drafter.ui.dialog;
+
+import java.util.List;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.beans.IBeanValueProperty;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.core.databinding.observable.map.IObservableMap;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.property.value.IValueProperty;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
+import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
+import org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport;
+import org.eclipse.jface.databinding.viewers.ViewerProperties;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.AccessibleTypeCatalog;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.ITypeCatalog;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.MemberKind;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.PropertyModel;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.StateKind;
+import org.eclipse.papyrus.uml.profile.drafter.ui.providers.TypeLabelProvider;
+import org.eclipse.papyrus.uml.profile.drafter.utils.UMLPrimitiveTypesModel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+
+/**
+ * A widget used to edit a list of {@link PropertyModel}.
+ * @author dumoulin
+ *
+ */
+public class PropertiesEditorWidget {
+ private DataBindingContext m_bindingContext;
+
+ private Composite contentArea;
+// private List<PropertyModel> properties;
+ private WritableList properties;
+ private NamedElement selectedElement;
+
+ private TableViewer treeViewer;
+ private TableViewerColumn nameViewerColumn;
+ private TableViewerColumn typeViewerColumn;
+ private TableViewerColumn statusViewerColumn;
+ private TableViewerColumn valueViewerColumn;
+
+ private TableViewerColumn memberViewerColumn;
+
+ private TableViewerColumn deletedViewerColumn;
+
+ /**
+ * Label provider associated to this class. Lazy creation.
+ */
+ private ILabelProvider typeLabelProvider;
+
+ /**
+ * The catalog of type associated to this class. Lazy creation.
+ */
+ private ITypeCatalog typeCatalog;
+
+ /**
+ * Library of UML Primitive types. Lazy loading.
+ */
+ private UMLPrimitiveTypesModel umlPrimitiveTypesLibrary;
+
+ /**
+ * Create the composite.
+ * @param parent
+ * @param stereotype The stereotype defining the taggedValues
+ * @param selectedElement The uml {@link NamedElement} for which taggedValue are edited
+ *
+ * @wbp.parser.entryPoint
+ */
+ public PropertiesEditorWidget(Composite parent, List<PropertyModel> properties, NamedElement selectedElement) {
+
+// this.properties = Properties.selfList(PropertyModel.class).observe(properties);
+ if( properties instanceof WritableList) {
+ this.properties = (WritableList)properties;
+ }
+ else {
+ this.properties = new WritableList(properties, PropertyModel.class);
+ }
+ this.selectedElement = selectedElement;
+ createContent(parent);
+ }
+
+
+ /**
+ * @param stereotype the stereotype to set
+ */
+ public void setProperties( List<PropertyModel> properties) {
+// this.properties = Properties.selfList(PropertyModel.class).observe(properties);
+ if( properties instanceof WritableList) {
+ this.properties = (WritableList)properties;
+ }
+ else {
+ this.properties = new WritableList(properties, PropertyModel.class);
+ }
+// treeViewer.setInput(properties);
+ }
+
+
+ /**
+ * Create the overall component.
+ * @param parent
+ */
+ protected void createContent(Composite parent) {
+
+ contentArea = createContentArea(parent);
+
+ // now lets bind the values
+ // No extra label provider / content provider / setInput required
+// WritableList input;
+// if( properties instanceof WritableList ) {
+// input = (WritableList)properties;
+// }
+// else {
+// input = new WritableList(properties, PropertyModel.class);
+// }
+// ViewerSupport.bind(treeViewer,
+// input,
+// BeanProperties.values(new String[] { "proposedName", "type", "modelStatus", "value" }));
+
+
+// fillContentArea();
+// createDialogContents();
+
+ }
+
+ /**
+ * Create the content area.
+ *
+ * @param parent
+ * @return
+ */
+ protected Composite createContentArea(Composite parent) {
+ // create a composite with standard margins and spacing
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.makeColumnsEqualWidth = true;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Composite tableTitle = new Composite(composite, SWT.NONE);
+ tableTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ tableTitle.setLayout(new FillLayout(SWT.HORIZONTAL));
+
+ Label label = new Label(tableTitle, SWT.NONE);
+ label.setText("Properties");
+
+ Button addPropertyButton = new Button(tableTitle, SWT.NONE);
+ addPropertyButton.setText("+");
+ addPropertyButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ addPropertyPressed(e);
+ }
+
+ });
+
+
+ Button removePropertyButton = new Button(tableTitle, SWT.NONE);
+ removePropertyButton.setText("-");
+ removePropertyButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ removePropertyPressed(e);
+ }
+
+ });
+
+ treeViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION );
+ Table tree = treeViewer.getTable();
+ GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
+ gd_tree.minimumHeight = 100;
+ tree.setLayoutData(gd_tree);
+
+ nameViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
+ TableColumn NameTableColumn = nameViewerColumn.getColumn();
+ NameTableColumn.setWidth(100);
+ NameTableColumn.setText("name");
+// treeViewerColumn.setLabelProvider( new TaggedValueNameColumnLabelProvider() );
+
+ // Type column
+ typeViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
+ TableColumn typeTableColumn = typeViewerColumn.getColumn();
+ typeTableColumn.setWidth(100);
+ typeTableColumn.setText("type");
+
+ statusViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
+ TableColumn statusTableColumn = statusViewerColumn.getColumn();
+ statusTableColumn.setWidth(67);
+ statusTableColumn.setText("status");
+
+ memberViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
+ TableColumn memberTableColumn = memberViewerColumn.getColumn();
+ memberTableColumn.setWidth(64);
+ memberTableColumn.setText("member");
+
+ deletedViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
+ TableColumn deletedTableColumn = deletedViewerColumn.getColumn();
+ deletedTableColumn.setWidth(37);
+ deletedTableColumn.setText("deleted");
+// treeViewerColumn_1.setLabelProvider( new TaggedValueNameColumnLabelProvider() );
+
+ valueViewerColumn = new TableViewerColumn(treeViewer, SWT.NONE);
+ TableColumn valueTableColumn = valueViewerColumn.getColumn();
+ valueTableColumn.setWidth(100);
+ valueTableColumn.setText("value");
+// treeViewerColumn_2.setLabelProvider( new TaggedValueValueColumnLabelProvider() );
+
+ tree.setHeaderVisible(true);
+ m_bindingContext = initDataBindings();
+// initManualDataBindings(m_bindingContext);
+
+ return composite;
+
+ }
+
+ /**
+ * The add button has been pressed.
+ * @param e
+ */
+ private void addPropertyPressed(SelectionEvent e) {
+ // Create PropertyModem
+ PropertyModel model;
+ try {
+ model = new PropertyModel(MemberKind.owned, "newProperty", getUMLPrimitiveTypeLibrary().getDefaultType());
+ } catch (NullPointerException e1) {
+ // Provide a Property with no type.
+ model = new PropertyModel(MemberKind.owned, "newProperty");
+ }
+
+ properties.add(model);
+ }
+
+ /**
+ * The remove button has been pressed.
+ * @param e
+ */
+ private void removePropertyPressed(SelectionEvent e) {
+ ISelection selection = treeViewer.getSelection();
+ if( selection instanceof IStructuredSelection ) {
+ IStructuredSelection structSelection = (IStructuredSelection)selection;
+ removeProperty((PropertyModel)structSelection.getFirstElement());
+ }
+ }
+
+ /**
+ * remove the specified property from the property list.
+ *
+ * @param propertyModel model to remove. Can be null.
+ */
+ private void removeProperty(PropertyModel propertyModel) {
+ if(propertyModel == null) {
+ return;
+ }
+
+ if(propertyModel.getStateKind() == StateKind.created) {
+ // We just created it. So we can safely remove
+ properties.remove(propertyModel);
+ }
+ else if( propertyModel.getMemberKind() == MemberKind.owned) {
+ // We just change the status of the model.
+ // This is done by sending the delete event
+ propertyModel.deleteModelEvent();
+ }
+ else {
+ // We do not allow removal of other MemberKind
+ }
+
+ }
+
+
+ private void createDialogContents() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Fill the content area with values found in stereotype.
+ */
+ private void fillContentArea() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Get the name of the taggedValue
+ * @author dumoulin
+ *
+ */
+ public class TaggedValueNameColumnLabelProvider extends ColumnLabelProvider {
+
+ @Override
+ public String getText(Object element) {
+
+ Property property = (Property)element;
+ return property.getName();
+ }
+ }
+
+ /**
+ * Get the value of the taggedValue
+ *
+ */
+ public class TaggedValueValueColumnLabelProvider extends ColumnLabelProvider {
+
+ @Override
+ public String getText(Object element) {
+
+ Property property = (Property)element;
+ Object value = selectedElement.getValue((Stereotype)property.getOwner(), property.getName());
+
+ if(value instanceof NamedElement) {
+ return ((NamedElement)value).getName();
+ }
+ // TODO
+ // collections and arrays
+ // dynamic objects
+ return value.toString();
+ }
+ }
+
+ /**
+ * Content Provider for TaggedValues hierarchy
+ *
+ */
+ private class MyContentProvider implements ITreeContentProvider {
+
+ private Object[] EMPTY_ARRAY = new Object[]{};
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ *
+ * @param inputElement
+ * @return
+ */
+ @Override
+ public Object[] getElements(Object inputElement) {
+
+
+ Stereotype stereotype = (Stereotype)inputElement;
+ // Return the stereotype's Properties
+ return stereotype.getAllAttributes().toArray();
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ *
+ * @param parentElement
+ * @return
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ return EMPTY_ARRAY;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Object getParent(Object element) {
+ Property property = (Property)element;
+ return property.getOwner();
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ }
+
+ /**
+ * Returns an ObservableValueEditingSupport instance which binds the given
+ * cell editor property to the given element property.
+ *
+ * @param viewer
+ * the column viewer
+ * @param dbc
+ * the DataBindingContext used for binding between the cell
+ * editor and the viewer element.
+ * @param cellEditor
+ * the cell editor
+ * @param cellEditorProperty
+ * the cell editor property to be bound to the element.
+ * @param elementProperty
+ * the element property to be bound to the cell editor.
+ * @return an ObservableValueEditingSupport instance using the given
+ * arguments.
+ * copied from org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport.create(ColumnViewer, DataBindingContext, CellEditor, IValueProperty, IValueProperty)
+ */
+ protected static EditingSupport create(ColumnViewer viewer, DataBindingContext dbc, final CellEditor cellEditor,
+ final IValueProperty cellEditorProperty,
+ final IValueProperty elementProperty) {
+
+ return new ObservableValueEditingSupport(viewer, dbc) {
+ protected IObservableValue doCreateCellEditorObservable( CellEditor cellEditor) {
+ //WidgetProperties.text(SWT.Modify).observe(cellEditor.getControl());
+ if( cellEditor instanceof ComboBoxViewerCellEditor) {
+ return cellEditorProperty.observe(((ComboBoxViewerCellEditor)cellEditor).getViewer() );
+ }
+
+ return cellEditorProperty.observe(cellEditor.getControl());
+ }
+
+ protected IObservableValue doCreateElementObservable( Object element, ViewerCell cell) {
+ return elementProperty.observe(element);
+ }
+
+ protected CellEditor getCellEditor(Object element) {
+ return cellEditor;
+ }
+
+
+ };
+ }
+
+ protected DataBindingContext initDataBindings() {
+ DataBindingContext bindingContext = new DataBindingContext();
+ //
+ ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
+ IObservableMap[] observeMaps = BeansObservables.observeMaps(listContentProvider.getKnownElements(), PropertyModel.class, new String[]{"proposedName", "type", "stateKind", "memberKind", "lifeStatusKind", "value"});
+ treeViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps) {
+ /**
+ * Handle Type
+ * @see org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider#getColumnText(java.lang.Object, int)
+ *
+ * @param element
+ * @param columnIndex
+ * @return
+ */
+ @Override
+ public String getColumnText(Object element, int columnIndex) {
+
+ if (columnIndex < attributeMaps.length) {
+ Object result = attributeMaps[columnIndex].get(element);
+ if(result instanceof Type) {
+ return getTypeLabelProvider().getText(result);
+ }
+ return result == null ? "" : result.toString(); //$NON-NLS-1$
+ }
+ return null;
+ }
+ });
+
+
+
+
+
+
+ treeViewer.setContentProvider(listContentProvider);
+ //
+ treeViewer.setInput(properties);
+
+ // Set Cell Editors
+ //
+ CellEditor cellEditor_0 = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorProperty_0 = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valueProperty_0 = BeanProperties.value("proposedName");
+ nameViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_0, cellEditorProperty_0, valueProperty_0));
+ //
+ // Type column
+// CellEditor cellEditor_1 = new TextCellEditor(treeViewer.getTable());
+// IValueProperty cellEditorProperty = WidgetProperties.text(SWT.Modify);
+// IBeanValueProperty valueProperty_1 = BeanProperties.value("type");
+// treeViewerColumn_1.setEditingSupport(create(treeViewer, bindingContext, cellEditor_1, cellEditorProperty, valueProperty_1));
+ // Use a dedicated ComboBox CellEditor for type
+ ComboBoxViewerCellEditor typeCellEditor = new ComboBoxViewerCellEditor(treeViewer.getTable());
+ typeCellEditor.setContentProvider(ArrayContentProvider.getInstance());
+ typeCellEditor.setLabelProvider(getTypeLabelProvider());
+ typeCellEditor.setInput(getTypeCatalog().getTypes());
+ // Use a special label provider
+
+ IValueProperty typeCellEditorBindAnchor = ViewerProperties.singleSelection();
+ WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty typeModelPropertyBindAnchor = BeanProperties.value("type");
+ typeViewerColumn.setEditingSupport(create(treeViewer, bindingContext, typeCellEditor, typeCellEditorBindAnchor, typeModelPropertyBindAnchor));
+
+ //
+ CellEditor cellEditor_2 = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorProperty_1 = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valueProperty_2 = BeanProperties.value("stateKind");
+ statusViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_2, cellEditorProperty_1, valueProperty_2));
+ //
+ CellEditor cellEditor_3 = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorProperty_2 = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valueProperty_3 = BeanProperties.value("value");
+ valueViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_3, cellEditorProperty_2, valueProperty_3));
+ //
+ //
+ CellEditor cellEditor_member = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorPropertyMember = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valuePropertyMember = BeanProperties.value("memberKind");
+ memberViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_member, cellEditorPropertyMember, valuePropertyMember));
+ //
+ CellEditor cellEditor_del = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorPropertyDel = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valuePropertyDel = BeanProperties.value("lifeStatusKind");
+ memberViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_del, cellEditorPropertyDel, valuePropertyDel));
+
+
+
+
+ return bindingContext;
+ }
+
+ /**
+ * Return the {@link TypeLabelProvider} associated to this class.
+ *
+ * @return
+ */
+ private ILabelProvider getTypeLabelProvider() {
+ if( typeLabelProvider == null) {
+ typeLabelProvider = new TypeLabelProvider();
+ }
+ return typeLabelProvider;
+ }
+
+ /**
+ * Return the {@link ITypeCatalog} associated to this class.
+ *
+ * @return
+ */
+ private ITypeCatalog getTypeCatalog() {
+ if( typeCatalog == null) {
+ typeCatalog = new AccessibleTypeCatalog(selectedElement, getUMLPrimitiveTypeLibrary());
+ }
+ return typeCatalog;
+ }
+
+ /**
+ * Get the Library of UML Primitive types. Lookup in the {@link ResourceSet} associated to the selected NamedElement.
+ *
+ * @return the library found.
+ *
+ * @throws UnsupportedOperationException If the Library can't be found in the associated {@link ResourceSet}.
+ */
+ private UMLPrimitiveTypesModel getUMLPrimitiveTypeLibrary() {
+ if( umlPrimitiveTypesLibrary == null) {
+ // Create primitiveTypeModel from the ResourceSet associated to the element.
+ // It will be used to add such types.
+ try {
+ umlPrimitiveTypesLibrary = new UMLPrimitiveTypesModel(selectedElement.eResource().getResourceSet());
+ } catch (UnsupportedOperationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ return umlPrimitiveTypesLibrary;
+ }
+
+
+ /**
+ * Additional databinding done manually.
+ * @param bindingContext
+ * @return
+ */
+ protected DataBindingContext initManualDataBindings(DataBindingContext bindingContext) {
+ //
+ //
+ CellEditor cellEditor_0 = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorProperty_0 = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valueProperty_0 = BeanProperties.value("proposedName");
+ nameViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_0, cellEditorProperty_0, valueProperty_0));
+ //
+ CellEditor cellEditor_1 = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorProperty = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valueProperty_1 = BeanProperties.value("type");
+ typeViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_1, cellEditorProperty, valueProperty_1));
+ //
+ CellEditor cellEditor_2 = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorProperty_1 = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valueProperty_2 = BeanProperties.value("modelStatus");
+ statusViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_2, cellEditorProperty_1, valueProperty_2));
+ //
+ CellEditor cellEditor_3 = new TextCellEditor(treeViewer.getTable());
+ IValueProperty cellEditorProperty_2 = WidgetProperties.text(SWT.Modify);
+ IBeanValueProperty valueProperty_3 = BeanProperties.value("value");
+ valueViewerColumn.setEditingSupport(create(treeViewer, bindingContext, cellEditor_3, cellEditorProperty_2, valueProperty_3));
+ //
+ return bindingContext;
+ }
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/StereotypeNameToProfileSynchronizer.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/StereotypeNameToProfileSynchronizer.java
index d9ca35fd2f5..705914757e0 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/StereotypeNameToProfileSynchronizer.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/StereotypeNameToProfileSynchronizer.java
@@ -1,212 +1,212 @@
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.profile.drafter.ui.dialog;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-
-import org.eclipse.papyrus.uml.profile.drafter.ProfileCatalog;
-import org.eclipse.papyrus.uml.profile.drafter.exceptions.NotFoundException;
-import org.eclipse.uml2.uml.Stereotype;
-
-
-/**
- * This class can be used to lookup {@link Stereotype} from stereotype and profile name.
- * The class lookup in the ProfileCatalog
- * <br>
- * When profile or stereotype name are set, the {@link Stereotype} is set accordingly. If no profile
- * can be found, Stereotype is set to null.
- *
- * @author cedric dumoulin
- *
- */
-public class StereotypeNameToProfileSynchronizer {
-
-
- protected String qualifiedName;
- protected String profileName;
- protected String stereotypeName;
-
- protected Stereotype stereotype;
- protected ProfileCatalog profileCatalog;
-
- /**
- * Event manager
- */
- private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
-
-
- /**
- *
- * Constructor.
- *
- * @param profileApplicator
- */
- public StereotypeNameToProfileSynchronizer( ProfileCatalog profileCatalog) {
- this.profileCatalog = profileCatalog;
- }
-
-
- /**
- * @return the qualifiedName
- */
- public String getQualifiedName() {
- return qualifiedName;
- }
-
-
- /**
- * @param qualifiedName the qualifiedName to set
- */
- public void setQualifiedName(String qualifiedName) {
- // Compute profile and stereotype name
- // TODO
- // doSet profile and stereotype name
- // TODO
-
- doSetQualifiedName(qualifiedName);
- }
-
- /**
- * @param profileName the profileName to set
- */
- protected void doSetQualifiedName(String qualifiedName) {
- System.err.println("Qualified name set to '" + qualifiedName + "'");
- firePropertyChange("profileName", this.qualifiedName, this.qualifiedName = qualifiedName);
- }
-
- /**
- * @return the profileName
- */
- public String getProfileName() {
- return profileName;
- }
-
- /**
- * @param profileName the profileName to set
- */
- public void setProfileName(String profileName) {
- doSetProfileName(profileName);
- checkStereotype();
- }
-
- /**
- * @param profileName the profileName to set
- */
- protected void doSetProfileName(String profileName) {
- System.err.println("ProfileName set to '" + profileName + "'");
- firePropertyChange("profileName", this.profileName, this.profileName = profileName);
- }
-
-
- /**
- * @return the stereotypeName
- */
- public String getStereotypeName() {
- return stereotypeName;
- }
-
-
- /**
- * @param stereotypeName the stereotypeName to set
- */
- public void setStereotypeName(String stereotypeName) {
- doSetStereotypeName(stereotypeName);
- checkStereotype();
- }
-
- /**
- * @param stereotypeName the stereotypeName to set
- */
- protected void doSetStereotypeName(String stereotypeName) {
- System.err.println("StereotypeName set to '" + stereotypeName + "'");
- firePropertyChange("stereotypeName", this.stereotypeName, this.stereotypeName = stereotypeName);
- }
-
-
- /**
- * @return the stereotype
- */
- public Stereotype getStereotype() {
- return stereotype;
- }
-
- /**
- * Set the stereotype property.
- * @param stereotype the stereotype to set
- */
- public void setStereotype(Stereotype stereotype) {
- doSetStereotype(stereotype);
- // Sync names
- // Need to take care of fired events and circular set
- doSetProfileName( stereotype.getProfile().getName() );
- doSetStereotypeName( stereotype.getName() );
- }
-
- /**
- * Set the stereotype property.
- * This value can't be set from outside.
- * @param stereotype the stereotype to set
- */
- protected void doSetStereotype(Stereotype stereotype) {
- System.err.println("Stereotype set to '" + (stereotype!=null?stereotype.getQualifiedName():"null") + "'");
- firePropertyChange("stereotype", this.stereotype, this.stereotype = stereotype);
- }
-
- /**
- * Stereotype or profile name have changed. Check if we can find and set a corresponding
- * {@link Stereotype}.
- */
- protected void checkStereotype() {
- if( stereotype!=null
- && stereotypeName == stereotype.getName()
- && profileName == stereotype.getProfile().getName() ) {
- // No change
- return;
- }
-
- try {
- Stereotype stereotype = profileCatalog.lookupStereotype(profileName, stereotypeName);
- doSetStereotype(stereotype);
- } catch (NotFoundException e) {
- // exit
- doSetStereotype(null);
- return;
- }
-
- }
-
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- changeSupport.addPropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- changeSupport.removePropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- changeSupport.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- changeSupport.removePropertyChangeListener(propertyName, listener);
- }
-
- protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
- changeSupport.firePropertyChange(propertyName, oldValue, newValue);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.dialog;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+import org.eclipse.papyrus.uml.profile.drafter.ProfileCatalog;
+import org.eclipse.papyrus.uml.profile.drafter.exceptions.NotFoundException;
+import org.eclipse.uml2.uml.Stereotype;
+
+
+/**
+ * This class can be used to lookup {@link Stereotype} from stereotype and profile name.
+ * The class lookup in the ProfileCatalog
+ * <br>
+ * When profile or stereotype name are set, the {@link Stereotype} is set accordingly. If no profile
+ * can be found, Stereotype is set to null.
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class StereotypeNameToProfileSynchronizer {
+
+
+ protected String qualifiedName;
+ protected String profileName;
+ protected String stereotypeName;
+
+ protected Stereotype stereotype;
+ protected ProfileCatalog profileCatalog;
+
+ /**
+ * Event manager
+ */
+ private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param profileApplicator
+ */
+ public StereotypeNameToProfileSynchronizer( ProfileCatalog profileCatalog) {
+ this.profileCatalog = profileCatalog;
+ }
+
+
+ /**
+ * @return the qualifiedName
+ */
+ public String getQualifiedName() {
+ return qualifiedName;
+ }
+
+
+ /**
+ * @param qualifiedName the qualifiedName to set
+ */
+ public void setQualifiedName(String qualifiedName) {
+ // Compute profile and stereotype name
+ // TODO
+ // doSet profile and stereotype name
+ // TODO
+
+ doSetQualifiedName(qualifiedName);
+ }
+
+ /**
+ * @param profileName the profileName to set
+ */
+ protected void doSetQualifiedName(String qualifiedName) {
+// System.err.println("Qualified name set to '" + qualifiedName + "'");
+ firePropertyChange("profileName", this.qualifiedName, this.qualifiedName = qualifiedName);
+ }
+
+ /**
+ * @return the profileName
+ */
+ public String getProfileName() {
+ return profileName;
+ }
+
+ /**
+ * @param profileName the profileName to set
+ */
+ public void setProfileName(String profileName) {
+ doSetProfileName(profileName);
+ checkStereotype();
+ }
+
+ /**
+ * @param profileName the profileName to set
+ */
+ protected void doSetProfileName(String profileName) {
+// System.err.println("ProfileName set to '" + profileName + "'");
+ firePropertyChange("profileName", this.profileName, this.profileName = profileName);
+ }
+
+
+ /**
+ * @return the stereotypeName
+ */
+ public String getStereotypeName() {
+ return stereotypeName;
+ }
+
+
+ /**
+ * @param stereotypeName the stereotypeName to set
+ */
+ public void setStereotypeName(String stereotypeName) {
+ doSetStereotypeName(stereotypeName);
+ checkStereotype();
+ }
+
+ /**
+ * @param stereotypeName the stereotypeName to set
+ */
+ protected void doSetStereotypeName(String stereotypeName) {
+// System.err.println("StereotypeName set to '" + stereotypeName + "'");
+ firePropertyChange("stereotypeName", this.stereotypeName, this.stereotypeName = stereotypeName);
+ }
+
+
+ /**
+ * @return the stereotype
+ */
+ public Stereotype getStereotype() {
+ return stereotype;
+ }
+
+ /**
+ * Set the stereotype property.
+ * @param stereotype the stereotype to set
+ */
+ public void setStereotype(Stereotype stereotype) {
+ doSetStereotype(stereotype);
+ // Sync names
+ // Need to take care of fired events and circular set
+ doSetProfileName( stereotype.getProfile().getName() );
+ doSetStereotypeName( stereotype.getName() );
+ }
+
+ /**
+ * Set the stereotype property.
+ * This value can't be set from outside.
+ * @param stereotype the stereotype to set
+ */
+ protected void doSetStereotype(Stereotype stereotype) {
+// System.err.println("Stereotype set to '" + (stereotype!=null?stereotype.getQualifiedName():"null") + "'");
+ firePropertyChange("stereotype", this.stereotype, this.stereotype = stereotype);
+ }
+
+ /**
+ * Stereotype or profile name have changed. Check if we can find and set a corresponding
+ * {@link Stereotype}.
+ */
+ protected void checkStereotype() {
+ if( stereotype!=null
+ && stereotypeName == stereotype.getName()
+ && profileName == stereotype.getProfile().getName() ) {
+ // No change
+ return;
+ }
+
+ try {
+ Stereotype stereotype = profileCatalog.lookupStereotype(profileName, stereotypeName);
+ doSetStereotype(stereotype);
+ } catch (NotFoundException e) {
+ // exit
+ doSetStereotype(null);
+ return;
+ }
+
+ }
+
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ changeSupport.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ changeSupport.removePropertyChangeListener(propertyName, listener);
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ changeSupport.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TaggedValuesEditorWidget.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TaggedValuesEditorWidget.java
index f420ff7e6cb..45d2db0b338 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TaggedValuesEditorWidget.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/dialog/TaggedValuesEditorWidget.java
@@ -1,244 +1,244 @@
-package org.eclipse.papyrus.uml.profile.drafter.ui.dialog;
-
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.TreeViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-
-public class TaggedValuesEditorWidget {
-
- private Composite contentArea;
- private Stereotype stereotype;
- private NamedElement selectedElement;
-
- private TreeViewer treeViewer;
-
- /**
- * Create the composite.
- * @param parent
- * @param stereotype The stereotype defining the taggedValues
- * @param selectedElement The uml {@link NamedElement} for which taggedValue are edited
- *
- * @wbp.parser.entryPoint
- */
- public TaggedValuesEditorWidget(Composite parent, Stereotype stereotype, NamedElement selectedElement) {
-
- this.stereotype = stereotype;
- this.selectedElement = selectedElement;
- createContent(parent);
- }
-
-
-
- /**
- * @return the stereotype
- */
- public Stereotype getStereotype() {
- return stereotype;
- }
-
-
-
- /**
- * @param stereotype the stereotype to set
- */
- public void setStereotype(Stereotype stereotype) {
- System.err.println(this.getClass().getSimpleName()
- + ".setStereotype(" + (stereotype!=null?stereotype.getName():"null") + ")");
- this.stereotype = stereotype;
- treeViewer.setInput(stereotype);
- }
-
-
- /**
- * Create the overall component.
- * @param parent
- */
- protected void createContent(Composite parent) {
- // TODO Auto-generated method stub
-
-
-
- contentArea = createContentArea(parent);
-
- treeViewer.setContentProvider(new MyContentProvider());
- // We provide the Stereotype's attributes
- treeViewer.setInput(stereotype);
-
-
-// fillContentArea();
-// createDialogContents();
-
- }
-
- /**
- * Create the content area.
- *
- * @param parent
- * @return
- */
- protected Composite createContentArea(Composite parent) {
- // create a composite with standard margins and spacing
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.makeColumnsEqualWidth = true;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- treeViewer = new TreeViewer(composite, SWT.BORDER);
- Tree tree = treeViewer.getTree();
- tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
-
- TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
- TreeColumn trclmnName = treeViewerColumn.getColumn();
- trclmnName.setWidth(100);
- trclmnName.setText("name");
- treeViewerColumn.setLabelProvider( new TaggedValueNameColumnLabelProvider() );
-
-
- TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(treeViewer, SWT.NONE);
- TreeColumn trclmnType = treeViewerColumn_1.getColumn();
- trclmnType.setWidth(100);
- trclmnType.setText("type");
- treeViewerColumn_1.setLabelProvider( new TaggedValueNameColumnLabelProvider() );
-
- TreeViewerColumn treeViewerColumn_2 = new TreeViewerColumn(treeViewer, SWT.NONE);
- TreeColumn trclmnValue = treeViewerColumn_2.getColumn();
- trclmnValue.setWidth(100);
- trclmnValue.setText("value");
- treeViewerColumn_2.setLabelProvider( new TaggedValueValueColumnLabelProvider() );
-
- return composite;
-
- }
-
- private void createDialogContents() {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Fill the content area with values found in stereotype.
- */
- private void fillContentArea() {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Get the name of the taggedValue
- * @author dumoulin
- *
- */
- public class TaggedValueNameColumnLabelProvider extends ColumnLabelProvider {
-
- @Override
- public String getText(Object element) {
-
- Property property = (Property)element;
- return property.getName();
- }
- }
-
- /**
- * Get the value of the taggedValue
- *
- */
- public class TaggedValueValueColumnLabelProvider extends ColumnLabelProvider {
-
- @Override
- public String getText(Object element) {
-
- Property property = (Property)element;
- Object value = selectedElement.getValue((Stereotype)property.getOwner(), property.getName());
-
- if(value instanceof NamedElement) {
- return ((NamedElement)value).getName();
- }
- // TODO
- // collections and arrays
- // dynamic objects
- return value.toString();
- }
- }
-
- /**
- * Content Provider for TaggedValues hierarchy
- *
- */
- private class MyContentProvider implements ITreeContentProvider {
-
- private Object[] EMPTY_ARRAY = new Object[]{};
-
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
- *
- * @param inputElement
- * @return
- */
- @Override
- public Object[] getElements(Object inputElement) {
-
-
- Stereotype stereotype = (Stereotype)inputElement;
- // Return the stereotype's Properties
- return stereotype.getAllAttributes().toArray();
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- *
- * @param parentElement
- * @return
- */
- @Override
- public Object[] getChildren(Object parentElement) {
- return EMPTY_ARRAY;
- }
-
-
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Object getParent(Object element) {
- Property property = (Property)element;
- return property.getOwner();
- }
-
- @Override
- public boolean hasChildren(Object element) {
- return false;
- }
-
- }
-
-}
+package org.eclipse.papyrus.uml.profile.drafter.ui.dialog;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+public class TaggedValuesEditorWidget {
+
+ private Composite contentArea;
+ private Stereotype stereotype;
+ private NamedElement selectedElement;
+
+ private TreeViewer treeViewer;
+
+ /**
+ * Create the composite.
+ * @param parent
+ * @param stereotype The stereotype defining the taggedValues
+ * @param selectedElement The uml {@link NamedElement} for which taggedValue are edited
+ *
+ * @wbp.parser.entryPoint
+ */
+ public TaggedValuesEditorWidget(Composite parent, Stereotype stereotype, NamedElement selectedElement) {
+
+ this.stereotype = stereotype;
+ this.selectedElement = selectedElement;
+ createContent(parent);
+ }
+
+
+
+ /**
+ * @return the stereotype
+ */
+ public Stereotype getStereotype() {
+ return stereotype;
+ }
+
+
+
+ /**
+ * @param stereotype the stereotype to set
+ */
+ public void setStereotype(Stereotype stereotype) {
+// System.err.println(this.getClass().getSimpleName()
+// + ".setStereotype(" + (stereotype!=null?stereotype.getName():"null") + ")");
+ this.stereotype = stereotype;
+ treeViewer.setInput(stereotype);
+ }
+
+
+ /**
+ * Create the overall component.
+ * @param parent
+ */
+ protected void createContent(Composite parent) {
+ // TODO Auto-generated method stub
+
+
+
+ contentArea = createContentArea(parent);
+
+ treeViewer.setContentProvider(new MyContentProvider());
+ // We provide the Stereotype's attributes
+ treeViewer.setInput(stereotype);
+
+
+// fillContentArea();
+// createDialogContents();
+
+ }
+
+ /**
+ * Create the content area.
+ *
+ * @param parent
+ * @return
+ */
+ protected Composite createContentArea(Composite parent) {
+ // create a composite with standard margins and spacing
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.makeColumnsEqualWidth = true;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ treeViewer = new TreeViewer(composite, SWT.BORDER);
+ Tree tree = treeViewer.getTree();
+ tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+
+ TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
+ TreeColumn trclmnName = treeViewerColumn.getColumn();
+ trclmnName.setWidth(100);
+ trclmnName.setText("name");
+ treeViewerColumn.setLabelProvider( new TaggedValueNameColumnLabelProvider() );
+
+
+ TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(treeViewer, SWT.NONE);
+ TreeColumn trclmnType = treeViewerColumn_1.getColumn();
+ trclmnType.setWidth(100);
+ trclmnType.setText("type");
+ treeViewerColumn_1.setLabelProvider( new TaggedValueNameColumnLabelProvider() );
+
+ TreeViewerColumn treeViewerColumn_2 = new TreeViewerColumn(treeViewer, SWT.NONE);
+ TreeColumn trclmnValue = treeViewerColumn_2.getColumn();
+ trclmnValue.setWidth(100);
+ trclmnValue.setText("value");
+ treeViewerColumn_2.setLabelProvider( new TaggedValueValueColumnLabelProvider() );
+
+ return composite;
+
+ }
+
+ private void createDialogContents() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Fill the content area with values found in stereotype.
+ */
+ private void fillContentArea() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * Get the name of the taggedValue
+ * @author dumoulin
+ *
+ */
+ public class TaggedValueNameColumnLabelProvider extends ColumnLabelProvider {
+
+ @Override
+ public String getText(Object element) {
+
+ Property property = (Property)element;
+ return property.getName();
+ }
+ }
+
+ /**
+ * Get the value of the taggedValue
+ *
+ */
+ public class TaggedValueValueColumnLabelProvider extends ColumnLabelProvider {
+
+ @Override
+ public String getText(Object element) {
+
+ Property property = (Property)element;
+ Object value = selectedElement.getValue((Stereotype)property.getOwner(), property.getName());
+
+ if(value instanceof NamedElement) {
+ return ((NamedElement)value).getName();
+ }
+ // TODO
+ // collections and arrays
+ // dynamic objects
+ return value.toString();
+ }
+ }
+
+ /**
+ * Content Provider for TaggedValues hierarchy
+ *
+ */
+ private class MyContentProvider implements ITreeContentProvider {
+
+ private Object[] EMPTY_ARRAY = new Object[]{};
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
+ *
+ * @param inputElement
+ * @return
+ */
+ @Override
+ public Object[] getElements(Object inputElement) {
+
+
+ Stereotype stereotype = (Stereotype)inputElement;
+ // Return the stereotype's Properties
+ return stereotype.getAllAttributes().toArray();
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ *
+ * @param parentElement
+ * @return
+ */
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ return EMPTY_ARRAY;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Object getParent(Object element) {
+ Property property = (Property)element;
+ return property.getOwner();
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ }
+
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AbstractBaseHandler.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AbstractBaseHandler.java
index eac15d22253..b478cf22fec 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AbstractBaseHandler.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AbstractBaseHandler.java
@@ -307,7 +307,6 @@ public abstract class AbstractBaseHandler extends AbstractHandler {
if( ! (evaluationContext instanceof IEvaluationContext)) {
setBaseEnabled(false);
- System.out.println(getCommandName() + ".setEnabled(" + isEnabled() + ") - no context");
return;
}
@@ -317,8 +316,6 @@ public abstract class AbstractBaseHandler extends AbstractHandler {
// Ask the subclass
setBaseEnabled(isEnabled(context, selections));
-
- System.out.println(getCommandName() + ".setEnabled(" + isEnabled() + ")");
}
/**
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AddProfileHandler.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AddProfileHandler.java
index c90443faf71..86d57179771 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AddProfileHandler.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/AddProfileHandler.java
@@ -1,232 +1,234 @@
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.profile.drafter.ui.handler;
-
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.uml.profile.drafter.ProfileApplicator;
-import org.eclipse.papyrus.uml.profile.drafter.exceptions.DraftProfileException;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.uml2.uml.AggregationKind;
-import org.eclipse.uml2.uml.Extension;
-import org.eclipse.uml2.uml.ExtensionEnd;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLFactory;
-
-
-/**
- * @author cedric dumoulin
- *
- */
-public class AddProfileHandler extends AbstractProfileBaseHandler {
-
- private List<NamedElement> cachedSelectionAsNamedElement;
-
- private String stereotypeNameInput;
- private String profileNameInput;
-
- private String taggedValeNameInput;
-
- /**
- * Constructor.
- *
- */
- public AddProfileHandler() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#getCommandName()
- *
- * @return
- */
- @Override
- public String getCommandName() {
- return "Add Profile";
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#preExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext)
- *
- * @param event
- * @param context
- * @return
- * @throws ExecutionException
- */
- @Override
- protected boolean preExecute(ExecutionEvent event, IEvaluationContext context) throws ExecutionException {
-
- // Open the dialog to ask the new name
- // TODO dialog should not be in the transaction !! put it outside !
- String inputName = null;
- InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Attach a Stereotype to Selected Element", "Enter the stereotype name.", inputName, null);
- if(dialog.open() == Window.OK) {
- inputName = dialog.getValue();
- if(inputName == null || inputName.length() <= 0) {
- return false;
- }
- } else {
- // cancelled
- return false;
- }
-
- taggedValeNameInput = "";
- String args[] = inputName.split(":");
- switch (args.length) {
- case 0:
- System.err.println("No names found in '" + inputName + "'" );
- return false;
- case 1:
- // Stereotype
- stereotypeNameInput = args[0];
- profileNameInput = "testProfile";
- break;
- case 2:
- // profile + Stereotype
- stereotypeNameInput = args[1].trim();
- profileNameInput = args[0].trim();
- break;
- case 3:
- // profile + Stereotype + tagged value
- stereotypeNameInput = args[1].trim();
- profileNameInput = args[0].trim();
- taggedValeNameInput = args[2].trim();
- break;
-
- default:
- break;
- }
-
- System.err.println("Try to apply stereotype '" + profileNameInput + ":" +stereotypeNameInput + "'");
- return true;
- }
-
- /**
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#doExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext, java.util.List)
- *
- * @param event
- * @param context
- * @param selections
- */
- @Override
- protected void doExecute(ExecutionEvent event, IEvaluationContext context) {
-
- System.err.println("Add Profile called. Selected elements:");
- List<NamedElement> selected = getSelectionAsNamedElements(context);
- for( NamedElement ele : selected) {
- System.err.println(ele.getName());
- }
- System.err.println("********************");
-
- if( selected.isEmpty()) {
- return;
- }
-
- // Try to apply the stereotype
- ProfileApplicator profileApplicator = new ProfileApplicator(selected.get(0));
- try {
- profileApplicator.applyStereotype2(profileNameInput, stereotypeNameInput);
- } catch (DraftProfileException e) {
- e.printStackTrace();
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#resetCachedValues()
- *
- */
- @Override
- protected void resetCachedValues() {
- super.resetCachedValues();
- cachedSelectionAsNamedElement = null;
- stereotypeNameInput = null;
- profileNameInput = null;
- taggedValeNameInput = null;
- }
-
- /**
- * Get the list of selected element of type 'NamedElement'.
- *
- * @param context
- * @return
- */
- protected List<NamedElement> getSelectionAsNamedElements(IEvaluationContext context) {
-
- if( cachedSelectionAsNamedElement == null) {
-
- cachedSelectionAsNamedElement = getSelectionsByType(context, NamedElement.class);
- }
-
- return cachedSelectionAsNamedElement;
- }
-
- protected Extension createExtension( Stereotype source, Type target) {
- //create the extension
- Extension newExtension = UMLFactory.eINSTANCE.createExtension();
-
- //create the endSource
- ExtensionEnd endSource = UMLFactory.eINSTANCE.createExtensionEnd();
-
- //initialize the endSource
- endSource.setName("extension_" + source.getName()); //$NON-NLS-1$ //$NON-NLS-2$
- endSource.setType(source);
- endSource.setAggregation(AggregationKind.COMPOSITE_LITERAL);
-
- //add the endSource to the extension
- newExtension.getOwnedEnds().add(endSource); // add extension end to extension
-
-
- //create source_property
- Property property = UMLFactory.eINSTANCE.createProperty();
- property.setName("base_" + target.getName());
- // property.setIsDerived(true);
- property.setType(target); // set the type
- property.setAssociation(newExtension); // Set the association link
- property.setAggregation(AggregationKind.NONE_LITERAL);
-
- newExtension.getMemberEnds().add(property);
-
- source.getOwnedAttributes().add(property);
-
- return newExtension;
- }
- /**
- *
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#isEnabled(org.eclipse.core.expressions.IEvaluationContext, java.util.List)
- *
- * @param context
- * @param selections
- * @return
- */
- @Override
- public boolean isEnabled(IEvaluationContext context, List<Object> selections) {
-
- if( ! selections.isEmpty() ) {
- return true;
- }
-
- return false;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.handler;
+
+import static org.eclipse.papyrus.uml.profile.drafter.Activator.log;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.uml.profile.drafter.ProfileApplicator;
+import org.eclipse.papyrus.uml.profile.drafter.exceptions.DraftProfileException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Extension;
+import org.eclipse.uml2.uml.ExtensionEnd;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class AddProfileHandler extends AbstractProfileBaseHandler {
+
+ private List<NamedElement> cachedSelectionAsNamedElement;
+
+ private String stereotypeNameInput;
+ private String profileNameInput;
+
+ private String taggedValeNameInput;
+
+ /**
+ * Constructor.
+ *
+ */
+ public AddProfileHandler() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#getCommandName()
+ *
+ * @return
+ */
+ @Override
+ public String getCommandName() {
+ return "Add Profile";
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#preExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext)
+ *
+ * @param event
+ * @param context
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected boolean preExecute(ExecutionEvent event, IEvaluationContext context) throws ExecutionException {
+
+ // Open the dialog to ask the new name
+ // TODO dialog should not be in the transaction !! put it outside !
+ String inputName = null;
+ InputDialog dialog = new InputDialog(Display.getCurrent().getActiveShell(), "Attach a Stereotype to Selected Element", "Enter the stereotype name.", inputName, null);
+ if(dialog.open() == Window.OK) {
+ inputName = dialog.getValue();
+ if(inputName == null || inputName.length() <= 0) {
+ return false;
+ }
+ } else {
+ // cancelled
+ return false;
+ }
+
+ taggedValeNameInput = "";
+ String args[] = inputName.split(":");
+ switch (args.length) {
+ case 0:
+ log.warn("No names found in '" + inputName + "'" );
+ return false;
+ case 1:
+ // Stereotype
+ stereotypeNameInput = args[0];
+ profileNameInput = "testProfile";
+ break;
+ case 2:
+ // profile + Stereotype
+ stereotypeNameInput = args[1].trim();
+ profileNameInput = args[0].trim();
+ break;
+ case 3:
+ // profile + Stereotype + tagged value
+ stereotypeNameInput = args[1].trim();
+ profileNameInput = args[0].trim();
+ taggedValeNameInput = args[2].trim();
+ break;
+
+ default:
+ break;
+ }
+
+// System.err.println("Try to apply stereotype '" + profileNameInput + ":" +stereotypeNameInput + "'");
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#doExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext, java.util.List)
+ *
+ * @param event
+ * @param context
+ * @param selections
+ */
+ @Override
+ protected void doExecute(ExecutionEvent event, IEvaluationContext context) {
+
+ List<NamedElement> selected = getSelectionAsNamedElements(context);
+
+// System.err.println("Add Profile called. Selected elements:");
+// for( NamedElement ele : selected) {
+// System.err.println(ele.getName());
+// }
+// System.err.println("********************");
+
+ if( selected.isEmpty()) {
+ return;
+ }
+
+ // Try to apply the stereotype
+ ProfileApplicator profileApplicator = new ProfileApplicator(selected.get(0));
+ try {
+ profileApplicator.applyStereotype2(profileNameInput, stereotypeNameInput);
+ } catch (DraftProfileException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#resetCachedValues()
+ *
+ */
+ @Override
+ protected void resetCachedValues() {
+ super.resetCachedValues();
+ cachedSelectionAsNamedElement = null;
+ stereotypeNameInput = null;
+ profileNameInput = null;
+ taggedValeNameInput = null;
+ }
+
+ /**
+ * Get the list of selected element of type 'NamedElement'.
+ *
+ * @param context
+ * @return
+ */
+ protected List<NamedElement> getSelectionAsNamedElements(IEvaluationContext context) {
+
+ if( cachedSelectionAsNamedElement == null) {
+
+ cachedSelectionAsNamedElement = getSelectionsByType(context, NamedElement.class);
+ }
+
+ return cachedSelectionAsNamedElement;
+ }
+
+ protected Extension createExtension( Stereotype source, Type target) {
+ //create the extension
+ Extension newExtension = UMLFactory.eINSTANCE.createExtension();
+
+ //create the endSource
+ ExtensionEnd endSource = UMLFactory.eINSTANCE.createExtensionEnd();
+
+ //initialize the endSource
+ endSource.setName("extension_" + source.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ endSource.setType(source);
+ endSource.setAggregation(AggregationKind.COMPOSITE_LITERAL);
+
+ //add the endSource to the extension
+ newExtension.getOwnedEnds().add(endSource); // add extension end to extension
+
+
+ //create source_property
+ Property property = UMLFactory.eINSTANCE.createProperty();
+ property.setName("base_" + target.getName());
+ // property.setIsDerived(true);
+ property.setType(target); // set the type
+ property.setAssociation(newExtension); // Set the association link
+ property.setAggregation(AggregationKind.NONE_LITERAL);
+
+ newExtension.getMemberEnds().add(property);
+
+ source.getOwnedAttributes().add(property);
+
+ return newExtension;
+ }
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#isEnabled(org.eclipse.core.expressions.IEvaluationContext, java.util.List)
+ *
+ * @param context
+ * @param selections
+ * @return
+ */
+ @Override
+ public boolean isEnabled(IEvaluationContext context, List<Object> selections) {
+
+ if( ! selections.isEmpty() ) {
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/CreateProfileHandler.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/CreateProfileHandler.java
index 05d8e558725..d1707d65bcf 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/CreateProfileHandler.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/CreateProfileHandler.java
@@ -1,215 +1,216 @@
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.profile.drafter.ui.handler;
-
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.papyrus.infra.core.resource.NotFoundException;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.uml.profile.utils.Util;
-import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.papyrus.uml.tools.model.UmlUtils;
-import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
-import org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition;
-import org.eclipse.papyrus.uml.tools.profile.definition.Version;
-import org.eclipse.uml2.uml.AggregationKind;
-import org.eclipse.uml2.uml.ElementImport;
-import org.eclipse.uml2.uml.Extension;
-import org.eclipse.uml2.uml.ExtensionEnd;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLFactory;
-
-
-/**
- * @author cedric dumoulin
- *
- */
-public class CreateProfileHandler extends AbstractBaseHandler {
-
- /**
- * Constructor.
- *
- */
- public CreateProfileHandler() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#getCommandName()
- *
- * @return
- */
- @Override
- public String getCommandName() {
- // TODO Auto-generated method stub
- return "Create new Profile";
- }
-
- /**
- * Compute the selection.
- * @param event
- * @param context
- * @return
- * @throws ExecutionException
- */
- @Override
- protected boolean preExecute(ExecutionEvent event, IEvaluationContext context) throws ExecutionException {
- // Get the selection here in order to not do it in the transaction.
- getCachedSelections(context);
-
- return super.preExecute(event, context);
- }
- /**
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#doExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext, java.util.List)
- *
- * @param event
- * @param context
- * @param selections
- */
- @Override
- protected void doExecute(ExecutionEvent event, IEvaluationContext context) {
-
- String stereotypeName ="MyNewStereotype";
- List<Object> selections = getCachedSelections(context);
-
- if( !(selections.get(0) instanceof Profile ) ) {
- return;
- }
- try {
- System.err.println("Create new profile called ...");
-
- Profile profile = (Profile)selections.get(0);
-
-
-
- // Create a new stereotype
- Stereotype stereotype = UMLFactory.eINSTANCE.createStereotype();
- stereotype.setName(stereotypeName);
- profile.getPackagedElements().add(stereotype);
- // TODO : set application
- ElementImport target = lookupMetaclass(profile, "Class");
- Extension extension = createExtension(stereotype, (Type)target.getImportedElement());
- extension.setName("E_" + stereotype.getName());
- profile.getPackagedElements().add(extension);
-
- // Define the profile
- profile.define();
-
- // Define the profile annotation (from Papyrus)
- // == adapt to Papyrus
- Version curVersion = Util.getProfileDefinitionVersion(profile);
- Version version = new Version(curVersion.getMajor(), curVersion.getMinor(), curVersion.getMicro()+4);
- PapyrusDefinitionAnnotation papyrusAnnotation = new PapyrusDefinitionAnnotation(version, "", "", "", "");
- // define the profile
- ProfileRedefinition.redefineProfile(profile, papyrusAnnotation);
- ProfileRedefinition.cleanProfile(profile);
-
-
- // Reapply to main package
- ServicesRegistry servicesRegistry = lookupServicesRegistry(context);
-
-// ModelSet modelSet = ServiceUtilsForIEvaluationContext.getInstance().getModelSet(context);
- UmlModel umlModel = UmlUtils.getUmlModelChecked(servicesRegistry);
- Package rootPackage = (Package)umlModel.lookupRoot();
-
- rootPackage.applyProfile(profile);
-
- System.err.println(" ... New profile created");
- } catch (NotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.err.println(" ... Profile creation failed !!");
- } catch (ServiceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.err.println(" ... Profile creation failed !!");
- }
-
-
- }
-
- /**
- * Lookup the metaclass of type "Class"
- *
- * @param profile
- * @return
- */
- private ElementImport lookupMetaclass(Profile profile, String aliasName) {
- //
- for( ElementImport ele : profile.getElementImports() ) {
- if(aliasName.equals(ele.getAlias() ) ) {
- return ele;
- }
- }
- // Not found;
- return null;
- }
-
- protected Extension createExtension( Stereotype source, Type target) {
- //create the extension
- Extension newExtension = UMLFactory.eINSTANCE.createExtension();
-
- //create the endSource
- ExtensionEnd endSource = UMLFactory.eINSTANCE.createExtensionEnd();
-
- //initialize the endSource
- endSource.setName("extension_" + source.getName()); //$NON-NLS-1$ //$NON-NLS-2$
- endSource.setType(source);
- endSource.setAggregation(AggregationKind.COMPOSITE_LITERAL);
-
- //add the endSource to the extension
- newExtension.getOwnedEnds().add(endSource); // add extension end to extension
-
-
- //create source_property
- Property property = UMLFactory.eINSTANCE.createProperty();
- property.setName("base_" + target.getName());
- // property.setIsDerived(true);
- property.setType(target); // set the type
- property.setAssociation(newExtension); // Set the association link
- property.setAggregation(AggregationKind.NONE_LITERAL);
-
- newExtension.getMemberEnds().add(property);
-
- source.getOwnedAttributes().add(property);
-
- return newExtension;
- }
- /**
- *
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#isEnabled(org.eclipse.core.expressions.IEvaluationContext, java.util.List)
- *
- * @param context
- * @param selections
- * @return
- */
- @Override
- public boolean isEnabled(IEvaluationContext context, List<Object> selections) {
-
- if( ! selections.isEmpty() && selections.get(0) instanceof Profile ) {
- return true;
- }
-
- return false;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.handler;
+
+import static org.eclipse.papyrus.uml.profile.drafter.Activator.log;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.uml.profile.utils.Util;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.model.UmlUtils;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition;
+import org.eclipse.papyrus.uml.tools.profile.definition.Version;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.ElementImport;
+import org.eclipse.uml2.uml.Extension;
+import org.eclipse.uml2.uml.ExtensionEnd;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class CreateProfileHandler extends AbstractBaseHandler {
+
+ /**
+ * Constructor.
+ *
+ */
+ public CreateProfileHandler() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#getCommandName()
+ *
+ * @return
+ */
+ @Override
+ public String getCommandName() {
+ // TODO Auto-generated method stub
+ return "Create new Profile";
+ }
+
+ /**
+ * Compute the selection.
+ * @param event
+ * @param context
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected boolean preExecute(ExecutionEvent event, IEvaluationContext context) throws ExecutionException {
+ // Get the selection here in order to not do it in the transaction.
+ getCachedSelections(context);
+
+ return super.preExecute(event, context);
+ }
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#doExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext, java.util.List)
+ *
+ * @param event
+ * @param context
+ * @param selections
+ */
+ @Override
+ protected void doExecute(ExecutionEvent event, IEvaluationContext context) {
+
+ String stereotypeName ="MyNewStereotype";
+ List<Object> selections = getCachedSelections(context);
+
+ if( !(selections.get(0) instanceof Profile ) ) {
+ return;
+ }
+ try {
+ log.info("Create new profile called ...");
+
+ Profile profile = (Profile)selections.get(0);
+
+
+
+ // Create a new stereotype
+ Stereotype stereotype = UMLFactory.eINSTANCE.createStereotype();
+ stereotype.setName(stereotypeName);
+ profile.getPackagedElements().add(stereotype);
+ // TODO : set application
+ ElementImport target = lookupMetaclass(profile, "Class");
+ Extension extension = createExtension(stereotype, (Type)target.getImportedElement());
+ extension.setName("E_" + stereotype.getName());
+ profile.getPackagedElements().add(extension);
+
+ // Define the profile
+ profile.define();
+
+ // Define the profile annotation (from Papyrus)
+ // == adapt to Papyrus
+ Version curVersion = Util.getProfileDefinitionVersion(profile);
+ Version version = new Version(curVersion.getMajor(), curVersion.getMinor(), curVersion.getMicro()+4);
+ PapyrusDefinitionAnnotation papyrusAnnotation = new PapyrusDefinitionAnnotation(version, "", "", "", "");
+ // define the profile
+ ProfileRedefinition.redefineProfile(profile, papyrusAnnotation);
+ ProfileRedefinition.cleanProfile(profile);
+
+
+ // Reapply to main package
+ ServicesRegistry servicesRegistry = lookupServicesRegistry(context);
+
+// ModelSet modelSet = ServiceUtilsForIEvaluationContext.getInstance().getModelSet(context);
+ UmlModel umlModel = UmlUtils.getUmlModelChecked(servicesRegistry);
+ Package rootPackage = (Package)umlModel.lookupRoot();
+
+ rootPackage.applyProfile(profile);
+
+ log.info(" ... New profile created");
+ } catch (NotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ log.error(" ... Profile creation failed !!", e);
+ } catch (ServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ log.error(" ... Profile creation failed !!", e);
+ }
+
+
+ }
+
+ /**
+ * Lookup the metaclass of type "Class"
+ *
+ * @param profile
+ * @return
+ */
+ private ElementImport lookupMetaclass(Profile profile, String aliasName) {
+ //
+ for( ElementImport ele : profile.getElementImports() ) {
+ if(aliasName.equals(ele.getAlias() ) ) {
+ return ele;
+ }
+ }
+ // Not found;
+ return null;
+ }
+
+ protected Extension createExtension( Stereotype source, Type target) {
+ //create the extension
+ Extension newExtension = UMLFactory.eINSTANCE.createExtension();
+
+ //create the endSource
+ ExtensionEnd endSource = UMLFactory.eINSTANCE.createExtensionEnd();
+
+ //initialize the endSource
+ endSource.setName("extension_" + source.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ endSource.setType(source);
+ endSource.setAggregation(AggregationKind.COMPOSITE_LITERAL);
+
+ //add the endSource to the extension
+ newExtension.getOwnedEnds().add(endSource); // add extension end to extension
+
+
+ //create source_property
+ Property property = UMLFactory.eINSTANCE.createProperty();
+ property.setName("base_" + target.getName());
+ // property.setIsDerived(true);
+ property.setType(target); // set the type
+ property.setAssociation(newExtension); // Set the association link
+ property.setAggregation(AggregationKind.NONE_LITERAL);
+
+ newExtension.getMemberEnds().add(property);
+
+ source.getOwnedAttributes().add(property);
+
+ return newExtension;
+ }
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#isEnabled(org.eclipse.core.expressions.IEvaluationContext, java.util.List)
+ *
+ * @param context
+ * @param selections
+ * @return
+ */
+ @Override
+ public boolean isEnabled(IEvaluationContext context, List<Object> selections) {
+
+ if( ! selections.isEmpty() && selections.get(0) instanceof Profile ) {
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/UpdateProfileHandler.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/UpdateProfileHandler.java
index 08e9b7a8f20..73b605d6912 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/UpdateProfileHandler.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/handler/UpdateProfileHandler.java
@@ -1,287 +1,286 @@
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.profile.drafter.ui.handler;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.uml.profile.drafter.Activator;
-import org.eclipse.papyrus.uml.profile.drafter.ProfileApplicator;
-import org.eclipse.papyrus.uml.profile.drafter.exceptions.DraftProfileException;
-import org.eclipse.papyrus.uml.profile.drafter.ui.dialog.IStereotypeUpdateArgs;
-import org.eclipse.papyrus.uml.profile.drafter.ui.dialog.StereotypeUpdateDialog;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.CommandBuilderVisitor;
-import org.eclipse.papyrus.uml.profile.drafter.ui.model.StereoptypeModel;
-import org.eclipse.papyrus.uml.profile.drafter.utils.UMLMetamodelUtils;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.uml2.uml.AggregationKind;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Extension;
-import org.eclipse.uml2.uml.ExtensionEnd;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLFactory;
-
-
-/**
- * @author cedric dumoulin
- *
- */
-public class UpdateProfileHandler extends AbstractProfileBaseHandler {
-
- private List<NamedElement> cachedSelectionAsNamedElement;
-
- private String stereotypeNameInput;
- private String profileNameInput;
-
- /**
- * Object used to hold the update values.
- */
- private IStereotypeUpdateArgs updateArgs;
-
- /**
- * Model used to populate the Dialog, and to retrieve values.
- */
- private StereoptypeModel stereoptypeModel;
-
- private String taggedValeNameInput;
-
- /**
- * Constructor.
- *
- */
- public UpdateProfileHandler() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#getCommandName()
- *
- * @return
- */
- @Override
- public String getCommandName() {
- return "Add Profile";
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#preExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext)
- *
- * @param event
- * @param context
- * @return
- * @throws ExecutionException
- */
- @Override
- protected boolean preExecute(ExecutionEvent event, IEvaluationContext context) throws ExecutionException {
-
- // Check if an element is selected.
- System.err.println("Add Profile called. Selected elements:");
- List<NamedElement> selected = getSelectionAsNamedElements(context);
- for( NamedElement ele : selected) {
- System.err.println(ele.getName());
- }
- System.err.println("********************");
-
- if( selected.isEmpty()) {
- // Stop if no NamedElement is selected
- return false;
- }
-
- // Open the dialog to ask the new name
- // TODO dialog should not be in the transaction !! put it outside !
-// String inputName = null;
-
- // PRofileDialog
- StereotypeUpdateDialog newDialog = new StereotypeUpdateDialog(Display.getCurrent().getActiveShell(), "Update Stereotype",
- selected.get(0), new ArrayList<Class>( getSelectedElementMetaclasses(context)) );
- if(newDialog.open() == Window.OK) {
-
- // Lookup commands
- stereoptypeModel = newDialog.getStereotypeModel();
-// CommandBuilderVisitor commandBuilderVisitor = new CommandBuilderVisitor();
-// stereoptypeModel.accept(commandBuilderVisitor);
-// if( ! commandBuilderVisitor.isExecutionRequested() ) {
-// return false;
-// }
-
-
- // old fashion
- updateArgs = newDialog.getUpdateArgs();
- if(updateArgs == null ) {
- return false;
- }
- } else {
- // cancelled
- return false;
- }
-
- stereotypeNameInput = updateArgs.getStereotypeName();
- profileNameInput = updateArgs.getProfileName();
-
- taggedValeNameInput = "";
-
- System.err.println("Try to apply stereotype '" + profileNameInput + ":" +stereotypeNameInput + "'");
- return true;
- }
-
- /**
- * Return the list of metaclasses corresponding to selected element.
- * @return A list of metaclasses, or an empty list if nothing is selected or if an error occurs.
- */
- private Set<Class> getSelectedElementMetaclasses(IEvaluationContext context) {
-
-
- List<NamedElement> selectedElements = getSelectionAsNamedElements(context);
- // If there is nothing to do, skip immediately
- if( selectedElements.isEmpty()) {
- return Collections.emptySet();
- }
-
-
- try {
- Set<Class> result = new HashSet<Class>();
- UMLMetamodelUtils umlMetamodelUtils = getUmlMetamodelUtils(context);
-
- for( NamedElement sel : selectedElements) {
- result.add(umlMetamodelUtils.getElementMetaclass(sel));
- }
- return result;
- } catch (DraftProfileException e) {
- Activator.log.error( e);
- return Collections.emptySet();
- }
- }
-
- /**
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#doExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext, java.util.List)
- *
- * @param event
- * @param context
- * @param selections
- */
- @Override
- protected void doExecute(ExecutionEvent event, IEvaluationContext context) {
-
-// System.err.println("Add Profile called. Selected elements:");
- List<NamedElement> selected = getSelectionAsNamedElements(context);
-// for( NamedElement ele : selected) {
-// System.err.println(ele.getName());
-// }
-// System.err.println("********************");
-//
-// if( selected.isEmpty()) {
-// return;
-// }
-
- // Try to apply the stereotype
- ProfileApplicator profileApplicator = new ProfileApplicator(selected.get(0));
- try {
-// profileApplicator.applyStereotype2(profileNameInput, stereotypeNameInput);
-// profileApplicator.updateStereotype(updateArgs);
- profileApplicator.updateStereotype(stereoptypeModel);
- } catch (DraftProfileException e) {
- e.printStackTrace();
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#resetCachedValues()
- *
- */
- @Override
- protected void resetCachedValues() {
- super.resetCachedValues();
- cachedSelectionAsNamedElement = null;
- stereotypeNameInput = null;
- profileNameInput = null;
- taggedValeNameInput = null;
- }
-
- /**
- * Get the list of selected element of type 'NamedElement'.
- *
- * @param context
- * @return
- */
- protected List<NamedElement> getSelectionAsNamedElements(IEvaluationContext context) {
-
- if( cachedSelectionAsNamedElement == null) {
-
- cachedSelectionAsNamedElement = getSelectionsByType(context, NamedElement.class);
- }
-
- return cachedSelectionAsNamedElement;
- }
-
- protected Extension createExtension( Stereotype source, Type target) {
- //create the extension
- Extension newExtension = UMLFactory.eINSTANCE.createExtension();
-
- //create the endSource
- ExtensionEnd endSource = UMLFactory.eINSTANCE.createExtensionEnd();
-
- //initialize the endSource
- endSource.setName("extension_" + source.getName()); //$NON-NLS-1$ //$NON-NLS-2$
- endSource.setType(source);
- endSource.setAggregation(AggregationKind.COMPOSITE_LITERAL);
-
- //add the endSource to the extension
- newExtension.getOwnedEnds().add(endSource); // add extension end to extension
-
-
- //create source_property
- Property property = UMLFactory.eINSTANCE.createProperty();
- property.setName("base_" + target.getName());
- // property.setIsDerived(true);
- property.setType(target); // set the type
- property.setAssociation(newExtension); // Set the association link
- property.setAggregation(AggregationKind.NONE_LITERAL);
-
- newExtension.getMemberEnds().add(property);
-
- source.getOwnedAttributes().add(property);
-
- return newExtension;
- }
- /**
- *
- * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#isEnabled(org.eclipse.core.expressions.IEvaluationContext, java.util.List)
- *
- * @param context
- * @param selections
- * @return
- */
- @Override
- public boolean isEnabled(IEvaluationContext context, List<Object> selections) {
-
- if( ! selections.isEmpty() ) {
- return true;
- }
-
- return false;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.handler;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.uml.profile.drafter.Activator;
+import org.eclipse.papyrus.uml.profile.drafter.ProfileApplicator;
+import org.eclipse.papyrus.uml.profile.drafter.exceptions.DraftProfileException;
+import org.eclipse.papyrus.uml.profile.drafter.ui.dialog.IStereotypeUpdateArgs;
+import org.eclipse.papyrus.uml.profile.drafter.ui.dialog.StereotypeUpdateDialog;
+import org.eclipse.papyrus.uml.profile.drafter.ui.model.StereoptypeModel;
+import org.eclipse.papyrus.uml.profile.drafter.utils.UMLMetamodelUtils;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Extension;
+import org.eclipse.uml2.uml.ExtensionEnd;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLFactory;
+
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class UpdateProfileHandler extends AbstractProfileBaseHandler {
+
+ private List<NamedElement> cachedSelectionAsNamedElement;
+
+ private String stereotypeNameInput;
+ private String profileNameInput;
+
+ /**
+ * Object used to hold the update values.
+ */
+ private IStereotypeUpdateArgs updateArgs;
+
+ /**
+ * Model used to populate the Dialog, and to retrieve values.
+ */
+ private StereoptypeModel stereoptypeModel;
+
+ private String taggedValeNameInput;
+
+ /**
+ * Constructor.
+ *
+ */
+ public UpdateProfileHandler() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#getCommandName()
+ *
+ * @return
+ */
+ @Override
+ public String getCommandName() {
+ return "Add Profile";
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#preExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext)
+ *
+ * @param event
+ * @param context
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected boolean preExecute(ExecutionEvent event, IEvaluationContext context) throws ExecutionException {
+
+ // Check if an element is selected.
+ List<NamedElement> selected = getSelectionAsNamedElements(context);
+
+// System.err.println("Add Profile called. Selected elements:");
+// for( NamedElement ele : selected) {
+// System.err.println(ele.getName());
+// }
+// System.err.println("********************");
+
+ if( selected.isEmpty()) {
+ // Stop if no NamedElement is selected
+ return false;
+ }
+
+ // Open the dialog to ask the new name
+ // TODO dialog should not be in the transaction !! put it outside !
+// String inputName = null;
+
+ // PRofileDialog
+ StereotypeUpdateDialog newDialog = new StereotypeUpdateDialog(Display.getCurrent().getActiveShell(), "Update Stereotype",
+ selected.get(0), new ArrayList<Class>( getSelectedElementMetaclasses(context)) );
+ if(newDialog.open() == Window.OK) {
+
+ // Lookup commands
+ stereoptypeModel = newDialog.getStereotypeModel();
+// CommandBuilderVisitor commandBuilderVisitor = new CommandBuilderVisitor();
+// stereoptypeModel.accept(commandBuilderVisitor);
+// if( ! commandBuilderVisitor.isExecutionRequested() ) {
+// return false;
+// }
+
+
+ // old fashion
+ updateArgs = newDialog.getUpdateArgs();
+ if(updateArgs == null ) {
+ return false;
+ }
+ } else {
+ // cancelled
+ return false;
+ }
+
+ stereotypeNameInput = updateArgs.getStereotypeName();
+ profileNameInput = updateArgs.getProfileName();
+
+ taggedValeNameInput = "";
+
+ return true;
+ }
+
+ /**
+ * Return the list of metaclasses corresponding to selected element.
+ * @return A list of metaclasses, or an empty list if nothing is selected or if an error occurs.
+ */
+ private Set<Class> getSelectedElementMetaclasses(IEvaluationContext context) {
+
+
+ List<NamedElement> selectedElements = getSelectionAsNamedElements(context);
+ // If there is nothing to do, skip immediately
+ if( selectedElements.isEmpty()) {
+ return Collections.emptySet();
+ }
+
+
+ try {
+ Set<Class> result = new HashSet<Class>();
+ UMLMetamodelUtils umlMetamodelUtils = getUmlMetamodelUtils(context);
+
+ for( NamedElement sel : selectedElements) {
+ result.add(umlMetamodelUtils.getElementMetaclass(sel));
+ }
+ return result;
+ } catch (DraftProfileException e) {
+ Activator.log.error( e);
+ return Collections.emptySet();
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#doExecute(org.eclipse.core.commands.ExecutionEvent, org.eclipse.core.expressions.IEvaluationContext, java.util.List)
+ *
+ * @param event
+ * @param context
+ * @param selections
+ */
+ @Override
+ protected void doExecute(ExecutionEvent event, IEvaluationContext context) {
+
+// System.err.println("Add Profile called. Selected elements:");
+ List<NamedElement> selected = getSelectionAsNamedElements(context);
+// for( NamedElement ele : selected) {
+// System.err.println(ele.getName());
+// }
+// System.err.println("********************");
+//
+// if( selected.isEmpty()) {
+// return;
+// }
+
+ // Try to apply the stereotype
+ ProfileApplicator profileApplicator = new ProfileApplicator(selected.get(0));
+ try {
+// profileApplicator.applyStereotype2(profileNameInput, stereotypeNameInput);
+// profileApplicator.updateStereotype(updateArgs);
+ profileApplicator.updateStereotype(stereoptypeModel);
+ } catch (DraftProfileException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#resetCachedValues()
+ *
+ */
+ @Override
+ protected void resetCachedValues() {
+ super.resetCachedValues();
+ cachedSelectionAsNamedElement = null;
+ stereotypeNameInput = null;
+ profileNameInput = null;
+ taggedValeNameInput = null;
+ }
+
+ /**
+ * Get the list of selected element of type 'NamedElement'.
+ *
+ * @param context
+ * @return
+ */
+ protected List<NamedElement> getSelectionAsNamedElements(IEvaluationContext context) {
+
+ if( cachedSelectionAsNamedElement == null) {
+
+ cachedSelectionAsNamedElement = getSelectionsByType(context, NamedElement.class);
+ }
+
+ return cachedSelectionAsNamedElement;
+ }
+
+ protected Extension createExtension( Stereotype source, Type target) {
+ //create the extension
+ Extension newExtension = UMLFactory.eINSTANCE.createExtension();
+
+ //create the endSource
+ ExtensionEnd endSource = UMLFactory.eINSTANCE.createExtensionEnd();
+
+ //initialize the endSource
+ endSource.setName("extension_" + source.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ endSource.setType(source);
+ endSource.setAggregation(AggregationKind.COMPOSITE_LITERAL);
+
+ //add the endSource to the extension
+ newExtension.getOwnedEnds().add(endSource); // add extension end to extension
+
+
+ //create source_property
+ Property property = UMLFactory.eINSTANCE.createProperty();
+ property.setName("base_" + target.getName());
+ // property.setIsDerived(true);
+ property.setType(target); // set the type
+ property.setAssociation(newExtension); // Set the association link
+ property.setAggregation(AggregationKind.NONE_LITERAL);
+
+ newExtension.getMemberEnds().add(property);
+
+ source.getOwnedAttributes().add(property);
+
+ return newExtension;
+ }
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.profile.drafter.ui.handler.AbstractBaseHandler#isEnabled(org.eclipse.core.expressions.IEvaluationContext, java.util.List)
+ *
+ * @param context
+ * @param selections
+ * @return
+ */
+ @Override
+ public boolean isEnabled(IEvaluationContext context, List<Object> selections) {
+
+ if( ! selections.isEmpty() ) {
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/StereotypeURL.java b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/StereotypeURL.java
index 72c4b3e95ae..693d0549ecb 100644
--- a/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/StereotypeURL.java
+++ b/plugins/uml/profile/org.eclipse.papyrus.uml.profile.drafter/src/org/eclipse/papyrus/uml/profile/drafter/ui/model/StereotypeURL.java
@@ -1,421 +1,416 @@
-/*****************************************************************************
- * Copyright (c) 2014 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.profile.drafter.ui.model;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-
-import org.eclipse.uml2.uml.Stereotype;
-
-
-/**
- * A class encapsulating an URL identifying a Stereotype.
- * The class does not ensure that a corresponding UML {@link Stereotype} exists. It is only a identifier to a Stereotype.
- *
- *
- * @author cedric dumoulin
- *
- */
-public class StereotypeURL {
-
- final static String QUALIFIED_NAME = "qualifiedName";
- final static String PROFILE_NAME = "profileName";
- final static String STEREOTYPEE_NAME = "stereotypeName";
- final static String RESOURCEE_NAME = "resourceName";
-
-
- protected String qualifiedName = "";
- protected String profileName = "";
- protected String stereotypeName = "";
- /**
- * The resource that should contains the Stereotype.
- * Not yet used
- * TODO : used this extra property
- */
- protected String resourceName = "";
-
- /**
- * Event manager
- */
- private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
- private static int count=0;
-
-
- /**
- *
- * Constructor.
- *
- */
- public StereotypeURL() {
- }
-
- /**
- * Constructor.
- *
- * @param qualifiedName
- */
- public StereotypeURL(String qualifiedName) {
- setQualifiedName(qualifiedName);
- }
-
-
-
- /**
- * Constructor.
- *
- * @param profileNames
- * @param stereotypeName
- */
- public StereotypeURL(String profileName, String stereotypeName) {
- this.profileName = profileName;
- this.stereotypeName = stereotypeName;
- this.qualifiedName = computeQualifiedName();
- }
-
-
- /**
- * @return the qualifiedName
- */
- public String getQualifiedName() {
- if(qualifiedName==null) {
- computeQualifiedName();
- }
-
- return qualifiedName;
- }
-
-
- /**
- * @param qualifiedName the qualifiedName to set
- */
- synchronized public void setQualifiedName(String qualifiedName) {
-
- qualifiedName = qualifiedName.trim();
-
- int num = count++;
-
- try {
-// qualifiedName+=count++;
- System.err.println("setQualifiedName(" + qualifiedName +" : " + num +")");
- if(qualifiedName == null) {
- return;
- }
-
- if(this.qualifiedName != null && this.qualifiedName.equals(qualifiedName)) {
- // No change
- return;
- }
-
- // Remember old values
- String stereotypeName="";
- String profileName="";
- String resourceName="";
-
-
- // Remove trailing '/'
- if( qualifiedName.startsWith("//")) {
- qualifiedName = qualifiedName.substring(2);
- }
- else if( qualifiedName.startsWith("/")) {
- qualifiedName = qualifiedName.substring(1);
- }
-
- // Is there a resource name ?
- // "resourceName/endOfName"
- int index = qualifiedName.indexOf("/");
- if(index > 0) {
- // Extract resourceName, and the end of the qualified name (ie: endOfName)
- resourceName = qualifiedName.substring(0, index);
- qualifiedName = qualifiedName.substring(index+1);
- }
-
-
- // Parse the qualifiedName and set other names accordingly.
- index = qualifiedName.lastIndexOf("::");
- if(index == -1) {
- // no profile names
- stereotypeName = qualifiedName;
- profileName = "";
- }
- else {
- stereotypeName = qualifiedName.substring(index+2);
- profileName = qualifiedName.substring(0, index);
- }
-
- StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(this.qualifiedName, this.qualifiedName=computeQualifiedName(resourceName, profileName, stereotypeName));
- ev.setStereotypeNameValues(this.stereotypeName, this.stereotypeName = stereotypeName);
- ev.setProfileNameValues(this.profileName, this.profileName = profileName);
- ev.setResourceNameValues(this.resourceName, this.resourceName = resourceName);
-
- qualifiedNameChanged(ev);
- } catch (Exception e) {
- System.err.println("Exception caught:" + e.getMessage());
-// e.printStackTrace();
- }
- System.err.println("exit setQualifiedName(" + qualifiedName +" : " + num +")");
-
- }
-
-
- /**
- * Clear this URL. All segments are set to null or empty.
- */
- public void clear() {
-
- StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(qualifiedName, qualifiedName = "");
- ev.setProfileNameValues(profileName, profileName= "");
- ev.setStereotypeNameValues(stereotypeName, stereotypeName= "");
- ev.setResourceNameValues(resourceName, resourceName= "");
-
- qualifiedNameChanged(ev);
- }
-
-
- /**
- * @return the stereotypeName
- */
- public String getStereotypeName() {
- return stereotypeName;
- }
-
-
- /**
- * @param stereotypeName the stereotypeName to set
- */
- public void setStereotypeName(String stereotypeName) {
-
- System.err.println("setStereotypeName(" + stereotypeName + ")");
- // StereotypeName should be set.
- if(stereotypeName == null) {
- return;
- }
-
- if(this.stereotypeName != null && this.stereotypeName.equals(stereotypeName)) {
- // No change
- return;
- }
-
- String oldStereotypeName = this.stereotypeName;
- this.stereotypeName = stereotypeName;
-
- StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(qualifiedName, qualifiedName = computeQualifiedName());
- ev.setStereotypeNameValues( oldStereotypeName, stereotypeName);
-
- qualifiedNameChanged(ev);
- }
-
-
-
-
- /**
- * @return the profileNames
- */
- public String getProfileName() {
- return profileName;
- }
-
- /**
- * @param profilePath The name of the profile to add to {@link #profileNames}.
- * @return the profileNames
- */
- public void setProfileName(String profileName) {
-
- System.err.println("setProfileName(" + profileName + ")");
- // parameter should be set.
- if(profileName == null) {
- return;
- }
-
- if(this.profileName != null && this.profileName.equals(profileName)) {
- // No change
- return;
- }
-
- String oldProfileName = this.profileName;
- this.profileName = profileName;
-
- StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(qualifiedName, qualifiedName = computeQualifiedName());
- ev.setProfileNameValues( oldProfileName, profileName);
-
- qualifiedNameChanged(ev);
- }
-
-
- /**
- * @return the resourceName
- */
- public String getResourceName() {
- return resourceName;
- }
-
-
- /**
- * @param resourceName the resourceName to set
- */
- public void setResourceName(String resourceName) {
-
- // parameter should be set.
- if(resourceName == null) {
- return;
- }
-
- if(this.resourceName != null && this.resourceName.equals(resourceName)) {
- // No change
- return;
- }
-
- String oldResourceName = this.resourceName;
- this.resourceName = resourceName;
-
- StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(qualifiedName, qualifiedName = computeQualifiedName());
- ev.setResourceNameValues( oldResourceName, resourceName);
-
- qualifiedNameChanged(ev);
-
- }
-
- /**
- * Method called when the {@link #qualifiedName} property has changed. This method is called directly by methods
- * modifying the properties.
- * The provided parameter is the event that has been created and filled with appropriate values. It is ready to be fired.
- *
- *
- * @param event The event indicating the changes. This event is not yet fired. The method should fire the event.
- *
- */
- protected void qualifiedNameChanged( StereotypeURLChangeEvent event) {
-
- // Fire QUALIFIED_NAME event
- // The event already hold the QUALIFIED_NAME id.
- changeSupport.firePropertyChange(event);
-
- // Also propagate other change events.
- if(event.isProfileNameChanged() ) {
- firePropertyChange(PROFILE_NAME, event.getOldProfileName(), event.getProfileName());
- }
- if(event.isStereotypeNameChanged() ) {
- firePropertyChange(STEREOTYPEE_NAME, event.getOldStereotypeName(), event.getStereotypeName());
- }
- if(event.isResourceNameChanged() ) {
- firePropertyChange(RESOURCEE_NAME, event.getOldResourceName(), event.getResourceName());
- }
- if(event.isQualifiedNameChanged() ) {
- firePropertyChange(QUALIFIED_NAME, event.getOldQualifiedName(), event.getQualifiedName());
- }
-
- }
-
- /**
- * Create a new {@link StereotypeURLChangeEvent} initialized with provided values.
- *
- * @param oldValue The old {@link #qualifiedName} value
- * @param newValue The new {@link #qualifiedName} value
- * @return
- */
- protected StereotypeURLChangeEvent createStereotypeURLChangeEvent( String oldValue, String newValue) {
- return new StereotypeURLChangeEvent(this, oldValue, newValue);
- }
-
- /**
- * Compute the qualifiedName from {@link #resourceName}, {@link #profileNames} and {@link #stereotypeName}.
- * Add necessary '::' and '/'.
- * Profile paths and stereotype name are separated with '::'.
- * ResourceName and paths are separated by '/'.
- *
- * @return
- */
- protected String computeQualifiedName() {
-
- return computeQualifiedName(resourceName, profileName, stereotypeName);
- }
-
- /**
- * Compute the qualifiedName from {@link #resourceName}, {@link #profileNames} and {@link #stereotypeName}.
- * Add necessary '::' and '/'.
- * Profile paths and stereotype name are separated with '::'.
- * ResourceName and paths are separated by '/'.
- *
- * @return
- */
- static public String computeQualifiedName(String resourceName, String profileName, String stereotypeName) {
-
- StringBuilder buf = new StringBuilder();
-
- if( resourceName != null && resourceName.length()>0) {
- buf.append("//").append(resourceName).append("/");
- }
- if( profileName != null && profileName.length()>0) {
- buf.append(profileName);
- }
-
- if( stereotypeName != null && stereotypeName.length()>0) {
- if(buf.length()>0 && buf.charAt(buf.length()-1)!='/' ) {
- buf.append("::");
- }
- buf.append(stereotypeName);
- }
-
- return buf.toString();
- }
-
- /**
- *
- * @see java.lang.Object#toString()
- *
- * @return
- */
- @Override
- public String toString() {
- return qualifiedName;
- }
-
- /**
- *
- * @param listener
- */
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- changeSupport.addPropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- changeSupport.removePropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- changeSupport.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- changeSupport.removePropertyChangeListener(propertyName, listener);
- }
-
- protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
- changeSupport.firePropertyChange(propertyName, oldValue, newValue);
- }
-
- protected void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue) {
- changeSupport.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
- }
-
-
- /**
- * @return the changeSupport
- */
- protected PropertyChangeSupport getChangeSupport() {
- return changeSupport;
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.profile.drafter.ui.model;
+
+import static org.eclipse.papyrus.uml.profile.drafter.Activator.log;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+import org.eclipse.uml2.uml.Stereotype;
+
+
+/**
+ * A class encapsulating an URL identifying a Stereotype.
+ * The class does not ensure that a corresponding UML {@link Stereotype} exists. It is only a identifier to a Stereotype.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class StereotypeURL {
+
+ final static String QUALIFIED_NAME = "qualifiedName";
+ final static String PROFILE_NAME = "profileName";
+ final static String STEREOTYPEE_NAME = "stereotypeName";
+ final static String RESOURCEE_NAME = "resourceName";
+
+
+ protected String qualifiedName = "";
+ protected String profileName = "";
+ protected String stereotypeName = "";
+ /**
+ * The resource that should contains the Stereotype.
+ * Not yet used
+ * TODO : used this extra property
+ */
+ protected String resourceName = "";
+
+ /**
+ * Event manager
+ */
+ private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
+ private static int count=0;
+
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public StereotypeURL() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param qualifiedName
+ */
+ public StereotypeURL(String qualifiedName) {
+ setQualifiedName(qualifiedName);
+ }
+
+
+
+ /**
+ * Constructor.
+ *
+ * @param profileNames
+ * @param stereotypeName
+ */
+ public StereotypeURL(String profileName, String stereotypeName) {
+ this.profileName = profileName;
+ this.stereotypeName = stereotypeName;
+ this.qualifiedName = computeQualifiedName();
+ }
+
+
+ /**
+ * @return the qualifiedName
+ */
+ public String getQualifiedName() {
+ if(qualifiedName==null) {
+ computeQualifiedName();
+ }
+
+ return qualifiedName;
+ }
+
+
+ /**
+ * @param qualifiedName the qualifiedName to set
+ */
+ synchronized public void setQualifiedName(String qualifiedName) {
+
+ qualifiedName = qualifiedName.trim();
+
+ int num = count++;
+
+ try {
+ if(qualifiedName == null) {
+ return;
+ }
+
+ if(this.qualifiedName != null && this.qualifiedName.equals(qualifiedName)) {
+ // No change
+ return;
+ }
+
+ // Remember old values
+ String stereotypeName="";
+ String profileName="";
+ String resourceName="";
+
+
+ // Remove trailing '/'
+ if( qualifiedName.startsWith("//")) {
+ qualifiedName = qualifiedName.substring(2);
+ }
+ else if( qualifiedName.startsWith("/")) {
+ qualifiedName = qualifiedName.substring(1);
+ }
+
+ // Is there a resource name ?
+ // "resourceName/endOfName"
+ int index = qualifiedName.indexOf("/");
+ if(index > 0) {
+ // Extract resourceName, and the end of the qualified name (ie: endOfName)
+ resourceName = qualifiedName.substring(0, index);
+ qualifiedName = qualifiedName.substring(index+1);
+ }
+
+
+ // Parse the qualifiedName and set other names accordingly.
+ index = qualifiedName.lastIndexOf("::");
+ if(index == -1) {
+ // no profile names
+ stereotypeName = qualifiedName;
+ profileName = "";
+ }
+ else {
+ stereotypeName = qualifiedName.substring(index+2);
+ profileName = qualifiedName.substring(0, index);
+ }
+
+ StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(this.qualifiedName, this.qualifiedName=computeQualifiedName(resourceName, profileName, stereotypeName));
+ ev.setStereotypeNameValues(this.stereotypeName, this.stereotypeName = stereotypeName);
+ ev.setProfileNameValues(this.profileName, this.profileName = profileName);
+ ev.setResourceNameValues(this.resourceName, this.resourceName = resourceName);
+
+ qualifiedNameChanged(ev);
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ }
+
+
+ /**
+ * Clear this URL. All segments are set to null or empty.
+ */
+ public void clear() {
+
+ StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(qualifiedName, qualifiedName = "");
+ ev.setProfileNameValues(profileName, profileName= "");
+ ev.setStereotypeNameValues(stereotypeName, stereotypeName= "");
+ ev.setResourceNameValues(resourceName, resourceName= "");
+
+ qualifiedNameChanged(ev);
+ }
+
+
+ /**
+ * @return the stereotypeName
+ */
+ public String getStereotypeName() {
+ return stereotypeName;
+ }
+
+
+ /**
+ * @param stereotypeName the stereotypeName to set
+ */
+ public void setStereotypeName(String stereotypeName) {
+
+ // StereotypeName should be set.
+ if(stereotypeName == null) {
+ return;
+ }
+
+ if(this.stereotypeName != null && this.stereotypeName.equals(stereotypeName)) {
+ // No change
+ return;
+ }
+
+ String oldStereotypeName = this.stereotypeName;
+ this.stereotypeName = stereotypeName;
+
+ StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(qualifiedName, qualifiedName = computeQualifiedName());
+ ev.setStereotypeNameValues( oldStereotypeName, stereotypeName);
+
+ qualifiedNameChanged(ev);
+ }
+
+
+
+
+ /**
+ * @return the profileNames
+ */
+ public String getProfileName() {
+ return profileName;
+ }
+
+ /**
+ * @param profilePath The name of the profile to add to {@link #profileNames}.
+ * @return the profileNames
+ */
+ public void setProfileName(String profileName) {
+
+ // parameter should be set.
+ if(profileName == null) {
+ return;
+ }
+
+ if(this.profileName != null && this.profileName.equals(profileName)) {
+ // No change
+ return;
+ }
+
+ String oldProfileName = this.profileName;
+ this.profileName = profileName;
+
+ StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(qualifiedName, qualifiedName = computeQualifiedName());
+ ev.setProfileNameValues( oldProfileName, profileName);
+
+ qualifiedNameChanged(ev);
+ }
+
+
+ /**
+ * @return the resourceName
+ */
+ public String getResourceName() {
+ return resourceName;
+ }
+
+
+ /**
+ * @param resourceName the resourceName to set
+ */
+ public void setResourceName(String resourceName) {
+
+ // parameter should be set.
+ if(resourceName == null) {
+ return;
+ }
+
+ if(this.resourceName != null && this.resourceName.equals(resourceName)) {
+ // No change
+ return;
+ }
+
+ String oldResourceName = this.resourceName;
+ this.resourceName = resourceName;
+
+ StereotypeURLChangeEvent ev = createStereotypeURLChangeEvent(qualifiedName, qualifiedName = computeQualifiedName());
+ ev.setResourceNameValues( oldResourceName, resourceName);
+
+ qualifiedNameChanged(ev);
+
+ }
+
+ /**
+ * Method called when the {@link #qualifiedName} property has changed. This method is called directly by methods
+ * modifying the properties.
+ * The provided parameter is the event that has been created and filled with appropriate values. It is ready to be fired.
+ *
+ *
+ * @param event The event indicating the changes. This event is not yet fired. The method should fire the event.
+ *
+ */
+ protected void qualifiedNameChanged( StereotypeURLChangeEvent event) {
+
+ // Fire QUALIFIED_NAME event
+ // The event already hold the QUALIFIED_NAME id.
+ changeSupport.firePropertyChange(event);
+
+ // Also propagate other change events.
+ if(event.isProfileNameChanged() ) {
+ firePropertyChange(PROFILE_NAME, event.getOldProfileName(), event.getProfileName());
+ }
+ if(event.isStereotypeNameChanged() ) {
+ firePropertyChange(STEREOTYPEE_NAME, event.getOldStereotypeName(), event.getStereotypeName());
+ }
+ if(event.isResourceNameChanged() ) {
+ firePropertyChange(RESOURCEE_NAME, event.getOldResourceName(), event.getResourceName());
+ }
+ if(event.isQualifiedNameChanged() ) {
+ firePropertyChange(QUALIFIED_NAME, event.getOldQualifiedName(), event.getQualifiedName());
+ }
+
+ }
+
+ /**
+ * Create a new {@link StereotypeURLChangeEvent} initialized with provided values.
+ *
+ * @param oldValue The old {@link #qualifiedName} value
+ * @param newValue The new {@link #qualifiedName} value
+ * @return
+ */
+ protected StereotypeURLChangeEvent createStereotypeURLChangeEvent( String oldValue, String newValue) {
+ return new StereotypeURLChangeEvent(this, oldValue, newValue);
+ }
+
+ /**
+ * Compute the qualifiedName from {@link #resourceName}, {@link #profileNames} and {@link #stereotypeName}.
+ * Add necessary '::' and '/'.
+ * Profile paths and stereotype name are separated with '::'.
+ * ResourceName and paths are separated by '/'.
+ *
+ * @return
+ */
+ protected String computeQualifiedName() {
+
+ return computeQualifiedName(resourceName, profileName, stereotypeName);
+ }
+
+ /**
+ * Compute the qualifiedName from {@link #resourceName}, {@link #profileNames} and {@link #stereotypeName}.
+ * Add necessary '::' and '/'.
+ * Profile paths and stereotype name are separated with '::'.
+ * ResourceName and paths are separated by '/'.
+ *
+ * @return
+ */
+ static public String computeQualifiedName(String resourceName, String profileName, String stereotypeName) {
+
+ StringBuilder buf = new StringBuilder();
+
+ if( resourceName != null && resourceName.length()>0) {
+ buf.append("//").append(resourceName).append("/");
+ }
+ if( profileName != null && profileName.length()>0) {
+ buf.append(profileName);
+ }
+
+ if( stereotypeName != null && stereotypeName.length()>0) {
+ if(buf.length()>0 && buf.charAt(buf.length()-1)!='/' ) {
+ buf.append("::");
+ }
+ buf.append(stereotypeName);
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ *
+ * @see java.lang.Object#toString()
+ *
+ * @return
+ */
+ @Override
+ public String toString() {
+ return qualifiedName;
+ }
+
+ /**
+ *
+ * @param listener
+ */
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ changeSupport.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ changeSupport.removePropertyChangeListener(propertyName, listener);
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ changeSupport.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+ protected void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue) {
+ changeSupport.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
+ }
+
+
+ /**
+ * @return the changeSupport
+ */
+ protected PropertyChangeSupport getChangeSupport() {
+ return changeSupport;
+ }
+
+
+}

Back to the top