blob: 3b28af3563e281e77b1b5219d3991fe0175027bb (
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
|
/*****************************************************************************
* Copyright (c) 2009 Atos Origin.
*
*
* 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:
* Atos Origin - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.ResizableEditPolicy;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentCombinedFragmentCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.util.OperandBoundsComputeHelper;
/**
* The customn DragDropEditPolicy for InteractionOperandEditPart.
*/
public class InteractionOperandDragDropEditPolicy extends ResizableEditPolicy {
/**
* Disable drag and allow only south resize. {@inheritDoc}
*/
public InteractionOperandDragDropEditPolicy() {
super();
setDragAllowed(false);
}
/**
* Handle resize InteractionOperand {@inheritDoc}
*/
@Override
protected Command getResizeCommand(ChangeBoundsRequest request) {
boolean isVertResize = (request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0;
boolean isHorResize = (request.getResizeDirection() & PositionConstants.EAST_WEST) != 0;
boolean isNorthResize = (request.getResizeDirection() & PositionConstants.NORTH) != 0;
boolean isSouthResize = (request.getResizeDirection() & PositionConstants.SOUTH) != 0;
if (isHorResize && !isVertResize) {
EditPart parent = getHost().getParent().getParent();
return parent.getCommand(request);
} else if (isVertResize) {
if (this.getHost() instanceof InteractionOperandEditPart && this.getHost().getParent() instanceof CombinedFragmentCombinedFragmentCompartmentEditPart) {
InteractionOperandEditPart currentIOEP = (InteractionOperandEditPart) this.getHost();
CombinedFragmentCombinedFragmentCompartmentEditPart compartEP = (CombinedFragmentCombinedFragmentCompartmentEditPart) this.getHost().getParent();
// if the OP's border same as/linked to the CF's border
if (this.getHost() == OperandBoundsComputeHelper.findFirstIOEP(compartEP) && isNorthResize
|| this.getHost() == OperandBoundsComputeHelper.findLastIOEP(compartEP) && isSouthResize) {
return getHost().getParent().getParent().getCommand(request);
} else {
return OperandBoundsComputeHelper.createIOEPResizeCommand(currentIOEP, request, compartEP);
}
}
}
return null;
}
}
|