Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » References are lost when Copy elements from project to project
References are lost when Copy elements from project to project [message #1778353] Wed, 13 December 2017 10:54 Go to next message
Pavel Bogdanov is currently offline Pavel BogdanovFriend
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 #1778384 is a reply to message #1778353] Wed, 13 December 2017 16:16 Go to previous messageGo to next message
Pavel Bogdanov is currently offline Pavel BogdanovFriend
Messages: 19
Registered: December 2017
Junior Member
P.S. I have found out that the main cause of my problem in class SiriusClipboardManager. It removes all external references from my EObject, but I need to restore it. Is there a way how do not to use this method, or, if it impossible, Is there a correct way to restore my references after paste?

Thank you,
Pavel
Re: References are lost when Copy elements from project to project [message #1778415 is a reply to message #1778384] Thu, 14 December 2017 05:58 Go to previous messageGo to next message
M V is currently offline M VFriend
Messages: 31
Registered: July 2017
Member
Hello,
how are the settings of your refrences in the EMF model?

It has also happened to me that they were declared derived. I don't know exactly how the ClipBoardManager works, but if it can use the ecoreutils, for example, it may be that they don't copy the reference if they are declared derived.

Alternatively, the paste utility can also help you if necessary.
https://www.eclipse.org/sirius/doc/specifier/diagrams/Diagrams.html#tools_specification
Re: References are lost when Copy elements from project to project [message #1778427 is a reply to message #1778415] Thu, 14 December 2017 08:17 Go to previous messageGo to next message
Pavel Bogdanov is currently offline Pavel BogdanovFriend
Messages: 19
Registered: December 2017
Junior Member
Hello, thank you in advice.

During debugging I've seen that significant properties here are Container, Containment, Derived and EOpposite and all of them are false.
Re: References are lost when Copy elements from project to project [message #1778434 is a reply to message #1778427] Thu, 14 December 2017 09:07 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6614
Registered: July 2009
Senior Member
Hi

If you look at EcoreUtil.Copier you will see that there are alternative choices for how external references are handled. This shows that even in a simple programming context you can get good/bad behaviour.

Once you introduce a ClipBoard intermediate, it gets harder and it seems that Sirius has made a simplistic kill the externals choice. If you DND between Sample Ecore Editor windows you will find disappointing functionality there too.

I suspect that EMF may offer a good solution. References whose target has not yet been loaded or which has been unloaded are set to proxies; a URI by which the content can be loaded on demand.

You could ensure that all external references are converted to proxies when the clipboard copy is created, then the proxies can be resolved on paste, possibly to equivalently URIed objects in the target diagram, possibly by importing the missing targets, possibly by a distinctive problem marker that offers a how-to-resolve dialog. This seems like it could be a standard Sirius functionality.

Regards

Ed Willink
Re: References are lost when Copy elements from project to project [message #1778438 is a reply to message #1778434] Thu, 14 December 2017 09:37 Go to previous messageGo to next message
Pavel Bogdanov is currently offline Pavel BogdanovFriend
Messages: 19
Registered: December 2017
Junior Member
Hello, Ed.

Thank you very much in advice. But I still don't completely understand where exactly I could intercept the clipboard to change it. If I try to change it in createInitializeCopyCommand() of ItemProvider, it fails with exception connected with object changes within transaction
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 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 470
Registered: May 2011
Senior Member
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
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: References are lost when Copy elements from project to project [message #1778454 is a reply to message #1778445] Thu, 14 December 2017 10:39 Go to previous messageGo to next message
Pavel Bogdanov is currently offline Pavel BogdanovFriend
Messages: 19
Registered: December 2017
Junior Member
Hello, Steve.

I see that class SiriusClipboardManager is final and cannot be ovverride, as I understand. Also it's not obvious to me about SiriusClipboardGlobalActionHandlerProvider - methods that use SiriusClipboardManager are private. What way I could do the override that you describe?

I cannot use an approach with addition of dependencies because my task is about implementing of Copy/Paste right.

Thank you,
Pavel
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 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 470
Registered: May 2011
Senior Member
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
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 Go to previous message
Pavel Bogdanov is currently offline Pavel BogdanovFriend
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
Previous Topic:Multiple models referenced by a same representation file
Next Topic:Sirius + EEF - the simplest way to customize property behaviour
Goto Forum:
  


Current Time: Mon Mar 30 17:18:12 GMT 2020

Powered by FUDForum. Page generated in 0.02494 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top