Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java86
1 files changed, 60 insertions, 26 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java
index 1fb1fa298d8..d72ac87c507 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/advice/DurationConstraintEditHelperAdvice.java
@@ -1,6 +1,6 @@
/*****************************************************************************
- * Copyright (c) 2017 CEA LIST and others.
- *
+ * Copyright (c) 2017 - 2018 CEA LIST, EclipseSource 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
@@ -11,8 +11,8 @@
* Contributors:
* CEA LIST - Initial API and implementation
* Vincent Lorenzo (CEA LIST) - vincent.lorenzo@cea.fr - bug 527259
+ * EclipseSource - Bug 536488, 536489
*****************************************************************************/
-
package org.eclipse.papyrus.uml.service.types.helper.advice;
import org.eclipse.core.commands.ExecutionException;
@@ -25,11 +25,12 @@ import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
import org.eclipse.uml2.uml.Duration;
import org.eclipse.uml2.uml.DurationConstraint;
import org.eclipse.uml2.uml.DurationInterval;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.UMLFactory;
/**
@@ -42,7 +43,7 @@ public class DurationConstraintEditHelperAdvice extends AbstractEditHelperAdvice
/**
* Add Duration value to the created Duration Interval
* Set name with prefix
- *
+ *
* @param durationInterval
*/
private void initDurationInterval(final DurationInterval durationInterval) {
@@ -65,47 +66,80 @@ public class DurationConstraintEditHelperAdvice extends AbstractEditHelperAdvice
maxDuration.setExpr(UMLFactory.eINSTANCE.createLiteralInteger());
}
-
/**
- * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterEditCommand(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ * <p>
+ * Configure the new DurationConstraint with
+ * </p>
*
- * @param request
* @return
*/
@Override
- public ICommand getAfterEditCommand(final IEditCommandRequest request) {
-
- ICommand composite = new CompositeCommand("After Edit Command of DurationConstraint");// $NON-NLS-0$
+ protected ICommand getAfterConfigureCommand(ConfigureRequest request) {
+ ICommand composite = new CompositeCommand("After Configure Command of DurationConstraint");// $NON-NLS-0$
+ ICommand afterConfigureCommand = super.getAfterConfigureCommand(request);
+ if (null != afterConfigureCommand && afterConfigureCommand.canExecute()) {
+ composite.compose(afterConfigureCommand);
+ }
- if (null != super.getAfterEditCommand(request) && super.getAfterEditCommand(request).canExecute()) {
- composite.compose(super.getAfterEditCommand(request));
+ EObject toConfigure = request.getElementToConfigure();
+ if (false == toConfigure instanceof DurationConstraint) {
+ return composite;
}
+ DurationConstraint constraint = (DurationConstraint) toConfigure;
+
// Create the command to initialize Duration Interval in case of Duration Constraint
- final ICommand command = new AbstractTransactionalCommand(request.getEditingDomain(), "Init DurationConstraint", null) {// $NON-NLS-0$
+ final ICommand initInterval = new AbstractTransactionalCommand(request.getEditingDomain(), "Init DurationConstraint Specification", null) { //$NON-NLS-1$
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- if (request instanceof ConfigureRequest) {
- ConfigureRequest configRequest = (ConfigureRequest) request;
- EObject element = configRequest.getElementToConfigure();
- if (element instanceof DurationConstraint) {
- if (((DurationConstraint) element).getSpecification() instanceof DurationInterval) {
- // initialize Duration Interval
- initDurationInterval((DurationInterval) ((DurationConstraint) element).getSpecification());
- }
- }
+ if (constraint.getSpecification() instanceof DurationInterval) {
+ // initialize Duration Interval
+ initDurationInterval((DurationInterval) constraint.getSpecification());
}
return CommandResult.newOKCommandResult();
-
}
};
+ composite.compose(initInterval);
+
+ // Create the command to initialize the ConstrainedElement (Multiplicity [1..2]
+ Element source = getSourceElement(request);
+ Element target = getTargetElement(request);
- if (command.canExecute()) {
- composite.compose(command);
+ if (source != null && target != null) {
+ final ICommand initConstrainedElements = new AbstractTransactionalCommand(request.getEditingDomain(), "Init DurationConstraint constrained elements", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ constraint.getConstrainedElements().add(0, source);
+ constraint.getConstrainedElements().add(1, target);
+ return CommandResult.newOKCommandResult();
+ }
+ };
+
+ composite.compose(initConstrainedElements);
}
+
return composite;
}
+ protected Element getSourceElement(ConfigureRequest request) {
+ Object paramObject = request.getParameter(CreateRelationshipRequest.SOURCE);
+ if (paramObject instanceof Element) {
+ return (Element) paramObject;
+ }
+
+ return null;
+ }
+
+ protected Element getTargetElement(ConfigureRequest request) {
+ Object paramObject = request.getParameter(CreateRelationshipRequest.TARGET);
+ if (paramObject instanceof Element) {
+ return (Element) paramObject;
+ }
+
+ return null;
+ }
+
}

Back to the top