Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Relocation of child nodes
Relocation of child nodes [message #721649] Fri, 02 September 2011 12:30 Go to next message
janpojer is currently offline janpojerFriend
Messages: 40
Registered: July 2011
Member
Hi,

I have child nodes attached to my parent node in my diagram. However i would like to rearrange them using my custom needs. Do you know what is the best way to change their loaction and where to do that (when i wish to do that after the parent node is created)?

Mine following code does not work...
Point pp = new Point();
pp.x = -5;
pp.y = 1;
rport.getFigure().setLocation(pp);


Thanks for help...
Re: Relocation of child nodes [message #721654 is a reply to message #721649] Fri, 02 September 2011 12:37 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

With GMF, you need to avoid using directly GEF APIs at runtime, since
your change would be not persisted, or even not applied.

Instead, you have to use the Request-Command mechanism. See
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.gmf.doc/reference/api/runtime/org/eclipse/gmf/runtime/emf/type/core/edithelper/AbstractEditHelper.html

The flow is:
1. Create your request
2. Give your request to the target Edit part's getCommand method
3. execute the created command using the DiagramEditDomain of your
GraphicalViewer.

Then your change will be applied and persisted.


On 02/09/2011 14:30, janpojer wrote:
> Hi,
>
> I have child nodes attached to my parent node in my diagram. However i
> would like to rearrange them using my custom needs. Do you know what is
> the best way to change their loaction and where to do that (when i wish
> to do that after the parent node is created)?
>
> Mine following code does not work...
>
> Point pp = new Point();
> pp.x = -5;
> pp.y = 1;
> rport.getFigure().setLocation(pp);
>
>
> Thanks for help...


--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: Relocation of child nodes [message #721884 is a reply to message #721654] Sat, 03 September 2011 11:25 Go to previous messageGo to next message
janpojer is currently offline janpojerFriend
Messages: 40
Registered: July 2011
Member
Hi,

thank you for the instrunctions. I am still a bit confused here. So whenever I need to attach some functionality to lets say edit operation. Precisely after the edit, I need to edit the after advice of the XEditHelper ?
So by create your own request you ment to modify the current edit request? Is there some good tutorial that talks about request modifications and such?

Thanks for the help...
Re: Relocation of child nodes [message #721923 is a reply to message #721654] Sat, 03 September 2011 16:11 Go to previous message
janpojer is currently offline janpojerFriend
Messages: 40
Registered: July 2011
Member
OK,
this is what i did:

1. I have created mine Request:
public class CustomRequest extends Request {
	public CustomRequest(Object type) {
		super.setType(type);
	}
}


2. I placed the perform request code into the XEditPart class:
protected void handleNotificationEvent(Notification notification) {
...
performRequest(new CustomRequest(RequestConstantsCustom.REQ_REPOSITION_PORTS));
...
}

public void performRequest(CustomRequest request) {
        if (RequestConstantsCustom.REQ_REPOSITION_PORTS.equals(request.getType())) {
            //allowed, continue
        	 Command command = this.getCommand(request);
             if (command != null) {
            	 System.out.println("Executing mine custom command");
                 getDiagramEditDomain().getDiagramCommandStack().execute(
                     command);
                 return;
             }
        } else {
        	Request r = (Request) request;
        	super.performRequest(r);
        }
}


3. I have created my own getCommand method within the xEditPart:
public Command getCommand(CustomRequest _request) {
	System.out.println("My Custom request...... "+_request.getType());
	Command command = new PortRepositionCommand(this);
	return command;
}


4. And finally I created my custom command that should reposition my ports:
public class PortRepositionCommand extends Command {
...
	public PortRepositionCommand(XFunctionEditPart xFunctionEditPart) {
		editPart = xFunctionEditPart;
	}

	public void execute() {
		List l = editPart.getChildren();
		for (int i = 0; i < l.size(); i++) {
			if (l.get(i) instanceof RequiredPortEditPart) {
				RequiredPortEditPart rport = (RequiredPortEditPart) l.get(i);
				Point point = rport.getLocation();
			}
			else if (l.get(i) instanceof ProvidedPortEditPart){
				ProvidedPortEditPart rport = (ProvidedPortEditPart) l.get(i);
				Point pp = new Point();
				pp.x = 0;
				pp.y = 0;
				rport.getFigure().setLocation(pp);
			}
		}
	}
}


Unfortunately nomatter how i modify the coordinates of pp it doesnt change the port location...

Note: this code does not do exactly what i need with the ports, but should change their position somehow. But nevertheless it doesnt move an inch... Any ideas what am I doing wrong?

Thanks...
Previous Topic:How to show Coordinate Properties
Next Topic:Link mapping problem : Type based link between two nodes
Goto Forum:
  


Current Time: Fri Apr 19 06:42:39 GMT 2024

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

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

Back to the top