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
|
/*****************************************************************************
* Copyright (c) 2014 CEA LIST.
*
* 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:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.commands;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
/**
* Insert a diagram with the specified owner and element
*/
public class InsertDiagramCommand extends RecordingCommand {
/** FIXME the domain of Recording command should be accessible */
protected TransactionalEditingDomain transactionalEditingDomain;
/** diagram to be inserted */
protected Diagram diagram;
/** owner of the diagram */
protected EObject owner;
/** element of the diagram */
protected EObject element;
/**
* Insert a diagram with the specified owner and element
*
* @param transactionalEditingDomain
* @param label
* of the command
* @param diagram
* to be inserted
* @param element
* of the diagram // FIXME
* @param owner
* of the diagram
*/
public InsertDiagramCommand(TransactionalEditingDomain transactionalEditingDomain, String label, Diagram diagram, EObject owner) {
this(transactionalEditingDomain, label, diagram, owner, null);
}
/**
* Insert a diagram with the specified owner and element
*
* @param transactionalEditingDomain
* @param label
* of the command
* @param diagram
* to be inserted
* @param element
* of the diagram
* @param owner
* of the diagram
*/
public InsertDiagramCommand(TransactionalEditingDomain transactionalEditingDomain, String label, Diagram diagram, EObject owner, EObject element) {
super(transactionalEditingDomain, label);
this.transactionalEditingDomain = transactionalEditingDomain; // FIXME the domain of Recording command should be accessible
this.diagram = diagram;
this.element = element;
this.owner = owner;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
*/
@Override
protected void doExecute() {
Resource targetResource = NotationUtils.getNotationResourceForDiagram(owner, transactionalEditingDomain);
DiagramUtils.setOwner(diagram, owner);
if (element != null){
diagram.setElement(element);
}
if(targetResource != null) {
targetResource.getContents().add(diagram);
}
}
}
|