Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsDrag& drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1072585/#msg_1072585
I am extending the generated EMF editor for my model . THe new editor have the original SelectionViewerPane and the new one FavoirateViewerPane.
The code of the two Pane and their attached Treeviewer is as follow:
adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
adapterFactory2 = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack1, new HashMap<Resource, Boolean>());
editingDomain2 = new AdapterFactoryEditingDomain(adapterFactory, commandStack2, new HashMap<Resource, Boolean>());
The two viewer Pane are in the same tab and the referenceSet of SelectionViewerPane is pointing to model1.family . while the other viewePane pointing to model2.family
My problems are :
• I want the modeler to be able to drag specific elements from model 1 and add it to the model2 , through the two EditorDomain (editingDomain , editingDomain2) . I was able to get this working , but the drag is happening at the parent level ; That is the parent should exist in the model2 so I can drag the child .
• Q1: The question is how I can override the EMF drag method,,, so that if the modeler drag the child, its associated parents will be added automatically
• Q2: How can I add a new elements to editingDomain : I am trying to use the method but not really sure which parameter to pass:
****AddCommand cmd = new AddCommand(editingDomain2, ?, ? )
I am new to EMF , and I really appreciate any support .
Regards
Salwa
]]>Salwa Alzahmi2013-07-23T05:02:16-00:00Re: Drag&amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1072618/#msg_1072618
Comments below.
On 23/07/2013 7:02 AM, Salwa Alzahmi wrote:
> Hello,
> I am extending the generated EMF editor for my model . THe new editor
> have the original SelectionViewerPane and the new one
> FavoirateViewerPane.
>
> The code of the two Pane and their attached Treeviewer is as follow:
>
> adapterFactory = new
> ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
> adapterFactory2 = new
> ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
>
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack1, new HashMap<Resource, Boolean>());
> editingDomain2 = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack2, new HashMap<Resource, Boolean>());
There are two editing domains?
>
> selectionViewer = (TreeViewer)viewerPane.getViewer();
> selectionViewer.setContentProvider(new
> AdapterFactoryContentProvider(adapterFactory));
> selectionViewer.setLabelProvider(new
> AdapterFactoryLabelProvider(adapterFactory));
> selectionViewer.setInput(editingDomain.getResourceSet());
>
>
> FavoirateViewer = (TreeViewer)
> FavoirateViewerPan.getViewer();
> //selectionMemberViewer.setContentProvider(new
> AdapterFactoryContentProvider(adapterFactory2));
> FavoirateViewer.setContentProvider(new
> AdapterFactoryContentProvider(adapterFactory2));
> FavoirateViewer.setLabelProvider(new
> AdapterFactoryLabelProvider(adapterFactory2));
> FavoirateViewer.setInput(editingDomain2.getResourceSet());
>
>
> The two viewer Pane are in the same tab and the referenceSet of
> SelectionViewerPane is pointing to model1.family . while the other
> viewePane pointing to model2.family
> My problems are :
> • I want the modeler to be able to drag specific elements from model 1
> and add it to the model2 , through the two EditorDomain
> (editingDomain , editingDomain2) . I was able to get this working ,
> but the drag is happening at the parent level ; That is the parent
> should exist in the model2 so I can drag the child . • Q1: The
> question is how I can override the EMF drag method,,, so that if the
> modeler drag the child, its associated parents will be added
> automatically
Command creation starts with
org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.createCommand(Class<?
extends Command>, CommandParameter) so that would be somewhere you could
detect it's a drag and drop command being created. Try setting a
breakpoint there to see how it's handled and how you could automatically
expand the collection of objects in the command parameter to include the
parents.
> • Q2: How can I add a new elements to editingDomain : I am trying to
> use the method but not really sure which parameter to pass:
> ****AddCommand cmd = new AddCommand(editingDomain2, ?, ? )
If you drag and drop the parents and the children that will hopefully be
sufficient.
I'm not really sure why you have two editing domains though. Is the
second viewer not like the outline viewer but rather a viewer that
maintains state beyond the lifetime of any one editor?
>
> I am new to EMF , and I really appreciate any support .
>
> Regards Salwa
>]]>Ed Merks2013-07-23T06:41:15-00:00Re: Drag&amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1073626/#msg_1073626
I tried what u suggested for editting the collection when drag command is issued , but unfortunately it doesnt work, Here is my code:
if (commandClass.getName().contains("DragAndDropCommand"))
{
Collection collection = new ArrayList();
if (commandParameter.getEOwner()!=null){
EObject parent = (EObject)commandParameter.getEOwner().eContainer();
while(parent!=null){
collection.add(parent);
parent = parent.eContainer();
}
commandParameter.getCollection().addAll(collection);
}
With This I have been able to add the parent elements to the commandParameter collection, but when i reach to the drop list "Target" , it doesn't accept it .
"
I'm not really sure why you have two editing domains though. Is the second viewer not like the outline viewer but rather a viewer that maintains state beyond the lifetime of any one editor?"
No Actually the second viewer , is representing another model elements , that why i created separate editing domain for it. basically the other viewer will show the subset elements of the one defined in viewer1 .. I am trying to give the modeler the ability to use the first viewer to model his whole system "it has some optional and mandatory elements". and once he is done , he can select some elements from viewer1 and add it to the viewer 2.
Since the drag wont work as I really want, I tried to create the elements in my second viewer programmaticly. like this :
editingDomain2.getCommandStack().execute(AddCommand.create(editingDomain2, EO, MymodelviewPackage.Literals.FEAT_MODEL_VIEW, e));
That works fine ,, But one thing about it is that I want to read from editingDomain1 and add it to editingDomain2 ... But it seem I need to handle parent and child by my self. and how actually I can get the children of a selected elements in editingDomain1
Thankx
Salwa
]]>Salwa Alzahmi2013-07-25T07:46:29-00:00Re: Drag&amp;amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1074130/#msg_1074130
Comments below.
On 25/07/2013 9:46 AM, Salwa Alzahmi wrote:
> Hello Ed ,
>
> I tried what u suggested for editting the collection when drag command
> is issued , but unfortunately it doesnt work, Here is my code: if
> (commandClass.getName().contains("DragAndDropCommand"))
> {
> Collection collection = new ArrayList();
> if (commandParameter.getEOwner()!=null){
> EObject parent =
> (EObject)commandParameter.getEOwner().eContainer();
> while(parent!=null){
> collection.add(parent);
> parent = parent.eContainer(); }
> commandParameter.getCollection().addAll(collection);
> }
>
> } Command command =
> super.createCommand(commandClass,commandParameter);
> With This I have been able to add the parent elements to the
> commandParameter collection, but when i reach to the drop list
> "Target" , it doesn't accept it .
> "
I see.
> I'm not really sure why you have two editing domains though. Is the
> second viewer not like the outline viewer but rather a viewer that
> maintains state beyond the lifetime of any one editor?"
> No Actually the second viewer , is representing another model elements
> , that why i created separate editing domain for it.
An editing domain contains a resource set that can contain any number of
resources from any number of models.
> basically the other viewer will show the subset elements of the one
> defined in viewer1 .. I am trying to give the modeler the ability to
> use the first viewer to model his whole system "it has some optional
> and mandatory elements". and once he is done , he can select some
> elements from viewer1 and add it to the viewer 2.
For a single editor you should have a single editing domain. For
example, the outline view and properties view share the editing domain
of the editor itself, not have their own.
>
> Since the drag wont work as I really want, I tried to create the
> elements in my second viewer programmaticly. like this :
> editingDomain2.getCommandStack().execute(AddCommand.create(editingDomain2,
> EO, MymodelviewPackage.Literals.FEAT_MODEL_VIEW, e)); That works fine
> ,, But one thing about it is that I want to read from editingDomain1
> and add it to editingDomain2 ... But it seem I need to handle parent
> and child by my self.
So go back an revisit this need for two editing domains. And if you
have more questions you need to show me exactly the design of your
model so that I know who the parent and children are related and I know
where the parent and child objects are contained.
>
> Thankx Salwa]]>Ed Merks2013-07-26T07:04:22-00:00Re: Drag&amp;amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1075922/#msg_1075922
"An editing domain contains a resource set that can contain any number of resources from any number of models."
--> the second editor domain actually representing a new instance of my model for example salwa2.mappingModel . while the first editor domain representing salwa1.mappingModel.
"For a single editor you should have a single editing domain. For example, the outline view and properties view share the editing domain of the editor itself, not have their own."
--> No actually I modified the GUI of the editor code , so I have now in the editor page two composite everyone with its own TreeViewer and EditorDomain. However the outline view is using the same editordomain of salwa1.mappingModel model.
Since what I am looking for is being able to copy some elements from TreeViewer(1) "salwa1.mappingModel" and add it to TreeViewer(2) "salwa2.mappingModel" , I tired many ways:
-->Modify the drag and drop command to include the parent when the user drag the child. ---> this technique has faild
-->I try to create an add command from editorDomain1 to editordomain 2 on selection. ---> That works but sadly that delete the elements from the source editor domain "editorDomain1 "
-->Last I try to issue copaytoclipboard and pastefromclipboard. ----> that work well ..
Now when I am trying to compare between two elements one from editordomain1 and the second from editordomain2 , I always get unmatched result although they are the same elements but just a copied version
Can you please help me to understand what is the problem .
Regards
Salwa
]]>Salwa Alzahmi2013-07-30T10:35:15-00:00Re: Drag&amp;amp;amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1075927/#msg_1075927
Comments below.
On 30/07/2013 12:35 PM, Salwa Alzahmi wrote:
> Hello Ed;
>
> "An editing domain contains a resource set that can contain any number
> of resources from any number of models."
> --> the second editor domain actually representing a new instance of
> my model for example salwa2.mappingModel . while the first editor
> domain representing salwa1.mappingModel.
More than one editing domain seems problematic to me.
>
>
> "For a single editor you should have a single editing domain. For
> example, the outline view and properties view share the editing domain
> of the editor itself, not have their own."
> --> No actually I modified the GUI of the editor code , so I have now
> in the editor page two composite everyone with its own TreeViewer and
> EditorDomain. However the outline view is using the same editordomain
> of salwa1.mappingModel model.
Again, one editor should have a single editing domain...
> Since what I am looking for is being able to copy some elements from
> TreeViewer(1) "salwa1.mappingModel" and add it to TreeViewer(2)
> "salwa2.mappingModel" , I tired many ways:
> -->Modify the drag and drop command to include the parent when the
> user drag the child. ---> this technique has faild
If you have multiple editing domains I'm not sure you'll ever get it
working just right. When the editor saves, it saves the resources in
the editing domain, but you have two, so how does save deal with that?
> -->I try to create an add command from editorDomain1 to editordomain
> 2 on selection. ---> That works but sadly that delete the elements
> from the source editor domain "editorDomain1 " -->Last I try to
> issue copaytoclipboard and pastefromclipboard. ----> that work well ..
GMF supports cross editing domain copying...
> Now when I am trying to compare between two elements one from
> editordomain1 and the second from editordomain2 , I always get
> unmatched result although they are the same elements but just a copied
> version Can you please help me to understand what is the problem .
It sounds like you're copying objects from one editing domain to
another, so yes of course you will have copies. The question keeps
coming back to why you have two editing domains...
>
> Regards Salwa
>]]>Ed Merks2013-07-30T10:44:34-00:00Re: Drag&amp;amp;amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1075945/#msg_1075945
Well I have two because as I told you before , one should hold the subset of the first one .. unless you have another suggestion !!
The save method will store the resourceSet of both EditorDomains each within its corresponding model file. in my case : "salwa1.mappingModel" and "salwa2.mappingModel.
Now my only problem is this:
"Now when I am trying to compare between two elements one from editordomain1 and the second from editordomain2 , I always get unmatched result although they are the same elements but just a copied vversion Can you please help me to understand what is the problem ."
]]>Salwa Alzahmi2013-07-30T11:34:34-00:00Re: Drag&amp;amp;amp;amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1075977/#msg_1075977
Comments below.
On 30/07/2013 1:34 PM, Salwa Alzahmi wrote:
> Thank you for your prompt reply :)
>
> Well I have two because as I told you before , one should hold the
> subset of the first one .. unless you have another suggestion !
Why do you need a subset? You can view a subset without having two
different editing domains (with clones of the same objects)...
> ! The save method will store the resourceSet of both EditorDomains
> each within its corresponding model file. in my case :
> "salwa1.mappingModel" and "salwa2.mappingModel.
But each has a command stack
> Now my only problem is this:
> "Now when I am trying to compare between two elements one from
> editordomain1 and the second from editordomain2 , I always get
> unmatched result although they are the same elements but just a copied
> vversion Can you please help me to understand what is the problem ."
> :( :(
Yes, you have two editing domains and seem to need the same objects to
be in more than one of them. Please explain exactly why you think you
need two editing domains.
>
>
>
>
>
>]]>Ed Merks2013-07-30T12:36:07-00:00Re: Drag&amp;amp;amp;amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1078716/#msg_1078716
Ok I need the subset because later I need to derive elements from another model based on each subset. That should happen dynamically, is that whatever the User add to the subset the other model will grow.
I do some can of manipulation for some elements in the subset . Also I need the property view to be active when the modeler have the focus on the subset viewer , and be able to save the subset resource-set later.
I should also change some elements appearance in the subset "the colors and text font" .
At till this stage everything goes smooth.
Regarding this problem: "when compare between two elements one from editordomain1 and the second from editordomain2 , I always get unmatched result although they are the same elements but just a copied
version" that obvious because the copied elements are not the same interms of their ID. I Auto generate am own ID for the model elements to overcome this prob.
" You can view a subset without having two different editing domains (with clones of the same objects)"..." if I clone can I do the above ..???
Thankx
Salwa]]>Salwa Alzahmi2013-08-03T12:28:12-00:00Re: Drag&amp;amp;amp;amp;amp; drop elements between two models
https://www.eclipse.org/forums/index.php/mv/msg/493718/1079165/#msg_1079165
Comments below.
On 03/08/2013 2:28 PM, Salwa Alzahmi wrote:
> Hi Ed,
>
> Ok I need the subset because later I need to derive elements from
> another model based on each subset.
That has nothing to do with two editing domains though...
> That should happen dynamically, is that whatever the User add to the
> subset the other model will grow.
> I do some can of manipulation for some elements in the subset . Also I
> need the property view to be active when the modeler have the focus on
> the subset viewer , and be able to save the subset resource-set later.
> I should also change some elements appearance in the subset "the
> colors and text font" .
> At till this stage everything goes smooth.
None of that requires two editing domains...
>
> Regarding this problem: "when compare between two elements one from
> editordomain1 and the second from editordomain2 , I always get
> unmatched result although they are the same elements but just a copied
> version" that obvious because the copied elements are not the same
> interms of their ID. I Auto generate am own ID for the model elements
> to overcome this prob.
> " You can view a subset without having two different editing domains
> (with clones of the same objects)"..." if I clone can I do the above
> ..???
If you insist on a design where you have two editing domains that have
clones of the same objects you'll have to live with that. But I still
fail to see the need for it.
>
> Thankx Salwa]]>Ed Merks2013-08-04T05:29:53-00:00