Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Manipulating Multiple Nodes in GMF Editor
Manipulating Multiple Nodes in GMF Editor [message #204413] Thu, 04 September 2008 14:45 Go to next message
Eclipse UserFriend
Hi All,

I am trying to allow my GMF editor to rewrite/append a particular property
of multiple nodes (of the same type) at the same time.

What the user should be able to do is:

1) select multiple nodes using Ctrl and the mouse cursor (clicking on them)
2) right click on them for a pop-up menu
3) by selecting one of the options get a SWT interface
4) write in the new property
5) save the property so all nodes are updated

I’ve got the menu bar for multiple nodes and SWT but I’m not sure how to
manipulate multiple nodes/change one of their properties at one time.

I’ve had success doing something similar for a single node but I’m not
sure how to proceed if there are multiple nodes involved.

I’ve tried to something like this to try and “capture” the XXX nodes I
want to manipulate but this is probably only suitable for a single node.

public void run(IAction action) {
final IGraphicalEditPart editPart = (IGraphicalEditPart) editPart_for_xxx;
EObject modelElement = editPart.resolveSemanticElement();
final XXX dialogue_elementer = (XXX) modelElement;
TransactionalEditingDomain editingDomain =
TransactionUtil.getEditingDomain(modelElement);


Thank you very much for your help,

Gaff
Re: Manipulating Multiple Nodes in GMF Editor [message #204444 is a reply to message #204413] Thu, 04 September 2008 18:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi Gaff,

You can access all selected elements by keeping a pointer to the current
selection in your selectionChanged method i.e.

protected ISelection selection;
public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}

and then you can access selection (which is in fact an
IStructuredSelection) in your run method and get from it all its elements.

Also, in case you are interested in giving it a spin, in Epsilon GMT we
have implemented a small language for writing such wizards for GMF/EMF
editors. You can find a relevant screencast in
http://www.eclipse.org/gmt/epsilon/cinema/GMFWizards2.htm

Cheers,
Dimitrios

Gaff wrote:
> Hi All,
>
> I am trying to allow my GMF editor to rewrite/append a particular
> property of multiple nodes (of the same type) at the same time.
> What the user should be able to do is:
>
> 1) select multiple nodes using Ctrl and the mouse cursor (clicking on them)
> 2) right click on them for a pop-up menu
> 3) by selecting one of the options get a SWT interface
> 4) write in the new property
> 5) save the property so all nodes are updated
>
> I?ve got the menu bar for multiple nodes and SWT but I?m not sure how to
> manipulate multiple nodes/change one of their properties at one time.
>
> I?ve had success doing something similar for a single node but I?m not
> sure how to proceed if there are multiple nodes involved.
>
> I?ve tried to something like this to try and ?capture? the XXX nodes I
> want to manipulate but this is probably only suitable for a single node.
>
> public void run(IAction action) {
> final IGraphicalEditPart editPart = (IGraphicalEditPart) editPart_for_xxx;
> EObject modelElement = editPart.resolveSemanticElement();
> final XXX dialogue_elementer = (XXX) modelElement;
> TransactionalEditingDomain editingDomain =
> TransactionUtil.getEditingDomain(modelElement);
>
>
> Thank you very much for your help,
>
> Gaff
>
>
>
Re: Manipulating Multiple Nodes in GMF Editor [message #204576 is a reply to message #204444] Fri, 05 September 2008 09:44 Go to previous messageGo to next message
Eclipse UserFriend
Hi Dimitrios,

Thanks for your help.

I have multiple nodes selected in "selection" but I'm unsure how I
access/edit them and their properties.

Is it possible to iteratively call each node and perform a function on
them in turn? So for node of type XXX something like:

while (not at end of “selection”){

xxx = present XXX node from “selection”

String node_name = xxx.getName();

… more calculations…

xxx.setName(something_new);

Next XXX node in “selection”
}

Thanks again for your help, really appreciate it.

Gaff
Re: Manipulating Multiple Nodes in GMF Editor [message #204584 is a reply to message #204576] Fri, 05 September 2008 10:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi Gaff,

Your code should look something like this:

protected ISelection selection;

public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}

public void run (IAction action) {

if ((selection instanceof IStructuredSelection)) {
IStructuredSelection structuredSelection =
(IStructuredSelection) selection;
Iterator it = structuredSelection.iterator();
while (it.hasNext()) {
Object selectedNode = it.next();
// Here you can do stuff with each node
}
}
}

Hope this helps.

Dimitrios

Gaff wrote:
> Hi Dimitrios,
>
> Thanks for your help.
> I have multiple nodes selected in "selection" but I'm unsure how I
> access/edit them and their properties.
>
> Is it possible to iteratively call each node and perform a function on
> them in turn? So for node of type XXX something like:
>
> while (not at end of ?selection?){
>
> xxx = present XXX node from ?selection?
>
> String node_name = xxx.getName();
>
> ? more calculations?
>
> xxx.setName(something_new);
>
> Next XXX node in ?selection?
> }
>
> Thanks again for your help, really appreciate it.
>
> Gaff
>
>
Re: Manipulating Multiple Nodes in GMF Editor [message #204592 is a reply to message #204444] Fri, 05 September 2008 11:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi Dimitrios,

I've made some progress but still a little stumped. I can “call” the
selected nodes using IStructuredSelection (as you suggested) and then use
the iterator function so I can go through the nodes.

My problem is that the nodes are returned as objects and not nodes. I’ve
tried to cast the objects into nodes (XXX) but I get a runtime error.

I think I’ve solved this kind of issue using editpart but they’re not
being used in this approach.

Any suggestions?

Thanks again for your help.

Gaff


protected ISelection selection;

public void selectionChanged(IAction action, ISelection selection) {
this.selection = selection;
}


public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}



public void run(IAction action) {
IStructuredSelection structuredSelection = (IStructuredSelection)
selection;

for (Iterator it = structuredSelection.iterator(); it.hasNext();){


EObject nextSelectedObject = (EObject) it.next();

XXX my_xxx = (XXX) nextSelectedObject; <ISSUE IS HERE>

System.out.println("The structured selection element name is " +
my_xxx.getName());

}
}
Re: Manipulating Multiple Nodes in GMF Editor [message #204599 is a reply to message #204584] Fri, 05 September 2008 11:13 Go to previous messageGo to next message
Eclipse UserFriend
Hi Dimitrios,

Just figured it out. My previous post was a little premature. Only issu
now is with correctly casting the object to a node.

How do I cast from an Object/EObject to a node?

Thanks for your help,

Gaff
Re: Manipulating Multiple Nodes in GMF Editor [message #204612 is a reply to message #204599] Fri, 05 September 2008 12:12 Go to previous messageGo to next message
Eclipse UserFriend
The iterated objects are instances of IGraphicalEditPart

You can get the underlying EObject for each by calling the graphical
edit part's resolveSemanticElement() method.

Cheers,
Dimitrios

Gaff wrote:
> Hi Dimitrios,
>
> Just figured it out. My previous post was a little premature. Only issu
> now is with correctly casting the object to a node.
>
> How do I cast from an Object/EObject to a node?
>
> Thanks for your help,
>
> Gaff
>
Re: Manipulating Multiple Nodes in GMF Editor [message #205011 is a reply to message #204592] Wed, 10 September 2008 07:19 Go to previous message
Eclipse UserFriend
Hello Gaff,

> EObject nextSelectedObject = (EObject) it.next();
Place a breakpoint here to see a type of the object in java debugger.

-----------------
Alex Shatalin
Previous Topic:Domain model and figure hierarchy out of sync
Next Topic:Model too complex for GMF
Goto Forum:
  


Current Time: Sat Jun 07 23:16:07 EDT 2025

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

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

Back to the top