References are lost when Copy elements from project to project [message #1778353] |
Wed, 13 December 2017 05:54  |
Eclipse User |
|
|
|
Hello, could someone help me with following problem:
I have a projects structure like that:
P
/ \
G G
/\ /\
KKKK
I'm trying to copy G1 content to another G2 project (it also reproduces for P -> P). I set a breakpoint to createInitializeCopyCommand(). When I copy elements from G1 I see that all references are alright, but when I change diagram to G2 and try to paste there, I see that all K references from my G1 are lost, just G-specific elements are OK.
Could you, please, suggest me how I can reimplement this behavior? Or maybe is there some way to store my K (or its URI) in some static variable until it is needed to paste and there is a way to restore K from it.
Thank you,
Pavel
|
|
|
|
|
|
|
|
|
|
|
Re: References are lost when Copy elements from project to project [message #1778659 is a reply to message #1778459] |
Tue, 19 December 2017 08:06  |
Eclipse User |
|
|
|
Hello,
thank you so much for you answers.
My problem has been solved. The way was following:
- Catch objects of copy and paste in createInitializeCopyCommand() of your ItemProvider
- To save objects of copy and paste in separate singleton that contains two maps copyOwners<Class<?>, EObject> and pasteOwners<Class<?>, EObject> and restore references when paste using method like this:
public void restore(EObject owner, Class<?> callPointClass, Class<?> rootContainerClass) {
if (rootContainerClass.isInstance(EcoreUtil.getRootContainer(owner))) {
copyOwners.put(callPointClass, owner);
} else {
pasteOwners.put(callPointClass, owner);
if (copyOwners.get(callPointClass) != null
&& pasteOwners.get(callPointClass) != null) {
Copier copier = new Copier();
copier.put(copyOwners.get(callPointClass), owner);
copier.copyReferences();
}
}
}
Here I assume that the difference between objects of copy and paste is the existence (!=null) of rootContainer of your diagram type.
The way with extension point is very complicated, I think. Maybe I don't know some ways how to do it convenient, but there are a lot of useful methods those are private. And you need to investigate a lot of things to rewrite it correctly.
So I did it this way. Maybe it will be helpful for somebody.
Best regards,
Pavel
|
|
|
Powered by
FUDForum. Page generated in 0.05234 seconds