References are lost when Copy elements from project to project [message #1778353] |
Wed, 13 December 2017 10:54 |
Pavel Bogdanov Messages: 19 Registered: December 2017 |
Junior Member |
|
|
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 #1778445 is a reply to message #1778438] |
Thu, 14 December 2017 10:07 |
|
Hello,
Indeed, only the copied element are pasted and references to elements outside of the editing domain are removed. You will need to copy the "K" elements as well as "G1" to paste them without some custom code.
Currently we only have a paste operation that can be defined in the VSM. We may include a copy operation in the roadmap for next year, but it is not confirmed yet.
Meanwhile, SiriusClipboardManager is contributed by the global action handler provider SiriusClipboardGlobalActionHandlerProvider with a priority High in org.eclipse.sirius.diagram.ui. I think that you can provide your own with a priority Highest and override SiriusClipboardManager with your own behavior that will add the referenced "K" element to the clipboard.
On a different approach, instead of copying the element G1 from project P1 to P2, can't you add a dependency in project P2 to the semantic resource containing G1 in project P1?
Regards,
Steve
Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Re: References are lost when Copy elements from project to project [message #1778459 is a reply to message #1778454] |
Thu, 14 December 2017 13:48 |
|
Hello,
My bad I mixed up some class names. I wanted to say to override the CopyToSiriusClipboardCommand with your own behavior that will add the referenced "K" element to the clipboard. What I add in mind was to provide your action handler like this
<extension point="org.eclipse.gmf.runtime.common.ui.services.action.globalActionHandlerProviders">
<GlobalActionHandlerProvider
class="mypackage.MyCustomSiriusClipboardGlobalActionHandlerProvider"
id="SiriusRender">
<Priority name="Highest"/>
<ViewId id="org.eclipse.sirius.diagram.ui.part.SiriusDiagramEditorID">
<ElementType class="org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart">
<GlobalActionId actionId="cut"/>
<GlobalActionId actionId="copy"/>
<GlobalActionId actionId="paste"/>
</ElementType>
</ViewId>
</GlobalActionHandlerProvider>
</extension>
In This MyCustomSiriusClipboardGlobalActionHandlerProvider override getGlobalActionHandler to add your own SiriusClipboardGlobalActionHandler. Finally in this SiriusClipboardGlobalActionHandler you would override the getCopyCommand with the overridden CopyToSiriusClipboardCommand.
Regards,
Steve
Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Re: References are lost when Copy elements from project to project [message #1778659 is a reply to message #1778459] |
Tue, 19 December 2017 13:06 |
Pavel Bogdanov Messages: 19 Registered: December 2017 |
Junior Member |
|
|
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.05216 seconds