blob: c43e98e399c0729138d9f4e90c40cb545b085a12 (
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
74
75
|
/*****************************************************************************
* Copyright (c) 2018 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christian W. Damus - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
import java.util.Set;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultCreationEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.papyrus.uml.service.types.utils.ElementUtil;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.Lifeline;
/**
* Custom creation edit policy for containers of {@link InteractionFragment}s, primarily
* for the creation of such fragments.
*
* @since 5.0
*/
public class InteractionFragmentContainerCreationEditPolicy extends DefaultCreationEditPolicy {
/**
* Initializes me.
*/
public InteractionFragmentContainerCreationEditPolicy() {
super();
}
@Override
protected Command getCreateElementAndViewCommand(CreateViewAndElementRequest request) {
IElementType typeToCreate = request.getViewAndElementDescriptor().getElementAdapter().getAdapter(IElementType.class);
if (!ElementUtil.isTypeOf(typeToCreate, UMLElementTypes.LIFELINE)) {
IEditCommandRequest semanticCreateRequest = (IEditCommandRequest) request.getViewAndElementDescriptor().getCreateElementRequestAdapter().getAdapter(IEditCommandRequest.class);
if (semanticCreateRequest != null) {
// What are the lifelines covered?
Rectangle rectangle = getCreationRectangle(request);
Set<Lifeline> covered = SequenceUtil.getCoveredLifelines(rectangle, getHost());
RequestParameterUtils.setCoveredLifelines(semanticCreateRequest, covered);
}
}
return super.getCreateElementAndViewCommand(request);
}
protected Rectangle getCreationRectangle(CreateViewAndElementRequest request) {
Point location = request.getLocation();
Dimension size = request.getSize();
if (size == null) {
return new Rectangle(location.x(), location.y(), 1, 1);
}
return new Rectangle(location, size);
}
}
|