Home » Modeling » EMF » Drag& drop elements between two models (Drag& drop elements between two models )
Drag& drop elements between two models [message #1072585] |
Tue, 23 July 2013 05:02 |
Salwa Alzahmi Messages: 37 Registered: June 2013 |
Member |
|
|
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>());
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
• 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
|
|
|
Re: Drag& drop elements between two models [message #1072618 is a reply to message #1072585] |
Tue, 23 July 2013 06:41 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Salwa,
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 Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Drag& drop elements between two models [message #1073626 is a reply to message #1072618] |
Thu, 25 July 2013 07:46 |
Salwa Alzahmi Messages: 37 Registered: June 2013 |
Member |
|
|
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'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
[Updated on: Thu, 25 July 2013 08:19] Report message to a moderator
|
|
|
Re: Drag&amp; drop elements between two models [message #1074130 is a reply to message #1073626] |
Fri, 26 July 2013 07:04 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Salwa,
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 Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Drag&amp;amp; drop elements between two models [message #1075927 is a reply to message #1075922] |
Tue, 30 July 2013 10:44 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Salwa,
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 Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | |
Re: Drag&amp;amp;amp;amp; drop elements between two models [message #1079165 is a reply to message #1078716] |
Sun, 04 August 2013 05:29 |
Ed Merks Messages: 33141 Registered: July 2009 |
Senior Member |
|
|
Salwa,
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 Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Thu Apr 25 22:16:07 GMT 2024
Powered by FUDForum. Page generated in 0.04523 seconds
|