Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-07-30 20:50:08 +0000
committerGerrit Code Review @ Eclipse.org2014-07-30 20:50:08 +0000
commita40f5c484b324fd64397fd96b86677d571a7e67e (patch)
tree60b36bd528d3404cfb30d4886ca38dbf22b523d6 /plugins
parent307b3a801bd47546023f881eafc5f406d142d538 (diff)
parent50b32e3051ee61d1c3e212f892be16b8f2288bba (diff)
downloadorg.eclipse.papyrus-a40f5c484b324fd64397fd96b86677d571a7e67e.tar.gz
org.eclipse.papyrus-a40f5c484b324fd64397fd96b86677d571a7e67e.tar.xz
org.eclipse.papyrus-a40f5c484b324fd64397fd96b86677d571a7e67e.zip
Merge "435995: Profile version numbers missing in the profile-upgrade-popup message https://bugs.eclipse.org/bugs/show_bug.cgi?id=435995"
Diffstat (limited to 'plugins')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java484
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java490
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF92
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/IPapyrusVersionConstants.java91
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/PapyrusDefinitionAnnotation.java225
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/ProfileRedefinition.java493
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/Version.java235
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/AppliedProfileContentProvider.java75
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/AppliedProfileLabelProvider.java76
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/ProfileApplicationContentProvider.java125
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/ProfileApplicationLabelProvider.java205
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ReapplyProfilesService.java422
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ui/RefreshProfileDialog.java365
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileDefinitionDialog.java1221
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/utils/Util.java1322
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java2
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF93
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java204
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java674
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/IPapyrusVersionConstants.java40
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/PapyrusDefinitionAnnotation.java152
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java330
-rw-r--r--plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/Version.java155
23 files changed, 4093 insertions, 3478 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
index 49086bb7a4f..e97545069ec 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/DefineProfileCommand.java
@@ -1,242 +1,242 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.profile.custom.commands;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-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.util.Diagnostician;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.uml.profile.Activator;
-import org.eclipse.papyrus.uml.profile.definition.PapyrusDefinitionAnnotation;
-import org.eclipse.papyrus.uml.profile.definition.ProfileRedefinition;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.util.UMLUtil;
-import org.eclipse.uml2.uml.util.UMLUtil.Profile2EPackageConverter;
-import org.eclipse.uml2.uml.util.UMLUtil.UML2EcoreConverter;
-
-
-/**
- * This command is used to define a profile
- *
- * @author VL222926
- *
- */
-public class DefineProfileCommand extends AbstractTransactionalCommand {
-
- /**
- * the {@link PapyrusDefinitionAnnotation}
- */
- private PapyrusDefinitionAnnotation papyrusAnnotation;
-
- /**
- * the profile to define
- */
- private Profile rootProfile;
-
- private boolean saveConstraint;
-
- /**
- *
- * Constructor.
- *
- * @param domain
- * @param papyrusAnnotation
- * @param rootProfile
- * @param viewer
- */
- public DefineProfileCommand(TransactionalEditingDomain domain, PapyrusDefinitionAnnotation papyrusAnnotation, Profile rootProfile, boolean saveConstraint) {
- super(domain, "DefineProfileCommand", null); //$NON-NLS-1$
- this.rootProfile = rootProfile;
- this.papyrusAnnotation = papyrusAnnotation;
- this.saveConstraint = saveConstraint;
- }
-
-
- /**
- * Define this package if it is a profile and its sub-profiles
- *
- * @param thePackage
- * the package to define (if it is a profile)
- */
- public static List<EPackage> defineProfiles(Package thePackage, 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__PROCESS);
-
- options.put(Profile2EPackageConverter.OPTION__UNTYPED_PROPERTIES, UMLUtil.OPTION__PROCESS); //Closer to the UML semantics of untyped properties
-
- List<EPackage> result = new LinkedList<EPackage>();
-
- // we want to define
- if(thePackage instanceof Profile) {
- EPackage profileDefinition = ((Profile)thePackage).define(options, null, null);
- result.add(profileDefinition);
- }
-
- Iterator<Package> it = thePackage.getNestedPackages().iterator();
- while(it.hasNext()) {
- Package p = it.next();
- List<EPackage> profileDefinitions = defineProfiles(p, saveConstraintInDef);
- result.addAll(profileDefinitions);
- }
-
- return result;
- }
-
- /**
- *
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
- * org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
-
- List<EPackage> profileDefinitions = defineProfiles(rootProfile, saveConstraint);
-
- IStatus result;
-
- //PackageUtil.defineProfiles(rootProfile);
- try {
- ProfileRedefinition.redefineProfile(rootProfile, papyrusAnnotation);
- ProfileRedefinition.cleanProfile(rootProfile);
- //TODO: Validate the new definition
-
- result = postValidate(profileDefinitions);
- } catch (ExecutionException ex) {
- throw ex;
- } catch (Exception e) {
- throw new ExecutionException("An error occurred during the profile definition", e);
- }
-
- return new CommandResult(result);
- }
-
- protected IStatus postValidate(List<EPackage> profileDefinitions) throws ExecutionException {
-
- EditingDomain domain = EMFHelper.resolveEditingDomain(rootProfile);
- AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
- Diagnostician diagnostician = createDiagnostician(adapterFactory, new NullProgressMonitor());
- diagnostic = diagnostician.createDefaultDiagnostic(rootProfile);
- Map<Object, Object> context = diagnostician.createDefaultContext();
-
- for(EPackage ePackage : profileDefinitions) {
- 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;
- }
-
- protected BasicDiagnostic diagnostic;
-
- public Diagnostic getDiagnostic() {
- return diagnostic;
- }
-
- 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);
- }
- };
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#getAffectedFiles()
- *
- * @return
- */
- @Override
- public List<IFile> getAffectedFiles() {
- IFile f = WorkspaceSynchronizer.getFile(rootProfile.eResource());
- return f != null ? Collections.<IFile> singletonList(f) : Collections.<IFile> emptyList();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.profile.custom.commands;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+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.util.Diagnostician;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.util.UMLUtil;
+import org.eclipse.uml2.uml.util.UMLUtil.Profile2EPackageConverter;
+import org.eclipse.uml2.uml.util.UMLUtil.UML2EcoreConverter;
+
+
+/**
+ * This command is used to define a profile
+ *
+ * @author VL222926
+ *
+ */
+public class DefineProfileCommand extends AbstractTransactionalCommand {
+
+ /**
+ * the {@link PapyrusDefinitionAnnotation}
+ */
+ private PapyrusDefinitionAnnotation papyrusAnnotation;
+
+ /**
+ * the profile to define
+ */
+ private Profile rootProfile;
+
+ private boolean saveConstraint;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * @param papyrusAnnotation
+ * @param rootProfile
+ * @param viewer
+ */
+ public DefineProfileCommand(TransactionalEditingDomain domain, PapyrusDefinitionAnnotation papyrusAnnotation, Profile rootProfile, boolean saveConstraint) {
+ super(domain, "DefineProfileCommand", null); //$NON-NLS-1$
+ this.rootProfile = rootProfile;
+ this.papyrusAnnotation = papyrusAnnotation;
+ this.saveConstraint = saveConstraint;
+ }
+
+
+ /**
+ * Define this package if it is a profile and its sub-profiles
+ *
+ * @param thePackage
+ * the package to define (if it is a profile)
+ */
+ public static List<EPackage> defineProfiles(Package thePackage, 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__PROCESS);
+
+ options.put(Profile2EPackageConverter.OPTION__UNTYPED_PROPERTIES, UMLUtil.OPTION__PROCESS); //Closer to the UML semantics of untyped properties
+
+ List<EPackage> result = new LinkedList<EPackage>();
+
+ // we want to define
+ if(thePackage instanceof Profile) {
+ EPackage profileDefinition = ((Profile)thePackage).define(options, null, null);
+ result.add(profileDefinition);
+ }
+
+ Iterator<Package> it = thePackage.getNestedPackages().iterator();
+ while(it.hasNext()) {
+ Package p = it.next();
+ List<EPackage> profileDefinitions = defineProfiles(p, saveConstraintInDef);
+ result.addAll(profileDefinitions);
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+
+ List<EPackage> profileDefinitions = defineProfiles(rootProfile, saveConstraint);
+
+ IStatus result;
+
+ //PackageUtil.defineProfiles(rootProfile);
+ try {
+ ProfileRedefinition.redefineProfile(rootProfile, papyrusAnnotation);
+ ProfileRedefinition.cleanProfile(rootProfile);
+ //TODO: Validate the new definition
+
+ result = postValidate(profileDefinitions);
+ } catch (ExecutionException ex) {
+ throw ex;
+ } catch (Exception e) {
+ throw new ExecutionException("An error occurred during the profile definition", e);
+ }
+
+ return new CommandResult(result);
+ }
+
+ protected IStatus postValidate(List<EPackage> profileDefinitions) throws ExecutionException {
+
+ EditingDomain domain = EMFHelper.resolveEditingDomain(rootProfile);
+ AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
+ Diagnostician diagnostician = createDiagnostician(adapterFactory, new NullProgressMonitor());
+ diagnostic = diagnostician.createDefaultDiagnostic(rootProfile);
+ Map<Object, Object> context = diagnostician.createDefaultContext();
+
+ for(EPackage ePackage : profileDefinitions) {
+ 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;
+ }
+
+ protected BasicDiagnostic diagnostic;
+
+ public Diagnostic getDiagnostic() {
+ return diagnostic;
+ }
+
+ 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);
+ }
+ };
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#getAffectedFiles()
+ *
+ * @return
+ */
+ @Override
+ public List<IFile> getAffectedFiles() {
+ IFile f = WorkspaceSynchronizer.getFile(rootProfile.eResource());
+ return f != null ? Collections.<IFile> singletonList(f) : Collections.<IFile> emptyList();
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java
index e6cb8eba9fe..86549cadc4a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/PreSaveProfileListener.java
@@ -1,245 +1,245 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.profile.service;
-
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.common.ui.dialogs.DiagnosticDialog;
-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.resource.Resource;
-import org.eclipse.emf.ecore.util.Diagnostician;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.provider.IItemLabelProvider;
-import org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.commands.CheckedOperationHistory;
-import org.eclipse.papyrus.infra.core.lifecycleevents.DoSaveEvent;
-import org.eclipse.papyrus.infra.core.lifecycleevents.ISaveEventListener;
-import org.eclipse.papyrus.infra.core.resource.IModel;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.papyrus.infra.services.validation.ValidationTool;
-import org.eclipse.papyrus.uml.diagram.profile.custom.commands.DefineProfileCommand;
-import org.eclipse.papyrus.uml.profile.Activator;
-import org.eclipse.papyrus.uml.profile.definition.PapyrusDefinitionAnnotation;
-import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileDefinitionDialog;
-import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Profile;
-
-/**
- * This class provides listeners
- *
- *
- * This class describes the actions to do just before the save action
- */
-public class PreSaveProfileListener implements ISaveEventListener {
-
- /**
- * If an error comes here, the save action can't be make entirely -> use try-catch!
- *
- * This function is called before the user make a "save" action
- */
- public void doSave(DoSaveEvent event) {
- if(event.isAutoSave()) {
- return;
- }
- try {
- //System.out.println("preSave Event received"); //$NON-NLS-1$
- /**
- * if the root is a profile, we must define it. If it's another thing, we
- * do nothing
- */
-
- Profile rootProfile = null;
- /**
- * Obtain the root profile
- */
- ServicesRegistry registry = event.getServiceRegistry();
-
- ModelSet modelSet = ServiceUtils.getInstance().getModelSet(registry);
-
- IModel umlModel = modelSet.getModel(UmlModel.MODEL_ID);
-
- EObject profileEObject = null;
- if(umlModel != null) {
- profileEObject = ((UmlModel)umlModel).lookupRoot();
- }
-
- if(profileEObject instanceof Profile) {
- rootProfile = (Profile)profileEObject;
- }
-
- if(rootProfile == null) {
- return; //We're not saving a profile model
- }
-
- /**
- * Does the user want define the profile?
- */
- String DEFINE_MSG = "In order to apply this profile, it had to be defined.\nWould you like to define it?";
- String PAPYRUS_QUESTION = "Papyrus question"; //$NON-NLS-1$
-
- Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
-
- boolean result = MessageDialog.openQuestion(activeShell, PAPYRUS_QUESTION, DEFINE_MSG);
- if(!result) {
- return;
- }
-
- ProfileDefinitionDialog dialog = new ProfileDefinitionDialog(activeShell, rootProfile);
- dialog.open();
- if(dialog.getReturnCode() == Window.OK) {
- PapyrusDefinitionAnnotation papyrusAnnotation = dialog.getPapyrusDefinitionAnnotation();
- TransactionalEditingDomain domain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry);
- //evaluate contraint of profiles
- AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
- Diagnostician diagnostician = createDiagnostician(adapterFactory, new NullProgressMonitor());
- BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(rootProfile);
- diagnostic.getSeverity();
- Map<Object, Object> context = diagnostician.createDefaultContext();
- diagnostician.validate(rootProfile, diagnostic, context);
- if(canDefine(diagnostic)) {
-
- DefineProfileCommand cmd = new DefineProfileCommand(domain, papyrusAnnotation, rootProfile, dialog.saveConstraintInDefinition());
- try {
- IStatus status = CheckedOperationHistory.getInstance().execute(cmd, new NullProgressMonitor(), null);
- switch(status.getSeverity()) {
- case IStatus.OK:
- MessageDialog.openInformation(activeShell, "The profile has been defined", "The profile has been successfully defined");
- break;
- case IStatus.WARNING:
- Activator.log.warn(status.getMessage());
- MessageDialog.openWarning(activeShell, "The profile has been defined", status.getMessage());
- break;
- case IStatus.ERROR:
- notifyErrors(activeShell, cmd.getDiagnostic());
- break;
- }
- } catch (ExecutionException e) {
- Activator.log.error(e);
- MessageDialog.openError(activeShell, "Uncaught exception", "An exception occurred during the profile definition: \n" + e.getMessage());
- }
- } else {
- handleDiagnostic(diagnostic, rootProfile);
- MessageDialog.openError(activeShell, "Profile not Valid", "The profile cannot be defined because it is invalid.");
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- protected void notifyErrors(Shell activeShell, Diagnostic diagnostic) {
- Activator.log.error(diagnostic.getMessage(), diagnostic.getException());
- DiagnosticDialog.openProblem(activeShell, "Profile definition failed", "The following errors occured during the profile definition", diagnostic);
- }
-
- protected boolean canDefine(Diagnostic diagnostic) {
- int severity = diagnostic.getSeverity();
- if(severity == Diagnostic.CANCEL) {
- return false;
- }
- if(severity == Diagnostic.ERROR) {
- //
- for(Diagnostic childDiagnostic : diagnostic.getChildren()) {
- if(childDiagnostic.getSeverity() != Diagnostic.ERROR) {
- continue;
- }
-
- if(childDiagnostic.getData().isEmpty()) {
- continue;
- }
-
- //Only fail on validation errors occuring on the UML Profile itself; do not fail on its Ecore definitions
- if(childDiagnostic.getData().get(0) instanceof Element) {
- return false;
- }
- }
- }
-
- //Ok, Warning, Info
- return true;
- }
-
- 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);
- }
- };
- }
-
- protected void handleDiagnostic(Diagnostic diagnostic, Profile profil) {
- // Do not show a dialog, as in the original version since the user sees the result directly
- // in the model explorer
- Resource resource = profil.eResource();
- if(resource != null) {
- if(profil != null) {
- ValidationTool vt = new ValidationTool(profil);
- vt.deleteSubMarkers();
- }
- // IPath path = new Path(resource.getURI().toPlatformString (false));
- // IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
- // IFile file = wsRoot.getFile(path);
- // eclipseResourcesUtil.deleteMarkers (file);
- EclipseResourcesUtil eclipseResourcesUtil = new EclipseResourcesUtil();
- for(Diagnostic childDiagnostic : diagnostic.getChildren()) {
- eclipseResourcesUtil.createMarkers(resource, childDiagnostic);
- // createMarkersOnDi (file, childDiagnostic);
- }
- }
- }
-
- /**
- * If an error comes here, the save action can't be make entirely -> use try-catch!
- *
- * This function is called before the user make a "save as" action
- */
- public void doSaveAs(DoSaveEvent event) {
- try {
- //System.out.println("preSaveAS Event received"); //$NON-NLS-1$
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.profile.service;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.ui.dialogs.DiagnosticDialog;
+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.resource.Resource;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.provider.IItemLabelProvider;
+import org.eclipse.emf.edit.ui.action.ValidateAction.EclipseResourcesUtil;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.commands.CheckedOperationHistory;
+import org.eclipse.papyrus.infra.core.lifecycleevents.DoSaveEvent;
+import org.eclipse.papyrus.infra.core.lifecycleevents.ISaveEventListener;
+import org.eclipse.papyrus.infra.core.resource.IModel;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+import org.eclipse.papyrus.infra.services.validation.ValidationTool;
+import org.eclipse.papyrus.uml.diagram.profile.custom.commands.DefineProfileCommand;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileDefinitionDialog;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Profile;
+
+/**
+ * This class provides listeners
+ *
+ *
+ * This class describes the actions to do just before the save action
+ */
+public class PreSaveProfileListener implements ISaveEventListener {
+
+ /**
+ * If an error comes here, the save action can't be make entirely -> use try-catch!
+ *
+ * This function is called before the user make a "save" action
+ */
+ public void doSave(DoSaveEvent event) {
+ if(event.isAutoSave()) {
+ return;
+ }
+ try {
+ //System.out.println("preSave Event received"); //$NON-NLS-1$
+ /**
+ * if the root is a profile, we must define it. If it's another thing, we
+ * do nothing
+ */
+
+ Profile rootProfile = null;
+ /**
+ * Obtain the root profile
+ */
+ ServicesRegistry registry = event.getServiceRegistry();
+
+ ModelSet modelSet = ServiceUtils.getInstance().getModelSet(registry);
+
+ IModel umlModel = modelSet.getModel(UmlModel.MODEL_ID);
+
+ EObject profileEObject = null;
+ if(umlModel != null) {
+ profileEObject = ((UmlModel)umlModel).lookupRoot();
+ }
+
+ if(profileEObject instanceof Profile) {
+ rootProfile = (Profile)profileEObject;
+ }
+
+ if(rootProfile == null) {
+ return; //We're not saving a profile model
+ }
+
+ /**
+ * Does the user want define the profile?
+ */
+ String DEFINE_MSG = "In order to apply this profile, it had to be defined.\nWould you like to define it?";
+ String PAPYRUS_QUESTION = "Papyrus question"; //$NON-NLS-1$
+
+ Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+
+ boolean result = MessageDialog.openQuestion(activeShell, PAPYRUS_QUESTION, DEFINE_MSG);
+ if(!result) {
+ return;
+ }
+
+ ProfileDefinitionDialog dialog = new ProfileDefinitionDialog(activeShell, rootProfile);
+ dialog.open();
+ if(dialog.getReturnCode() == Window.OK) {
+ PapyrusDefinitionAnnotation papyrusAnnotation = dialog.getPapyrusDefinitionAnnotation();
+ TransactionalEditingDomain domain = ServiceUtils.getInstance().getTransactionalEditingDomain(registry);
+ //evaluate contraint of profiles
+ AdapterFactory adapterFactory = domain instanceof AdapterFactoryEditingDomain ? ((AdapterFactoryEditingDomain)domain).getAdapterFactory() : null;
+ Diagnostician diagnostician = createDiagnostician(adapterFactory, new NullProgressMonitor());
+ BasicDiagnostic diagnostic = diagnostician.createDefaultDiagnostic(rootProfile);
+ diagnostic.getSeverity();
+ Map<Object, Object> context = diagnostician.createDefaultContext();
+ diagnostician.validate(rootProfile, diagnostic, context);
+ if(canDefine(diagnostic)) {
+
+ DefineProfileCommand cmd = new DefineProfileCommand(domain, papyrusAnnotation, rootProfile, dialog.saveConstraintInDefinition());
+ try {
+ IStatus status = CheckedOperationHistory.getInstance().execute(cmd, new NullProgressMonitor(), null);
+ switch(status.getSeverity()) {
+ case IStatus.OK:
+ MessageDialog.openInformation(activeShell, "The profile has been defined", "The profile has been successfully defined");
+ break;
+ case IStatus.WARNING:
+ Activator.log.warn(status.getMessage());
+ MessageDialog.openWarning(activeShell, "The profile has been defined", status.getMessage());
+ break;
+ case IStatus.ERROR:
+ notifyErrors(activeShell, cmd.getDiagnostic());
+ break;
+ }
+ } catch (ExecutionException e) {
+ Activator.log.error(e);
+ MessageDialog.openError(activeShell, "Uncaught exception", "An exception occurred during the profile definition: \n" + e.getMessage());
+ }
+ } else {
+ handleDiagnostic(diagnostic, rootProfile);
+ MessageDialog.openError(activeShell, "Profile not Valid", "The profile cannot be defined because it is invalid.");
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected void notifyErrors(Shell activeShell, Diagnostic diagnostic) {
+ Activator.log.error(diagnostic.getMessage(), diagnostic.getException());
+ DiagnosticDialog.openProblem(activeShell, "Profile definition failed", "The following errors occured during the profile definition", diagnostic);
+ }
+
+ protected boolean canDefine(Diagnostic diagnostic) {
+ int severity = diagnostic.getSeverity();
+ if(severity == Diagnostic.CANCEL) {
+ return false;
+ }
+ if(severity == Diagnostic.ERROR) {
+ //
+ for(Diagnostic childDiagnostic : diagnostic.getChildren()) {
+ if(childDiagnostic.getSeverity() != Diagnostic.ERROR) {
+ continue;
+ }
+
+ if(childDiagnostic.getData().isEmpty()) {
+ continue;
+ }
+
+ //Only fail on validation errors occuring on the UML Profile itself; do not fail on its Ecore definitions
+ if(childDiagnostic.getData().get(0) instanceof Element) {
+ return false;
+ }
+ }
+ }
+
+ //Ok, Warning, Info
+ return true;
+ }
+
+ 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);
+ }
+ };
+ }
+
+ protected void handleDiagnostic(Diagnostic diagnostic, Profile profil) {
+ // Do not show a dialog, as in the original version since the user sees the result directly
+ // in the model explorer
+ Resource resource = profil.eResource();
+ if(resource != null) {
+ if(profil != null) {
+ ValidationTool vt = new ValidationTool(profil);
+ vt.deleteSubMarkers();
+ }
+ // IPath path = new Path(resource.getURI().toPlatformString (false));
+ // IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
+ // IFile file = wsRoot.getFile(path);
+ // eclipseResourcesUtil.deleteMarkers (file);
+ EclipseResourcesUtil eclipseResourcesUtil = new EclipseResourcesUtil();
+ for(Diagnostic childDiagnostic : diagnostic.getChildren()) {
+ eclipseResourcesUtil.createMarkers(resource, childDiagnostic);
+ // createMarkersOnDi (file, childDiagnostic);
+ }
+ }
+ }
+
+ /**
+ * If an error comes here, the save action can't be make entirely -> use try-catch!
+ *
+ * This function is called before the user make a "save as" action
+ */
+ public void doSaveAs(DoSaveEvent event) {
+ try {
+ //System.out.println("preSaveAS Event received"); //$NON-NLS-1$
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF b/plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF
index ff38ca97222..e6a16b85d90 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF
@@ -1,46 +1,46 @@
-Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.uml.profile,
- org.eclipse.papyrus.uml.profile.constraints,
- org.eclipse.papyrus.uml.profile.definition,
- org.eclipse.papyrus.uml.profile.preference,
- org.eclipse.papyrus.uml.profile.providers,
- org.eclipse.papyrus.uml.profile.structure,
- org.eclipse.papyrus.uml.profile.tree,
- org.eclipse.papyrus.uml.profile.tree.objects,
- org.eclipse.papyrus.uml.profile.ui.dialogs,
- org.eclipse.papyrus.uml.profile.ui.items,
- org.eclipse.papyrus.uml.profile.utils,
- org.eclipse.papyrus.uml.profile.validation,
- org.eclipse.papyrus.uml.profile.wizard
-Require-Bundle: org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0",
- org.eclipse.core.runtime;bundle-version="3.8.0",
- org.eclipse.emf.transaction;bundle-version="1.4.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.emf.readonly;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.validation;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
- org.eclipse.uml2.uml;bundle-version="4.0.0",
- org.eclipse.ui,
- org.eclipse.ui.ide;bundle-version="3.8.0",
- org.eclipse.papyrus.uml.extensionpoints;bundle-version="1.0.0",
- org.eclipse.uml2.uml.editor;bundle-version="4.0.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
- org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.300",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
- com.google.guava;bundle-version="11.0.0",
- org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.modelrepair;bundle-version="1.0.0"
-Bundle-Vendor: %providerName
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.0.0.qualifier
-Bundle-Name: %pluginName
-Bundle-Localization: plugin
-Bundle-Activator: org.eclipse.papyrus.uml.profile.Activator
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.uml.profile;singleton:=true
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-
+Manifest-Version: 1.0
+Export-Package: org.eclipse.papyrus.uml.profile,
+ org.eclipse.papyrus.uml.profile.constraints,
+ org.eclipse.papyrus.uml.profile.definition,
+ org.eclipse.papyrus.uml.profile.preference,
+ org.eclipse.papyrus.uml.profile.providers,
+ org.eclipse.papyrus.uml.profile.structure,
+ org.eclipse.papyrus.uml.profile.tree,
+ org.eclipse.papyrus.uml.profile.tree.objects,
+ org.eclipse.papyrus.uml.profile.ui.dialogs,
+ org.eclipse.papyrus.uml.profile.ui.items,
+ org.eclipse.papyrus.uml.profile.utils,
+ org.eclipse.papyrus.uml.profile.validation,
+ org.eclipse.papyrus.uml.profile.wizard
+Require-Bundle: org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0",
+ org.eclipse.core.runtime;bundle-version="3.8.0",
+ org.eclipse.emf.transaction;bundle-version="1.4.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.emf.readonly;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.validation;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
+ org.eclipse.uml2.uml;bundle-version="4.0.0",
+ org.eclipse.ui,
+ org.eclipse.ui.ide;bundle-version="3.8.0",
+ org.eclipse.papyrus.uml.extensionpoints;bundle-version="1.0.0",
+ org.eclipse.uml2.uml.editor;bundle-version="4.0.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
+ org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.300",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
+ com.google.guava;bundle-version="11.0.0",
+ org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
+ org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.modelrepair;bundle-version="1.0.0"
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.0.0.qualifier
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Bundle-Activator: org.eclipse.papyrus.uml.profile.Activator
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.papyrus.uml.profile;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/IPapyrusVersionConstants.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/IPapyrusVersionConstants.java
index 8be61716d26..fea47778d96 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/IPapyrusVersionConstants.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/IPapyrusVersionConstants.java
@@ -1,40 +1,51 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.definition;
-
-/**
- * Constant fields for papyrus profile version
- */
-public interface IPapyrusVersionConstants {
-
- /** source for eAnnotation that qualifies the profile definition */
- public final String PAPYRUS_EANNOTATION_SOURCE = "PapyrusVersion";
-
- /** key for version detail */
- public final String PAPYRUS_VERSION_KEY = "Version";
-
- /** key for author detail */
- public final String PAPYRUS_AUTHOR_KEY = "Author";
-
- /** key for copyright detail */
- public final String PAPYRUS_COPYRIGHT_KEY = "Copyright";
-
- /** key for date detail */
- public final String PAPYRUS_DATE_KEY = "Date";
-
- /** key for comment detail */
- public final String PAPYRUS_COMMENT_KEY = "Comment";
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.definition;
+
+/**
+ * Constant fields for papyrus profile version
+ *
+ *
+ * @deprecated API was moved to the plugin org.eclipse.papyrus.uml.tools for Bug 435995.
+ * It was preserved for standard releases of Papyrus 1.0.0
+ * @see org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants
+ */
+@Deprecated
+public interface IPapyrusVersionConstants extends org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants {
+
+ /** source for eAnnotation that qualifies the profile definition */
+ @Deprecated
+ public final String PAPYRUS_EANNOTATION_SOURCE = "PapyrusVersion";
+
+ /** key for version detail */
+ @Deprecated
+ public final String PAPYRUS_VERSION_KEY = "Version";
+
+ /** key for author detail */
+ @Deprecated
+ public final String PAPYRUS_AUTHOR_KEY = "Author";
+
+ /** key for copyright detail */
+ @Deprecated
+ public final String PAPYRUS_COPYRIGHT_KEY = "Copyright";
+
+ /** key for date detail */
+ @Deprecated
+ public final String PAPYRUS_DATE_KEY = "Date";
+
+ /** key for comment detail */
+ @Deprecated
+ public final String PAPYRUS_COMMENT_KEY = "Comment";
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/PapyrusDefinitionAnnotation.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/PapyrusDefinitionAnnotation.java
index c571742010b..3c6d3a8a966 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/PapyrusDefinitionAnnotation.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/PapyrusDefinitionAnnotation.java
@@ -1,152 +1,73 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.definition;
-
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EcoreFactory;
-
-/**
- * Class that defines various information about a profile definition (author,
- * version, etc.)
- */
-public class PapyrusDefinitionAnnotation {
-
- /** version of the definition */
- private Version version = Version.emptyVersion;
-
- /** Comment of the definition */
- private String comment = "";
-
- /** Copyright of the definition */
- private String copyright = "";
-
- /** date of the definition */
- private String date = "";
-
- /** author of the definition */
- private String author = "";
-
- /** undefined PapyrusDefinitionAnnotation */
- public static PapyrusDefinitionAnnotation UNDEFINED_ANNOTATION = new PapyrusDefinitionAnnotation(
- Version.emptyVersion, "<undefined>", "", "", "<undefined>");
-
- /**
- * Creates a new PapyrusDefinitionAnnotation.
- *
- * @param version
- * the version of the definition
- * @param comment
- * the comment associated to this definition
- * @param copyright
- * the copyright of this definition
- * @param date
- * the date this definition was generated
- * @param the
- * author responsible of this definition
- */
- public PapyrusDefinitionAnnotation(Version version, String comment, String copyright, String date, String author) {
- this.version = version;
- this.comment = comment;
- this.copyright = copyright;
- this.author = author;
- this.date = date;
- }
-
- /**
- * Creates a Eannotation from the given configuration
- *
- * @return the eAnnotation corresponding to this configuration
- */
- public EAnnotation convertToEAnnotation() {
- EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
- // set various values (default if elements are null)
- annotation.setSource(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
- annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY, version.toString());
- annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_COMMENT_KEY, comment);
- annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_COPYRIGHT_KEY, copyright);
- annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_DATE_KEY, date);
- annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_AUTHOR_KEY, author);
- return annotation;
- }
-
- /**
- * Return the PapyrusDefinitionAnnotation corresponding to the given
- * EAnnotation
- *
- * @param annotation
- * the annotation to parse
- * @return a image of the given annotation, with default values if needed.
- */
- public static PapyrusDefinitionAnnotation parseEAnnotation(EAnnotation annotation) {
- final String versionValue = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY);
- Version version;
- try {
- version = Version.parseVersion(versionValue);
- } catch (IllegalArgumentException e) {
- version = Version.emptyVersion;
- }
- final String comment = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COMMENT_KEY);
- final String copyright = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COPYRIGHT_KEY);
- final String date = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_DATE_KEY);
- final String author = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_AUTHOR_KEY);
- return new PapyrusDefinitionAnnotation(version, (comment != null) ? comment : "",
- (copyright != null) ? copyright : "", (date != null) ? date : "", (author != null) ? author : "");
- }
-
- /**
- * Returns the version of the definition of the profile
- *
- * @return the version of the definition of the profile
- */
- public Version getVersion() {
- return version;
- }
-
- /**
- * Returns the comment associated to the definition of the profile
- *
- * @return the comment associated to the definition of the profile
- */
- public String getComment() {
- return comment;
- }
-
- /**
- * Returns the copyright associated to the definition of the profile
- *
- * @return the copyright associated to the definition of the profile
- */
- public String getCopyright() {
- return copyright;
- }
-
- /**
- * Returns the date associated to the definition of the profile
- *
- * @return the date associated to the definition of the profile
- */
- public String getDate() {
- return date;
- }
-
- /**
- * Returns the author responsible to the definition of the profile
- *
- * @return the author responsible to the definition of the profile
- */
- public String getAuthor() {
- return author;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.definition;
+
+import org.eclipse.emf.ecore.EAnnotation;
+
+
+
+
+/**
+ * Class that defines various information about a profile definition (author,
+ * version, etc.)
+ *
+ *
+ * @deprecated API was moved to the plugin org.eclipse.papyrus.uml.tools for Bug 435995.
+ * It was preserved for standard releases of Papyrus 1.0.0
+ * @see org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation
+ */
+@Deprecated
+public class PapyrusDefinitionAnnotation extends org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation {
+
+ /** undefined PapyrusDefinitionAnnotation */
+ public static PapyrusDefinitionAnnotation UNDEFINED_ANNOTATION = new PapyrusDefinitionAnnotation(Version.emptyVersion, "<undefined>", "", "", "<undefined>");
+
+ /**
+ * Instantiates a new papyrus definition annotation.
+ *
+ * @param version
+ * the version
+ * @param comment
+ * the comment
+ * @param copyright
+ * the copyright
+ * @param date
+ * the date
+ * @param author
+ * the author
+ */
+ public PapyrusDefinitionAnnotation(Version version, String comment, String copyright, String date, String author) {
+ super(version, comment, copyright, date, author);
+ }
+
+ /** Copy constructor for legacy support. */
+ PapyrusDefinitionAnnotation(org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation annotation) {
+ this(new Version(annotation.getVersion()), annotation.getComment(), annotation.getCopyright(), annotation.getDate(), annotation.getAuthor());
+ }
+
+ /**
+ * Return the PapyrusDefinitionAnnotation corresponding to the given
+ * EAnnotation
+ *
+ * @param annotation
+ * the annotation to parse
+ * @return a image of the given annotation, with default values if needed.
+ */
+ @Deprecated
+ public static PapyrusDefinitionAnnotation parseEAnnotation(EAnnotation annotation) {
+ return new PapyrusDefinitionAnnotation(org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation.parseEAnnotation(annotation));
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/ProfileRedefinition.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/ProfileRedefinition.java
index c82136b6892..4edec30ae9b 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/ProfileRedefinition.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/ProfileRedefinition.java
@@ -1,330 +1,163 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.definition;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.papyrus.uml.profile.Message;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-
-
-/**
- * <p>
- * this class is used to manage the redefinition of profiles:
- * </p>
- * The normal definition in UML is like this:
- * <ul>
- * <li>Stereotype-->Eclass</li>
- * <li>Enumeration-->EEnumeration :local copy
- * <li>Datatype-->EClass</li>
- * <li>Property--> EReference or EAttribute with ref on local copy</li>
- * <li>PrimitiveType-> Edatatype : local copy</li>
- * </ul>
- * In papyrus:
- * <ul>
- * <li>Stereotype-->Eclass
- * <li>Enumeration-->EEnumeration:local copy
- * <li>Datatype-->EClass
- * <li>Property--> EReference or EAttribute with ref on direct definition
- * <li>PrimitiveType-> Edatatype : local copy
- * </ul>
- */
-public class ProfileRedefinition {
-
- /**
- * this method is used to redefine profile even if it contains subpackages
- * or subprofiles
- *
- * @param thepackage
- * the given profile that we want to define
- * @param definitionAnnotation
- * the definition annotation that is used to create the version
- * annotation
- */
- public static void redefineProfile(Package thepackage, PapyrusDefinitionAnnotation definitionAnnotation) {
- // he wants to define
- if(thepackage instanceof Profile) {
- Profile profile = (Profile)thepackage;
- // get profile definition
- EPackage profileDefinition = profile.getDefinition();
- // collect all EClassifier of the definition
- ArrayList<EClassifier> tempList = new ArrayList<EClassifier>();
- for(int i = 0; i < profileDefinition.getEClassifiers().size(); i++) {
- tempList.add(profileDefinition.getEClassifiers().get(i));
- }
-
- // for all EClass
- Iterator<EClassifier> eClassIter = tempList.iterator();
- while(eClassIter.hasNext()) {
- EClassifier eclassifier = eClassIter.next();
- if(eclassifier instanceof EClass) {
- // redefine Eclass
- redefineEclass((EClass)eclassifier);
- }
- }
-
- // add profile definition annotation
- if(definitionAnnotation != null) {
- profile.getDefinition().getEAnnotations().add(definitionAnnotation.convertToEAnnotation());
- }
- }
- Iterator<Package> it = thepackage.getNestedPackages().iterator();
- while(it.hasNext()) {
- Package p = it.next();
- ProfileRedefinition.redefineProfile(p, definitionAnnotation);
- }
- }
-
- /**
- * redefine only real definition or do nothing
- *
- * @param eclass
- * the given eclass that we want to redefine
- */
- public static void redefineEclass(EClass eclass) {
- if(isADirectDefinition(eclass)) {
- // 1. redefine inheritances
- EList<EClass> eSuperTypes = eclass.getESuperTypes();
-
- /* copy in order to avoid concurrent access */
- ArrayList<EClass> superTypesList = new ArrayList<EClass>();
- for(int j = 0; j < eSuperTypes.size(); j++) {
- superTypesList.add(eSuperTypes.get(j));
- }
- // for each super types :we test if this is a direct definition
- // if not we remove the local copy and replace by direct definition
- Iterator<EClass> superIter = superTypesList.iterator();
- while(superIter.hasNext()) {
- EClass currentSuperClass = superIter.next();
- if(!isADirectDefinition(currentSuperClass)) {
- EClass directSuperClass = (EClass)lookForDirectDefinitionFrom(currentSuperClass);
- eclass.getESuperTypes().remove(currentSuperClass);
- eclass.getESuperTypes().add(directSuperClass);
- }
- }
- // 2.redefine eReferences
- // temp copy of the list
- Iterator<EReference> iterReference = eclass.getEReferences().iterator();
- ArrayList<EReference> referenceList = new ArrayList<EReference>();
- while(iterReference.hasNext()) {
- referenceList.add(iterReference.next());
- }
- // for each reference of the EClass
- Iterator<EReference> refIterator = referenceList.iterator();
- while(refIterator.hasNext()) {
- redefineEReference(refIterator.next(), eclass.getEPackage());
- }
-
- }
- }
-
- /**
- * this class is used to redefine EReference with direct definition
- *
- * @param eReference
- * the given EReference that we want to redefine
- */
- public static void redefineEReference(EReference eReference, EPackage profileDefinition) {
- EReference oldEOpposite = eReference.getEOpposite();
- EClassifier oldType = eReference.getEType();
-
- // 2.1 the type is an EClass
- if(oldType instanceof EClass) {
- // redefine type
- eReference.setEType(lookForDirectDefinitionFrom(oldType));
- // redefine the Opposite
- if(oldEOpposite != null) {
- eReference.setEOpposite(lookForEquivalentEreference((EClass)eReference.getEType(), oldEOpposite));
- }
- }
- }
-
-
- /**
- * return id this Eclass is the real Definition
- *
- * @param eclass
- * the eclass that we want to test
- * @return true if this is the real definition or not is this is a local
- * copy
- */
- public static boolean isADirectDefinition(EClass eclass) {
- if(eclass.getEAnnotations().size() > 0) {
- EAnnotation eAnnotation = eclass.getEAnnotations().get(0);
- if(eAnnotation.getReferences().size() > 0) {
- if(!(eAnnotation.getReferences().get(0) instanceof org.eclipse.uml2.uml.Classifier)) {
- String errMsg = "Problem because of the definition of " + eclass.getName() + " in " + eclass.getEPackage().getNsURI();
- Message.error(errMsg);
- }
- org.eclipse.uml2.uml.Classifier theClassifier = (org.eclipse.uml2.uml.Classifier)eAnnotation.getReferences().get(0);
- Package nearestPackage = theClassifier.getNearestPackage();
-
- if(nearestPackage instanceof Profile) {
- if(eclass.equals(((Profile)nearestPackage).getDefinition(theClassifier))) {
- return true;
- }
- }
- }
- }
- return false;
- }
-
- /**
- * look for the real definition of the stereotype where the EClass may be
- * the definition
- *
- * @param eclass
- * that maybe the real definition (maybe a local copy of
- * definition)
- * @return the real definition or the itself
- */
- public static EClassifier lookForDirectDefinitionFrom(EClassifier eClassifier) {
- if(eClassifier.getEAnnotations().size() > 0) {
- EAnnotation eAnnotation = eClassifier.getEAnnotations().get(0);
- if(eAnnotation.getReferences().size() > 0) {
- org.eclipse.uml2.uml.Classifier theClassifier = (org.eclipse.uml2.uml.Classifier)eAnnotation.getReferences().get(0);
- Package nearestPackage = theClassifier.getNearestPackage();
- if(nearestPackage instanceof Profile) {
- return (EClassifier)((Profile)nearestPackage).getDefinition(theClassifier);
- }
- return eClassifier;
- }
- }
- return eClassifier;
- }
-
- /**
- * this method is used to look for an EReference equivalent to a given
- * EReference same name and type
- *
- * @param eclass
- * the given EClass where we look for the equivalent EReference
- * @param eReference
- * the given EReference
- * @return the return EReference or null
- */
- private static EReference lookForEquivalentEreference(EClass eclass, EReference eReference) {
- Iterator<EReference> refIterator = eclass.getEReferences().iterator();
- while(refIterator.hasNext()) {
- EReference currentEReference = refIterator.next();
- if(currentEReference.getName().equals(eReference.getName())) {
- if(currentEReference.getEType().getName().endsWith(eReference.getEType().getName())) {
- return currentEReference;
- }
- }
- }
- return null;
- }
-
- /**
- * this method is used to suppress all local copy of EClass in each Profile.
- *
- * @param thePackage
- * that we want to clean
- */
- public static void cleanProfile(Package thePackage) {
- if(thePackage instanceof Profile) {
- Profile profile = (Profile)thePackage;
- // get profile definition
- EPackage profileDefinition = profile.getDefinition();
-
- // collect all EClassifier of the definition
- ArrayList<EClassifier> tempList = new ArrayList<EClassifier>();
- for(int i = 0; i < profileDefinition.getEClassifiers().size(); i++) {
- tempList.add(profileDefinition.getEClassifiers().get(i));
- }
-
- // for all EClass
- Iterator<EClassifier> eClassIter = tempList.iterator();
- while(eClassIter.hasNext()) {
- EClassifier eclassifier = eClassIter.next();
-
- if(eclassifier instanceof EClass) {
-
- // this is a direct Definition?
- if(!isADirectDefinition((EClass)eclassifier)) {
- // no, so it is removed
- profileDefinition.getEClassifiers().remove(eclassifier);
- }
-
- }
- }
- }
- Iterator<Package> it = thePackage.getNestedPackages().iterator();
- while(it.hasNext()) {
- Package p = it.next();
- ProfileRedefinition.cleanProfile(p);
- }
- }
-
-
- /**
- * this method is used to created an EAttribute from an Ereference
- *
- * @param container
- * the Eclass that will contain the eattribute
- * @param eReference
- * from this, the eattribute will be created
- * @return the created Eattribute
- */
- public static EAttribute createEAttribute(EClass container, EReference eReference) {
-
- EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
- eAttribute.setEType(eReference.getEType());
- eAttribute.setName(eReference.getName());
- eAttribute.setChangeable(eReference.isChangeable());
- eAttribute.setLowerBound(eReference.getLowerBound());
- eAttribute.setUpperBound(eReference.getUpperBound());
- eAttribute.setOrdered(eReference.isOrdered());
- eAttribute.setDerived(eReference.isDerived());
- eAttribute.setTransient(eReference.isTransient());
- eAttribute.setUnique(eReference.isUnique());
- eAttribute.setUnsettable(eReference.isUnsettable());
- eAttribute.setVolatile(eReference.isVolatile());
- container.getEStructuralFeatures().add(eAttribute);
- return eAttribute;
- }
-
-
-
- /**
- * this method is used to obtain the classifier from its definition
- *
- * @param eclass
- * that is a definition
- * @return the classifier that produce this definition
- */
- public static Classifier getUMLClassifierFromDefinition(EClassifier eclass) {
- if(eclass.getEAnnotations().size() > 0) {
- EAnnotation eAnnotation = eclass.getEAnnotations().get(0);
- if(eAnnotation.getReferences().size() > 0) {
- org.eclipse.uml2.uml.Classifier theClassifier = (org.eclipse.uml2.uml.Classifier)eAnnotation.getReferences().get(0);
- return theClassifier;
- }
- }
- return null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.definition;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Package;
+
+
+
+/**
+ * <p>
+ * this class is used to manage the redefinition of profiles:
+ * </p>
+ * The normal definition in UML is like this:
+ * <ul>
+ * <li>Stereotype-->Eclass</li>
+ * <li>Enumeration-->EEnumeration :local copy
+ * <li>Datatype-->EClass</li>
+ * <li>Property--> EReference or EAttribute with ref on local copy</li>
+ * <li>PrimitiveType-> Edatatype : local copy</li>
+ * </ul>
+ * In papyrus:
+ * <ul>
+ * <li>Stereotype-->Eclass
+ * <li>Enumeration-->EEnumeration:local copy
+ * <li>Datatype-->EClass
+ * <li>Property--> EReference or EAttribute with ref on direct definition
+ * <li>PrimitiveType-> Edatatype : local copy
+ * </ul>
+ * .
+ *
+ *
+ * @deprecated API was moved to the plugin org.eclipse.papyrus.uml.tools for Bug 435995.
+ * It was preserved for standard releases of Papyrus 1.0.0
+ * @see org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition
+ */
+@Deprecated
+public class ProfileRedefinition extends org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition {
+
+
+ /**
+ * Redefine profile.
+ *
+ * @param thepackage
+ * the thepackage
+ * @param definitionAnnotation
+ * the definition annotation
+ */
+ @Deprecated
+ public static void redefineProfile(Package thepackage, org.eclipse.papyrus.uml.profile.definition.PapyrusDefinitionAnnotation definitionAnnotation) {
+ org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition.redefineProfile(thepackage, definitionAnnotation);
+ }
+
+ /**
+ * redefine only real definition or do nothing.
+ *
+ * @param eclass
+ * the given eclass that we want to redefine
+ */
+ @Deprecated
+ public static void redefineEclass(EClass eclass) {
+ org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition.redefineEclass(eclass);
+ }
+
+ /**
+ * Redefine e reference.
+ *
+ * @param eReference
+ * the e reference
+ * @param profileDefinition
+ * the profile definition
+ */
+ @Deprecated
+ public static void redefineEReference(EReference eReference, EPackage profileDefinition) {
+ org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition.redefineEReference(eReference, profileDefinition);
+ }
+
+
+ /**
+ * return id this Eclass is the real Definition.
+ *
+ * @param eclass
+ * the eclass that we want to test
+ * @return true if this is the real definition or not is this is a local
+ * copy
+ */
+ @Deprecated
+ public static boolean isADirectDefinition(EClass eclass) {
+ return org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition.isADirectDefinition(eclass);
+ }
+
+ /**
+ * look for the real definition of the stereotype where the EClass may be
+ * the definition.
+ *
+ * @param eClassifier
+ * the e classifier
+ * @return the real definition or the itself
+ */
+ @Deprecated
+ public static EClassifier lookForDirectDefinitionFrom(EClassifier eClassifier) {
+ return org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition.lookForDirectDefinitionFrom(eClassifier);
+ }
+
+
+ /**
+ * this method is used to suppress all local copy of EClass in each Profile.
+ *
+ * @param thePackage
+ * that we want to clean
+ */
+ @Deprecated
+ public static void cleanProfile(Package thePackage) {
+ org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition.cleanProfile(thePackage);
+ }
+
+
+ /**
+ * this method is used to created an EAttribute from an Ereference.
+ *
+ * @param container
+ * the Eclass that will contain the eattribute
+ * @param eReference
+ * from this, the eattribute will be created
+ * @return the created Eattribute
+ */
+ @Deprecated
+ public static EAttribute createEAttribute(EClass container, EReference eReference) {
+ return org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition.createEAttribute(container, eReference);
+ }
+
+
+
+ /**
+ * this method is used to obtain the classifier from its definition.
+ *
+ * @param eclass
+ * that is a definition
+ * @return the classifier that produce this definition
+ */
+ @Deprecated
+ public static Classifier getUMLClassifierFromDefinition(EClassifier eclass) {
+ return org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition.getUMLClassifierFromDefinition(eclass);
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/Version.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/Version.java
index 941250609e3..59a5017f9b7 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/Version.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/definition/Version.java
@@ -1,155 +1,80 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.definition;
-
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-
-/**
- * Representation of the version number for a profile
- */
-public class Version {
-
- /** major version number */
- protected int major;
-
- /** minor version number */
- protected int minor;
-
- /** micro version number */
- protected int micro;
-
- /** separator for the version string */
- private final static String SEPARATOR = ".";
-
- /** The empty version "0.0.0". Equivalent to calling <code>new Version(0,0,0)</code> */
- public static final Version emptyVersion = new Version(0, 0, 0);
-
- /**
- * Creates a new Version
- *
- * @param major
- * the major version value (should be positive)
- * @param minor
- * the minor version value (should be positive)
- * @param micro
- * the micro version value (should be positive)
- */
- public Version(int major, int minor, int micro) {
- this.major = major;
- this.minor = minor;
- this.micro = micro;
- }
-
- /**
- * Creates a new Version, parsing a string value
- *
- * @param value
- * the string representing the version
- */
- public Version(String value) throws IllegalArgumentException {
- try {
- StringTokenizer st = new StringTokenizer(value, SEPARATOR, true);
- major = Integer.parseInt(st.nextToken());
-
- if(st.hasMoreTokens()) {
- st.nextToken(); // consume delimiter
- minor = Integer.parseInt(st.nextToken());
-
- if(st.hasMoreTokens()) {
- st.nextToken(); // consume delimiter
- micro = Integer.parseInt(st.nextToken());
-
- if(st.hasMoreTokens()) {
- throw new IllegalArgumentException("invalid format");
- }
- }
- }
- } catch (NoSuchElementException e) {
- throw new IllegalArgumentException("invalid format");
- }
- }
-
- /**
- * Returns the major version number
- *
- * @return The major version number
- */
- public int getMajor() {
- return major;
- }
-
- /**
- * Returns the minor version number
- *
- * @return The minor version number
- */
- public int getMinor() {
- return minor;
- }
-
- /**
- * Returns the micro version number
- *
- * @return The micro version number
- */
- public int getMicro() {
- return micro;
- }
-
- /**
- * Updates the version numbers
- *
- * @param major
- * the new major value
- * @param minor
- * the new minor value
- * @param micro
- * the new micro value
- */
- public void updateVersion(int major, int minor, int micro) {
- this.major = major;
- this.minor = minor;
- this.micro = micro;
- }
-
- // org.osgi.framework.Version
- /**
- * Creates a version given the specific String
- *
- * @param version
- * the string to parse
- * @return the version value corresponding to the String
- */
- public static Version parseVersion(String version) throws IllegalArgumentException {
- if(version == null) {
- return emptyVersion;
- }
-
- version = version.trim();
- if(version.length() == 0) {
- return emptyVersion;
- }
- return new Version(version);
- }
-
- /**
- * Returns the string corresponding to the version
- */
- @Override
- public String toString() {
- return major + SEPARATOR + minor + SEPARATOR + micro;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.definition;
+
+
+
+
+/**
+ * Representation of the version number for a profile
+ *
+ * @deprecated API was moved to the plugin org.eclipse.papyrus.uml.tools for Bug 435995.
+ * It was preserved for standard releases of Papyrus 1.0.0
+ * @see org.eclipse.papyrus.uml.tools.profile.definition.Version
+ */
+@Deprecated
+public class Version extends org.eclipse.papyrus.uml.tools.profile.definition.Version {
+
+
+ /** The empty version "0.0.0". Equivalent to calling <code>new Version(0,0,0)</code> */
+ @Deprecated
+ public static final Version emptyVersion = new Version(0, 0, 0);
+
+ /**
+ * Instantiates a new version.
+ *
+ * @param major
+ * the major
+ * @param minor
+ * the minor
+ * @param micro
+ * the micro
+ */
+ public Version(int major, int minor, int micro) {
+ super(major, minor, micro);
+ }
+
+ /** Copy constructor for legacy support. */
+ Version(org.eclipse.papyrus.uml.tools.profile.definition.Version version) {
+ this(version.getMajor(), version.getMinor(), version.getMicro());
+ }
+
+ /**
+ * Instantiates a new version.
+ *
+ * @param value
+ * the value
+ */
+ public Version(String value) {
+ super(value);
+ }
+
+ /**
+ * Creates a version given the specific String
+ *
+ * @param version
+ * the string to parse
+ * @return the version value corresponding to the String
+ */
+ @Deprecated
+ public static Version parseVersion(String version) throws IllegalArgumentException {
+ return new Version(org.eclipse.papyrus.uml.tools.profile.definition.Version.parseVersion(version));
+ }
+
+
+
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/AppliedProfileContentProvider.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/AppliedProfileContentProvider.java
deleted file mode 100644
index 0ef33fdbdc5..00000000000
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/AppliedProfileContentProvider.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.providers;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
-import org.eclipse.papyrus.uml.tools.utils.ProfileUtil;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-
-
-public class AppliedProfileContentProvider extends AbstractStaticContentProvider implements ITreeContentProvider {
-
- protected Package rootPackage;
-
- public AppliedProfileContentProvider(Package rootPackage) {
- this.rootPackage = rootPackage;
- }
-
- public Object[] getElements() {
- return new Package[]{ rootPackage };
- }
-
- public Object[] getChildren(Object parentElement) {
- if(parentElement instanceof Profile) {
- return new Object[0];
- }
-
- if(parentElement instanceof Package) {
- Package parentPackage = (Package)parentElement;
- List<Package> children = new LinkedList<Package>();
- children.addAll(parentPackage.getNestedPackages());
-
- List<Profile> appliedProfiles = new LinkedList<Profile>(parentPackage.getAppliedProfiles());
- for(Profile profile : appliedProfiles) {
- if(ProfileUtil.isDirty(parentPackage, profile)) {
- children.add(profile);
- }
- }
-
- return children.toArray();
- }
- return new Object[0];
- }
-
- public Object getParent(Object element) {
- if(element instanceof Profile) {
- return null;
- }
-
- if(element instanceof Package) {
- return ((Package)element).getNestingPackage();
- }
-
- return null;
- }
-
- public boolean hasChildren(Object element) {
- return getChildren(element).length > 0;
- }
-
-
-}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/AppliedProfileLabelProvider.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/AppliedProfileLabelProvider.java
deleted file mode 100644
index 2f6660e940f..00000000000
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/AppliedProfileLabelProvider.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.providers;
-
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Profile;
-
-public class AppliedProfileLabelProvider extends StyledCellLabelProvider {
-
- private final ILabelProvider umlLabelProvider = new UMLLabelProvider();
-
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- int columnIndex = cell.getColumnIndex();
-
- StyledString styledText = getStyledText(element, columnIndex);
-
- cell.setText(styledText.getString());
- cell.setStyleRanges(styledText.getStyleRanges());
- cell.setImage(getImage(element, columnIndex));
- }
-
- protected StyledString getStyledText(Object element, int columnIndex) {
- if(columnIndex == 1 && element instanceof Profile) {
- Profile profile = (Profile)element;
-
- StyledString styledString = new StyledString(profile.getQualifiedName());
-
- return styledString;
- }
-
- return new StyledString(getText(element, columnIndex));
- }
-
- protected String getText(Object element, int columnIndex) {
- switch(columnIndex) {
- case 0:
- return umlLabelProvider.getText(element);
- case 1:
- if(element instanceof Profile) {
- return ((Profile)element).getQualifiedName();
- }
- default:
- return "";
- }
- }
-
- protected Image getImage(Object element, int columnIndex) {
- switch(columnIndex) {
- case 0:
- return umlLabelProvider.getImage(element);
- case 1:
- if(element instanceof Profile) {
- return umlLabelProvider.getImage(element);
- }
- default:
- return null;
- }
- }
-
-}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/ProfileApplicationContentProvider.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/ProfileApplicationContentProvider.java
new file mode 100644
index 00000000000..0fe99ae7af7
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/ProfileApplicationContentProvider.java
@@ -0,0 +1,125 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.providers;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
+import org.eclipse.papyrus.uml.tools.utils.ProfileUtil;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+
+
+/**
+ * Content provider for dialogs of profile application migration.
+ * <p>
+ * Give Packages and Profile Application of dirty profile starting from a root Package.
+ * </p>
+ */
+public class ProfileApplicationContentProvider extends AbstractStaticContentProvider implements ITreeContentProvider {
+
+ /** The root package. */
+ protected Package rootPackage = null;
+
+ /**
+ * Instantiates a new profile application content provider.
+ *
+ * @param rootPackage
+ * the root package
+ */
+ public ProfileApplicationContentProvider(Package rootPackage) {
+ this.rootPackage = rootPackage;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements()
+ *
+ * @return
+ */
+ public Object[] getElements() {
+ return new Package[]{ rootPackage };
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ *
+ * @param parentElement
+ * @return
+ */
+ public Object[] getChildren(Object parentElement) {
+ Object[] children = null;
+
+ // Case 1 : Element is a Profile then stop exploration
+ if(parentElement instanceof ProfileApplication) {
+ children = new Object[0];
+ } else if(parentElement instanceof Package) {
+ // Case 2 : Element is Package
+ Package parentPackage = (Package)parentElement;
+
+ List<Object> childrenList = new LinkedList<Object>();
+
+
+ // Parse applied profiles of parent to find dirty ones and get profile application
+ List<Profile> appliedProfiles = new LinkedList<Profile>(parentPackage.getAppliedProfiles());
+ for(Profile profile : appliedProfiles) {
+ if(ProfileUtil.isDirty(parentPackage, profile)) {
+ childrenList.add(parentPackage.getProfileApplication(profile));
+ }
+ }
+
+ // Get nested packages
+ childrenList.addAll(parentPackage.getNestedPackages());
+
+ children = childrenList.toArray();
+ } else {
+ // Default : no child
+ children = new Object[0];
+ }
+
+
+ return children;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ public Object getParent(Object element) {
+ Object parent = null;
+
+ if(element instanceof Package) {
+ parent = ((Package)element).getNestingPackage();
+ } else if(element instanceof ProfileApplication) {
+ parent = ((ProfileApplication)element).getApplyingPackage();
+ }
+
+ return parent;
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/ProfileApplicationLabelProvider.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/ProfileApplicationLabelProvider.java
new file mode 100644
index 00000000000..c3da5255d9d
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/providers/ProfileApplicationLabelProvider.java
@@ -0,0 +1,205 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 435995
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.providers;
+
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.papyrus.uml.profile.utils.Util;
+import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants;
+import org.eclipse.papyrus.uml.tools.profile.definition.Version;
+import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+
+/**
+ * Label provider for Profile application. It decorates structure returned by {@link ProfileApplicationContentProvider}.
+ */
+public class ProfileApplicationLabelProvider extends StyledCellLabelProvider {
+
+ /** The Constant PACKAGE_ELEMENT_COLUMN_INDEX. */
+ private static final int PACKAGE_ELEMENT_COLUMN_INDEX = 0;
+
+ /** The Constant PROFILE_APPLICATION_UPDATE_VERSION_COLUMN_INDEX. */
+ private static final int PROFILE_APPLICATION_UPDATE_VERSION_COLUMN_INDEX = 3;
+
+ /** The Constant PROFILE_APPLICATION_NAME_COLUMN_INDEX. */
+ private static final int PROFILE_APPLICATION_NAME_COLUMN_INDEX = 2;
+
+ /** The Constant PROFILE_APPLICATION_VERSION_COLUMN_INDEX. */
+ private static final int PROFILE_APPLICATION_VERSION_COLUMN_INDEX = 1;
+
+ /** The UML label provider. */
+ private final ILabelProvider umlLabelProvider = new UMLLabelProvider();
+
+
+ /**
+ * Update.
+ *
+ * @param cell
+ * the cell
+ * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
+ */
+ @Override
+ public void update(ViewerCell cell) {
+ Object element = cell.getElement();
+ int columnIndex = cell.getColumnIndex();
+
+ StyledString styledText = getStyledText(element, columnIndex);
+
+ cell.setText(styledText.getString());
+ cell.setStyleRanges(styledText.getStyleRanges());
+ cell.setImage(getImage(element, columnIndex));
+ }
+
+ /**
+ * Gets the styled text.
+ *
+ * @param element
+ * the element
+ * @param columnIndex
+ * the column index
+ * @return the styled text
+ */
+ protected StyledString getStyledText(Object element, int columnIndex) {
+ return new StyledString(getText(element, columnIndex));
+ }
+
+ /**
+ * Return the last version of profile applied to UML model.
+ *
+ * @param profileApplication
+ * the profile application
+ * @return Known applied version
+ */
+ private Version extractProfileApplicationVersion(ProfileApplication profileApplication) {
+ Version version = null;
+
+ EAnnotation versionAnnotation = profileApplication.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ if(versionAnnotation == null) {
+ EPackage appliedDefinition = profileApplication.getAppliedDefinition();
+ if(appliedDefinition != null) {
+ versionAnnotation = appliedDefinition.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ }
+ }
+
+ if(versionAnnotation != null) {
+ String versionValue = versionAnnotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY);
+ version = new Version(versionValue);
+ }
+
+ if(version == null) {
+ version = Version.emptyVersion;
+ }
+
+ return version;
+ }
+
+ /**
+ * Gets the text.
+ *
+ * @param element
+ * the element
+ * @param columnIndex
+ * the column index
+ * @return the text
+ */
+ protected String getText(Object element, int columnIndex) {
+ String result = null;
+
+ // Case 1: Element is a Profile Application
+ if(element instanceof ProfileApplication) {
+ ProfileApplication profileApplication = (ProfileApplication)element;
+
+ switch(columnIndex) {
+ case PACKAGE_ELEMENT_COLUMN_INDEX:
+ result = umlLabelProvider.getText(profileApplication.getAppliedProfile());
+ break;
+ case PROFILE_APPLICATION_VERSION_COLUMN_INDEX:
+ Version profileVersion = extractProfileApplicationVersion(profileApplication);
+ result = profileVersion.toString();
+ break;
+ case PROFILE_APPLICATION_NAME_COLUMN_INDEX:
+ Profile appliedProfile = profileApplication.getAppliedProfile();
+
+ if(appliedProfile == null) {
+ result = "<Missing Profile>";
+ } else if (appliedProfile.eIsProxy()) {
+ EPackage definition = profileApplication.getAppliedDefinition();
+ if(definition != null) {
+ result = umlLabelProvider.getText(definition);
+ } else {
+ result = "<Unresolved Profile>";
+ }
+ } else {
+ result = appliedProfile.getQualifiedName();
+ }
+ break;
+ case PROFILE_APPLICATION_UPDATE_VERSION_COLUMN_INDEX:
+ Version latestProfileVersion = Util.getProfileDefinitionVersion(profileApplication.getAppliedProfile());
+ result = latestProfileVersion.toString();
+ break;
+ default:
+ //Nothing to do
+ break;
+ }
+ } else {
+ switch(columnIndex) {
+ case PACKAGE_ELEMENT_COLUMN_INDEX:
+ result = umlLabelProvider.getText(element);
+ break;
+ default:
+ //Nothing to do
+ break;
+ }
+ }
+
+ return (result == null) ? "" : result; //$NON-NLS-1$
+ }
+
+ /**
+ * Gets the image.
+ *
+ * @param element
+ * the element
+ * @param columnIndex
+ * the column index
+ * @return the image
+ */
+ protected Image getImage(Object element, int columnIndex) {
+ switch(columnIndex) {
+ case PACKAGE_ELEMENT_COLUMN_INDEX:
+ return umlLabelProvider.getImage(element);
+ case PROFILE_APPLICATION_NAME_COLUMN_INDEX:
+ if(element instanceof ProfileApplication) {
+ return umlLabelProvider.getImage(((ProfileApplication)element).getAppliedProfile());
+ }
+ default:
+ return null;
+ }
+ }
+
+ /**
+ * @see org.eclipse.jface.viewers.StyledCellLabelProvider#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ umlLabelProvider.dispose();
+ super.dispose();
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ReapplyProfilesService.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ReapplyProfilesService.java
index fc7fee822c2..49b59f38510 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ReapplyProfilesService.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ReapplyProfilesService.java
@@ -1,211 +1,211 @@
-/*****************************************************************************
- * Copyright (c) 2013, 2014 CEA LIST and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 434302
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.service;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Map;
-
-import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.NotFoundException;
-import org.eclipse.papyrus.infra.core.services.EditorLifecycleEventListener;
-import org.eclipse.papyrus.infra.core.services.EditorLifecycleManager;
-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.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.uml.modelrepair.service.IStereotypeRepairService;
-import org.eclipse.papyrus.uml.profile.Activator;
-import org.eclipse.papyrus.uml.profile.service.ui.RefreshProfileDialog;
-import org.eclipse.papyrus.uml.profile.validation.ProfileValidationHelper;
-import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
-import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.papyrus.uml.tools.utils.ProfileUtil;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-
-/**
- * If a local profile is applied on this model, and this profile has been
- * redefined recently, the user will be asked whether the profile should
- * be reapplied.
- *
- *
- * @author Camille Letavernier
- *
- */
-public class ReapplyProfilesService implements IService, EditorLifecycleEventListener {
-
- private ServicesRegistry servicesRegistry;
-
- private org.eclipse.uml2.uml.Package rootPackage;
-
- private IStereotypeRepairService stereotypeRepairService;
-
- /**
- * {@inheritDoc}
- */
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
- this.servicesRegistry = servicesRegistry;
- }
-
- /**
- * {@inheritDoc}
- */
- public void startService() throws ServiceException {
- try {
- EditorLifecycleManager lifecyleManager = servicesRegistry.getService(EditorLifecycleManager.class);
- lifecyleManager.addEditorLifecycleEventsListener(this);
- } catch (ServiceException ex) {
- return; //If the EditorLifecycleManager is not present, do nothing
- }
-
- try {
- stereotypeRepairService = servicesRegistry.getService(IStereotypeRepairService.class);
- } catch (ServiceException ex) {
- // If there's no stereotype repair service, then we don't have to worry about waiting for it
- }
- }
-
- protected void checkProfiles(IMultiDiagramEditor editor) {
- ModelSet modelSet;
- try {
- modelSet = servicesRegistry.getService(ModelSet.class);
- } catch (ServiceException ex) {
- return;
- }
-
- UmlModel umlModel = (UmlModel)modelSet.getModel(UmlModel.MODEL_ID);
- if(umlModel == null) {
- return;
- }
-
- rootPackage = getRootPackage(umlModel);
-
- if(rootPackage == null) {
- return;
- }
-
- checkAndRefreshProfiles(rootPackage, editor);
- }
-
- protected Package getRootPackage(UmlModel umlModel) {
- try {
- EObject root = umlModel.lookupRoot();
- if(root instanceof Package) {
- return (Package)root;
- }
- } catch (NotFoundException ex) {
- //Ignore the exception: On diagram creation, the root isn't defined yet.
- //There's not profile application, and nothing to do.
- //Activator.log.error(ex);
- }
- return null;
- }
-
- protected boolean checkAndRefreshProfiles(Package currentPackage, IMultiDiagramEditor editor) {
- if(Display.getCurrent() == null) {
- return false;
- }
-
- for(Profile profile : currentPackage.getAppliedProfiles()) {
- if(ProfileUtil.isDirty(currentPackage, profile)) {
- RefreshProfileDialog dialog = new RefreshProfileDialog(editor.getSite().getShell(), this.rootPackage);
- dialog.setCallback(getCallback(dialog));
- dialog.open();
- return true;
- }
- }
-
- for(Package nestedPackage : currentPackage.getNestedPackages()) {
- if(checkAndRefreshProfiles(nestedPackage, editor)) {
- return true;
- }
- }
-
- return false;
- }
-
- protected Runnable getCallback(final RefreshProfileDialog dialog) {
- return new Runnable() {
-
- public void run() {
- Map<Package, Collection<Profile>> profilesToReapply = dialog.getProfilesToReapply();
- EditingDomain domain = EMFHelper.resolveEditingDomain(rootPackage);
-
- if(domain instanceof TransactionalEditingDomain) {
-
- //Create a flat list of profiles, for validation
- Collection<Profile> allProfiles = new LinkedList<Profile>();
- for(Collection<Profile> profiles : profilesToReapply.values()) {
- allProfiles.addAll(profiles);
- }
-
- //Validate and apply
- if(ProfileValidationHelper.checkApplicableProfiles(Display.getCurrent().getActiveShell(), allProfiles)) {
- CompoundCommand command = new CompoundCommand();
- for(Map.Entry<Package, Collection<Profile>> profiles : profilesToReapply.entrySet()) {
- command.append(new ApplyProfileCommand(profiles.getKey(), profiles.getValue(), (TransactionalEditingDomain)domain));
- }
-
- domain.getCommandStack().execute(command);
- }
-
- } else {
- Activator.log.error(new IllegalArgumentException("Cannot reapply profiles on Package " + rootPackage.getQualifiedName() + ". The EditingDomain cannot be found"));
- }
-
- }
-
- };
- }
-
- /**
- * {@inheritDoc}
- */
- public void disposeService() throws ServiceException {
- this.rootPackage = null;
- this.stereotypeRepairService = null;
- this.servicesRegistry = null;
- }
-
- public void postInit(IMultiDiagramEditor editor) {
- //Nothing
- }
-
- public void postDisplay(final IMultiDiagramEditor editor) {
- if(stereotypeRepairService == null) {
- // Just check profiles, now
- checkProfiles(editor);
- } else {
- // Ensure that we only kick in the profile migration after any pending repair has completed
- stereotypeRepairService.getPostRepairExecutor().execute(new Runnable() {
-
- public void run() {
- checkProfiles(editor);
- }
- });
- }
- }
-
- public void beforeClose(IMultiDiagramEditor editor) {
- //Nothing
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013, 2014 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 434302
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 435995
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.service;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.NotFoundException;
+import org.eclipse.papyrus.infra.core.services.EditorLifecycleEventListener;
+import org.eclipse.papyrus.infra.core.services.EditorLifecycleManager;
+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.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.uml.modelrepair.service.IStereotypeRepairService;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.papyrus.uml.profile.service.ui.RefreshProfileDialog;
+import org.eclipse.papyrus.uml.profile.validation.ProfileValidationHelper;
+import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
+import org.eclipse.papyrus.uml.tools.model.UmlModel;
+import org.eclipse.papyrus.uml.tools.utils.ProfileUtil;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+
+/**
+ * If a local profile is applied on this model, and this profile has been
+ * redefined recently, the user will be asked whether the profile should
+ * be reapplied.
+ *
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class ReapplyProfilesService implements IService, EditorLifecycleEventListener {
+
+ private ServicesRegistry servicesRegistry;
+
+ private org.eclipse.uml2.uml.Package rootPackage;
+
+ private IStereotypeRepairService stereotypeRepairService;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+ this.servicesRegistry = servicesRegistry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void startService() throws ServiceException {
+ try {
+ EditorLifecycleManager lifecyleManager = servicesRegistry.getService(EditorLifecycleManager.class);
+ lifecyleManager.addEditorLifecycleEventsListener(this);
+ } catch (ServiceException ex) {
+ return; //If the EditorLifecycleManager is not present, do nothing
+ }
+
+ try {
+ stereotypeRepairService = servicesRegistry.getService(IStereotypeRepairService.class);
+ } catch (ServiceException ex) {
+ // If there's no stereotype repair service, then we don't have to worry about waiting for it
+ }
+ }
+
+ protected void checkProfiles(IMultiDiagramEditor editor) {
+ ModelSet modelSet;
+ try {
+ modelSet = servicesRegistry.getService(ModelSet.class);
+ } catch (ServiceException ex) {
+ return;
+ }
+
+ UmlModel umlModel = (UmlModel)modelSet.getModel(UmlModel.MODEL_ID);
+ if(umlModel == null) {
+ return;
+ }
+
+ rootPackage = getRootPackage(umlModel);
+
+ if(rootPackage == null) {
+ return;
+ }
+
+ checkAndRefreshProfiles(rootPackage, editor);
+ }
+
+ protected Package getRootPackage(UmlModel umlModel) {
+ try {
+ EObject root = umlModel.lookupRoot();
+ if(root instanceof Package) {
+ return (Package)root;
+ }
+ } catch (NotFoundException ex) {
+ //Ignore the exception: On diagram creation, the root isn't defined yet.
+ //There's not profile application, and nothing to do.
+ //Activator.log.error(ex);
+ }
+ return null;
+ }
+
+ protected boolean checkAndRefreshProfiles(Package currentPackage, IMultiDiagramEditor editor) {
+ if(Display.getCurrent() == null) {
+ return false;
+ }
+
+ for(Profile profile : currentPackage.getAppliedProfiles()) {
+ if(ProfileUtil.isDirty(currentPackage, profile)) {
+ RefreshProfileDialog dialog = new RefreshProfileDialog(editor.getSite().getShell(), this.rootPackage);
+ dialog.setCallback(getCallback(dialog));
+ dialog.open();
+ return true;
+ }
+ }
+
+ for(Package nestedPackage : currentPackage.getNestedPackages()) {
+ if(checkAndRefreshProfiles(nestedPackage, editor)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected Runnable getCallback(final RefreshProfileDialog dialog) {
+ return new Runnable() {
+
+ public void run() {
+ Map<Package, Collection<Profile>> profilesToReapply = dialog.getProfilesToReapply();
+ EditingDomain domain = EMFHelper.resolveEditingDomain(rootPackage);
+
+ if(domain instanceof TransactionalEditingDomain) {
+
+ //Create a flat list of profiles, for validation
+ Collection<Profile> allProfiles = new LinkedList<Profile>();
+ for(Collection<Profile> profiles : profilesToReapply.values()) {
+ allProfiles.addAll(profiles);
+ }
+
+ //Validate and apply
+ if(ProfileValidationHelper.checkApplicableProfiles(Display.getCurrent().getActiveShell(), allProfiles)) {
+ CompoundCommand command = new CompoundCommand();
+ for(Map.Entry<Package, Collection<Profile>> profiles : profilesToReapply.entrySet()) {
+ command.append(new ApplyProfileCommand(profiles.getKey(), profiles.getValue(), (TransactionalEditingDomain)domain));
+ }
+
+ domain.getCommandStack().execute(command);
+ }
+
+ } else {
+ Activator.log.error(new IllegalArgumentException("Cannot reapply profiles on Package " + rootPackage.getQualifiedName() + ". The EditingDomain cannot be found"));
+ }
+
+ }
+
+ };
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void disposeService() throws ServiceException {
+ this.rootPackage = null;
+ this.stereotypeRepairService = null;
+ this.servicesRegistry = null;
+ }
+
+ public void postInit(IMultiDiagramEditor editor) {
+ //Nothing
+ }
+
+ public void postDisplay(final IMultiDiagramEditor editor) {
+ if(stereotypeRepairService == null) {
+ // Just check profiles, now
+ checkProfiles(editor);
+ } else {
+ // Ensure that we only kick in the profile migration after any pending repair has completed
+ stereotypeRepairService.getPostRepairExecutor().execute(new Runnable() {
+
+ public void run() {
+ checkProfiles(editor);
+ }
+ });
+ }
+ }
+
+ public void beforeClose(IMultiDiagramEditor editor) {
+ //Nothing
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ui/RefreshProfileDialog.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ui/RefreshProfileDialog.java
index 5993559d5cc..ee3c087fcfb 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ui/RefreshProfileDialog.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/service/ui/RefreshProfileDialog.java
@@ -1,178 +1,187 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.service.ui;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.TableLayout;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.papyrus.uml.profile.providers.AppliedProfileContentProvider;
-import org.eclipse.papyrus.uml.profile.providers.AppliedProfileLabelProvider;
-import org.eclipse.papyrus.uml.tools.utils.ProfileUtil;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.TreeEditor;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.dialogs.SelectionDialog;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-
-public class RefreshProfileDialog extends SelectionDialog {
-
- protected final Map<Package, Collection<Profile>> profilesToReapply;
-
- protected Runnable callback;
-
- protected Package rootPackage;
-
- public RefreshProfileDialog(Shell parentShell, Package rootPackage) {
- super(parentShell);
- setBlockOnOpen(false);
- this.rootPackage = rootPackage;
- profilesToReapply = new HashMap<Package, Collection<Profile>>();
- setTitle("Some profiles have changed");
- }
-
- public void setCallback(Runnable callback) {
- this.callback = callback;
- }
-
- @Override
- public void create() {
- super.create();
-
- Label descriptionLabel = new Label(getDialogArea(), SWT.WRAP);
- descriptionLabel.setText("Some local profiles have changed. Select the ones you want to re-apply");
-
- TreeViewer viewer = new TreeViewer(getDialogArea());
- viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- Tree tree = viewer.getTree();
-
- TableLayout layout = new TableLayout();
-
- TreeColumn propertyColumn = new TreeColumn(tree, SWT.CENTER);
- propertyColumn.setText("Package");
- layout.addColumnData(new ColumnWeightData(30, 300, true));
-
- TreeColumn ownerColumn = new TreeColumn(tree, SWT.CENTER);
- ownerColumn.setText("Profile");
- layout.addColumnData(new ColumnWeightData(60, 150, true));
-
- TreeColumn checkColumn = new TreeColumn(tree, SWT.CENTER);
- checkColumn.setText("Reapply");
- layout.addColumnData(new ColumnWeightData(10, 70, true));
-
- tree.setLayout(layout);
- tree.setHeaderVisible(true);
-
- viewer.setContentProvider(new AppliedProfileContentProvider(rootPackage));
- viewer.setLabelProvider(new AppliedProfileLabelProvider());
-
- viewer.setInput(new Object());
-
- installEditors(viewer);
-
- getDialogArea().layout();
-
- getShell().pack();
- }
-
- protected void installEditors(TreeViewer viewer) {
- viewer.expandAll();
- for(TreeItem item : viewer.getTree().getItems()) {
- installEditors(item, rootPackage);
- }
- }
-
- protected void installEditors(TreeItem treeItem, final Package parentPackage) {
- Package currentPackage = (Package)treeItem.getData();
- if(currentPackage instanceof Profile) {
-
- final Profile profile = (Profile)currentPackage;
-
- if(ProfileUtil.isDirty(parentPackage, profile)) {
- Tree tree = treeItem.getParent();
-
- final Button checkbox = new Button(tree, SWT.CHECK);
-
- checkbox.setSelection(true);
- getProfilesToReapply(parentPackage).add(profile);
-
- checkbox.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent e) {
- if(checkbox.getSelection()) {
- getProfilesToReapply(parentPackage).add(profile);
- } else {
- getProfilesToReapply(parentPackage).remove(profile);
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- //Nothing
- }
-
- });
-
- TreeEditor editor = new TreeEditor(tree);
- editor.horizontalAlignment = SWT.CENTER;
- editor.grabHorizontal = true;
-
- editor.setEditor(checkbox, treeItem, 2);
- }
- }
-
- for(TreeItem subitem : treeItem.getItems()) {
- installEditors(subitem, currentPackage);
- }
- }
-
- @Override
- protected Composite getDialogArea() {
- return (Composite)super.getDialogArea();
- }
-
- protected Collection<Profile> getProfilesToReapply(Package currentPackage) {
- if(!profilesToReapply.containsKey(currentPackage)) {
- profilesToReapply.put(currentPackage, new LinkedHashSet<Profile>());
- }
-
- return profilesToReapply.get(currentPackage);
- }
-
- @Override
- protected void okPressed() {
- setSelectionResult(profilesToReapply.values().toArray());
- if(callback != null) {
- callback.run();
- }
- super.okPressed();
- }
-
- public Map<Package, Collection<Profile>> getProfilesToReapply() {
- return profilesToReapply;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.service.ui;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.uml.profile.providers.ProfileApplicationContentProvider;
+import org.eclipse.papyrus.uml.profile.providers.ProfileApplicationLabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TreeEditor;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.dialogs.SelectionDialog;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+
+public class RefreshProfileDialog extends SelectionDialog {
+
+ protected final Map<Package, Collection<Profile>> profilesToReapply;
+
+ protected Runnable callback;
+
+ protected Package rootPackage;
+
+ public RefreshProfileDialog(Shell parentShell, Package rootPackage) {
+ super(parentShell);
+ setBlockOnOpen(false);
+ this.rootPackage = rootPackage;
+ profilesToReapply = new HashMap<Package, Collection<Profile>>();
+ setTitle("Some profiles have changed");
+ }
+
+ public void setCallback(Runnable callback) {
+ this.callback = callback;
+ }
+
+ @Override
+ public void create() {
+ super.create();
+
+ Label descriptionLabel = new Label(getDialogArea(), SWT.WRAP);
+ descriptionLabel.setText("Some local profiles have changed. Select the ones you want to re-apply");
+
+ TreeViewer viewer = new TreeViewer(getDialogArea());
+ viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Tree tree = viewer.getTree();
+
+ TableLayout layout = new TableLayout();
+
+ TreeColumn propertyColumn = new TreeColumn(tree, SWT.CENTER);
+ propertyColumn.setText("Package");
+ layout.addColumnData(new ColumnWeightData(30, 300, true));
+
+ TreeColumn propertyVersionColumn = new TreeColumn(tree, SWT.CENTER);
+ propertyVersionColumn.setText("Version");
+ layout.addColumnData(new ColumnWeightData(30, 100, true));
+
+ TreeColumn ownerColumn = new TreeColumn(tree, SWT.CENTER);
+ ownerColumn.setText("Profile");
+ layout.addColumnData(new ColumnWeightData(60, 150, true));
+
+ TreeColumn ownerVersionColumn = new TreeColumn(tree, SWT.CENTER);
+ ownerVersionColumn.setText("Version");
+ layout.addColumnData(new ColumnWeightData(30, 100, true));
+
+ TreeColumn checkColumn = new TreeColumn(tree, SWT.CENTER);
+ checkColumn.setText("Reapply");
+ layout.addColumnData(new ColumnWeightData(10, 70, true));
+
+ tree.setLayout(layout);
+ tree.setHeaderVisible(true);
+
+ viewer.setContentProvider(new ProfileApplicationContentProvider(rootPackage));
+ viewer.setLabelProvider(new ProfileApplicationLabelProvider());
+
+ viewer.setInput(new Object());
+
+ installEditors(viewer);
+
+ getDialogArea().layout();
+
+ getShell().pack();
+ }
+
+ protected void installEditors(TreeViewer viewer) {
+ viewer.expandAll();
+ for(TreeItem item : viewer.getTree().getItems()) {
+ installEditors(item, rootPackage);
+ }
+ }
+
+ protected void installEditors(TreeItem treeItem, final Object parentPackage) {
+ Object currentDataItem = treeItem.getData();
+ if(currentDataItem instanceof ProfileApplication) {
+
+ final ProfileApplication profileApplication = (ProfileApplication)currentDataItem;
+
+ Tree tree = treeItem.getParent();
+
+ final Button checkbox = new Button(tree, SWT.CHECK);
+
+ checkbox.setSelection(true);
+
+ getProfilesToReapply((Package)profileApplication.getOwner()).add(profileApplication.getAppliedProfile());
+
+ checkbox.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ if(checkbox.getSelection()) {
+ getProfilesToReapply((Package)profileApplication.getOwner()).add(profileApplication.getAppliedProfile());
+ } else {
+ getProfilesToReapply((Package)profileApplication.getOwner()).remove(profileApplication.getAppliedProfile());
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ //Nothing
+ }
+
+ });
+
+ TreeEditor editor = new TreeEditor(tree);
+ editor.horizontalAlignment = SWT.CENTER;
+ editor.grabHorizontal = true;
+
+ editor.setEditor(checkbox, treeItem, 4);
+ }
+
+
+ for(TreeItem subitem : treeItem.getItems()) {
+ installEditors(subitem, currentDataItem);
+ }
+ }
+
+ @Override
+ protected Composite getDialogArea() {
+ return (Composite)super.getDialogArea();
+ }
+
+ protected Collection<Profile> getProfilesToReapply(Package currentPackage) {
+ if(!profilesToReapply.containsKey(currentPackage)) {
+ profilesToReapply.put(currentPackage, new LinkedHashSet<Profile>());
+ }
+
+ return profilesToReapply.get(currentPackage);
+ }
+
+ @Override
+ protected void okPressed() {
+ setSelectionResult(profilesToReapply.values().toArray());
+ if(callback != null) {
+ callback.run();
+ }
+ super.okPressed();
+ }
+
+ public Map<Package, Collection<Profile>> getProfilesToReapply() {
+ return profilesToReapply;
+ }
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileDefinitionDialog.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileDefinitionDialog.java
index ee49278e18f..e23b3d3df2e 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileDefinitionDialog.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ProfileDefinitionDialog.java
@@ -1,609 +1,612 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.ui.dialogs;
-
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.TimeZone;
-
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.papyrus.uml.profile.Activator;
-import org.eclipse.papyrus.uml.profile.ImageManager;
-import org.eclipse.papyrus.uml.profile.definition.PapyrusDefinitionAnnotation;
-import org.eclipse.papyrus.uml.profile.definition.Version;
-import org.eclipse.papyrus.uml.profile.preference.ProfileDefinitionPreferenceConstants;
-import org.eclipse.papyrus.uml.profile.utils.Util;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.uml2.uml.Profile;
-
-
-public class ProfileDefinitionDialog extends TitleAreaDialog {
-
- /** path to the banner image */
- public final static String PROFILE_DEFINITION = ImageManager.IMAGE_PATH + "wizban/NewDefinition.gif"; //$NON-NLS-1$
-
- /** Text area that displays previous version of the profile definition */
- protected Text oldVersionText;
-
- /** button to select the new version number (dev) */
- protected Button devVersionButton;
-
- /** button to select the new version number (release) */
- protected Button releaseVersionButton;
-
- /** button to select the new version number (major release) */
- protected Button majorReleaseVersionButton;
-
- /** button to select the new version number (custom version) */
- protected Button customVersionButton;
-
- /** Text area where custom version number can be entered */
- protected Text customVersionText;
-
- /** Profile which is redefined */
- protected Profile profileToDefine;
-
- /** development version */
- private Version devVersionValue;
-
- /** release version */
- private Version releaseVersionValue;
-
- /** major release version */
- private Version majorReleaseVersionValue;
-
- /** oldVersion Value */
- private Version oldVersionValue;
-
- /** custom Version Value */
- private Version customReleaseVersionValue;
-
- /** custom Version Value */
- private Version newVersionValue;
-
- /** Definition information */
- protected PapyrusDefinitionAnnotation papyrusDefinitionAnnotation;
-
- /** Comment text area */
- private Text commentText;
-
- /** Copyright text area */
- private Text copyrightText;
-
- /** Author text area */
- private Text authorText;
-
- /** Date text Area */
- private Text dateText;
-
- /** check button for preference store */
- private Button savePreferencesButton;
- protected boolean saveConstraint=false;
-
- /** list of previous definition annotations */
- List<PapyrusDefinitionAnnotation> oldVersionAnnotations = new ArrayList<PapyrusDefinitionAnnotation>();
-
- /** Combo that displays the history of comments */
- Combo commentHistory;
-
- /** list of comments history */
- final List<String> availableComments = new ArrayList<String>();
-
- private Button constraintCheck;
-
-
- /**
- * Creates a new ProfileDefinitionDialog
- *
- * @param parentShell
- * the parent shell for this dialog
- */
- public ProfileDefinitionDialog(Shell parentShell, Profile profileToDefine) {
- super(parentShell);
- setShellStyle(getShellStyle() | SWT.RESIZE);
- this.profileToDefine = profileToDefine;
-
- computeHistoryAnnotations();
- }
-
- /**
- * retrieve version annotation history
- */
- private void computeHistoryAnnotations() {
- // get all annotations for the given profile
- oldVersionAnnotations = Util.getAllPapyrusDefinitionAnnotation(profileToDefine);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void okPressed() {
- // save author and copyright in preference store
- if(savePreferencesButton.getSelection()) {
- Activator.getDefault().getPreferenceStore().setValue(ProfileDefinitionPreferenceConstants.PREF_AUTHOR_NAME, authorText.getText());
- Activator.getDefault().getPreferenceStore().setValue(ProfileDefinitionPreferenceConstants.PREF_COPYRIGHT, copyrightText.getText());
- }
-
- // creates the new Papyrus Definition Annotation
- papyrusDefinitionAnnotation = new PapyrusDefinitionAnnotation(newVersionValue, commentText.getText(), copyrightText.getText(), dateText.getText(), authorText.getText());
- if(constraintCheck!=null){
- saveConstraint= constraintCheck.getSelection();
- }
-
- super.okPressed();
- }
-
- public boolean saveConstraintInDefinition(){
- return saveConstraint;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- protected Control createDialogArea(Composite parent) {
- // top level composite
- Composite parentComposite = (Composite)super.createDialogArea(parent);
-
- setTitle("Information about new definition");
- setTitleImage(ImageManager.getImage(PROFILE_DEFINITION));
-
- // create a composite with standard margins and spacing
- Composite composite = new Composite(parentComposite, SWT.NONE);
- GridLayout layout = new GridLayout(2, true);
- layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
- layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
- layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- composite.setFont(parentComposite.getFont());
-
- // compute initial values
- computeVersionValues();
-
- // fill composite with information about new definition:
- // 1. version
- // 2. author
- // 3. comment
- // 4. date
- // 5. copyright
- // 6. save constraint into the definition
-
- GridData gd;
-
- Composite versionArea = createVersionArea(composite);
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- versionArea.setLayoutData(gd);
-
- Composite infoArea = createInfoArea(composite);
- gd = new GridData(SWT.FILL, SWT.FILL, true, true);
- infoArea.setLayoutData(gd);
-
- Composite commentArea = createCommentArea(composite);
- gd = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1);
- commentArea.setLayoutData(gd);
-
- Composite copyrightArea = createCopyrightArea(composite);
- gd = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1);
- copyrightArea.setLayoutData(gd);
-
- Composite advancedArea = createAdvancedArea(composite);
- gd = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1);
- advancedArea.setLayoutData(gd);
- Composite constraintArea = createSaveConstraintAera(composite);
- gd = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1);
- constraintArea.setLayoutData(gd);
-
- applyDialogFont(parentComposite);
- return parentComposite;
- }
-
- /**
- * Creates and returns the content of the advanced area.
- *
- * @param composite
- * The parent composite to contain the advanced area
- */
- private Composite createAdvancedArea(Composite composite) {
- Composite parent = new Composite(composite, SWT.CENTER);
- GridLayout layout = new GridLayout();
- parent.setLayout(layout);
- // new copyright area
- savePreferencesButton = new Button(parent, SWT.CHECK);
- savePreferencesButton.setText("Store author and copyright values in preferences.");
- GridData gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
- savePreferencesButton.setLayoutData(gd);
- return parent;
- }
-
- /**
- * Creates and returns the content of the copyright area.
- *
- * @param composite
- * The parent composite to contain the copyright area
- */
- private Composite createSaveConstraintAera(Composite composite) {
- Group group = new Group(composite, SWT.CENTER);
- group.setText("Constraints"); //$NON-NLS-1$
- GridLayout layout = new GridLayout();
- group.setLayout(layout);
-
- // new copyright area
- constraintCheck = new Button(group, SWT.RADIO);
- // Enable button by default, see bug #411256
- constraintCheck.setSelection(true);
- // should look
- constraintCheck.setText("Save OCL constraints, if any, into the profile definition"); //$NON-NLS-1$
- Button writeToPlugin = new Button(group, SWT.RADIO);
- writeToPlugin.setText("Ignore OCL constraints, if any. (use validation plugin generator instead)"); //$NON-NLS-1$
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
- gd.heightHint = 60;
- group.setLayoutData(gd);
- return group;
- }
- /**
- * Creates and returns the content of the copyright area.
- *
- * @param composite
- * The parent composite to contain the copyright area
- */
- private Composite createCopyrightArea(Composite composite) {
- Group group = new Group(composite, SWT.CENTER);
- group.setText("Copyright"); //$NON-NLS-1$
- GridLayout layout = new GridLayout();
- group.setLayout(layout);
-
- // new copyright area
- copyrightText = new Text(group, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
- // should look
- copyrightText.setText(Activator.getDefault().getPreferenceStore().getString(ProfileDefinitionPreferenceConstants.PREF_COPYRIGHT));
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
- gd.heightHint = 60;
- copyrightText.setLayoutData(gd);
- return group;
- }
-
- /**
- * Creates and returns the content of the information area.
- *
- * @param composite
- * The parent composite to contain the information area
- */
- private Composite createInfoArea(Composite composite) {
- Group group = new Group(composite, SWT.CENTER);
- group.setText("Info");
- GridLayout layout = new GridLayout(2, false);
- group.setLayout(layout);
-
- Label dateLabel = new Label(group, SWT.LEFT);
- dateLabel.setText("Date");
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- dateLabel.setLayoutData(gd);
- dateText = new Text(group, SWT.SINGLE | SWT.BORDER);
- final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- final TimeZone local = TimeZone.getDefault();
- sdf.setTimeZone(local);
- // new Date() gets current date/elapsedTime
- final String dateString = sdf.format(new Date());
- dateText.setText(dateString);
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- dateText.setLayoutData(gd);
-
- Label authorLabel = new Label(group, SWT.LEFT);
- authorLabel.setText("Author");
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- authorLabel.setLayoutData(gd);
- authorText = new Text(group, SWT.SINGLE | SWT.BORDER);
- // should look in preferences...
- authorText.setText(Activator.getDefault().getPreferenceStore().getString(ProfileDefinitionPreferenceConstants.PREF_AUTHOR_NAME));
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- authorText.setLayoutData(gd);
-
- return group;
- }
-
- /**
- * Creates and returns the content of the comment area.
- *
- * @param composite
- * The parent composite to contain the comment area
- */
- private Composite createCommentArea(Composite composite) {
- Group group = new Group(composite, SWT.CENTER);
- group.setText("Comments");
- GridLayout layout = new GridLayout(1, false);
- group.setLayout(layout);
-
- // new comment area
- commentText = new Text(group, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
- commentText.setText("");
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
- gd.heightHint = 60;
- commentText.setLayoutData(gd);
-
- commentHistory = new Combo(group, SWT.READ_ONLY | SWT.DROP_DOWN);
-
- Iterator<PapyrusDefinitionAnnotation> it = oldVersionAnnotations.listIterator();
- while(it.hasNext()) {
- String comment = it.next().getComment();
- if(comment != null && !"".equals(comment)) {
- availableComments.add(comment);
- }
- }
-
- for(String comment : availableComments) {
- // should be max 80 characters or something like that
- commentHistory.add(comment.substring(0, Math.min(comment.length(), 80)));
- }
-
- commentHistory.addSelectionListener(new SelectionListener() {
-
- /** @{inheritedDoc */
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- /** @{inheritedDoc */
- public void widgetSelected(SelectionEvent e) {
- int index = commentHistory.getSelectionIndex();
- if(index == -1) {
- return;
- }
- String text = availableComments.get(index);
- commentText.setText(text);
- }
-
- });
-
- gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
- commentHistory.setLayoutData(gd);
- return group;
- }
-
- /**
- * Creates and returns the content of the version area.
- *
- * @param composite
- * The parent composite to contain the version area
- */
- private Composite createVersionArea(Composite composite) {
- Group group = new Group(composite, SWT.CENTER);
- group.setText("Version");
- GridLayout layout = new GridLayout(2, false);
- group.setLayout(layout);
-
- // old version label
- Label oldVersionLabel = new Label(group, SWT.LEFT);
- oldVersionLabel.setText("Previous Version");
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- oldVersionLabel.setLayoutData(gd);
- final Text oldVersionText = new Text(group, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
- oldVersionText.setText(oldVersionValue.toString());
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- oldVersionText.setLayoutData(gd);
-
-
- // new version:
- // 1. Development version
- // 2. Release
- // 3. Major release
- // 4. Custom
- devVersionButton = new Button(group, SWT.CHECK);
- devVersionButton.setText("Development Version");
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- devVersionButton.setLayoutData(gd);
- devVersionButton.setSelection(true);
- devVersionButton.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent e) {
- developmentVersionButtonPressed();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- });
- final Text devVersionText = new Text(group, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
- devVersionText.setText(devVersionValue.toString());
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- devVersionText.setLayoutData(gd);
-
- // RELEASE AREA
- releaseVersionButton = new Button(group, SWT.CHECK);
- releaseVersionButton.setText("Release Version");
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- releaseVersionButton.setLayoutData(gd);
- releaseVersionButton.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent e) {
- releaseVersionButtonPressed();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- });
- final Text releaseVersionText = new Text(group, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
- releaseVersionText.setText(releaseVersionValue.toString());
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- releaseVersionText.setLayoutData(gd);
-
- // MAJOR RELEASE AREA
- majorReleaseVersionButton = new Button(group, SWT.CHECK);
- majorReleaseVersionButton.setText("Major Release");
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- majorReleaseVersionButton.setLayoutData(gd);
- majorReleaseVersionButton.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent e) {
- majorReleaseVersionButtonPressed();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- });
- final Text majorReleaseVersionText = new Text(group, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
- majorReleaseVersionText.setText(majorReleaseVersionValue.toString());
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- majorReleaseVersionText.setLayoutData(gd);
-
- // CUSTOM VERSION AREA
- customVersionButton = new Button(group, SWT.CHECK);
- customVersionButton.setText("Custom");
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- customVersionButton.setLayoutData(gd);
- customVersionButton.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent e) {
- customVersionButtonPressed();
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- });
- customVersionText = new Text(group, SWT.SINGLE | SWT.BORDER);
- customVersionText.setEditable(false); // by default
- customVersionText.setText(customReleaseVersionValue.toString());
- gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
- customVersionText.setLayoutData(gd);
- customVersionText.addFocusListener(new FocusListener() {
-
- public void focusGained(FocusEvent e) {
- customVersionText.setText(customReleaseVersionValue.toString());
- }
-
- public void focusLost(FocusEvent e) {
- try {
- customReleaseVersionValue = Version.parseVersion(customVersionText.getText());
- newVersionValue = customReleaseVersionValue;
- setErrorMessage(null);
- } catch (IllegalArgumentException iae) {
- setErrorMessage("Custom version number format should be X.Y.Z, not " + customVersionText.getText());
- customReleaseVersionValue = devVersionValue; // default value
- developmentVersionButtonPressed();
- }
- }
- });
-
- return group;
- }
-
- /**
- * compute the value of the versions
- */
- private void computeVersionValues() {
- oldVersionValue = Util.getProfileDefinitionVersion(profileToDefine);
- devVersionValue = new Version(oldVersionValue.getMajor(), oldVersionValue.getMinor(), oldVersionValue.getMicro() + 1);
- releaseVersionValue = new Version(oldVersionValue.getMajor(), oldVersionValue.getMinor() + 1, 0);
- majorReleaseVersionValue = new Version(oldVersionValue.getMajor() + 1, 0, 0);
- customReleaseVersionValue = devVersionValue;
- newVersionValue = devVersionValue;
- }
-
- /**
- * Action called as the development version button is pressed
- *
- * @param e
- * the selection event that triggers this behavior
- */
- private void developmentVersionButtonPressed() {
- devVersionButton.setSelection(true);
- releaseVersionButton.setSelection(false);
- majorReleaseVersionButton.setSelection(false);
- customVersionButton.setSelection(false);
- newVersionValue = devVersionValue;
- customVersionText.setEditable(false);
- }
-
- /**
- * Action called as the release version button is pressed
- *
- * @param e
- * the selection event that triggers this behavior
- */
- private void releaseVersionButtonPressed() {
- devVersionButton.setSelection(false);
- releaseVersionButton.setSelection(true);
- majorReleaseVersionButton.setSelection(false);
- customVersionButton.setSelection(false);
- newVersionValue = releaseVersionValue;
- customVersionText.setEditable(false);
- }
-
- /**
- * Action called as the major release version button is pressed
- *
- * @param e
- * the selection event that triggers this behavior
- */
- private void majorReleaseVersionButtonPressed() {
- devVersionButton.setSelection(false);
- releaseVersionButton.setSelection(false);
- majorReleaseVersionButton.setSelection(true);
- customVersionButton.setSelection(false);
- newVersionValue = majorReleaseVersionValue;
- customVersionText.setEditable(false);
- }
-
- /**
- * Action called as the release version button is pressed
- *
- * @param e
- * the selection event that triggers this behavior
- */
- private void customVersionButtonPressed() {
- devVersionButton.setSelection(false);
- releaseVersionButton.setSelection(false);
- majorReleaseVersionButton.setSelection(false);
- customVersionButton.setSelection(true);
- newVersionValue = customReleaseVersionValue;
- customVersionText.setEditable(true);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- setShellStyle(getShellStyle() | SWT.RESIZE);
- shell.setText("Profile Definition"); //$NON-NLS-1$
- }
-
- /**
- * Returns the defined PapyrusDefinitionAnnotation
- *
- * @return the papyrusDefinitionAnnotation
- */
- public PapyrusDefinitionAnnotation getPapyrusDefinitionAnnotation() {
- return papyrusDefinitionAnnotation;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.ui.dialogs;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TimeZone;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.papyrus.uml.profile.ImageManager;
+import org.eclipse.papyrus.uml.profile.preference.ProfileDefinitionPreferenceConstants;
+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.Version;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.uml2.uml.Profile;
+
+
+public class ProfileDefinitionDialog extends TitleAreaDialog {
+
+ /** path to the banner image */
+ public final static String PROFILE_DEFINITION = ImageManager.IMAGE_PATH + "wizban/NewDefinition.gif"; //$NON-NLS-1$
+
+ /** Text area that displays previous version of the profile definition */
+ protected Text oldVersionText;
+
+ /** button to select the new version number (dev) */
+ protected Button devVersionButton;
+
+ /** button to select the new version number (release) */
+ protected Button releaseVersionButton;
+
+ /** button to select the new version number (major release) */
+ protected Button majorReleaseVersionButton;
+
+ /** button to select the new version number (custom version) */
+ protected Button customVersionButton;
+
+ /** Text area where custom version number can be entered */
+ protected Text customVersionText;
+
+ /** Profile which is redefined */
+ protected Profile profileToDefine;
+
+ /** development version */
+ private Version devVersionValue;
+
+ /** release version */
+ private Version releaseVersionValue;
+
+ /** major release version */
+ private Version majorReleaseVersionValue;
+
+ /** oldVersion Value */
+ private Version oldVersionValue;
+
+ /** custom Version Value */
+ private Version customReleaseVersionValue;
+
+ /** custom Version Value */
+ private Version newVersionValue;
+
+ /** Definition information */
+ protected PapyrusDefinitionAnnotation papyrusDefinitionAnnotation;
+
+ /** Comment text area */
+ private Text commentText;
+
+ /** Copyright text area */
+ private Text copyrightText;
+
+ /** Author text area */
+ private Text authorText;
+
+ /** Date text Area */
+ private Text dateText;
+
+ /** check button for preference store */
+ private Button savePreferencesButton;
+
+ protected boolean saveConstraint = false;
+
+ /** list of previous definition annotations */
+ List<PapyrusDefinitionAnnotation> oldVersionAnnotations = new ArrayList<PapyrusDefinitionAnnotation>();
+
+ /** Combo that displays the history of comments */
+ Combo commentHistory;
+
+ /** list of comments history */
+ final List<String> availableComments = new ArrayList<String>();
+
+ private Button constraintCheck;
+
+
+ /**
+ * Creates a new ProfileDefinitionDialog
+ *
+ * @param parentShell
+ * the parent shell for this dialog
+ */
+ public ProfileDefinitionDialog(Shell parentShell, Profile profileToDefine) {
+ super(parentShell);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ this.profileToDefine = profileToDefine;
+
+ computeHistoryAnnotations();
+ }
+
+ /**
+ * retrieve version annotation history
+ */
+ private void computeHistoryAnnotations() {
+ // get all annotations for the given profile
+ oldVersionAnnotations = Util.getAllPapyrusDefinitionAnnotation(profileToDefine);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void okPressed() {
+ // save author and copyright in preference store
+ if(savePreferencesButton.getSelection()) {
+ Activator.getDefault().getPreferenceStore().setValue(ProfileDefinitionPreferenceConstants.PREF_AUTHOR_NAME, authorText.getText());
+ Activator.getDefault().getPreferenceStore().setValue(ProfileDefinitionPreferenceConstants.PREF_COPYRIGHT, copyrightText.getText());
+ }
+
+ // creates the new Papyrus Definition Annotation
+ papyrusDefinitionAnnotation = new PapyrusDefinitionAnnotation(newVersionValue, commentText.getText(), copyrightText.getText(), dateText.getText(), authorText.getText());
+ if(constraintCheck != null) {
+ saveConstraint = constraintCheck.getSelection();
+ }
+
+ super.okPressed();
+ }
+
+ public boolean saveConstraintInDefinition() {
+ return saveConstraint;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ // top level composite
+ Composite parentComposite = (Composite)super.createDialogArea(parent);
+
+ setTitle("Information about new definition");
+ setTitleImage(ImageManager.getImage(PROFILE_DEFINITION));
+
+ // create a composite with standard margins and spacing
+ Composite composite = new Composite(parentComposite, SWT.NONE);
+ GridLayout layout = new GridLayout(2, true);
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setFont(parentComposite.getFont());
+
+ // compute initial values
+ computeVersionValues();
+
+ // fill composite with information about new definition:
+ // 1. version
+ // 2. author
+ // 3. comment
+ // 4. date
+ // 5. copyright
+ // 6. save constraint into the definition
+
+ GridData gd;
+
+ Composite versionArea = createVersionArea(composite);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ versionArea.setLayoutData(gd);
+
+ Composite infoArea = createInfoArea(composite);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ infoArea.setLayoutData(gd);
+
+ Composite commentArea = createCommentArea(composite);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1);
+ commentArea.setLayoutData(gd);
+
+ Composite copyrightArea = createCopyrightArea(composite);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1);
+ copyrightArea.setLayoutData(gd);
+
+ Composite advancedArea = createAdvancedArea(composite);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1);
+ advancedArea.setLayoutData(gd);
+ Composite constraintArea = createSaveConstraintAera(composite);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 1);
+ constraintArea.setLayoutData(gd);
+
+ applyDialogFont(parentComposite);
+ return parentComposite;
+ }
+
+ /**
+ * Creates and returns the content of the advanced area.
+ *
+ * @param composite
+ * The parent composite to contain the advanced area
+ */
+ private Composite createAdvancedArea(Composite composite) {
+ Composite parent = new Composite(composite, SWT.CENTER);
+ GridLayout layout = new GridLayout();
+ parent.setLayout(layout);
+ // new copyright area
+ savePreferencesButton = new Button(parent, SWT.CHECK);
+ savePreferencesButton.setText("Store author and copyright values in preferences.");
+ GridData gd = new GridData(SWT.BEGINNING, SWT.CENTER, false, true);
+ savePreferencesButton.setLayoutData(gd);
+ return parent;
+ }
+
+ /**
+ * Creates and returns the content of the copyright area.
+ *
+ * @param composite
+ * The parent composite to contain the copyright area
+ */
+ private Composite createSaveConstraintAera(Composite composite) {
+ Group group = new Group(composite, SWT.CENTER);
+ group.setText("Constraints"); //$NON-NLS-1$
+ GridLayout layout = new GridLayout();
+ group.setLayout(layout);
+
+ // new copyright area
+ constraintCheck = new Button(group, SWT.RADIO);
+ // Enable button by default, see bug #411256
+ constraintCheck.setSelection(true);
+ // should look
+ constraintCheck.setText("Save OCL constraints, if any, into the profile definition"); //$NON-NLS-1$
+ Button writeToPlugin = new Button(group, SWT.RADIO);
+ writeToPlugin.setText("Ignore OCL constraints, if any. (use validation plugin generator instead)"); //$NON-NLS-1$
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
+ gd.heightHint = 60;
+ group.setLayoutData(gd);
+ return group;
+ }
+
+ /**
+ * Creates and returns the content of the copyright area.
+ *
+ * @param composite
+ * The parent composite to contain the copyright area
+ */
+ private Composite createCopyrightArea(Composite composite) {
+ Group group = new Group(composite, SWT.CENTER);
+ group.setText("Copyright"); //$NON-NLS-1$
+ GridLayout layout = new GridLayout();
+ group.setLayout(layout);
+
+ // new copyright area
+ copyrightText = new Text(group, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+ // should look
+ copyrightText.setText(Activator.getDefault().getPreferenceStore().getString(ProfileDefinitionPreferenceConstants.PREF_COPYRIGHT));
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
+ gd.heightHint = 60;
+ copyrightText.setLayoutData(gd);
+ return group;
+ }
+
+ /**
+ * Creates and returns the content of the information area.
+ *
+ * @param composite
+ * The parent composite to contain the information area
+ */
+ private Composite createInfoArea(Composite composite) {
+ Group group = new Group(composite, SWT.CENTER);
+ group.setText("Info");
+ GridLayout layout = new GridLayout(2, false);
+ group.setLayout(layout);
+
+ Label dateLabel = new Label(group, SWT.LEFT);
+ dateLabel.setText("Date");
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ dateLabel.setLayoutData(gd);
+ dateText = new Text(group, SWT.SINGLE | SWT.BORDER);
+ final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ final TimeZone local = TimeZone.getDefault();
+ sdf.setTimeZone(local);
+ // new Date() gets current date/elapsedTime
+ final String dateString = sdf.format(new Date());
+ dateText.setText(dateString);
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ dateText.setLayoutData(gd);
+
+ Label authorLabel = new Label(group, SWT.LEFT);
+ authorLabel.setText("Author");
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ authorLabel.setLayoutData(gd);
+ authorText = new Text(group, SWT.SINGLE | SWT.BORDER);
+ // should look in preferences...
+ authorText.setText(Activator.getDefault().getPreferenceStore().getString(ProfileDefinitionPreferenceConstants.PREF_AUTHOR_NAME));
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ authorText.setLayoutData(gd);
+
+ return group;
+ }
+
+ /**
+ * Creates and returns the content of the comment area.
+ *
+ * @param composite
+ * The parent composite to contain the comment area
+ */
+ private Composite createCommentArea(Composite composite) {
+ Group group = new Group(composite, SWT.CENTER);
+ group.setText("Comments");
+ GridLayout layout = new GridLayout(1, false);
+ group.setLayout(layout);
+
+ // new comment area
+ commentText = new Text(group, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+ commentText.setText("");
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
+ gd.heightHint = 60;
+ commentText.setLayoutData(gd);
+
+ commentHistory = new Combo(group, SWT.READ_ONLY | SWT.DROP_DOWN);
+
+ Iterator<PapyrusDefinitionAnnotation> it = oldVersionAnnotations.listIterator();
+ while(it.hasNext()) {
+ String comment = it.next().getComment();
+ if(comment != null && !"".equals(comment)) {
+ availableComments.add(comment);
+ }
+ }
+
+ for(String comment : availableComments) {
+ // should be max 80 characters or something like that
+ commentHistory.add(comment.substring(0, Math.min(comment.length(), 80)));
+ }
+
+ commentHistory.addSelectionListener(new SelectionListener() {
+
+ /** @{inheritedDoc */
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ /** @{inheritedDoc */
+ public void widgetSelected(SelectionEvent e) {
+ int index = commentHistory.getSelectionIndex();
+ if(index == -1) {
+ return;
+ }
+ String text = availableComments.get(index);
+ commentText.setText(text);
+ }
+
+ });
+
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
+ commentHistory.setLayoutData(gd);
+ return group;
+ }
+
+ /**
+ * Creates and returns the content of the version area.
+ *
+ * @param composite
+ * The parent composite to contain the version area
+ */
+ private Composite createVersionArea(Composite composite) {
+ Group group = new Group(composite, SWT.CENTER);
+ group.setText("Version");
+ GridLayout layout = new GridLayout(2, false);
+ group.setLayout(layout);
+
+ // old version label
+ Label oldVersionLabel = new Label(group, SWT.LEFT);
+ oldVersionLabel.setText("Previous Version");
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ oldVersionLabel.setLayoutData(gd);
+ final Text oldVersionText = new Text(group, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
+ oldVersionText.setText(oldVersionValue.toString());
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ oldVersionText.setLayoutData(gd);
+
+
+ // new version:
+ // 1. Development version
+ // 2. Release
+ // 3. Major release
+ // 4. Custom
+ devVersionButton = new Button(group, SWT.CHECK);
+ devVersionButton.setText("Development Version");
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ devVersionButton.setLayoutData(gd);
+ devVersionButton.setSelection(true);
+ devVersionButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ developmentVersionButtonPressed();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ final Text devVersionText = new Text(group, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
+ devVersionText.setText(devVersionValue.toString());
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ devVersionText.setLayoutData(gd);
+
+ // RELEASE AREA
+ releaseVersionButton = new Button(group, SWT.CHECK);
+ releaseVersionButton.setText("Release Version");
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ releaseVersionButton.setLayoutData(gd);
+ releaseVersionButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ releaseVersionButtonPressed();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ final Text releaseVersionText = new Text(group, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
+ releaseVersionText.setText(releaseVersionValue.toString());
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ releaseVersionText.setLayoutData(gd);
+
+ // MAJOR RELEASE AREA
+ majorReleaseVersionButton = new Button(group, SWT.CHECK);
+ majorReleaseVersionButton.setText("Major Release");
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ majorReleaseVersionButton.setLayoutData(gd);
+ majorReleaseVersionButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ majorReleaseVersionButtonPressed();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ final Text majorReleaseVersionText = new Text(group, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
+ majorReleaseVersionText.setText(majorReleaseVersionValue.toString());
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ majorReleaseVersionText.setLayoutData(gd);
+
+ // CUSTOM VERSION AREA
+ customVersionButton = new Button(group, SWT.CHECK);
+ customVersionButton.setText("Custom");
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ customVersionButton.setLayoutData(gd);
+ customVersionButton.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ customVersionButtonPressed();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ customVersionText = new Text(group, SWT.SINGLE | SWT.BORDER);
+ customVersionText.setEditable(false); // by default
+ customVersionText.setText(customReleaseVersionValue.toString());
+ gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ customVersionText.setLayoutData(gd);
+ customVersionText.addFocusListener(new FocusListener() {
+
+ public void focusGained(FocusEvent e) {
+ customVersionText.setText(customReleaseVersionValue.toString());
+ }
+
+ public void focusLost(FocusEvent e) {
+ try {
+ customReleaseVersionValue = Version.parseVersion(customVersionText.getText());
+ newVersionValue = customReleaseVersionValue;
+ setErrorMessage(null);
+ } catch (IllegalArgumentException iae) {
+ setErrorMessage("Custom version number format should be X.Y.Z, not " + customVersionText.getText());
+ customReleaseVersionValue = devVersionValue; // default value
+ developmentVersionButtonPressed();
+ }
+ }
+ });
+
+ return group;
+ }
+
+ /**
+ * compute the value of the versions
+ */
+ private void computeVersionValues() {
+ oldVersionValue = Util.getProfileDefinitionVersion(profileToDefine);
+ devVersionValue = new Version(oldVersionValue.getMajor(), oldVersionValue.getMinor(), oldVersionValue.getMicro() + 1);
+ releaseVersionValue = new Version(oldVersionValue.getMajor(), oldVersionValue.getMinor() + 1, 0);
+ majorReleaseVersionValue = new Version(oldVersionValue.getMajor() + 1, 0, 0);
+ customReleaseVersionValue = devVersionValue;
+ newVersionValue = devVersionValue;
+ }
+
+ /**
+ * Action called as the development version button is pressed
+ *
+ * @param e
+ * the selection event that triggers this behavior
+ */
+ private void developmentVersionButtonPressed() {
+ devVersionButton.setSelection(true);
+ releaseVersionButton.setSelection(false);
+ majorReleaseVersionButton.setSelection(false);
+ customVersionButton.setSelection(false);
+ newVersionValue = devVersionValue;
+ customVersionText.setEditable(false);
+ }
+
+ /**
+ * Action called as the release version button is pressed
+ *
+ * @param e
+ * the selection event that triggers this behavior
+ */
+ private void releaseVersionButtonPressed() {
+ devVersionButton.setSelection(false);
+ releaseVersionButton.setSelection(true);
+ majorReleaseVersionButton.setSelection(false);
+ customVersionButton.setSelection(false);
+ newVersionValue = releaseVersionValue;
+ customVersionText.setEditable(false);
+ }
+
+ /**
+ * Action called as the major release version button is pressed
+ *
+ * @param e
+ * the selection event that triggers this behavior
+ */
+ private void majorReleaseVersionButtonPressed() {
+ devVersionButton.setSelection(false);
+ releaseVersionButton.setSelection(false);
+ majorReleaseVersionButton.setSelection(true);
+ customVersionButton.setSelection(false);
+ newVersionValue = majorReleaseVersionValue;
+ customVersionText.setEditable(false);
+ }
+
+ /**
+ * Action called as the release version button is pressed
+ *
+ * @param e
+ * the selection event that triggers this behavior
+ */
+ private void customVersionButtonPressed() {
+ devVersionButton.setSelection(false);
+ releaseVersionButton.setSelection(false);
+ majorReleaseVersionButton.setSelection(false);
+ customVersionButton.setSelection(true);
+ newVersionValue = customReleaseVersionValue;
+ customVersionText.setEditable(true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ shell.setText("Profile Definition"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the defined PapyrusDefinitionAnnotation
+ *
+ * @return the papyrusDefinitionAnnotation
+ */
+ public PapyrusDefinitionAnnotation getPapyrusDefinitionAnnotation() {
+ return papyrusDefinitionAnnotation;
+ }
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/utils/Util.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/utils/Util.java
index ae9dcb8c61a..5b7f60f754f 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/utils/Util.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/utils/Util.java
@@ -1,661 +1,661 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - add getNearestProfileApplication
- *****************************************************************************/
-package org.eclipse.papyrus.uml.profile.utils;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.papyrus.uml.profile.Activator;
-import org.eclipse.papyrus.uml.profile.Message;
-import org.eclipse.papyrus.uml.profile.definition.IPapyrusVersionConstants;
-import org.eclipse.papyrus.uml.profile.definition.PapyrusDefinitionAnnotation;
-import org.eclipse.papyrus.uml.profile.definition.Version;
-import org.eclipse.uml2.uml.Comment;
-import org.eclipse.uml2.uml.DataType;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.ElementImport;
-import org.eclipse.uml2.uml.Enumeration;
-import org.eclipse.uml2.uml.EnumerationLiteral;
-import org.eclipse.uml2.uml.InstanceSpecification;
-import org.eclipse.uml2.uml.LiteralBoolean;
-import org.eclipse.uml2.uml.LiteralInteger;
-import org.eclipse.uml2.uml.LiteralString;
-import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.PackageImport;
-import org.eclipse.uml2.uml.PrimitiveType;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.ProfileApplication;
-import org.eclipse.uml2.uml.Slot;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.StructuralFeature;
-import org.eclipse.uml2.uml.TemplateBinding;
-import org.eclipse.uml2.uml.TemplateSignature;
-import org.eclipse.uml2.uml.TemplateableElement;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.ValueSpecification;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-
-/**
- * Some utils extracted from com.cea.utils classes (package and element)
- * TODO: not all are used, cleanup with respect to types
- */
-public class Util {
-
- /**
- * Return a usable string label for passed object.
- *
- * @param object
- * the object
- *
- * @return the label
- */
- public static String getLabel(Object object, boolean shortLabel) {
- String label = "";
-
- if(object == null) {
- return "undefined";
- }
-
- if(object instanceof ValueSpecification) {
- label = getLabel((ValueSpecification)object);
-
- } else if(object instanceof Element) {
- Element cE = (Element)object;
- String cName = null;
- String suffix = "";
- String cComLabel = "";
-
- NamedElement cNE = null;
- if(object instanceof NamedElement) {
- cNE = (NamedElement)object;
-
- } else if(object instanceof PackageImport) {
- PackageImport cPI = (PackageImport)object;
- suffix = " (PackageImport)";
- cNE = cPI.getImportedPackage();
-
- } else if(object instanceof ElementImport) {
- ElementImport cEI = (ElementImport)object;
- suffix = " (ElementImport)";
- cNE = cEI.getImportedElement();
-
- } else if(object instanceof ProfileApplication) {
- ProfileApplication cPA = (ProfileApplication)object;
- suffix = " (ProfileApplication)";
- cNE = cPA.getAppliedProfile();
-
- } else if(object instanceof Comment) {
- Comment cCom = (Comment)object;
- suffix = " (Comment)";
- String cComBody = cCom.getBody();
- if(cComBody != null && cComBody.length() >= 10) {
- cComLabel = cComBody.substring(0, 9) + "...";
- } else {
- cComLabel = cComBody;
- }
- } else if(object instanceof TemplateSignature) {
- TemplateableElement te = ((TemplateSignature)object).getTemplate();
- suffix = " (TemplateSignature owner)";
- if(te instanceof NamedElement) {
- cNE = (NamedElement)te;
- }
- } else if(object instanceof TemplateBinding) {
- TemplateableElement te = ((TemplateBinding)object).getBoundElement();
- suffix = " (TemplateBinding bound-element)";
- if(te instanceof NamedElement) {
- cNE = (NamedElement)te;
- }
- }
- if(shortLabel) {
- if(object instanceof Comment) {
- cName = cComLabel;
- } else if(cNE != null) {
- cName = cNE.getName();
- }
- } else {
- if(object instanceof Comment) {
- cName = cComLabel + suffix;
- } else if(cNE != null) {
- cName = cNE.getQualifiedName() + suffix;
- }
- }
-
- if(cName != null) {
- label = cName;
- } else {
- label = cE.toString();
- }
- }
-
- return label;
- }
-
-
- /**
- * Check if a type is a metaclass.
- *
- * @param type
- * to check
- *
- * @return true if type is metaclass, else false
- */
- public static boolean isMetaclass(Type type) {
- boolean isMetaclass = false;
-
- if((type instanceof org.eclipse.uml2.uml.Class) && (type.getAppliedStereotypes() != null) && (type.getAppliedStereotypes().size() > 0)) {
-
- Stereotype firstStereotype = type.getAppliedStereotypes().get(0);
-
- if(firstStereotype.getName().equals("Metaclass")) {
- isMetaclass = true;
- }
- }
- return isMetaclass;
- }
-
- /**
- * Check if the type is a UML Metaclass
- *
- * @param type
- * @return
- */
- public static boolean isMetaclass(EClassifier type) {
- return type.getEPackage() == UMLPackage.eINSTANCE;
- }
-
- /**
- * Convert the list of element in a list of string after some basic checks.
- *
- * @param elements
- * the elements
- *
- * @return the string array from list
- */
- public static String[] getStringArrayFromList(List<Element> elements) {
-
- ArrayList<String> tmp = new ArrayList<String>();
-
- // if no possible selection : abort
- if(elements.size() == 0) {
- return null;
- }
-
- // First create tmp list
- Iterator<Element> it = elements.iterator();
- while(it.hasNext()) {
- Object current = it.next();
-
- String label = getLabel(current, false);
- tmp.add(label);
- }
-
- // if no possible selection : abort
- if(tmp.size() == 0) {
- return null;
- }
-
- // Put this in array
- String[] elementsNames = new String[tmp.size()];
- for(int i = 0; i < tmp.size(); i++) {
- elementsNames[i] = tmp.get(i);
- }
-
- // PostCondition
- if(elementsNames.length != elements.size()) {
- Message.error("Number of elements in name list does not match number or elements.");
- elementsNames = null;
- }
- return elementsNames;
- }
-
- /**
- * Treat a string provided by the user for a primitiveType and return
- * the corresponding object.
- *
- * @param dialogValue
- * user input string
- * @param type
- * expected
- *
- * @return object
- */
- public static Object getValueObjectFromString(String dialogValue, Type type) {
- Object newValue = null;
- String typeName = type.getQualifiedName();
-
- try {
- if(type instanceof PrimitiveType || ((type instanceof DataType) && !(type instanceof Enumeration))) {
- if(typeName.equals("UMLPrimitiveTypes::Integer")) {
- newValue = Integer.valueOf(dialogValue);
-
- } else if(typeName.equals("UMLPrimitiveTypes::UnlimitedNatural")) {
- if(Integer.signum(Integer.parseInt(dialogValue)) != -1) {
- newValue = Integer.valueOf(dialogValue);
-
- } else {
- Message.warning("UnlimitedNatural must be positive or null.");
- }
-
- } else if(typeName.equals("UMLPrimitiveTypes::String")) {
- newValue = dialogValue;
-
- } else if(typeName.equals("UMLPrimitiveTypes::Boolean")) {
- newValue = Boolean.valueOf(dialogValue);
-
- } else { // user defined primitive type
- newValue = dialogValue;
- }
-
- } else if(type instanceof Enumeration) {
- Enumeration enumeration = (Enumeration)type;
- EnumerationLiteral literal = enumeration.getOwnedLiteral(dialogValue);
-
- if(literal != null) {
- newValue = literal;
- }
- }
- } catch (NumberFormatException e) {
- Message.warning("Bad format number.");
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return newValue;
- }
-
- /**
- * Helper function used by getInstancesFilteredByType
- */
- private static void checkAndAddElement(EObject currentEObj, @SuppressWarnings("rawtypes") Class metaType, Stereotype appliedStereotype, ArrayList<Element> filteredElements) {
- if(currentEObj instanceof Element) {
- Element piCurrentElt = (Element)currentEObj;
- if(appliedStereotype != null) {
-
- // It is not sufficient to call getAppliedStereotypes, since we also want to
- // retrieve elements that apply a sub-stereotype
- if(piCurrentElt.getAppliedSubstereotype(appliedStereotype, null) != null) {
- filteredElements.add(piCurrentElt);
- }
- Iterator<Stereotype> appStIter = piCurrentElt.getAppliedStereotypes().iterator();
- while(appStIter.hasNext()) {
- Stereotype currentSt = appStIter.next();
-
- if(currentSt.conformsTo(appliedStereotype)) {
- filteredElements.add(piCurrentElt);
- }
- }
-
- } else { // if (appliedStereotype == null)
- if(metaType.isInstance(piCurrentElt)) {
- filteredElements.add(piCurrentElt);
- }
-
- /** add imported meta elements */
- else if(piCurrentElt instanceof ElementImport) {
- Iterator<EObject> eIter = ((ElementImport)piCurrentElt).getImportedElement().eAllContents();
- while(eIter.hasNext()) {
- EObject currentEIelt = eIter.next();
- if((currentEIelt instanceof Element) && (metaType.isInstance(currentEIelt))) {
- filteredElements.add((Element)currentEIelt);
- }
- }
- }
- }
- }
- }
-
- /**
- * Retrieve an ArrayList of all instances in the model that
- * are instances of the java.lang.Class metaType or with a
- * stereotype applied
- *
- * @param metaType
- * selected classes
- * @param model
- * to check
- * @param appliedStereotype
- * may be null, metatype is ignored if not null
- * @return an arraylist containing the selected instances
- */
- public static ArrayList<Element> getInstancesFilteredByType(Element element, @SuppressWarnings("rawtypes") Class metaType, Stereotype appliedStereotype) {
- // retrieve parent element
- Package topPackage = Util.topPackage(element);
- Assert.isNotNull(topPackage, "Top package should not be null for element " + element);
- Iterator<EObject> iter = topPackage.eAllContents();
- ArrayList<Element> filteredElements = new ArrayList<Element>();
-
- while(iter.hasNext()) {
- EObject currentEObj = iter.next();
-
- // If currentElt is an ElementImport, it is replaced by the imported
- // Element.
- if(currentEObj instanceof ElementImport) {
- ElementImport elementImport = (ElementImport)currentEObj;
- currentEObj = elementImport.getImportedElement();
- }
-
- /* package imports treatment */
- else if(currentEObj instanceof PackageImport) {
- Package importedPkg = ((PackageImport)currentEObj).getImportedPackage();
- if(importedPkg != null) {
- Iterator<EObject> piIter = importedPkg.eAllContents();
- while(piIter.hasNext()) {
- EObject piCurrentEObj = piIter.next();
- checkAndAddElement(piCurrentEObj, metaType, appliedStereotype, filteredElements);
- }
- }
- }
-
- // Filtering elements
- checkAndAddElement(currentEObj, metaType, appliedStereotype, filteredElements);
- }
-
- return filteredElements;
- }
-
- /**
- * Reorder stereotype applications.
- *
- * @param element
- * the element
- * @param stereotypes
- * the stereotypes
- */
- public static void reorderStereotypeApplications(Element element, EList<Stereotype> stereotypes) {
- for(Iterator<Stereotype> s = stereotypes.iterator(); s.hasNext();) {
- EObject stereotypeApplication = element.getStereotypeApplication(s.next());
- if(stereotypeApplication != null) {
- UMLUtil.setBaseElement(stereotypeApplication, null);
- UMLUtil.setBaseElement(stereotypeApplication, element);
- Resource eResource = stereotypeApplication.eResource();
- if(eResource != null) {
- EList<EObject> contents = eResource.getContents();
- contents.move(contents.size() - 1, stereotypeApplication);
- }
- }
- }
- }
-
- /**
- * Return the labe for a value specification
- *
- * @param object
- * @return
- */
- public static String getLabel(ValueSpecification value) {
- String label = "";
-
- if(value instanceof LiteralBoolean) {
- label = "<LiteralBoolean> ";
- } else if(value instanceof LiteralInteger) {
- label = "<LiteralInteger> ";
- } else if(value instanceof LiteralString) {
- label = "<LiteralString> ";
- } else if(value instanceof LiteralUnlimitedNatural) {
- label = "<LiteralUnlimitedNatural> ";
- } else {
- label = "<ValueSpecification> ";
- }
-
- // Add the value
- label = label + value.stringValue();
-
- return label;
- }
-
- /**
- * Return the label for a value specification
- *
- * @param object
- * @return
- */
- public static String getOriginLabel(ValueSpecification value) {
- String label = getLabel(value);
-
- Element owner = value.getOwner();
- // Add parent qualified name when possible
- if(owner instanceof NamedElement) {
- NamedElement ownerNE = (NamedElement)value.getOwner();
- if(ownerNE.isSetName()) {
- label = label + " (" + ownerNE.getQualifiedName() + ")";
- }
- } else if(owner instanceof Slot) {
- Slot ownerSlot = (Slot)owner;
- InstanceSpecification ownerISpec = ownerSlot.getOwningInstance();
- StructuralFeature definingFeature = ownerSlot.getDefiningFeature();
- label = label + " (" + ownerISpec.getQualifiedName() + "::" + definingFeature.getLabel() + ")";
-
- } // else nothing
-
- return label;
- }
-
- /**
- * This method is used to look for the top package that contains this element.
- *
- * @param element
- * the element for which top package must be returned
- * @return the top package
- */
- public static Package topPackage(Element element) {
- if(element.getOwner() == null) {
- return (Package)element;
- } else {
- return topPackage(element.getOwner());
- }
- }
-
- /**
- * Returns every PapyrusDefinitionAnnotation corresponding to the version of profile definitions
- *
- * @param profile
- * the profile to study
- * @return every eAnnotations associated to the profile definitions or an empty list if no
- * eAnnotation exists for given profile
- */
- public static List<PapyrusDefinitionAnnotation> getAllPapyrusDefinitionAnnotation(Profile profile) {
- List<PapyrusDefinitionAnnotation> definitions = new ArrayList<PapyrusDefinitionAnnotation>();
- Iterator<EAnnotation> it = getAllPapyrusVersionAnnotation(profile).iterator();
- while(it.hasNext()) {
- definitions.add(PapyrusDefinitionAnnotation.parseEAnnotation(it.next()));
- }
- return definitions;
- }
-
- /**
- * Returns every eAnnotations associated to the profile definitions
- *
- * @param profile
- * the profile to study
- * @return every eAnnotations associated to the profile definitions or an empty list if no
- * eAnnotation exists for given profile
- */
- public static List<EAnnotation> getAllPapyrusVersionAnnotation(Profile profile) {
- List<EAnnotation> annotations = new ArrayList<EAnnotation>();
- EAnnotation definitions = profile.getEAnnotation("http://www.eclipse.org/uml2/2.0.0/UML");
- if(definitions == null) {
- return annotations;
- }
-
- Iterator<EObject> it = definitions.getContents().iterator();
- while(it.hasNext()) {
- // content are EPackage
- EPackage object = (EPackage)it.next();
- EAnnotation annotation = object.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
- if(annotation != null) {
- annotations.add(annotation);
- }
- }
- return annotations;
- }
-
- /**
- * Returns the eAnnotation associated to the current profile definition
- *
- * @return the eAnnotation associated to the current profile definition or <code>null</code> if no
- * eAnnotation exists for given profile
- */
- public static EAnnotation getPapyrusVersionAnnotation(Profile profile) {
- if(profile.getDefinition() != null) {
- return profile.getDefinition().getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
- }
- return null;
- }
-
- /**
- * Returns the version of the current profile definition
- *
- * @param profile
- * the profile to check
- * @return the version of the current profile definition
- */
- public static Version getProfileDefinitionVersion(Profile profile) {
- return getDefinitionVersion(profile.getDefinition());
- }
-
- /**
- * Returns the author of the current profile definition
- *
- * @param profile
- * the profile to check
- * @return the author of the current profile definition or the empty string if none was given
- */
- public static String getProfileDefinitionAuthor(Profile profile) {
- EAnnotation annotation = getPapyrusVersionAnnotation(profile);
- if(annotation == null) {
- return "";
- } else {
- // retrieve the version from the annotation
- final String value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_AUTHOR_KEY);
- return (value != null) ? value : "";
- }
- }
-
- /**
- * Returns the date of the current profile definition
- *
- * @param profile
- * the profile to check
- * @return the date of the current profile definition or the empty string if none was given
- */
- public static String getProfileDefinitionDate(Profile profile) {
- EAnnotation annotation = getPapyrusVersionAnnotation(profile);
- if(annotation == null) {
- return "";
- } else {
- // retrieve the version from the annotation
- final String value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_DATE_KEY);
- return (value != null) ? value : "";
- }
- }
-
- /**
- * Returns the comment of the current profile definition
- *
- * @param profile
- * the profile to check
- * @return the comment of the current profile definition or the empty string if none was given
- */
- public static String getProfileDefinitionComment(Profile profile) {
- EAnnotation annotation = getPapyrusVersionAnnotation(profile);
- if(annotation == null) {
- return "";
- } else {
- // retrieve the version from the annotation
- final String value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COMMENT_KEY);
- return (value != null) ? value : "";
- }
- }
-
- /**
- * Returns the copyright of the current profile definition
- *
- * @param profile
- * the profile to check
- * @return the copyright of the current profile definition or the empty string if none was given
- */
- public static String getProfileDefinitionCopyright(Profile profile) {
- EAnnotation annotation = getPapyrusVersionAnnotation(profile);
- if(annotation == null) {
- return "";
- } else {
- // retrieve the version from the annotation
- final String value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COPYRIGHT_KEY);
- return (value != null) ? value : "";
- }
- }
-
- /**
- * We look for the nearest profile application from the Element, owning the stereotype;
- *
- * @param stereotype
- * @return
- * the nearest profile application owning the stereotype
- */
- public static ProfileApplication getNearestProfileApplicationFor(final Element element, final Stereotype stereotype) {
- ProfileApplication profileApplication = null;
- Profile profile = stereotype.getProfile();
- EObject container = element;
- while(profileApplication == null && container != null) {
- if(container instanceof Package) {
- profileApplication = ((Package)container).getProfileApplication(profile);
- }
- container = container.eContainer();
- }
- return profileApplication;
- }
-
- /**
- * Returns the Version of the specified Profile Definition.
- * It is never null, but can be empty (Version.emptyVersion)
- *
- * @param definition
- * @return
- */
- public static Version getDefinitionVersion(EPackage definition) {
- if(definition == null) {
- return Version.emptyVersion;
- }
-
- EAnnotation annotation = definition.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
- if(annotation == null) {
- return Version.emptyVersion;
- } else {
- // retrieve the version from the annotation
- Version version;
- String value = "";
- try {
- value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY);
- version = new Version((value != null) ? value : "");
- } catch (Exception e) {
- Activator.logWarning("impossible to parse the version value: " + value);
- version = Version.emptyVersion;
- }
- return version;
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - add getNearestProfileApplication
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.utils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.papyrus.uml.profile.Message;
+import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants;
+import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation;
+import org.eclipse.papyrus.uml.tools.profile.definition.Version;
+import org.eclipse.uml2.uml.Comment;
+import org.eclipse.uml2.uml.DataType;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.ElementImport;
+import org.eclipse.uml2.uml.Enumeration;
+import org.eclipse.uml2.uml.EnumerationLiteral;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.LiteralBoolean;
+import org.eclipse.uml2.uml.LiteralInteger;
+import org.eclipse.uml2.uml.LiteralString;
+import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PackageImport;
+import org.eclipse.uml2.uml.PrimitiveType;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+import org.eclipse.uml2.uml.Slot;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.StructuralFeature;
+import org.eclipse.uml2.uml.TemplateBinding;
+import org.eclipse.uml2.uml.TemplateSignature;
+import org.eclipse.uml2.uml.TemplateableElement;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.ValueSpecification;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+
+/**
+ * Some utils extracted from com.cea.utils classes (package and element)
+ * TODO: not all are used, cleanup with respect to types
+ */
+public class Util {
+
+ /**
+ * Return a usable string label for passed object.
+ *
+ * @param object
+ * the object
+ *
+ * @return the label
+ */
+ public static String getLabel(Object object, boolean shortLabel) {
+ String label = "";
+
+ if(object == null) {
+ return "undefined";
+ }
+
+ if(object instanceof ValueSpecification) {
+ label = getLabel((ValueSpecification)object);
+
+ } else if(object instanceof Element) {
+ Element cE = (Element)object;
+ String cName = null;
+ String suffix = "";
+ String cComLabel = "";
+
+ NamedElement cNE = null;
+ if(object instanceof NamedElement) {
+ cNE = (NamedElement)object;
+
+ } else if(object instanceof PackageImport) {
+ PackageImport cPI = (PackageImport)object;
+ suffix = " (PackageImport)";
+ cNE = cPI.getImportedPackage();
+
+ } else if(object instanceof ElementImport) {
+ ElementImport cEI = (ElementImport)object;
+ suffix = " (ElementImport)";
+ cNE = cEI.getImportedElement();
+
+ } else if(object instanceof ProfileApplication) {
+ ProfileApplication cPA = (ProfileApplication)object;
+ suffix = " (ProfileApplication)";
+ cNE = cPA.getAppliedProfile();
+
+ } else if(object instanceof Comment) {
+ Comment cCom = (Comment)object;
+ suffix = " (Comment)";
+ String cComBody = cCom.getBody();
+ if(cComBody != null && cComBody.length() >= 10) {
+ cComLabel = cComBody.substring(0, 9) + "...";
+ } else {
+ cComLabel = cComBody;
+ }
+ } else if(object instanceof TemplateSignature) {
+ TemplateableElement te = ((TemplateSignature)object).getTemplate();
+ suffix = " (TemplateSignature owner)";
+ if(te instanceof NamedElement) {
+ cNE = (NamedElement)te;
+ }
+ } else if(object instanceof TemplateBinding) {
+ TemplateableElement te = ((TemplateBinding)object).getBoundElement();
+ suffix = " (TemplateBinding bound-element)";
+ if(te instanceof NamedElement) {
+ cNE = (NamedElement)te;
+ }
+ }
+ if(shortLabel) {
+ if(object instanceof Comment) {
+ cName = cComLabel;
+ } else if(cNE != null) {
+ cName = cNE.getName();
+ }
+ } else {
+ if(object instanceof Comment) {
+ cName = cComLabel + suffix;
+ } else if(cNE != null) {
+ cName = cNE.getQualifiedName() + suffix;
+ }
+ }
+
+ if(cName != null) {
+ label = cName;
+ } else {
+ label = cE.toString();
+ }
+ }
+
+ return label;
+ }
+
+
+ /**
+ * Check if a type is a metaclass.
+ *
+ * @param type
+ * to check
+ *
+ * @return true if type is metaclass, else false
+ */
+ public static boolean isMetaclass(Type type) {
+ boolean isMetaclass = false;
+
+ if((type instanceof org.eclipse.uml2.uml.Class) && (type.getAppliedStereotypes() != null) && (type.getAppliedStereotypes().size() > 0)) {
+
+ Stereotype firstStereotype = type.getAppliedStereotypes().get(0);
+
+ if(firstStereotype.getName().equals("Metaclass")) {
+ isMetaclass = true;
+ }
+ }
+ return isMetaclass;
+ }
+
+ /**
+ * Check if the type is a UML Metaclass
+ *
+ * @param type
+ * @return
+ */
+ public static boolean isMetaclass(EClassifier type) {
+ return type.getEPackage() == UMLPackage.eINSTANCE;
+ }
+
+ /**
+ * Convert the list of element in a list of string after some basic checks.
+ *
+ * @param elements
+ * the elements
+ *
+ * @return the string array from list
+ */
+ public static String[] getStringArrayFromList(List<Element> elements) {
+
+ ArrayList<String> tmp = new ArrayList<String>();
+
+ // if no possible selection : abort
+ if(elements.size() == 0) {
+ return null;
+ }
+
+ // First create tmp list
+ Iterator<Element> it = elements.iterator();
+ while(it.hasNext()) {
+ Object current = it.next();
+
+ String label = getLabel(current, false);
+ tmp.add(label);
+ }
+
+ // if no possible selection : abort
+ if(tmp.size() == 0) {
+ return null;
+ }
+
+ // Put this in array
+ String[] elementsNames = new String[tmp.size()];
+ for(int i = 0; i < tmp.size(); i++) {
+ elementsNames[i] = tmp.get(i);
+ }
+
+ // PostCondition
+ if(elementsNames.length != elements.size()) {
+ Message.error("Number of elements in name list does not match number or elements.");
+ elementsNames = null;
+ }
+ return elementsNames;
+ }
+
+ /**
+ * Treat a string provided by the user for a primitiveType and return
+ * the corresponding object.
+ *
+ * @param dialogValue
+ * user input string
+ * @param type
+ * expected
+ *
+ * @return object
+ */
+ public static Object getValueObjectFromString(String dialogValue, Type type) {
+ Object newValue = null;
+ String typeName = type.getQualifiedName();
+
+ try {
+ if(type instanceof PrimitiveType || ((type instanceof DataType) && !(type instanceof Enumeration))) {
+ if(typeName.equals("UMLPrimitiveTypes::Integer")) {
+ newValue = Integer.valueOf(dialogValue);
+
+ } else if(typeName.equals("UMLPrimitiveTypes::UnlimitedNatural")) {
+ if(Integer.signum(Integer.parseInt(dialogValue)) != -1) {
+ newValue = Integer.valueOf(dialogValue);
+
+ } else {
+ Message.warning("UnlimitedNatural must be positive or null.");
+ }
+
+ } else if(typeName.equals("UMLPrimitiveTypes::String")) {
+ newValue = dialogValue;
+
+ } else if(typeName.equals("UMLPrimitiveTypes::Boolean")) {
+ newValue = Boolean.valueOf(dialogValue);
+
+ } else { // user defined primitive type
+ newValue = dialogValue;
+ }
+
+ } else if(type instanceof Enumeration) {
+ Enumeration enumeration = (Enumeration)type;
+ EnumerationLiteral literal = enumeration.getOwnedLiteral(dialogValue);
+
+ if(literal != null) {
+ newValue = literal;
+ }
+ }
+ } catch (NumberFormatException e) {
+ Message.warning("Bad format number.");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return newValue;
+ }
+
+ /**
+ * Helper function used by getInstancesFilteredByType
+ */
+ private static void checkAndAddElement(EObject currentEObj, @SuppressWarnings("rawtypes") Class metaType, Stereotype appliedStereotype, ArrayList<Element> filteredElements) {
+ if(currentEObj instanceof Element) {
+ Element piCurrentElt = (Element)currentEObj;
+ if(appliedStereotype != null) {
+
+ // It is not sufficient to call getAppliedStereotypes, since we also want to
+ // retrieve elements that apply a sub-stereotype
+ if(piCurrentElt.getAppliedSubstereotype(appliedStereotype, null) != null) {
+ filteredElements.add(piCurrentElt);
+ }
+ Iterator<Stereotype> appStIter = piCurrentElt.getAppliedStereotypes().iterator();
+ while(appStIter.hasNext()) {
+ Stereotype currentSt = appStIter.next();
+
+ if(currentSt.conformsTo(appliedStereotype)) {
+ filteredElements.add(piCurrentElt);
+ }
+ }
+
+ } else { // if (appliedStereotype == null)
+ if(metaType.isInstance(piCurrentElt)) {
+ filteredElements.add(piCurrentElt);
+ }
+
+ /** add imported meta elements */
+ else if(piCurrentElt instanceof ElementImport) {
+ Iterator<EObject> eIter = ((ElementImport)piCurrentElt).getImportedElement().eAllContents();
+ while(eIter.hasNext()) {
+ EObject currentEIelt = eIter.next();
+ if((currentEIelt instanceof Element) && (metaType.isInstance(currentEIelt))) {
+ filteredElements.add((Element)currentEIelt);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Retrieve an ArrayList of all instances in the model that
+ * are instances of the java.lang.Class metaType or with a
+ * stereotype applied
+ *
+ * @param metaType
+ * selected classes
+ * @param model
+ * to check
+ * @param appliedStereotype
+ * may be null, metatype is ignored if not null
+ * @return an arraylist containing the selected instances
+ */
+ public static ArrayList<Element> getInstancesFilteredByType(Element element, @SuppressWarnings("rawtypes") Class metaType, Stereotype appliedStereotype) {
+ // retrieve parent element
+ Package topPackage = Util.topPackage(element);
+ Assert.isNotNull(topPackage, "Top package should not be null for element " + element);
+ Iterator<EObject> iter = topPackage.eAllContents();
+ ArrayList<Element> filteredElements = new ArrayList<Element>();
+
+ while(iter.hasNext()) {
+ EObject currentEObj = iter.next();
+
+ // If currentElt is an ElementImport, it is replaced by the imported
+ // Element.
+ if(currentEObj instanceof ElementImport) {
+ ElementImport elementImport = (ElementImport)currentEObj;
+ currentEObj = elementImport.getImportedElement();
+ }
+
+ /* package imports treatment */
+ else if(currentEObj instanceof PackageImport) {
+ Package importedPkg = ((PackageImport)currentEObj).getImportedPackage();
+ if(importedPkg != null) {
+ Iterator<EObject> piIter = importedPkg.eAllContents();
+ while(piIter.hasNext()) {
+ EObject piCurrentEObj = piIter.next();
+ checkAndAddElement(piCurrentEObj, metaType, appliedStereotype, filteredElements);
+ }
+ }
+ }
+
+ // Filtering elements
+ checkAndAddElement(currentEObj, metaType, appliedStereotype, filteredElements);
+ }
+
+ return filteredElements;
+ }
+
+ /**
+ * Reorder stereotype applications.
+ *
+ * @param element
+ * the element
+ * @param stereotypes
+ * the stereotypes
+ */
+ public static void reorderStereotypeApplications(Element element, EList<Stereotype> stereotypes) {
+ for(Iterator<Stereotype> s = stereotypes.iterator(); s.hasNext();) {
+ EObject stereotypeApplication = element.getStereotypeApplication(s.next());
+ if(stereotypeApplication != null) {
+ UMLUtil.setBaseElement(stereotypeApplication, null);
+ UMLUtil.setBaseElement(stereotypeApplication, element);
+ Resource eResource = stereotypeApplication.eResource();
+ if(eResource != null) {
+ EList<EObject> contents = eResource.getContents();
+ contents.move(contents.size() - 1, stereotypeApplication);
+ }
+ }
+ }
+ }
+
+ /**
+ * Return the labe for a value specification
+ *
+ * @param object
+ * @return
+ */
+ public static String getLabel(ValueSpecification value) {
+ String label = "";
+
+ if(value instanceof LiteralBoolean) {
+ label = "<LiteralBoolean> ";
+ } else if(value instanceof LiteralInteger) {
+ label = "<LiteralInteger> ";
+ } else if(value instanceof LiteralString) {
+ label = "<LiteralString> ";
+ } else if(value instanceof LiteralUnlimitedNatural) {
+ label = "<LiteralUnlimitedNatural> ";
+ } else {
+ label = "<ValueSpecification> ";
+ }
+
+ // Add the value
+ label = label + value.stringValue();
+
+ return label;
+ }
+
+ /**
+ * Return the label for a value specification
+ *
+ * @param object
+ * @return
+ */
+ public static String getOriginLabel(ValueSpecification value) {
+ String label = getLabel(value);
+
+ Element owner = value.getOwner();
+ // Add parent qualified name when possible
+ if(owner instanceof NamedElement) {
+ NamedElement ownerNE = (NamedElement)value.getOwner();
+ if(ownerNE.isSetName()) {
+ label = label + " (" + ownerNE.getQualifiedName() + ")";
+ }
+ } else if(owner instanceof Slot) {
+ Slot ownerSlot = (Slot)owner;
+ InstanceSpecification ownerISpec = ownerSlot.getOwningInstance();
+ StructuralFeature definingFeature = ownerSlot.getDefiningFeature();
+ label = label + " (" + ownerISpec.getQualifiedName() + "::" + definingFeature.getLabel() + ")";
+
+ } // else nothing
+
+ return label;
+ }
+
+ /**
+ * This method is used to look for the top package that contains this element.
+ *
+ * @param element
+ * the element for which top package must be returned
+ * @return the top package
+ */
+ public static Package topPackage(Element element) {
+ if(element.getOwner() == null) {
+ return (Package)element;
+ } else {
+ return topPackage(element.getOwner());
+ }
+ }
+
+ /**
+ * Returns every PapyrusDefinitionAnnotation corresponding to the version of profile definitions
+ *
+ * @param profile
+ * the profile to study
+ * @return every eAnnotations associated to the profile definitions or an empty list if no
+ * eAnnotation exists for given profile
+ */
+ public static List<PapyrusDefinitionAnnotation> getAllPapyrusDefinitionAnnotation(Profile profile) {
+ List<PapyrusDefinitionAnnotation> definitions = new ArrayList<PapyrusDefinitionAnnotation>();
+ Iterator<EAnnotation> it = getAllPapyrusVersionAnnotation(profile).iterator();
+ while(it.hasNext()) {
+ definitions.add(PapyrusDefinitionAnnotation.parseEAnnotation(it.next()));
+ }
+ return definitions;
+ }
+
+ /**
+ * Returns every eAnnotations associated to the profile definitions
+ *
+ * @param profile
+ * the profile to study
+ * @return every eAnnotations associated to the profile definitions or an empty list if no
+ * eAnnotation exists for given profile
+ */
+ public static List<EAnnotation> getAllPapyrusVersionAnnotation(Profile profile) {
+ List<EAnnotation> annotations = new ArrayList<EAnnotation>();
+ EAnnotation definitions = profile.getEAnnotation("http://www.eclipse.org/uml2/2.0.0/UML");
+ if(definitions == null) {
+ return annotations;
+ }
+
+ Iterator<EObject> it = definitions.getContents().iterator();
+ while(it.hasNext()) {
+ // content are EPackage
+ EPackage object = (EPackage)it.next();
+ EAnnotation annotation = object.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ if(annotation != null) {
+ annotations.add(annotation);
+ }
+ }
+ return annotations;
+ }
+
+ /**
+ * Returns the eAnnotation associated to the current profile definition
+ *
+ * @return the eAnnotation associated to the current profile definition or <code>null</code> if no
+ * eAnnotation exists for given profile
+ */
+ public static EAnnotation getPapyrusVersionAnnotation(Profile profile) {
+ if(profile.getDefinition() != null) {
+ return profile.getDefinition().getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the version of the current profile definition
+ *
+ * @param profile
+ * the profile to check
+ * @return the version of the current profile definition
+ */
+ public static Version getProfileDefinitionVersion(Profile profile) {
+ return getDefinitionVersion(profile.getDefinition());
+ }
+
+ /**
+ * Returns the author of the current profile definition
+ *
+ * @param profile
+ * the profile to check
+ * @return the author of the current profile definition or the empty string if none was given
+ */
+ public static String getProfileDefinitionAuthor(Profile profile) {
+ EAnnotation annotation = getPapyrusVersionAnnotation(profile);
+ if(annotation == null) {
+ return "";
+ } else {
+ // retrieve the version from the annotation
+ final String value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_AUTHOR_KEY);
+ return (value != null) ? value : "";
+ }
+ }
+
+ /**
+ * Returns the date of the current profile definition
+ *
+ * @param profile
+ * the profile to check
+ * @return the date of the current profile definition or the empty string if none was given
+ */
+ public static String getProfileDefinitionDate(Profile profile) {
+ EAnnotation annotation = getPapyrusVersionAnnotation(profile);
+ if(annotation == null) {
+ return "";
+ } else {
+ // retrieve the version from the annotation
+ final String value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_DATE_KEY);
+ return (value != null) ? value : "";
+ }
+ }
+
+ /**
+ * Returns the comment of the current profile definition
+ *
+ * @param profile
+ * the profile to check
+ * @return the comment of the current profile definition or the empty string if none was given
+ */
+ public static String getProfileDefinitionComment(Profile profile) {
+ EAnnotation annotation = getPapyrusVersionAnnotation(profile);
+ if(annotation == null) {
+ return "";
+ } else {
+ // retrieve the version from the annotation
+ final String value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COMMENT_KEY);
+ return (value != null) ? value : "";
+ }
+ }
+
+ /**
+ * Returns the copyright of the current profile definition
+ *
+ * @param profile
+ * the profile to check
+ * @return the copyright of the current profile definition or the empty string if none was given
+ */
+ public static String getProfileDefinitionCopyright(Profile profile) {
+ EAnnotation annotation = getPapyrusVersionAnnotation(profile);
+ if(annotation == null) {
+ return "";
+ } else {
+ // retrieve the version from the annotation
+ final String value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COPYRIGHT_KEY);
+ return (value != null) ? value : "";
+ }
+ }
+
+ /**
+ * We look for the nearest profile application from the Element, owning the stereotype;
+ *
+ * @param stereotype
+ * @return
+ * the nearest profile application owning the stereotype
+ */
+ public static ProfileApplication getNearestProfileApplicationFor(final Element element, final Stereotype stereotype) {
+ ProfileApplication profileApplication = null;
+ Profile profile = stereotype.getProfile();
+ EObject container = element;
+ while(profileApplication == null && container != null) {
+ if(container instanceof Package) {
+ profileApplication = ((Package)container).getProfileApplication(profile);
+ }
+ container = container.eContainer();
+ }
+ return profileApplication;
+ }
+
+ /**
+ * Returns the Version of the specified Profile Definition.
+ * It is never null, but can be empty (Version.emptyVersion)
+ *
+ * @param definition
+ * @return
+ */
+ public static Version getDefinitionVersion(EPackage definition) {
+ if(definition == null) {
+ return Version.emptyVersion;
+ }
+
+ EAnnotation annotation = definition.getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ if(annotation == null) {
+ return Version.emptyVersion;
+ } else {
+ // retrieve the version from the annotation
+ Version version;
+ String value = "";
+ try {
+ value = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY);
+ version = new Version((value != null) ? value : "");
+ } catch (Exception e) {
+ Activator.logWarning("impossible to parse the version value: " + value);
+ version = Version.emptyVersion;
+ }
+ return version;
+ }
+ }
+}
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java
index 2941d14fbac..5a2d74f7d32 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/widgets/ProfileApplicationEditor.java
@@ -36,7 +36,6 @@ import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.widgets.editors.MultipleReferenceEditor;
-import org.eclipse.papyrus.uml.profile.definition.Version;
import org.eclipse.papyrus.uml.profile.ui.dialogs.ElementImportTreeSelectionDialog.ImportSpec;
import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileTreeSelectionDialog;
import org.eclipse.papyrus.uml.profile.utils.Util;
@@ -46,6 +45,7 @@ import org.eclipse.papyrus.uml.properties.messages.Messages;
import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.Message;
import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.RegisteredProfileSelectionDialog;
import org.eclipse.papyrus.uml.tools.importsources.PackageImportSourceDialog;
+import org.eclipse.papyrus.uml.tools.profile.definition.Version;
import org.eclipse.papyrus.uml.tools.utils.ProfileUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
index 513bd01748a..49082c3bd77 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/META-INF/MANIFEST.MF
@@ -1,46 +1,47 @@
-Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.uml.tools,
- org.eclipse.papyrus.uml.tools.adapters,
- org.eclipse.papyrus.uml.tools.commands,
- org.eclipse.papyrus.uml.tools.databinding,
- org.eclipse.papyrus.uml.tools.helper,
- org.eclipse.papyrus.uml.tools.importsources,
- org.eclipse.papyrus.uml.tools.listeners,
- org.eclipse.papyrus.uml.tools.model,
- org.eclipse.papyrus.uml.tools.namereferences,
- org.eclipse.papyrus.uml.tools.providers,
- org.eclipse.papyrus.uml.tools.util
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.uml2.uml;bundle-version="4.1.0";visibility:=reexport,
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
- org.eclipse.core.databinding;bundle-version="1.4.1",
- org.eclipse.emf.databinding;bundle-version="1.2.0",
- org.eclipse.core.databinding.property;bundle-version="1.4.0",
- org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0",
- org.eclipse.uml2.common.edit;bundle-version="1.6.0",
- org.eclipse.uml2.uml.edit;bundle-version="4.0.0",
- org.eclipse.papyrus.infra.services.validation;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.4.0",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
- org.eclipse.core.expressions;bundle-version="3.4.0",
- org.eclipse.uml2.uml,
- org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.extensionpoints;bundle-version="1.0.0",
- org.eclipse.uml2.uml.validation;bundle-version="5.0.0"
-Bundle-Vendor: Eclipse Modeling Project
-Bundle-ActivationPolicy: lazy
-Bundle-Version: 1.0.0.qualifier
-Bundle-Name: UML Tools
-Bundle-Activator: org.eclipse.papyrus.uml.tools.Activator
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.uml.tools;singleton:=true
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-
+Manifest-Version: 1.0
+Export-Package: org.eclipse.papyrus.uml.tools,
+ org.eclipse.papyrus.uml.tools.adapters,
+ org.eclipse.papyrus.uml.tools.commands,
+ org.eclipse.papyrus.uml.tools.databinding,
+ org.eclipse.papyrus.uml.tools.helper,
+ org.eclipse.papyrus.uml.tools.importsources,
+ org.eclipse.papyrus.uml.tools.listeners,
+ org.eclipse.papyrus.uml.tools.model,
+ org.eclipse.papyrus.uml.tools.namereferences,
+ org.eclipse.papyrus.uml.tools.profile.definition,
+ org.eclipse.papyrus.uml.tools.providers,
+ org.eclipse.papyrus.uml.tools.util
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.uml2.uml;bundle-version="4.1.0";visibility:=reexport,
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
+ org.eclipse.core.databinding;bundle-version="1.4.1",
+ org.eclipse.emf.databinding;bundle-version="1.2.0",
+ org.eclipse.core.databinding.property;bundle-version="1.4.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0",
+ org.eclipse.uml2.common.edit;bundle-version="1.6.0",
+ org.eclipse.uml2.uml.edit;bundle-version="4.0.0",
+ org.eclipse.papyrus.infra.services.validation;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.emf.type.core;bundle-version="1.4.0",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
+ org.eclipse.core.expressions;bundle-version="3.4.0",
+ org.eclipse.uml2.uml,
+ org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.0.0",
+ org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.extensionpoints;bundle-version="1.0.0",
+ org.eclipse.uml2.uml.validation;bundle-version="5.0.0"
+Bundle-Vendor: Eclipse Modeling Project
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 1.0.0.qualifier
+Bundle-Name: UML Tools
+Bundle-Activator: org.eclipse.papyrus.uml.tools.Activator
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.papyrus.uml.tools;singleton:=true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java
index 45e402d2edf..b49760e8580 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java
@@ -1,74 +1,130 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.commands;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-
-/**
- * A command to apply a profile on a UML Package
- *
- * @author Camille Letavernier
- */
-public class ApplyProfileCommand extends RecordingCommand {
-
- private Package umlPackage;
-
- private Collection<Profile> profiles;
-
- /**
- *
- * Constructor.
- *
- * @param umlPackage
- * The UML Package on which the profiles will be applied
- * @param profiles
- * The list of profiles to apply
- * @param editingDomain
- * The EditingDomain
- */
- public ApplyProfileCommand(Package umlPackage, Collection<Profile> profiles, TransactionalEditingDomain editingDomain) {
- super(editingDomain);
- this.umlPackage = umlPackage;
- this.profiles = profiles;
- }
-
- /**
- *
- * Constructor.
- *
- * @param umlPackage
- * The UML Package on which the profile will be applied
- * @param profile
- * The profile to apply
- * @param editingDomain
- * The EditingDomain
- */
- public ApplyProfileCommand(Package umlPackage, Profile profile, TransactionalEditingDomain editingDomain) {
- super(editingDomain);
- this.umlPackage = umlPackage;
- this.profiles = Collections.singletonList(profile);
- }
-
- @Override
- protected void doExecute() {
- for(Profile profile : profiles) {
- umlPackage.applyProfile(profile);
- }
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.commands;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+
+/**
+ * A command to apply a profile on a UML Package and save applied version of profile.
+ * <p>
+ * It is possible to disable save of version, passing boolean value to constructor.
+ * </p>
+ *
+ * @author Camille Letavernier
+ */
+public class ApplyProfileCommand extends RecordingCommand {
+
+ /** The uml package. */
+ private Package umlPackage;
+
+ /** The profiles. */
+ private Collection<Profile> profiles;
+
+ /** The save profile application version. */
+ private boolean saveProfileApplicationVersion;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param umlPackage
+ * The UML Package on which the profiles will be applied
+ * @param profiles
+ * The list of profiles to apply
+ * @param editingDomain
+ * The EditingDomain
+ */
+ public ApplyProfileCommand(Package umlPackage, Collection<Profile> profiles, TransactionalEditingDomain editingDomain) {
+ this(umlPackage, profiles, editingDomain, true);
+ }
+
+ /**
+ * Instantiates a new apply profile command.
+ *
+ * @param umlPackage
+ * the uml package
+ * @param profiles
+ * the profiles
+ * @param editingDomain
+ * the editing domain
+ * @param saveProfileApplicationVersion
+ * the save profile application version
+ */
+ public ApplyProfileCommand(Package umlPackage, Collection<Profile> profiles, TransactionalEditingDomain editingDomain, boolean saveProfileApplicationVersion) {
+ super(editingDomain);
+ this.umlPackage = umlPackage;
+ this.profiles = profiles;
+ this.saveProfileApplicationVersion = saveProfileApplicationVersion;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param umlPackage
+ * The UML Package on which the profile will be applied
+ * @param profile
+ * The profile to apply
+ * @param editingDomain
+ * The EditingDomain
+ */
+ public ApplyProfileCommand(Package umlPackage, Profile profile, TransactionalEditingDomain editingDomain) {
+ this(umlPackage, profile, editingDomain, true);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param umlPackage
+ * The UML Package on which the profile will be applied
+ * @param profile
+ * The profile to apply
+ * @param editingDomain
+ * The EditingDomain
+ * @param saveProfileApplicationVersion
+ * the save profile application version
+ */
+ public ApplyProfileCommand(Package umlPackage, Profile profile, TransactionalEditingDomain editingDomain, boolean saveProfileApplicationVersion) {
+ this(umlPackage, Collections.singletonList(profile), editingDomain, saveProfileApplicationVersion);
+ }
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+ @Override
+ protected void doExecute() {
+ for(Profile profile : profiles) {
+ // Apply profile
+ umlPackage.applyProfile(profile);
+
+ // Save version of applied profile if necessary
+ if(saveProfileApplicationVersion) {
+ ProfileApplication profileApplication = umlPackage.getProfileApplication(profile);
+ EAnnotation versionAnnotation = profile.getDefinition().getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ profileApplication.getEAnnotations().add(0, EcoreUtil.copy(versionAnnotation));
+ }
+ }
+ }
+
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java
index 1b209eef5aa..b90aa19af2e 100644
--- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/databinding/ProfileApplicationObservableList.java
@@ -1,337 +1,337 @@
-/*****************************************************************************
- * Copyright (c) 2011, 2014 CEA LIST and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - 402525
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.databinding;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.databinding.observable.IObserving;
-import org.eclipse.core.databinding.observable.list.ListDiff;
-import org.eclipse.core.databinding.observable.list.ListDiffEntry;
-import org.eclipse.core.databinding.observable.list.WritableList;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
-import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
-import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
-import org.eclipse.papyrus.uml.tools.commands.UnapplyProfileCommand;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-
-/**
- *
- * An IObservableList for Profile application
- *
- * @author Camille Letavernier
- */
-@SuppressWarnings({ "unchecked", "rawtypes" })
-public class ProfileApplicationObservableList extends WritableList implements ICommitListener, IObserving {
-
- private Package umlSource;
-
- private EditingDomain domain;
-
- private final List<Command> commands;
-
- private AbstractStereotypeListener listener;
-
- /**
- *
- * Constructor.
- *
- * @param umlSource
- * The Package on which the profiles are applied or unapplied
- * @param domain
- * The editing domain on which the commands are executed
- */
- public ProfileApplicationObservableList(Package umlSource, EditingDomain domain) {
- super(new LinkedList<Object>(umlSource.getAppliedProfiles()), Profile.class);
- this.umlSource = umlSource;
- this.domain = domain;
- commands = new LinkedList<Command>();
-
- listener = new AbstractStereotypeListener(umlSource) {
-
- @Override
- protected void handleUnappliedStereotype(final EObject newValue) {
- ProfileApplicationObservableList.this.fireListChange(new ListDiff() {
-
- @Override
- public ListDiffEntry[] getDifferences() {
- return new ListDiffEntry[]{ new ListDiffEntry() {
-
- @Override
- public int getPosition() {
- return 0;
- }
-
- @Override
- public boolean isAddition() {
- return false;
- }
-
- @Override
- public Object getElement() {
- return newValue;
- }
-
- } };
- }
-
- });
- }
-
- @Override
- protected void handleAppliedStereotype(final EObject newValue) {
- ProfileApplicationObservableList.this.fireListChange(new ListDiff() {
-
- @Override
- public ListDiffEntry[] getDifferences() {
- return new ListDiffEntry[]{ new ListDiffEntry() {
-
- @Override
- public int getPosition() {
- return 0;
- }
-
- @Override
- public boolean isAddition() {
- return true;
- }
-
- @Override
- public Object getElement() {
- return newValue;
- }
-
- } };
- }
-
- });
- }
- };
- }
-
- public Object getObserved() {
- return umlSource;
- }
-
- @Override
- public synchronized void dispose() {
- super.dispose();
- this.listener.dispose();
- }
-
- public void commit(AbstractEditor editor) {
- if(commands.isEmpty()) {
- return;
- }
-
- CompoundCommand compoundCommand = new CompoundCommand() {
-
- @Override
- public void execute() {
- super.execute();
- refreshCacheList();
- }
-
- @Override
- public void undo() {
- super.undo();
- refreshCacheList();
- }
-
- @Override
- public void redo() {
- super.redo();
- refreshCacheList();
- }
-
- /**
- * We have a sequential execution : the method canExecute() in
- * the command n+1 depends on the result of the command n. We can't
- * check every command's canExecute() method here, so we only
- * check the first one.
- */
- @Override
- public boolean canExecute() {
- return commandList.isEmpty() ? false : commandList.get(0).canExecute();
- }
- //TODO : edit the execute() method to call the remaining canExecute() checks
- //during the execution
- //(n).canExecute()
- //(n).execute()
- //(n+1).canExecute()
- //(n+1).execute()
-
- //Problem : this is the StrictCompoundCommand's behavior. However, in the
- //StrictCompoundCommand implementation, the execute() is called outside of
- //the current CommandStack, which is forbidden
- };
-
- for(Command cmd : commands) {
- compoundCommand.append(cmd);
- }
-
- domain.getCommandStack().execute(compoundCommand);
- refreshCacheList();
- commands.clear();
- }
-
- private void refreshCacheList() {
- wrappedList.clear();
- wrappedList.addAll(umlSource.getAppliedProfiles());
- fireListChange(null);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void clear() {
- removeAll(new LinkedList<Object>(wrappedList));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean add(Object o) {
- if(!(o instanceof Profile)) {
- return false;
- }
-
- Profile profile = EMFHelper.reloadIntoContext((Profile)o, umlSource);
- Command command = new ApplyProfileCommand(umlSource, profile, (TransactionalEditingDomain)domain);
-
- commands.add(command);
-
- return wrappedList.add(o);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean remove(Object o) {
-
- if(!(o instanceof Profile)) {
- return false;
- }
-
- final Profile profile = (Profile)o;
- Command command = new UnapplyProfileCommand(umlSource, profile, (TransactionalEditingDomain)domain);
-
- commands.add(command);
-
- return wrappedList.remove(o);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean addAll(Collection c) {
- //We only apply the profiles that are not applied yet (To avoid removing them when undo is called)
- c.removeAll(wrappedList);
-
- Collection<Profile> profiles = new LinkedList<Profile>();
- for(Object element : c) {
- if(element instanceof Profile) {
- profiles.add(EMFHelper.reloadIntoContext((Profile)element, umlSource));
- } else {
- throw new IllegalArgumentException("The new value should only contain profiles");
- }
- }
- Command command = new ApplyProfileCommand(umlSource, profiles, (TransactionalEditingDomain)domain);
-
- commands.add(command);
-
- return wrappedList.addAll(c);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean removeAll(Collection c) {
- Command command = new UnapplyProfileCommand(umlSource, c, (TransactionalEditingDomain)domain);
-
- commands.add(command);
-
- return wrappedList.removeAll(c);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean retainAll(Collection c) {
- List<Object> objectsToRemove = new LinkedList<Object>();
- for(Object object : c) {
- if(!contains(object)) {
- objectsToRemove.add(object);
- }
- }
- return removeAll(objectsToRemove);
- }
-
- //Unsupported operations. Some of them have a "proxy" implementation
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void add(int index, Object value) {
- add(value); //The list is not ordered
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean addAll(int index, Collection c) {
- return addAll(c); //The list is not ordered
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object set(int index, Object element) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object move(int oldIndex, int newIndex) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object remove(int index) {
- throw new UnsupportedOperationException();
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011, 2014 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - 402525
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.databinding;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.IObserving;
+import org.eclipse.core.databinding.observable.list.ListDiff;
+import org.eclipse.core.databinding.observable.list.ListDiffEntry;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
+import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
+import org.eclipse.papyrus.uml.tools.commands.ApplyProfileCommand;
+import org.eclipse.papyrus.uml.tools.commands.UnapplyProfileCommand;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+
+/**
+ *
+ * An IObservableList for Profile application
+ *
+ * @author Camille Letavernier
+ */
+@SuppressWarnings({ "unchecked", "rawtypes" })
+public class ProfileApplicationObservableList extends WritableList implements ICommitListener, IObserving {
+
+ private Package umlSource;
+
+ private EditingDomain domain;
+
+ private final List<Command> commands;
+
+ private AbstractStereotypeListener listener;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param umlSource
+ * The Package on which the profiles are applied or unapplied
+ * @param domain
+ * The editing domain on which the commands are executed
+ */
+ public ProfileApplicationObservableList(Package umlSource, EditingDomain domain) {
+ super(new LinkedList<Object>(umlSource.getAppliedProfiles()), Profile.class);
+ this.umlSource = umlSource;
+ this.domain = domain;
+ commands = new LinkedList<Command>();
+
+ listener = new AbstractStereotypeListener(umlSource) {
+
+ @Override
+ protected void handleUnappliedStereotype(final EObject newValue) {
+ ProfileApplicationObservableList.this.fireListChange(new ListDiff() {
+
+ @Override
+ public ListDiffEntry[] getDifferences() {
+ return new ListDiffEntry[]{ new ListDiffEntry() {
+
+ @Override
+ public int getPosition() {
+ return 0;
+ }
+
+ @Override
+ public boolean isAddition() {
+ return false;
+ }
+
+ @Override
+ public Object getElement() {
+ return newValue;
+ }
+
+ } };
+ }
+
+ });
+ }
+
+ @Override
+ protected void handleAppliedStereotype(final EObject newValue) {
+ ProfileApplicationObservableList.this.fireListChange(new ListDiff() {
+
+ @Override
+ public ListDiffEntry[] getDifferences() {
+ return new ListDiffEntry[]{ new ListDiffEntry() {
+
+ @Override
+ public int getPosition() {
+ return 0;
+ }
+
+ @Override
+ public boolean isAddition() {
+ return true;
+ }
+
+ @Override
+ public Object getElement() {
+ return newValue;
+ }
+
+ } };
+ }
+
+ });
+ }
+ };
+ }
+
+ public Object getObserved() {
+ return umlSource;
+ }
+
+ @Override
+ public synchronized void dispose() {
+ super.dispose();
+ this.listener.dispose();
+ }
+
+ public void commit(AbstractEditor editor) {
+ if(commands.isEmpty()) {
+ return;
+ }
+
+ CompoundCommand compoundCommand = new CompoundCommand() {
+
+ @Override
+ public void execute() {
+ super.execute();
+ refreshCacheList();
+ }
+
+ @Override
+ public void undo() {
+ super.undo();
+ refreshCacheList();
+ }
+
+ @Override
+ public void redo() {
+ super.redo();
+ refreshCacheList();
+ }
+
+ /**
+ * We have a sequential execution : the method canExecute() in
+ * the command n+1 depends on the result of the command n. We can't
+ * check every command's canExecute() method here, so we only
+ * check the first one.
+ */
+ @Override
+ public boolean canExecute() {
+ return commandList.isEmpty() ? false : commandList.get(0).canExecute();
+ }
+ //TODO : edit the execute() method to call the remaining canExecute() checks
+ //during the execution
+ //(n).canExecute()
+ //(n).execute()
+ //(n+1).canExecute()
+ //(n+1).execute()
+
+ //Problem : this is the StrictCompoundCommand's behavior. However, in the
+ //StrictCompoundCommand implementation, the execute() is called outside of
+ //the current CommandStack, which is forbidden
+ };
+
+ for(Command cmd : commands) {
+ compoundCommand.append(cmd);
+ }
+
+ domain.getCommandStack().execute(compoundCommand);
+ refreshCacheList();
+ commands.clear();
+ }
+
+ private void refreshCacheList() {
+ wrappedList.clear();
+ wrappedList.addAll(umlSource.getAppliedProfiles());
+ fireListChange(null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear() {
+ removeAll(new LinkedList<Object>(wrappedList));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean add(Object o) {
+ if(!(o instanceof Profile)) {
+ return false;
+ }
+
+ Profile profile = EMFHelper.reloadIntoContext((Profile)o, umlSource);
+ Command command = new ApplyProfileCommand(umlSource, profile, (TransactionalEditingDomain)domain);
+
+ commands.add(command);
+
+
+ return wrappedList.add(o);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean remove(Object o) {
+
+ if(!(o instanceof Profile)) {
+ return false;
+ }
+
+ final Profile profile = (Profile)o;
+ Command command = new UnapplyProfileCommand(umlSource, profile, (TransactionalEditingDomain)domain);
+
+ commands.add(command);
+
+ return wrappedList.remove(o);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean addAll(Collection c) {
+ //We only apply the profiles that are not applied yet (To avoid removing them when undo is called)
+ c.removeAll(wrappedList);
+
+ Collection<Profile> profiles = new LinkedList<Profile>();
+ for(Object element : c) {
+ if(element instanceof Profile) {
+ profiles.add(EMFHelper.reloadIntoContext((Profile)element, umlSource));
+ } else {
+ throw new IllegalArgumentException("The new value should only contain profiles");
+ }
+ }
+ Command command = new ApplyProfileCommand(umlSource, profiles, (TransactionalEditingDomain)domain);
+
+ commands.add(command);
+
+ return wrappedList.addAll(c);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean removeAll(Collection c) {
+ Command command = new UnapplyProfileCommand(umlSource, c, (TransactionalEditingDomain)domain);
+
+ commands.add(command);
+
+ return wrappedList.removeAll(c);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean retainAll(Collection c) {
+ List<Object> objectsToRemove = new LinkedList<Object>();
+ for(Object object : c) {
+ if(!contains(object)) {
+ objectsToRemove.add(object);
+ }
+ }
+ return removeAll(objectsToRemove);
+ }
+
+ //Unsupported operations. Some of them have a "proxy" implementation
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void add(int index, Object value) {
+ add(value); //The list is not ordered
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean addAll(int index, Collection c) {
+ return addAll(c); //The list is not ordered
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object set(int index, Object element) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object move(int oldIndex, int newIndex) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object remove(int index) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/IPapyrusVersionConstants.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/IPapyrusVersionConstants.java
new file mode 100644
index 00000000000..b1fa525facb
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/IPapyrusVersionConstants.java
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.profile.definition;
+
+/**
+ * Constant fields for papyrus profile version
+ */
+public interface IPapyrusVersionConstants {
+
+ /** source for eAnnotation that qualifies the profile definition */
+ public final String PAPYRUS_EANNOTATION_SOURCE = "PapyrusVersion";
+
+ /** key for version detail */
+ public final String PAPYRUS_VERSION_KEY = "Version";
+
+ /** key for author detail */
+ public final String PAPYRUS_AUTHOR_KEY = "Author";
+
+ /** key for copyright detail */
+ public final String PAPYRUS_COPYRIGHT_KEY = "Copyright";
+
+ /** key for date detail */
+ public final String PAPYRUS_DATE_KEY = "Date";
+
+ /** key for comment detail */
+ public final String PAPYRUS_COMMENT_KEY = "Comment";
+
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/PapyrusDefinitionAnnotation.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/PapyrusDefinitionAnnotation.java
new file mode 100644
index 00000000000..b3e18e3e9bb
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/PapyrusDefinitionAnnotation.java
@@ -0,0 +1,152 @@
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.profile.definition;
+
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EcoreFactory;
+
+/**
+ * Class that defines various information about a profile definition (author,
+ * version, etc.)
+ */
+public class PapyrusDefinitionAnnotation {
+
+ /** version of the definition */
+ private Version version = Version.emptyVersion;
+
+ /** Comment of the definition */
+ private String comment = "";
+
+ /** Copyright of the definition */
+ private String copyright = "";
+
+ /** date of the definition */
+ private String date = "";
+
+ /** author of the definition */
+ private String author = "";
+
+ /** undefined PapyrusDefinitionAnnotation */
+ public static PapyrusDefinitionAnnotation UNDEFINED_ANNOTATION = new PapyrusDefinitionAnnotation(
+ Version.emptyVersion, "<undefined>", "", "", "<undefined>");
+
+ /**
+ * Creates a new PapyrusDefinitionAnnotation.
+ *
+ * @param version
+ * the version of the definition
+ * @param comment
+ * the comment associated to this definition
+ * @param copyright
+ * the copyright of this definition
+ * @param date
+ * the date this definition was generated
+ * @param the
+ * author responsible of this definition
+ */
+ public PapyrusDefinitionAnnotation(Version version, String comment, String copyright, String date, String author) {
+ this.version = version;
+ this.comment = comment;
+ this.copyright = copyright;
+ this.author = author;
+ this.date = date;
+ }
+
+ /**
+ * Creates a Eannotation from the given configuration
+ *
+ * @return the eAnnotation corresponding to this configuration
+ */
+ public EAnnotation convertToEAnnotation() {
+ EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ // set various values (default if elements are null)
+ annotation.setSource(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE);
+ annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY, version.toString());
+ annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_COMMENT_KEY, comment);
+ annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_COPYRIGHT_KEY, copyright);
+ annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_DATE_KEY, date);
+ annotation.getDetails().put(IPapyrusVersionConstants.PAPYRUS_AUTHOR_KEY, author);
+ return annotation;
+ }
+
+ /**
+ * Return the PapyrusDefinitionAnnotation corresponding to the given
+ * EAnnotation
+ *
+ * @param annotation
+ * the annotation to parse
+ * @return a image of the given annotation, with default values if needed.
+ */
+ public static PapyrusDefinitionAnnotation parseEAnnotation(EAnnotation annotation) {
+ final String versionValue = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_VERSION_KEY);
+ Version version;
+ try {
+ version = Version.parseVersion(versionValue);
+ } catch (IllegalArgumentException e) {
+ version = Version.emptyVersion;
+ }
+ final String comment = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COMMENT_KEY);
+ final String copyright = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_COPYRIGHT_KEY);
+ final String date = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_DATE_KEY);
+ final String author = annotation.getDetails().get(IPapyrusVersionConstants.PAPYRUS_AUTHOR_KEY);
+ return new PapyrusDefinitionAnnotation(version, (comment != null) ? comment : "",
+ (copyright != null) ? copyright : "", (date != null) ? date : "", (author != null) ? author : "");
+ }
+
+ /**
+ * Returns the version of the definition of the profile
+ *
+ * @return the version of the definition of the profile
+ */
+ public Version getVersion() {
+ return version;
+ }
+
+ /**
+ * Returns the comment associated to the definition of the profile
+ *
+ * @return the comment associated to the definition of the profile
+ */
+ public String getComment() {
+ return comment;
+ }
+
+ /**
+ * Returns the copyright associated to the definition of the profile
+ *
+ * @return the copyright associated to the definition of the profile
+ */
+ public String getCopyright() {
+ return copyright;
+ }
+
+ /**
+ * Returns the date associated to the definition of the profile
+ *
+ * @return the date associated to the definition of the profile
+ */
+ public String getDate() {
+ return date;
+ }
+
+ /**
+ * Returns the author responsible to the definition of the profile
+ *
+ * @return the author responsible to the definition of the profile
+ */
+ public String getAuthor() {
+ return author;
+ }
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java
new file mode 100644
index 00000000000..9123a0bebc2
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/ProfileRedefinition.java
@@ -0,0 +1,330 @@
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.profile.definition;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.papyrus.uml.tools.Activator;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+
+
+/**
+ * <p>
+ * this class is used to manage the redefinition of profiles:
+ * </p>
+ * The normal definition in UML is like this:
+ * <ul>
+ * <li>Stereotype-->Eclass</li>
+ * <li>Enumeration-->EEnumeration :local copy
+ * <li>Datatype-->EClass</li>
+ * <li>Property--> EReference or EAttribute with ref on local copy</li>
+ * <li>PrimitiveType-> Edatatype : local copy</li>
+ * </ul>
+ * In papyrus:
+ * <ul>
+ * <li>Stereotype-->Eclass
+ * <li>Enumeration-->EEnumeration:local copy
+ * <li>Datatype-->EClass
+ * <li>Property--> EReference or EAttribute with ref on direct definition
+ * <li>PrimitiveType-> Edatatype : local copy
+ * </ul>
+ */
+public class ProfileRedefinition {
+
+ /**
+ * this method is used to redefine profile even if it contains subpackages
+ * or subprofiles
+ *
+ * @param thepackage
+ * the given profile that we want to define
+ * @param definitionAnnotation
+ * the definition annotation that is used to create the version
+ * annotation
+ */
+ public static void redefineProfile(Package thepackage, PapyrusDefinitionAnnotation definitionAnnotation) {
+ // he wants to define
+ if(thepackage instanceof Profile) {
+ Profile profile = (Profile)thepackage;
+ // get profile definition
+ EPackage profileDefinition = profile.getDefinition();
+ // collect all EClassifier of the definition
+ ArrayList<EClassifier> tempList = new ArrayList<EClassifier>();
+ for(int i = 0; i < profileDefinition.getEClassifiers().size(); i++) {
+ tempList.add(profileDefinition.getEClassifiers().get(i));
+ }
+
+ // for all EClass
+ Iterator<EClassifier> eClassIter = tempList.iterator();
+ while(eClassIter.hasNext()) {
+ EClassifier eclassifier = eClassIter.next();
+ if(eclassifier instanceof EClass) {
+ // redefine Eclass
+ redefineEclass((EClass)eclassifier);
+ }
+ }
+
+ // add profile definition annotation
+ if(definitionAnnotation != null) {
+ profile.getDefinition().getEAnnotations().add(definitionAnnotation.convertToEAnnotation());
+ }
+ }
+ Iterator<Package> it = thepackage.getNestedPackages().iterator();
+ while(it.hasNext()) {
+ Package p = it.next();
+ ProfileRedefinition.redefineProfile(p, definitionAnnotation);
+ }
+ }
+
+ /**
+ * redefine only real definition or do nothing
+ *
+ * @param eclass
+ * the given eclass that we want to redefine
+ */
+ public static void redefineEclass(EClass eclass) {
+ if(isADirectDefinition(eclass)) {
+ // 1. redefine inheritances
+ EList<EClass> eSuperTypes = eclass.getESuperTypes();
+
+ /* copy in order to avoid concurrent access */
+ ArrayList<EClass> superTypesList = new ArrayList<EClass>();
+ for(int j = 0; j < eSuperTypes.size(); j++) {
+ superTypesList.add(eSuperTypes.get(j));
+ }
+ // for each super types :we test if this is a direct definition
+ // if not we remove the local copy and replace by direct definition
+ Iterator<EClass> superIter = superTypesList.iterator();
+ while(superIter.hasNext()) {
+ EClass currentSuperClass = superIter.next();
+ if(!isADirectDefinition(currentSuperClass)) {
+ EClass directSuperClass = (EClass)lookForDirectDefinitionFrom(currentSuperClass);
+ eclass.getESuperTypes().remove(currentSuperClass);
+ eclass.getESuperTypes().add(directSuperClass);
+ }
+ }
+ // 2.redefine eReferences
+ // temp copy of the list
+ Iterator<EReference> iterReference = eclass.getEReferences().iterator();
+ ArrayList<EReference> referenceList = new ArrayList<EReference>();
+ while(iterReference.hasNext()) {
+ referenceList.add(iterReference.next());
+ }
+ // for each reference of the EClass
+ Iterator<EReference> refIterator = referenceList.iterator();
+ while(refIterator.hasNext()) {
+ redefineEReference(refIterator.next(), eclass.getEPackage());
+ }
+
+ }
+ }
+
+ /**
+ * this class is used to redefine EReference with direct definition
+ *
+ * @param eReference
+ * the given EReference that we want to redefine
+ */
+ public static void redefineEReference(EReference eReference, EPackage profileDefinition) {
+ EReference oldEOpposite = eReference.getEOpposite();
+ EClassifier oldType = eReference.getEType();
+
+ // 2.1 the type is an EClass
+ if(oldType instanceof EClass) {
+ // redefine type
+ eReference.setEType(lookForDirectDefinitionFrom(oldType));
+ // redefine the Opposite
+ if(oldEOpposite != null) {
+ eReference.setEOpposite(lookForEquivalentEreference((EClass)eReference.getEType(), oldEOpposite));
+ }
+ }
+ }
+
+
+ /**
+ * return id this Eclass is the real Definition
+ *
+ * @param eclass
+ * the eclass that we want to test
+ * @return true if this is the real definition or not is this is a local
+ * copy
+ */
+ public static boolean isADirectDefinition(EClass eclass) {
+ if(eclass.getEAnnotations().size() > 0) {
+ EAnnotation eAnnotation = eclass.getEAnnotations().get(0);
+ if(eAnnotation.getReferences().size() > 0) {
+ if(!(eAnnotation.getReferences().get(0) instanceof org.eclipse.uml2.uml.Classifier)) {
+ String errMsg = "Problem because of the definition of " + eclass.getName() + " in " + eclass.getEPackage().getNsURI();
+ Activator.log.error(errMsg, null);
+ }
+ org.eclipse.uml2.uml.Classifier theClassifier = (org.eclipse.uml2.uml.Classifier)eAnnotation.getReferences().get(0);
+ Package nearestPackage = theClassifier.getNearestPackage();
+
+ if(nearestPackage instanceof Profile) {
+ if(eclass.equals(((Profile)nearestPackage).getDefinition(theClassifier))) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * look for the real definition of the stereotype where the EClass may be
+ * the definition
+ *
+ * @param eclass
+ * that maybe the real definition (maybe a local copy of
+ * definition)
+ * @return the real definition or the itself
+ */
+ public static EClassifier lookForDirectDefinitionFrom(EClassifier eClassifier) {
+ if(eClassifier.getEAnnotations().size() > 0) {
+ EAnnotation eAnnotation = eClassifier.getEAnnotations().get(0);
+ if(eAnnotation.getReferences().size() > 0) {
+ org.eclipse.uml2.uml.Classifier theClassifier = (org.eclipse.uml2.uml.Classifier)eAnnotation.getReferences().get(0);
+ Package nearestPackage = theClassifier.getNearestPackage();
+ if(nearestPackage instanceof Profile) {
+ return (EClassifier)((Profile)nearestPackage).getDefinition(theClassifier);
+ }
+ return eClassifier;
+ }
+ }
+ return eClassifier;
+ }
+
+ /**
+ * this method is used to look for an EReference equivalent to a given
+ * EReference same name and type
+ *
+ * @param eclass
+ * the given EClass where we look for the equivalent EReference
+ * @param eReference
+ * the given EReference
+ * @return the return EReference or null
+ */
+ private static EReference lookForEquivalentEreference(EClass eclass, EReference eReference) {
+ Iterator<EReference> refIterator = eclass.getEReferences().iterator();
+ while(refIterator.hasNext()) {
+ EReference currentEReference = refIterator.next();
+ if(currentEReference.getName().equals(eReference.getName())) {
+ if(currentEReference.getEType().getName().endsWith(eReference.getEType().getName())) {
+ return currentEReference;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * this method is used to suppress all local copy of EClass in each Profile.
+ *
+ * @param thePackage
+ * that we want to clean
+ */
+ public static void cleanProfile(Package thePackage) {
+ if(thePackage instanceof Profile) {
+ Profile profile = (Profile)thePackage;
+ // get profile definition
+ EPackage profileDefinition = profile.getDefinition();
+
+ // collect all EClassifier of the definition
+ ArrayList<EClassifier> tempList = new ArrayList<EClassifier>();
+ for(int i = 0; i < profileDefinition.getEClassifiers().size(); i++) {
+ tempList.add(profileDefinition.getEClassifiers().get(i));
+ }
+
+ // for all EClass
+ Iterator<EClassifier> eClassIter = tempList.iterator();
+ while(eClassIter.hasNext()) {
+ EClassifier eclassifier = eClassIter.next();
+
+ if(eclassifier instanceof EClass) {
+
+ // this is a direct Definition?
+ if(!isADirectDefinition((EClass)eclassifier)) {
+ // no, so it is removed
+ profileDefinition.getEClassifiers().remove(eclassifier);
+ }
+
+ }
+ }
+ }
+ Iterator<Package> it = thePackage.getNestedPackages().iterator();
+ while(it.hasNext()) {
+ Package p = it.next();
+ ProfileRedefinition.cleanProfile(p);
+ }
+ }
+
+
+ /**
+ * this method is used to created an EAttribute from an Ereference
+ *
+ * @param container
+ * the Eclass that will contain the eattribute
+ * @param eReference
+ * from this, the eattribute will be created
+ * @return the created Eattribute
+ */
+ public static EAttribute createEAttribute(EClass container, EReference eReference) {
+
+ EAttribute eAttribute = EcoreFactory.eINSTANCE.createEAttribute();
+ eAttribute.setEType(eReference.getEType());
+ eAttribute.setName(eReference.getName());
+ eAttribute.setChangeable(eReference.isChangeable());
+ eAttribute.setLowerBound(eReference.getLowerBound());
+ eAttribute.setUpperBound(eReference.getUpperBound());
+ eAttribute.setOrdered(eReference.isOrdered());
+ eAttribute.setDerived(eReference.isDerived());
+ eAttribute.setTransient(eReference.isTransient());
+ eAttribute.setUnique(eReference.isUnique());
+ eAttribute.setUnsettable(eReference.isUnsettable());
+ eAttribute.setVolatile(eReference.isVolatile());
+ container.getEStructuralFeatures().add(eAttribute);
+ return eAttribute;
+ }
+
+
+
+ /**
+ * this method is used to obtain the classifier from its definition
+ *
+ * @param eclass
+ * that is a definition
+ * @return the classifier that produce this definition
+ */
+ public static Classifier getUMLClassifierFromDefinition(EClassifier eclass) {
+ if(eclass.getEAnnotations().size() > 0) {
+ EAnnotation eAnnotation = eclass.getEAnnotations().get(0);
+ if(eAnnotation.getReferences().size() > 0) {
+ org.eclipse.uml2.uml.Classifier theClassifier = (org.eclipse.uml2.uml.Classifier)eAnnotation.getReferences().get(0);
+ return theClassifier;
+ }
+ }
+ return null;
+ }
+}
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/Version.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/Version.java
new file mode 100644
index 00000000000..64099936eeb
--- /dev/null
+++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/profile/definition/Version.java
@@ -0,0 +1,155 @@
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.tools.profile.definition;
+
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+
+/**
+ * Representation of the version number for a profile
+ */
+public class Version {
+
+ /** major version number */
+ protected int major;
+
+ /** minor version number */
+ protected int minor;
+
+ /** micro version number */
+ protected int micro;
+
+ /** separator for the version string */
+ private final static String SEPARATOR = ".";
+
+ /** The empty version "0.0.0". Equivalent to calling <code>new Version(0,0,0)</code> */
+ public static final Version emptyVersion = new Version(0, 0, 0);
+
+ /**
+ * Creates a new Version
+ *
+ * @param major
+ * the major version value (should be positive)
+ * @param minor
+ * the minor version value (should be positive)
+ * @param micro
+ * the micro version value (should be positive)
+ */
+ public Version(int major, int minor, int micro) {
+ this.major = major;
+ this.minor = minor;
+ this.micro = micro;
+ }
+
+ /**
+ * Creates a new Version, parsing a string value
+ *
+ * @param value
+ * the string representing the version
+ */
+ public Version(String value) throws IllegalArgumentException {
+ try {
+ StringTokenizer st = new StringTokenizer(value, SEPARATOR, true);
+ major = Integer.parseInt(st.nextToken());
+
+ if(st.hasMoreTokens()) {
+ st.nextToken(); // consume delimiter
+ minor = Integer.parseInt(st.nextToken());
+
+ if(st.hasMoreTokens()) {
+ st.nextToken(); // consume delimiter
+ micro = Integer.parseInt(st.nextToken());
+
+ if(st.hasMoreTokens()) {
+ throw new IllegalArgumentException("invalid format");
+ }
+ }
+ }
+ } catch (NoSuchElementException e) {
+ throw new IllegalArgumentException("invalid format");
+ }
+ }
+
+ /**
+ * Returns the major version number
+ *
+ * @return The major version number
+ */
+ public int getMajor() {
+ return major;
+ }
+
+ /**
+ * Returns the minor version number
+ *
+ * @return The minor version number
+ */
+ public int getMinor() {
+ return minor;
+ }
+
+ /**
+ * Returns the micro version number
+ *
+ * @return The micro version number
+ */
+ public int getMicro() {
+ return micro;
+ }
+
+ /**
+ * Updates the version numbers
+ *
+ * @param major
+ * the new major value
+ * @param minor
+ * the new minor value
+ * @param micro
+ * the new micro value
+ */
+ public void updateVersion(int major, int minor, int micro) {
+ this.major = major;
+ this.minor = minor;
+ this.micro = micro;
+ }
+
+ // org.osgi.framework.Version
+ /**
+ * Creates a version given the specific String
+ *
+ * @param version
+ * the string to parse
+ * @return the version value corresponding to the String
+ */
+ public static Version parseVersion(String version) throws IllegalArgumentException {
+ if(version == null) {
+ return emptyVersion;
+ }
+
+ version = version.trim();
+ if(version.length() == 0) {
+ return emptyVersion;
+ }
+ return new Version(version);
+ }
+
+ /**
+ * Returns the string corresponding to the version
+ */
+ @Override
+ public String toString() {
+ return major + SEPARATOR + minor + SEPARATOR + micro;
+ }
+}

Back to the top