|
|
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 |
Eclipse User |
|
|
|
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 |
emil salageanu 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 |
Eclipse User |
|
|
|
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 #553666 is a reply to message #553623] |
Wed, 18 August 2010 12:23 |
Eclipse User |
|
|
|
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02258 seconds