diff options
author | Vincent Lorenzo | 2019-02-07 14:31:53 +0000 |
---|---|---|
committer | Vincent Lorenzo | 2019-02-08 10:30:32 +0000 |
commit | 7074b2202f43c0e2a755dc12104c07e877213f76 (patch) | |
tree | bd2b1d3f3bb577699a9ae91afd03553fbce29514 | |
parent | f62bca5a83ee451a2d864d9e7394db07a5d81abb (diff) | |
download | org.eclipse.papyrus-7074b2202f43c0e2a755dc12104c07e877213f76.tar.gz org.eclipse.papyrus-7074b2202f43c0e2a755dc12104c07e877213f76.tar.xz org.eclipse.papyrus-7074b2202f43c0e2a755dc12104c07e877213f76.zip |
Revert "Bug 447665: [Profiles] Removing profiles definitions causing a profile"
This patch revert the code changes, but keeps the declared new plugin version, by facility, to avoid possible inconsistent
versioning of plugins.
This reverts commit 5e61a5490724d2ddf52caf45af21744482e8ada8.
Change-Id: Iea4cb8d266e877130066f0c98fa730eb25bc625a
14 files changed, 43 insertions, 684 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 3baa77179ad..e635477e288 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 @@ -63,9 +63,8 @@ import org.eclipse.uml2.uml.util.UMLUtil.UML2EcoreConverter; * This command is used to define a profile * * @author Vincent Lorenzo - * @deprecated since 3.2. Use {@code org.eclipse.papyrus.uml.tools.commands.DefineProfileCommand} instead. + * */ -@Deprecated public class DefineProfileCommand extends AbstractTransactionalCommand { /** @@ -104,7 +103,7 @@ public class DefineProfileCommand extends AbstractTransactionalCommand { * the package to define (if it is a profile) */ public static List<EPackage> defineProfiles(Package thePackage, boolean saveConstraintInDef) { - Map<String, String> options = new HashMap<>(); + Map<String, String> options = new HashMap<String, String>(); options.put(UML2EcoreConverter.OPTION__ECORE_TAGGED_VALUES, UMLUtil.OPTION__PROCESS); options.put(UML2EcoreConverter.OPTION__DERIVED_FEATURES, UMLUtil.OPTION__REPORT); @@ -125,8 +124,8 @@ public class DefineProfileCommand extends AbstractTransactionalCommand { options.put(UML2EcoreConverter.OPTION__VALIDATION_DELEGATES, handleConstraints); options.put(UML2EcoreConverter.OPTION__INVOCATION_DELEGATES, handleConstraints); options.put(UML2EcoreConverter.OPTION__OPERATION_BODIES, handleConstraints); - - // Assure that "right" (consistent with xtext editor) OCL delegate is used , see bug 512428 + + // Assure that "right" (consistent with xtext editor) OCL delegate is used , see bug 512428 options.put(UML2EcoreConverter.OPTION__OCL_DELEGATE_URI, "http://www.eclipse.org/emf/2002/Ecore/OCL/Pivot"); //$NON-NLS-1$ options.put(UML2EcoreConverter.OPTION__COMMENTS, UMLUtil.OPTION__IGNORE); @@ -134,7 +133,7 @@ public class DefineProfileCommand extends AbstractTransactionalCommand { options.put(UML2EcoreConverter.OPTION__UNTYPED_PROPERTIES, UMLUtil.OPTION__PROCESS); // Closer to the UML semantics of untyped properties - List<Profile> toDefine = new ArrayList<>(); + List<Profile> toDefine = new ArrayList<Profile>(); for (TreeIterator<EObject> all = UML2Util.getAllContents(thePackage, true, false); all.hasNext();) { EObject next = all.next(); if (next instanceof Profile) { @@ -150,7 +149,7 @@ public class DefineProfileCommand extends AbstractTransactionalCommand { ProfileUtil.sortProfiles(toDefine); } - List<EPackage> result = new ArrayList<>(toDefine.size()); + List<EPackage> result = new ArrayList<EPackage>(toDefine.size()); for (Profile next : toDefine) { result.add(next.define(options, null, null)); } @@ -254,7 +253,7 @@ public class DefineProfileCommand extends AbstractTransactionalCommand { IFile f = WorkspaceSynchronizer.getFile(rootProfile.eResource()); return f != null ? Collections.<IFile> singletonList(f) : Collections.<IFile> emptyList(); } - + /** * Clean undefine tag. */ 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 e3e659edbd7..7ee18d130d7 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 @@ -59,10 +59,7 @@ import org.eclipse.uml2.uml.Profile; * * * This class describes the actions to do just before the save action - * - * @deprecated since 3.2 */ -@Deprecated public class PreSaveProfileListener implements ISaveEventListener { /** @@ -70,13 +67,12 @@ public class PreSaveProfileListener implements ISaveEventListener { * * This function is called before the user make a "save" action */ - @Override public void doSave(DoSaveEvent event) { if (event.isAutoSave()) { return; } try { - // System.out.println("preSave Event received"); //$NON-NLS-1$ + //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 @@ -241,10 +237,9 @@ public class PreSaveProfileListener implements ISaveEventListener { * * This function is called before the user make a "save as" action */ - @Override public void doSaveAs(DoSaveEvent event) { try { - // System.out.println("preSaveAS Event received"); //$NON-NLS-1$ + //System.out.println("preSaveAS Event received"); //$NON-NLS-1$ } catch (Exception e) { e.printStackTrace(); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/ProfileService.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/ProfileService.java index 86e5492fb8c..233611afedf 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/ProfileService.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/service/ProfileService.java @@ -28,9 +28,7 @@ import org.eclipse.papyrus.infra.ui.lifecycleevents.LifeCycleEventsProvider; * This class is registered as a Papyrus service. * It then registered itself to the {@link LifeCycleEventsProvider}. * - * @deprecated since 3.2. */ -@Deprecated public class ProfileService implements IService { /** @@ -57,17 +55,16 @@ public class ProfileService implements IService { */ public ProfileService() { aboutToSaveListener = new PreSaveProfileListener(); - // System.out.println("ProfileService created"); //$NON-NLS-1$ + // System.out.println("ProfileService created"); //$NON-NLS-1$ } /** * @see org.eclipse.papyrus.infra.core.services.IService#disposeService() * */ - @Override public void disposeService() { deactivate(); - // System.out.println("ProfileService disposed"); //$NON-NLS-1$ + // System.out.println("ProfileService disposed"); //$NON-NLS-1$ } @@ -79,7 +76,6 @@ public class ProfileService implements IService { * * @param servicesRegistry */ - @Override public void init(ServicesRegistry servicesRegistry) { this.servicesRegistry = servicesRegistry; @@ -89,10 +85,9 @@ public class ProfileService implements IService { * @see org.eclipse.papyrus.infra.core.services.IService#startService() * */ - @Override public void startService() { activate(); - // System.out.println("ProfileService started"); //$NON-NLS-1$ + // System.out.println("ProfileService started"); //$NON-NLS-1$ } /** diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml index 78c0adbeb0b..d5893b4f545 100755 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/plugin.xml @@ -186,6 +186,15 @@ <extension point="org.eclipse.ui.handlers" id="menu-handlers"> <?gmfgen generated="true"?> </extension> +<extension + point="org.eclipse.papyrus.infra.core.service"> + <service + classname="org.eclipse.papyrus.uml.diagram.profile.service.ProfileService" + priority="1" + startKind="startup" + useClassTypeAsKey="true"> + </service> +</extension> <extension point="org.eclipse.ui.preferencePages" id="prefpages"> <?gmfgen generated="true"?> <page diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleProfileDefinition.xwt b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleProfileDefinition.xwt index 80ecfba7400..33846103795 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleProfileDefinition.xwt +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/Model/UML/ui/SingleProfileDefinition.xwt @@ -10,14 +10,14 @@ <Composite.layout> <ppel:PropertiesLayout numColumns="2"></ppel:PropertiesLayout> </Composite.layout> - <ppe:StringEditor input="{Binding}" + <ppe:StringLabel input="{Binding}" property="ProfileDefinitionAnnotation:PapyrusVersion:Version" - readOnly="true"></ppe:StringEditor> - <ppe:StringEditor input="{Binding}" - property="ProfileDefinitionAnnotation:PapyrusVersion:Date" readOnly="true"></ppe:StringEditor> - <ppe:StringEditor input="{Binding}" + readOnly="true"></ppe:StringLabel> + <ppe:StringLabel input="{Binding}" + property="ProfileDefinitionAnnotation:PapyrusVersion:Date" readOnly="true"></ppe:StringLabel> + <ppe:StringLabel input="{Binding}" property="ProfileDefinitionAnnotation:PapyrusVersion:Author" - readOnly="true"></ppe:StringEditor> + readOnly="true"></ppe:StringLabel> </Composite> <Composite> <Composite.layout> diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionModelElement.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionModelElement.java index 280ed80ace9..8ca3ea5d907 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionModelElement.java +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionModelElement.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013, 2014, 2018 CEA LIST and others. + * 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 2.0 @@ -11,7 +11,6 @@ * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation * Christian W. Damus (CEA) - bug 323802 - * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 447665 * *****************************************************************************/ package org.eclipse.papyrus.uml.properties.modelelement; @@ -22,28 +21,19 @@ import org.eclipse.emf.databinding.EMFObservables; import org.eclipse.emf.ecore.EAnnotation; import org.eclipse.emf.ecore.EcorePackage; import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.emf.transaction.RollbackException; -import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.papyrus.infra.core.services.ServiceException; -import org.eclipse.papyrus.infra.core.utils.TransactionHelper; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject; import org.eclipse.papyrus.infra.properties.ui.modelelement.AbstractModelElement; import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; -import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; -import org.eclipse.papyrus.uml.tools.Activator; +import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList; import org.eclipse.uml2.uml.Profile; import org.eclipse.uml2.uml.util.UMLUtil; -/** - * Model Element for Profile Definitions. - */ -public class ProfileDefinitionModelElement extends AbstractModelElement { - /** The Constant RETRIEVE_EANNOTATION_ERROR. */ - private static final String RETRIEVE_EANNOTATION_ERROR = "Failed to retrieve Profile Defintion root annotation."; //$NON-NLS-1$ +public class ProfileDefinitionModelElement extends AbstractModelElement { /** * The Profile::definitions property. Contains the list of definitions (EPackage) of this profile @@ -61,43 +51,17 @@ public class ProfileDefinitionModelElement extends AbstractModelElement { if (DEFINITIONS.equals(propertyPath)) { if (profile != null) { - EditingDomain domain = EMFHelper.resolveEditingDomain(profile); - EAnnotation definitions = getProfileDefinitionsRootAnnotation((TransactionalEditingDomain) domain); - return new ProfileDefinitionObservableValue(profile, EMFObservables.observeList(definitions, EcorePackage.eINSTANCE.getEAnnotation_Contents()), domain, definitions, EcorePackage.eINSTANCE.getEAnnotation_Contents()); - + EAnnotation definitions = profile.getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI); + if (definitions != null) { + EditingDomain domain = EMFHelper.resolveEditingDomain(profile); + return new PapyrusObservableList(EMFObservables.observeList(definitions, EcorePackage.eINSTANCE.getEAnnotation_Contents()), domain, definitions, EcorePackage.eINSTANCE.getEAnnotation_Contents()); + } } } return Observables.emptyObservableList(); } - /** - * Gets the profile definitions root annotation. - * - * @param domain - * the domain - * @return the profile definitions root annotation - */ - private EAnnotation getProfileDefinitionsRootAnnotation(final TransactionalEditingDomain domain) { - - try { - TransactionHelper.run(domain, new Runnable() { - @Override - public void run() { - UMLUtil.getEAnnotation(profile, UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI, true); - } - }); - - } catch (InterruptedException e) { - Activator.log.error(RETRIEVE_EANNOTATION_ERROR, e); - } catch (RollbackException e) { - Activator.log.error(RETRIEVE_EANNOTATION_ERROR, e); - } - - return profile.getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI); - - } - @Override public ILabelProvider getLabelProvider(String propertyPath) { try { @@ -107,24 +71,6 @@ public class ProfileDefinitionModelElement extends AbstractModelElement { } } - /** - * {@inheritDoc} - * - * @see org.eclipse.papyrus.views.properties.modelelement.AbstractModelElement#getValueFactory(java.lang.String) - */ - @Override - public ReferenceValueFactory getValueFactory(final String propertyPath) { - ReferenceValueFactory valueFactory = null; - if (DEFINITIONS.equals(propertyPath)) { - valueFactory = new ProfileDefinitionValueFactory(profile, EcorePackage.eINSTANCE.getEAnnotation_Contents()); - } else { - // Try with inherited implementation - valueFactory = super.getValueFactory(propertyPath); - } - - return valueFactory; - } - @Override public boolean isOrdered(String propertyPath) { return false; diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionObservableValue.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionObservableValue.java deleted file mode 100644 index 2523dc0247c..00000000000 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionObservableValue.java +++ /dev/null @@ -1,105 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2018 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.uml.properties.modelelement; - -import java.util.List; - -import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.papyrus.infra.gmfdiag.common.databinding.GMFObservableList; -import org.eclipse.papyrus.uml.tools.commands.DefineProfileCommand; -import org.eclipse.papyrus.uml.tools.commands.UndefineProfileCommand; -import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants; -import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation; -import org.eclipse.papyrus.uml.tools.util.IPapyrusProfileDefinition; -import org.eclipse.uml2.uml.Profile; - -/** - * Observable for Profile Definition list of a profile. - */ -public class ProfileDefinitionObservableValue extends GMFObservableList { - - /** The profile which contains definitions. */ - private Profile profile = null; - - /** - * Instantiates a new profile definition observable value. - * - * @param profile - * the profile - * @param wrappedList - * the wrapped list - * @param domain - * the domain - * @param source - * the source - * @param feature - * the feature - */ - public ProfileDefinitionObservableValue(final Profile profile, final List<?> wrappedList, final EditingDomain domain, final EObject source, final EStructuralFeature feature) { - super(wrappedList, domain, source, feature); - this.profile = profile; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getAddCommand(java.lang.Object) - * - * @param value - * @return - */ - @Override - public Command getAddCommand(final Object value) { - Command addCommand = null; - if (value instanceof IPapyrusProfileDefinition) { - EObject rootProfile = EcoreUtil.getRootContainer(profile); - if (rootProfile instanceof Profile) { - addCommand = new DefineProfileCommand((TransactionalEditingDomain) editingDomain, (IPapyrusProfileDefinition) value, (Profile) rootProfile); - } - } else { - // Get command from parent - addCommand = super.getAddCommand(value); - } - - return addCommand; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableList#getRemoveCommand(java.lang.Object) - */ - @Override - public Command getRemoveCommand(final Object value) { - Command removeCommand = null; - if (value instanceof EPackage) { - EObject rootProfile = EcoreUtil.getRootContainer(profile); - PapyrusDefinitionAnnotation papyrusAnnotation = PapyrusDefinitionAnnotation.parseEAnnotation(((EPackage) value).getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE)); - if (rootProfile instanceof Profile) { - removeCommand = new UndefineProfileCommand((TransactionalEditingDomain) editingDomain, papyrusAnnotation, (Profile) rootProfile); - } - } else { - removeCommand = super.getRemoveCommand(value); - } - return removeCommand; - } -} diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionValueFactory.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionValueFactory.java deleted file mode 100644 index 5c3794911d5..00000000000 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ProfileDefinitionValueFactory.java +++ /dev/null @@ -1,90 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2018 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.uml.properties.modelelement; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EReference; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.papyrus.infra.properties.ui.creation.EcorePropertyEditorFactory; -import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory; -import org.eclipse.papyrus.uml.profile.ui.dialogs.ProfileDefinitionDialog; -import org.eclipse.papyrus.uml.tools.util.PapyrusProfileDefinition; -import org.eclipse.swt.widgets.Control; -import org.eclipse.uml2.uml.Profile; - -/** - * Property Editor Factory for Profile Definition. - */ -public class ProfileDefinitionValueFactory extends EcorePropertyEditorFactory implements ReferenceValueFactory { - - /** The Constant EDIT_DIALOG_TITLE. */ - private static final String EDIT_DIALOG_TITLE = "Edit Profile Definition"; //$NON-NLS-1$ - - /** The profile to define. */ - private final Profile profileToDefine; - - /** - * Instantiates a new profile definition value factory. - * - * @param profile - * The profile. - * @param referenceIn - * The reference. - */ - public ProfileDefinitionValueFactory(final Profile profile, final EReference referenceIn) { - super(referenceIn); - profileToDefine = profile; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.papyrus.views.properties.creation.EcorePropertyEditorFactory#doCreateObject(org.eclipse.swt.widgets.Control, java.lang.Object) - */ - @Override - protected Object doCreateObject(final Control widget, final Object context) { - Object createdObject = null; - EObject rootProfile = EcoreUtil.getRootContainer(profileToDefine); - if (rootProfile instanceof Profile) { - ProfileDefinitionDialog dialog = new ProfileDefinitionDialog(widget.getShell(), (Profile) rootProfile); - int returnDialog = dialog.open(); - if (Dialog.OK == returnDialog) { - createdObject = new PapyrusProfileDefinition(dialog.getPapyrusDefinitionAnnotation(), dialog.saveConstraintInDefinition()); - } - } - - return createdObject; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.papyrus.views.properties.creation.EcorePropertyEditorFactory#getEditionDialogTitle(java.lang.Object) - */ - @Override - public String getEditionDialogTitle(final Object objectToEdit) { - String dialogTitle = null; - if (objectToEdit instanceof EPackage) { - dialogTitle = EDIT_DIALOG_TITLE; - } else { - dialogTitle = super.getEditionDialogTitle(objectToEdit); - } - - return dialogTitle; - } -} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DefineProfileCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DefineProfileCommand.java deleted file mode 100644 index d46d0832785..00000000000 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/DefineProfileCommand.java +++ /dev/null @@ -1,247 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2010, 2014 CEA LIST, Christian W. Damus, and others. - * - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation - * Christian W. Damus - bug 451613 - * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 447665 - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.commands; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -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.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.common.util.TreeIterator; -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.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.papyrus.infra.emf.utils.EMFHelper; -import org.eclipse.papyrus.uml.tools.Activator; -import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation; -import org.eclipse.papyrus.uml.tools.profile.definition.ProfileRedefinition; -import org.eclipse.papyrus.uml.tools.util.IPapyrusProfileDefinition; -import org.eclipse.papyrus.uml.tools.utils.ProfileUtil; -import org.eclipse.uml2.common.util.UML2Util; -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 Vincent Lorenzo - * @since 4.2 - */ -public class DefineProfileCommand extends RecordingCommand { - - /** The Constant COMMAND_LABEL. */ - private static final String COMMAND_LABEL = "Define Profile Command"; - - /** - * the {@link PapyrusDefinitionAnnotation} - */ - private IPapyrusProfileDefinition papyrusAnnotation; - - /** - * the profile to define - */ - private Profile rootProfile; - - - /** - * Instantiates a new define profile command. - * - * @param domain - * the domain - * @param papyrusAnnotation - * the papyrus annotation - * @param rootProfile - * the root profile - */ - public DefineProfileCommand(final TransactionalEditingDomain domain, final IPapyrusProfileDefinition papyrusAnnotation, final Profile rootProfile) { - super(domain, COMMAND_LABEL, null); - this.rootProfile = rootProfile; - this.papyrusAnnotation = papyrusAnnotation; - } - - - /** - * 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<>(); - - options.put(UML2EcoreConverter.OPTION__ECORE_TAGGED_VALUES, UMLUtil.OPTION__PROCESS); - options.put(UML2EcoreConverter.OPTION__DERIVED_FEATURES, UMLUtil.OPTION__REPORT); - options.put(UML2EcoreConverter.OPTION__DUPLICATE_FEATURE_INHERITANCE, UMLUtil.OPTION__PROCESS); - options.put(UML2EcoreConverter.OPTION__DUPLICATE_FEATURES, UMLUtil.OPTION__PROCESS); - options.put(UML2EcoreConverter.OPTION__DUPLICATE_OPERATIONS, UMLUtil.OPTION__REPORT); - options.put(UML2EcoreConverter.OPTION__DUPLICATE_OPERATION_INHERITANCE, UMLUtil.OPTION__REPORT); - options.put(UML2EcoreConverter.OPTION__REDEFINING_OPERATIONS, UMLUtil.OPTION__REPORT); - options.put(UML2EcoreConverter.OPTION__REDEFINING_PROPERTIES, UMLUtil.OPTION__REPORT); - options.put(UML2EcoreConverter.OPTION__SUBSETTING_PROPERTIES, UMLUtil.OPTION__REPORT); - options.put(UML2EcoreConverter.OPTION__UNION_PROPERTIES, UMLUtil.OPTION__PROCESS); - options.put(UML2EcoreConverter.OPTION__SUPER_CLASS_ORDER, UMLUtil.OPTION__REPORT); - options.put(UML2EcoreConverter.OPTION__ANNOTATION_DETAILS, UMLUtil.OPTION__REPORT); - - // Generate constraints for the validation - String handleConstraints = saveConstraintInDef ? UMLUtil.OPTION__PROCESS : UMLUtil.OPTION__IGNORE; - options.put(UML2EcoreConverter.OPTION__INVARIANT_CONSTRAINTS, handleConstraints); - options.put(UML2EcoreConverter.OPTION__VALIDATION_DELEGATES, handleConstraints); - options.put(UML2EcoreConverter.OPTION__INVOCATION_DELEGATES, handleConstraints); - options.put(UML2EcoreConverter.OPTION__OPERATION_BODIES, handleConstraints); - // - - options.put(UML2EcoreConverter.OPTION__COMMENTS, UMLUtil.OPTION__IGNORE); - options.put(Profile2EPackageConverter.OPTION__FOREIGN_DEFINITIONS, UMLUtil.OPTION__PROCESS); - - options.put(UML2EcoreConverter.OPTION__UNTYPED_PROPERTIES, UMLUtil.OPTION__PROCESS); // Closer to the UML semantics of untyped properties - - List<Profile> toDefine = new ArrayList<>(); - for (TreeIterator<EObject> all = UML2Util.getAllContents(thePackage, true, false); all.hasNext();) { - EObject next = all.next(); - if (next instanceof Profile) { - toDefine.add((Profile) next); - } else if (!(next instanceof Package)) { - all.prune(); - } - } - - if (toDefine.size() > 1) { - // Sort the profiles in dependency order: used profiles ahead of the profiles that use them. This ensures that - // Ecore definitions are available for reference in the 4.1.0-style annotations instead of 4.0.0-style - ProfileUtil.sortProfiles(toDefine); - } - - List<EPackage> result = new ArrayList<>(toDefine.size()); - for (Profile next : toDefine) { - result.add(next.define(options, null, null)); - } - - return result; - } - - - /** - * Post validate. - * - * @param profileDefinitions - * the profile definitions - * @return the i status - * @throws ExecutionException - * the execution exception - */ - 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; - } - - /** - * Creates the diagnostician. - * - * @param adapterFactory - * the adapter factory - * @param progressMonitor - * the progress monitor - * @return the diagnostician - */ - 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); - } - }; - } - - - /** - * {@inheritDoc} - * - * @see org.eclipse.emf.transaction.RecordingCommand#doExecute() - * - */ - @Override - protected void doExecute() { - - List<EPackage> profileDefinitions = defineProfiles(rootProfile, papyrusAnnotation.saveConstraintDefinition()); - - ProfileRedefinition.redefineProfile(rootProfile, papyrusAnnotation.getPapyrusAnnotation()); - ProfileRedefinition.cleanProfile(rootProfile); - try { - postValidate(profileDefinitions); - } catch (ExecutionException e) { - Activator.log.error(e); - } - - - } -} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java index b5c5ca11789..6e168a7b7da 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/UndefineProfileCommand.java @@ -35,7 +35,8 @@ import org.eclipse.uml2.uml.util.UMLUtil; /** * Removed all Profile Definitions of all Profile model. - + * + * @author Gabriel Pascual * @since 4.1 * */ 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 index ca17409a362..73901b41aeb 100644 --- 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 @@ -151,39 +151,4 @@ public class PapyrusDefinitionAnnotation { public String getAuthor() { return author; } - - /** - * {@inheritDoc} - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - boolean equal = false; - if (obj instanceof PapyrusDefinitionAnnotation) { - PapyrusDefinitionAnnotation definitionAnnotation = (PapyrusDefinitionAnnotation) obj; - equal = definitionAnnotation.author.equals(this.author) && - definitionAnnotation.comment.equals(this.comment) && - definitionAnnotation.copyright.equals(this.copyright) && - definitionAnnotation.version.toString().equals(this.version.toString()); - } - return equal; - } - - /** - * {@inheritDoc} - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - int hash = 1; - - hash = hash * 13 * this.author.hashCode(); - hash = hash * 32 * this.comment.hashCode(); - hash = hash * 21 * this.copyright.hashCode(); - hash = hash * 8 * this.version.toString().hashCode(); - - return hash; - } } diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/IPapyrusProfileDefinition.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/IPapyrusProfileDefinition.java deleted file mode 100644 index 69e05846c53..00000000000 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/IPapyrusProfileDefinition.java +++ /dev/null @@ -1,41 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2018 CEA LIST and others. - * - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.uml.tools.util; - -import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation; - -/** - * Interface for Papyrus Definition of Profile. - * - * @since 4.2 - */ -public interface IPapyrusProfileDefinition { - - /** - * Gets the papyrus annotation. - * - * @return the papyrus annotation - */ - public PapyrusDefinitionAnnotation getPapyrusAnnotation(); - - /** - * Save constraint. - * - * @return true, if successful - */ - public boolean saveConstraintDefinition(); -} diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/PapyrusProfileDefinition.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/PapyrusProfileDefinition.java deleted file mode 100644 index f96f908fdbb..00000000000 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/util/PapyrusProfileDefinition.java +++ /dev/null @@ -1,68 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2018 CEA LIST and others. - * - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.uml.tools.util; - -import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation; - -/** - * Class for Papyrus Profile definition. - * - * @since 4.2 - */ -public class PapyrusProfileDefinition implements IPapyrusProfileDefinition { - - /** The annotation. */ - private final PapyrusDefinitionAnnotation annotation; - - /** The save constraint definition. */ - private final boolean saveConstraintDefinition; - - - /** - * Instantiates a new papyrus profile definition. - * - * @param papyrusDefinitionAnnotation - * the papyrus definition annotation. - * @param saveConstraint - * the save constraint. - */ - public PapyrusProfileDefinition(final PapyrusDefinitionAnnotation papyrusDefinitionAnnotation, final boolean saveConstraint) { - annotation = papyrusDefinitionAnnotation; - saveConstraintDefinition = saveConstraint; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.papyrus.uml.tools.util.IPapyrusProfileDefinition#getPapyrusAnnotation() - */ - @Override - public PapyrusDefinitionAnnotation getPapyrusAnnotation() { - return annotation; - } - - /** - * {@inheritDoc} - * - * @see org.eclipse.papyrus.uml.tools.util.IPapyrusProfileDefinition#saveConstraintDefinition() - */ - @Override - public boolean saveConstraintDefinition() { - return saveConstraintDefinition; - } - -} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/tests/DefineProfileCommandTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/tests/DefineProfileCommandTest.java index 3313d712dc8..9ad1ac9836b 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/tests/DefineProfileCommandTest.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/custom/commands/tests/DefineProfileCommandTest.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2014 Christian W. Damus and others. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -10,7 +10,7 @@ * * Contributors: * Christian W. Damus - Initial API and implementation - * + * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.profile.custom.commands.tests; @@ -22,13 +22,13 @@ import static org.hamcrest.MatcherAssert.assertThat; import org.eclipse.emf.ecore.EAnnotation; import org.eclipse.emf.ecore.ENamedElement; +import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper; import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; import org.eclipse.papyrus.junit.utils.rules.ModelSetFixture; import org.eclipse.papyrus.junit.utils.rules.PluginResource; -import org.eclipse.papyrus.uml.tools.commands.DefineProfileCommand; +import org.eclipse.papyrus.uml.diagram.profile.custom.commands.DefineProfileCommand; import org.eclipse.papyrus.uml.tools.profile.definition.PapyrusDefinitionAnnotation; import org.eclipse.papyrus.uml.tools.profile.definition.Version; -import org.eclipse.papyrus.uml.tools.util.PapyrusProfileDefinition; import org.eclipse.uml2.uml.Profile; import org.junit.Rule; import org.junit.Test; @@ -80,8 +80,8 @@ public class DefineProfileCommandTest extends AbstractPapyrusTest { void executeDefineCommand(Profile profile, String version) { PapyrusDefinitionAnnotation annotation = new PapyrusDefinitionAnnotation(Version.parseVersion(version), "", "", "", ""); - DefineProfileCommand command = new DefineProfileCommand(modelSet.getEditingDomain(), new PapyrusProfileDefinition(annotation, true), profile); - modelSet.getEditingDomain().getCommandStack().execute(command); + DefineProfileCommand command = new DefineProfileCommand(modelSet.getEditingDomain(), annotation, profile, true); + modelSet.getEditingDomain().getCommandStack().execute(GMFtoEMFCommandWrapper.wrap(command)); } static EAnnotation getUMLAnnotation(ENamedElement namedElement) { |