diff options
3 files changed, 332 insertions, 139 deletions
diff --git a/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/utils/RTPortUtils.java b/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/utils/RTPortUtils.java index f34f8e242..45cd1630a 100644 --- a/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/utils/RTPortUtils.java +++ b/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/utils/RTPortUtils.java @@ -13,10 +13,18 @@ *****************************************************************************/ package org.eclipse.papyrusrt.umlrt.core.utils; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.UnexecutableCommand; import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.common.core.command.CompositeCommand; +import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; import org.eclipse.papyrusrt.umlrt.profile.UMLRealTime.RTPort; +import org.eclipse.papyrusrt.umlrt.profile.UMLRealTime.UMLRealTimePackage; import org.eclipse.uml2.uml.Operation; import org.eclipse.uml2.uml.Port; +import org.eclipse.uml2.uml.UMLPackage; import org.eclipse.uml2.uml.util.UMLUtil; /** @@ -105,5 +113,53 @@ public class RTPortUtils { return kind; } + /** + * Returns the command that sets all parameters of the specified port to turn him into the new kind + * + * @param port + * the port to set + * @param newKind + * the new kind of the RTPort + * @return the command that sets all parameters of the specified port to turn him into the new kind or <code>null</code> + */ + public static Command getChangeKindCommand(Port port, RTPortKindEnum newKind) { + Command command = null; + switch (newKind) { + case EXTERNAL: + command = getRTPortKindChangeCommand(port, true, true, true); + break; + case INTERNAL: + command = getRTPortKindChangeCommand(port, false, true, true); + break; + case RELAY: + command = getRTPortKindChangeCommand(port, true, true, false); + break; + case SAP: + command = getRTPortKindChangeCommand(port, false, false, true); + break; + case SPP: + command = getRTPortKindChangeCommand(port, true, false, true); + break; + default: + // Relay Port by Default + command = getRTPortKindChangeCommand(port, true, true, false); + break; + } + return command; + } + + protected static Command getRTPortKindChangeCommand(Port port, boolean service, boolean wired, boolean behavior) { + RTPort rtPort = getStereotypeApplication(port); + if (rtPort == null) { + return UnexecutableCommand.INSTANCE; + } + + CompositeCommand command = new CompositeCommand("Setting RTPort Kind"); // //$NON-NLS-1$ + command.add(new SetValueCommand(new SetRequest(port, UMLPackage.eINSTANCE.getPort_IsBehavior(), behavior))); + command.add(new SetValueCommand(new SetRequest(port, UMLPackage.eINSTANCE.getPort_IsService(), service))); + command.add(new SetValueCommand(new SetRequest(rtPort, UMLRealTimePackage.eINSTANCE.getRTPort_IsWired(), wired))); + command.add(new SetValueCommand(new SetRequest(rtPort, UMLRealTimePackage.eINSTANCE.getRTPort_IsPublish(), !wired && service))); + return GMFtoEMFCommandWrapper.wrap(command); + } } diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/widgets/PortRTKindObservableValue.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/widgets/PortRTKindObservableValue.java index f8bbda56b..d3dfad9b9 100644 --- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/widgets/PortRTKindObservableValue.java +++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/widgets/PortRTKindObservableValue.java @@ -15,24 +15,16 @@ import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.IObserving; import org.eclipse.core.databinding.observable.value.ValueDiff; import org.eclipse.emf.common.command.Command; -import org.eclipse.emf.common.command.CompoundCommand; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gmf.runtime.common.core.command.ICommand; -import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; -import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; -import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; -import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue; import org.eclipse.papyrusrt.umlrt.core.utils.RTPortKindEnum; import org.eclipse.papyrusrt.umlrt.core.utils.RTPortUtils; -import org.eclipse.papyrusrt.umlrt.profile.UMLRealTime.UMLRealTimePackage; import org.eclipse.uml2.uml.Port; -import org.eclipse.uml2.uml.UMLPackage; import org.eclipse.uml2.uml.util.UMLUtil; /** @@ -74,6 +66,9 @@ public class PortRTKindObservableValue extends PapyrusObservableValue implements protected AdapterImpl getListener() { return new AdapterImpl() { + /** + * {@inheritDoc} + */ @Override public void notifyChanged(Notification notification) { Object notifier = notification.getNotifier(); @@ -109,9 +104,7 @@ public class PortRTKindObservableValue extends PapyrusObservableValue implements } /** - * @see org.eclipse.emf.databinding.EObjectObservableValue#getValueType() - * - * @return + * {@inheritDoc} */ @Override public Object getValueType() { @@ -119,155 +112,31 @@ public class PortRTKindObservableValue extends PapyrusObservableValue implements } /** - * @see org.eclipse.emf.databinding.EObjectObservableValue#getObserved() - * - * @return + * {@inheritDoc} */ @Override public Object getObserved() { return port; } - - /** - * @see org.eclipse.emf.databinding.EObjectObservableValue#doGetValue() - * - * @return + * {@inheritDoc} */ @Override protected Object doGetValue() { return RTPortUtils.getKind(port); } - - - /** - * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue#getCommand(java.lang.Object) - * - * @param value - * @return + * {@inheritDoc} */ @Override public Command getCommand(Object value) { Command command = null; if (value instanceof RTPortKindEnum) { - // For Each Kind of Port, set the property accordingly - switch ((RTPortKindEnum) value) { - case EXTERNAL: - command = getCommandForRTPort(true, true, true); - break; - case INTERNAL: - command = getCommandForRTPort(true, false, true); - break; - case RELAY: - command = getCommandForRTPort(false, true, true); - break; - case SAP: - command = getCommandForRTPort(true, false, false); - break; - case SPP: - command = getCommandForRTPort(true, true, false); - break; - default: - // Relay Port by Default - command = getCommandForRTPort(false, true, true); - break; - } + return RTPortUtils.getChangeKindCommand(port, (RTPortKindEnum) value); } return command; } - /** - * Get the Command to set the RT Port properties. - * - * @param behavior - * Value of isBehavior attribute - * @param service - * Value of isService attribute - * @param wired - * Value of isWired attribute - * @return the command for rt port - */ - protected Command getCommandForRTPort(boolean behavior, boolean service, boolean wired) { - CompoundCommand command = new CompoundCommand(); - command.append(getSetBehaviorCommand(behavior)); - command.append(getSetServiceCommand(service)); - command.append(getSetWiredCommand(wired)); - return command; - } - - /** - * Gets the Command to set the publish parameter. - * - * @param publish - * The publish value to be set - * @return The Command to set the isPublish parameter - */ - protected Command getSetPublishCommand(final boolean publish) { - IElementEditService serviceEdit = ElementEditServiceUtils.getCommandProvider(stereotypeApplication); - EStructuralFeature feature = UMLRealTimePackage.eINSTANCE.getRTPort_IsPublish(); - SetRequest request = new SetRequest(stereotypeApplication, feature, publish); - ICommand gmfCommand = serviceEdit.getEditCommand(request); - Command cmd = GMFtoEMFCommandWrapper.wrap(gmfCommand); - - return cmd; - } - - - /** - * Gets the Command to set the wired parameter. - * - * @param wired - * The wired value to be set - * @return The Command to set the isWired parameter - */ - protected Command getSetWiredCommand(final boolean wired) { - IElementEditService serviceEdit = ElementEditServiceUtils.getCommandProvider(stereotypeApplication); - EStructuralFeature feature = UMLRealTimePackage.eINSTANCE.getRTPort_IsWired(); - SetRequest request = new SetRequest(stereotypeApplication, feature, wired); - ICommand gmfCommand = serviceEdit.getEditCommand(request); - Command cmd = GMFtoEMFCommandWrapper.wrap(gmfCommand); - - return cmd; - } - - /** - * Gets the Command to set the service parameter. - * - * @param service - * The service value to be set - * @return The Command to set the isService parameter - */ - protected Command getSetServiceCommand(final boolean service) { - Command cmd = null; - IElementEditService serviceEdit = ElementEditServiceUtils.getCommandProvider(port); - EStructuralFeature feature = UMLPackage.eINSTANCE.getPort_IsService(); - SetRequest request = new SetRequest(port, feature, service); - ICommand gmfCommand = serviceEdit.getEditCommand(request); - cmd = GMFtoEMFCommandWrapper.wrap(gmfCommand); - - return cmd; - } - - /** - * Gets the Command to set the behavior parameter. - * - * @param behavior - * The behavior value to be set - * @return The Command to set the isBehavior parameter - */ - protected Command getSetBehaviorCommand(final boolean behavior) { - Command cmd = null; - IElementEditService serviceEdit = ElementEditServiceUtils.getCommandProvider(port); - EStructuralFeature feature = UMLPackage.eINSTANCE.getPort_IsBehavior(); - SetRequest request = new SetRequest(port, feature, behavior); - ICommand gmfCommand = serviceEdit.getEditCommand(request); - cmd = GMFtoEMFCommandWrapper.wrap(gmfCommand); - - return cmd; - } - - } diff --git a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/RTPortUtilsTest.java b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/RTPortUtilsTest.java index 3725eb02b..033bef362 100644 --- a/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/RTPortUtilsTest.java +++ b/tests/junit/umlrt/core/org.eclipse.papyrusrt.umlrt.core.tests/src/org/eclipse/papyrusrt/umlrt/core/tests/utils/RTPortUtilsTest.java @@ -12,7 +12,11 @@ package org.eclipse.papyrusrt.umlrt.core.tests.utils; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.eclipse.emf.common.command.Command; 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; @@ -125,4 +129,268 @@ public class RTPortUtilsTest extends AbstractPapyrusTest { assertEquals("error in RTPortUtils#getKind(Port)", RTPortKindEnum.SPP, RTPortUtils.getKind(capsule_legacySpp)); } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSAPtoSPP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_sap, RTPortKindEnum.SPP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSAPtoSAP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_sap, RTPortKindEnum.SAP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSAPtoExternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_sap, RTPortKindEnum.EXTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSAPtoInternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_sap, RTPortKindEnum.INTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSAPtoRelay() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_sap, RTPortKindEnum.RELAY); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSPPtoSPP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_spp, RTPortKindEnum.SPP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSPPtoSAP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_spp, RTPortKindEnum.SAP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSPPtoExternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_spp, RTPortKindEnum.EXTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSPPtoInternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_spp, RTPortKindEnum.INTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromSPPtoRelay() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_spp, RTPortKindEnum.RELAY); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromRelaytoSPP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_relay, RTPortKindEnum.SPP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromRelaytoSAP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_relay, RTPortKindEnum.SAP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromRelaytoExternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_relay, RTPortKindEnum.EXTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromRelaytoInternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_relay, RTPortKindEnum.INTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromRelaytoRelay() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_relay, RTPortKindEnum.RELAY); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromExternaltoSPP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_externalBehavior, RTPortKindEnum.SPP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromExternaltoSAP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_externalBehavior, RTPortKindEnum.SAP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromExternaltoExternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_externalBehavior, RTPortKindEnum.EXTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromExternaltoInternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_externalBehavior, RTPortKindEnum.INTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromExternaltoRelay() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_externalBehavior, RTPortKindEnum.RELAY); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromInternaltoSPP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_internalBehavior, RTPortKindEnum.SPP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromInternaltoSAP() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_internalBehavior, RTPortKindEnum.SAP); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromInternaltoExternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_internalBehavior, RTPortKindEnum.EXTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromInternaltoInternal() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_internalBehavior, RTPortKindEnum.INTERNAL); + } + + /** + * Test {@link RTPortUtils#getChangeKindCommand(Port, RTPortKindEnum)} + */ + @Test + public void testRTPortUtils_getChangeFromInternaltoRelay() throws Exception { + testRTPortUtils_getChangeKindcommand(capsule_internalBehavior, RTPortKindEnum.RELAY); + } + + protected void testRTPortUtils_getChangeKindcommand(Port portToModify, RTPortKindEnum newKind) { + RTPortKindEnum oldKind = RTPortUtils.getKind(portToModify); + + Command command = RTPortUtils.getChangeKindCommand(portToModify, newKind); + if (!command.canExecute()) { + fail("Change command is not executable"); + } + command.execute(); + checkPort(portToModify, newKind); + + if (!command.canUndo()) { + fail("Change command is not undoable"); + } + command.undo(); + checkPort(portToModify, oldKind); + + command.redo(); + checkPort(portToModify, newKind); + + command.undo(); + // check not dirty + + + } + + protected void checkPort(Port port, RTPortKindEnum kind) { + switch (kind) { + case EXTERNAL: + assertTrue("Service: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isService(port)); + assertTrue("Wired: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isWired(port)); + assertTrue("Behavior: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isBehavior(port)); + assertFalse("Publish: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isPublish(port)); + break; + case INTERNAL: + assertFalse("Service: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isService(port)); + assertTrue("Wired: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isWired(port)); + assertTrue("Behavior: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isBehavior(port)); + assertFalse("Publish: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isPublish(port)); + break; + case RELAY: + assertTrue("Service: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isService(port)); + assertTrue("Wired: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isWired(port)); + assertFalse("Behavior: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isBehavior(port)); + assertFalse("Publish: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isPublish(port)); + break; + case SPP: + // assertTrue("Service: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isService(port)); // legacy + assertFalse("Wired: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isWired(port)); + assertTrue("Behavior: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isBehavior(port)); + assertTrue("Publish: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isPublish(port)); + break; + case SAP: + // assertTrue("Service: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isService(port));// legacy + assertFalse("Wired: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isWired(port)); + assertTrue("Behavior: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isBehavior(port)); + assertFalse("Publish: error in RTPortUtils#getChangeKindCommand(Port)", RTPortUtils.isPublish(port)); + break; + + default: + break; + } + } + } |