blob: 87f44c61a18a2cedf233915ffb0fc26875eef963 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package org.eclipse.papyrus.uml.service.types.helper.advice;
import java.util.Arrays;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.common.core.command.IdentityCommand;
import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
import org.eclipse.gmf.runtime.emf.type.core.commands.GetEditContextCommand;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest;
import org.eclipse.papyrus.uml.service.types.command.ElementOwnedElementCreateCommand;
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
public class ElementOwnedElementEditHelperAdvice extends AbstractEditHelperAdvice {
@Override
protected ICommand getBeforeEditContextCommand(final GetEditContextRequest request) {
GetEditContextCommand command = new GetEditContextCommand(request);
command.setEditContext(request.getEditHelperContext());
return command;
}
protected boolean canCreate(EObject source, EObject target) {
if ((source != null) && !(source instanceof org.eclipse.uml2.uml.Namespace)) {
return false;
}
if ((target != null) && !(target instanceof org.eclipse.uml2.uml.Namespace)) {
return false;
}
return true;
}
@Override
protected ICommand getBeforeCreateRelationshipCommand(CreateRelationshipRequest request) {
// Be careful, This advice is binded to Element elementtype directly
List<ISpecializationType> subs = Arrays.asList(ElementTypeRegistry.getInstance().getSpecializationsOf(UMLElementTypes.ELEMENT_OWNEDELEMENT.getId()));
if (!subs.contains(request.getElementType()))
{
return IdentityCommand.INSTANCE;
}
EObject source = request.getSource();
EObject target = request.getTarget();
boolean noSourceOrTarget = (source == null || target == null);
boolean noSourceAndTarget = (source == null && target == null);
if (!noSourceAndTarget && !canCreate(source, target)) {
return UnexecutableCommand.INSTANCE;
}
if (noSourceOrTarget && !noSourceAndTarget) {
// The request isn't complete yet. Return the identity command so
// that the create relationship gesture is enabled.
return IdentityCommand.INSTANCE;
}
return new ElementOwnedElementCreateCommand(request);
}
}
|