blob: ca2070468a537fcc54dc2992c6df6a452d8eb8ef (
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*****************************************************************************
* Copyright (c) 2012 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:
* Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.infra.emf.compare.diff.internal.command;
import org.eclipse.emf.common.command.AbstractCommand;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
/**
*
* This command allows to copy the XMI_ID from one EObject to another one, only if they are not owned by the same resource
*
*/
//TODO should be moved in infra.emf plugin when the problem of the saùme resource will be corrected in Papyrus
public class CopyXMIIDCommand extends AbstractCommand {
/**
* the EObject which provides the XMI_ID
*/
private final EObject source;
/**
* the EObject which receive the XMI_ID
*/
private final EObject target;
/**
* the initial XMI_ID of the target
*/
private String initialID;
/**
*
* Constructor.
*
* @param source
* the EObject which provides the XMI_ID
* @param target
* the EObject which receive the XMI_ID
*/
public CopyXMIIDCommand(final EObject source, final EObject target) {
this.source = source;
this.target = target;
this.initialID = null;
setLabel("Copy XMI_ID command"); //$NON-NLS-1$
}
/**
*
* @see org.eclipse.emf.common.command.Command#execute()
*
*/
public void execute() {
final Resource sourceResource = source.eResource();
final Resource targetResource = target.eResource();
if(sourceResource instanceof XMIResource && targetResource instanceof XMIResource) {
if(sourceResource != targetResource) {//see bug 377189: [Nested UML Compare] the merged elements have the same XMI ID
final String xmi_id = EMFHelper.getXMIID(this.source);
this.initialID = EMFHelper.getXMIID(target);
((XMIResource)this.target.eResource()).setID(this.target, xmi_id);
}
}
}
/**
*
* @see org.eclipse.emf.common.command.Command#redo()
*
*/
public void redo() {
execute();
}
/**
*
* @see org.eclipse.emf.common.command.AbstractCommand#prepare()
*
* @return
*/
@Override
protected boolean prepare() {
return true;
}
/**
*
* @see org.eclipse.emf.common.command.AbstractCommand#undo()
*
*/
@Override
public void undo() {
final Resource targetResource = target.eResource();
if(targetResource instanceof XMIResource) {
((XMIResource)this.target.eResource()).setID(this.target, this.initialID);
}
}
}
|