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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*****************************************************************************
* 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 v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* CEA LIST - Initial API and implementation
* EclipseSource - Bug 533770
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.referencialgrilling;
import java.util.List;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
import org.eclipse.papyrus.uml.diagram.sequence.command.SetResizeCommand;
/**
* This class is used to allow the resize and adding of children of the combined Fragment
*
*/
public class ResizeOperandEditPolicy extends GraphicalEditPolicy {
/**
* @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
*
*/
@Override
public void activate() {
super.activate();
}
/**
* @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
*
*/
@Override
public void deactivate() {
super.activate();
}
/**
* Factors incoming requests into various specific methods.
*
* @see org.eclipse.gef.EditPolicy#getCommand(Request)
*/
@Override
public Command getCommand(Request request) {
if (RequestConstants.REQ_RESIZE_CHILDREN.equals(request.getType())) {
CompositeCommand compositeCommand = new CompositeCommand("Resize Operands");
ChangeBoundsRequest changeBoundsRequest = (ChangeBoundsRequest) request;
List<?> editParts = changeBoundsRequest.getEditParts();
// the user can resize only one InteractionOperand
if (editParts.size() > 1) {
return null;
}
TransactionalEditingDomain editingDomain = getEditingDomain();
Object currentEditPart = editParts.get(0);
updateCurrentChildSize(compositeCommand, changeBoundsRequest, editingDomain, currentEditPart);
return new ICommandProxy(compositeCommand);
}
return null;
}
protected TransactionalEditingDomain getEditingDomain() {
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
return editingDomain;
}
private void updateCurrentChildSize(CompositeCommand compositeCommand, ChangeBoundsRequest changeBoundsRequest, TransactionalEditingDomain editingDomain, Object currentEditPart) {
GraphicalEditPart operandPart = (GraphicalEditPart) currentEditPart;
View shapeView = NotationHelper.findView(operandPart);
Dimension size = operandPart.getFigure().getSize();
size.expand(changeBoundsRequest.getSizeDelta().width, changeBoundsRequest.getSizeDelta().height);
ICommand setBoundsCommand = new SetResizeCommand(editingDomain, "Resize Operands", new EObjectAdapter(shapeView), size);
compositeCommand.add(setBoundsCommand);
}
}
|