Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Force a figure to be sticked to another one (with drag and drop enabled)
Force a figure to be sticked to another one (with drag and drop enabled) [message #553189] Mon, 16 August 2010 15:50 Go to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Hello,

I would like to force a figure to be sticked to another one. For
example, the x coordinate must remain fixed but the y one can change
using drag and drop... Is it possible to implement such mechanism with GMF?

Thanks very much for your help!
Thierry
Re: Force a figure to be sticked to another one (with drag and drop enabled) [message #553302 is a reply to message #553189] Tue, 17 August 2010 06:01 Go to previous messageGo to next message
Robert Wloch is currently offline Robert WlochFriend
Messages: 109
Registered: July 2009
Senior Member
Hello Thierry,

you could register a listener on the bounds of figure A and when they change update the bounds of figure B by the displacement of figure A.

Rob
Re: Force a figure to be sticked to another one (with drag and drop enabled) [message #553324 is a reply to message #553302] Tue, 17 August 2010 07:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Hello Rob,

Thanks very much for your answer and the hint. Using this approach, I
can detect moving and changing figure position... A strange thing, the
content of my figure is displayed anymore (I'm using a svg figure). Only
outline is displayed when I select the figure...

Thierry

> Hello Thierry,
>
> you could register a listener on the bounds of figure A and when they
> change update the bounds of figure B by the displacement of figure A.
>
> Rob
Re: Force a figure to be sticked to another one (with drag and drop enabled) [message #553361 is a reply to message #553324] Tue, 17 August 2010 09:24 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
I have already done this, here's the simplest way to do it:

Write a class which extends the ResizableEditPolicyEx, like this:


public class MoveParentWithChildEditPolicy extends ResizableEditPolicyEx {

	/**
	 * delegates the move request to the parent
	 * @generated NOT
	 */
	protected Command getMoveCommand(ChangeBoundsRequest request) {

		
		EditPart parentEditPart = getHost().getParent();
		return parentEditPart.getCommand(request);
	}

	
	
	/**
	 * 
	 * Show parent move feedback instead of this figure move feedback
	 * 
	 * @generated NOT
	 */
	  protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
	        IFigure feedback = getDragSourceFeedbackFigure();
	        
	        PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
	        getHostFigure().translateToAbsolute(rect);

	        rect.translate(request.getMoveDelta());
	        
	        IFigure f = getHostFigure().getParent();
	        
	        rect.setSize(f.getSize());
	        
	        Dimension min = f.getMinimumSize().getCopy();
	        Dimension max = f.getMaximumSize().getCopy();
	        IMapMode mmode = MapModeUtil.getMapMode(f);
	        min.height = mmode.LPtoDP(min.height);
	        min.width = mmode.LPtoDP(min.width);
	        max.height = mmode.LPtoDP(max.height);
	        max.width = mmode.LPtoDP(max.width);
	        
	        if (min.width>rect.width)
	            rect.width = min.width;
	        else if (max.width < rect.width)
	            rect.width = max.width;
	        
	        if (min.height>rect.height)
	            rect.height = min.height;
	        else if (max.height < rect.height)
	            rect.height = max.height;
	        
	        
	        
	       
	        feedback.translateToRelative(rect);
	        feedback.setBounds(rect);
	    }



Then, in the child EditPart, install this edit policy :

protected void createDefaultEditPolicies() {
            // .............. initial code here ................
            //add this: 

		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
				new MoveParentWithChildEditPolicy());
	}



Hope it helps,


Cheers,
Emil.

[Updated on: Tue, 17 August 2010 09:27]

Report message to a moderator

Re: Force a figure to be sticked to another one (with drag and drop enabled) [message #553616 is a reply to message #553361] Wed, 18 August 2010 08:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Hello Emil,

To be sure... The policy must be installed in the child edit part, the
one which only must be moved vertically? If I have fig1 (the one which
can be moved by drag and drop) which is contained in a compartment of
fig2 (as described below), the policy must be installed in fig1?

Fig2
|-----|--------|
| Fig1| |
| | |
|-----|--------|

It seems that both methods of the MoveParentWithChildEditPolicy class
aren't called...

Thanks in advance for your help.
Thierry

> I have already done this, here's the simplest way to do it:
>
> Write a class which extends the ResizableEditPolicyEx, like this:
>
>
> public class MoveParentWithChildEditPolicy extends ResizableEditPolicyEx {
>
> /**
> * checks that the EditPart hosting this policy cannot move its
> figure outside the parent's bounds
> * @generated NOT
> */
> protected Command getMoveCommand(ChangeBoundsRequest request) {
>
>
> EditPart parentEditPart = getHost().getParent();
> return parentEditPart.getCommand(request);
> }
>
>
>
> /**
> * * Show parent move feedback instead of this figure move
> feedback
> * * @generated NOT
> */
> protected void showChangeBoundsFeedback(ChangeBoundsRequest
> request) {
> IFigure feedback = getDragSourceFeedbackFigure();
> PrecisionRectangle rect = new
> PrecisionRectangle(getInitialFeedbackBounds().getCopy());
> getHostFigure().translateToAbsolute(rect);
>
> rect.translate(request.getMoveDelta());
> IFigure f = getHostFigure().getParent();
> rect.setSize(f.getSize());
> Dimension min = f.getMinimumSize().getCopy();
> Dimension max = f.getMaximumSize().getCopy();
> IMapMode mmode = MapModeUtil.getMapMode(f);
> min.height = mmode.LPtoDP(min.height);
> min.width = mmode.LPtoDP(min.width);
> max.height = mmode.LPtoDP(max.height);
> max.width = mmode.LPtoDP(max.width);
> if (min.width>rect.width)
> rect.width = min.width;
> else if (max.width < rect.width)
> rect.width = max.width;
> if (min.height>rect.height)
> rect.height = min.height;
> else if (max.height < rect.height)
> rect.height = max.height;
>
> feedback.translateToRelative(rect);
> feedback.setBounds(rect);
> }
>
>
>
> Then, in the child EditPart, install this edit policy :
>
>
> protected void createDefaultEditPolicies() {
> // .............. initial code here ................
> //add this:
> installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
> new MoveParentWithChildEditPolicy());
> }
>
>
>
> Hope it helps,
>
> Cheers, Emil.
>
Re: Force a figure to be sticked to another one (with drag and drop enabled) [message #553623 is a reply to message #553616] Wed, 18 August 2010 08:36 Go to previous messageGo to next message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Install the edit part for the child AND for the compartment. The child will send the move request to the compartement, the compartment will send it to the main figure which will move.

I think you don't even need the method I wrote
protected void showChangeBoundsFeedback(ChangeBoundsRequest request)


you could just delegate that also to the parent.

Cheers,
Emil.
Re: Force a figure to be sticked to another one (with drag and drop enabled) [message #553666 is a reply to message #553623] Wed, 18 August 2010 12:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: templth.yahoo.fr

Hello Emil,

That's strange but it doesn't seem to be called...

Here is what I done:

- Figure 1 (the one I try to drag and drop):

protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();

installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
new ServerItemSemanticEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
new MoveParentWithChildEditPolicy());
}

- Figure 2 (the compartment):

protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
new Figure2CompartmentItemSemanticEditPolicy());
installEditPolicy(EditPolicyRoles.CREATION_ROLE,
new CreationEditPolicy());
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,
new DragDropEditPolicy());
installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,
new Figure2CompartmentCanonicalEditPolicy());
installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE,
new MoveParentWithChildEditPolicy());
}

Is it correct?
Thanks very much in advance.
Thierry

> Install the edit part for the child AND for the compartment. The child
> will send the move request to the compartement, the compartment will
> send it to the main figure which will move.
> I think you don't even need the method I wrote
> protected void showChangeBoundsFeedback(ChangeBoundsRequest request)
>
>
> you could just delegate that also to the parent.
> Cheers, Emil.
Re: Force a figure to be sticked to another one (with drag and drop enabled) [message #553675 is a reply to message #553666] Wed, 18 August 2010 13:03 Go to previous message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Well,

I cannot help you more then that Smile
Do a little debugging to see if your getModeCommand() method is called or not. If it not called, take a look at the getCommand() method in the parnet edit part.

Good luck,

Emil.
Previous Topic:add an element that will be the same size as the editor one
Next Topic:Rounded / curved connection
Goto Forum:
  


Current Time: Fri Apr 19 09:12:01 GMT 2024

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

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

Back to the top