blob: 42e37fdeddeb21dd817426ab1f49faed610a311a (
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
76
77
78
79
80
81
82
83
84
85
86
|
/***************************************************************************
* Copyright (c) 2008 Conselleria de Infraestructuras y Transporte,
* Generalitat de la Comunitat Valenciana . 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: Francisco Javier Cano Muñoz - Initial API implementation
*
******************************************************************************/
package org.eclipse.papyrus.diagram.sequence.edit.policies;
import java.util.List;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
import org.eclipse.uml2.uml.Interaction;
import org.eclipse.papyrus.diagram.common.editpolicies.DiagramDragDropEditPolicy;
import org.eclipse.papyrus.diagram.common.editpolicies.ViewResolver;
import org.eclipse.papyrus.diagram.sequence.edit.commands.InitializeInteractionViewCommand;
/**
* Drag and Drop edit policy for the sequence <Diagram>. Will perform the
* drag&drop of an <Interaction> correctly, creating views according to the
* general order of the <Message>s in the <Interaction>.
*
* @author fjcano
*
*/
public class SequenceDiagramDragAndDropEditPolicy extends
DiagramDragDropEditPolicy {
/**
* Default constructor.
*
* @param resolver
*/
public SequenceDiagramDragAndDropEditPolicy(ViewResolver resolver) {
super(resolver);
}
@Override
public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
// - get Interaction from DropRequest
List<EObject> nodeObjects = findNodesInDrop(dropRequest);
// We are only interested in Interactions
List<Interaction> interactionObjects = new BasicEList<Interaction>();
for (EObject obj : nodeObjects) {
if (obj instanceof Interaction)
interactionObjects.add((Interaction) obj);
}
if (interactionObjects.size() == 0) {
return UnexecutableCommand.INSTANCE;
}
// - build and return command
IGraphicalEditPart parentEditPart = getHost() instanceof IGraphicalEditPart ? (IGraphicalEditPart) getHost()
: null;
if (parentEditPart != null) {
TransactionalEditingDomain domain = parentEditPart
.getEditingDomain();
if (domain != null) {
CompoundCommand cCommand = new CompoundCommand();
for (Interaction interaction : interactionObjects) {
InitializeInteractionViewCommand command = new InitializeInteractionViewCommand(
domain, "Initialize Interaction view", null);
command.setParentEditPart(parentEditPart);
command.setInteraction(interaction);
command.setOffset(dropRequest.getLocation());
cCommand.add(new ICommandProxy(command));
}
return cCommand;
}
}
return UnexecutableCommand.INSTANCE;
}
}
|