Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Make Figure resizable but not repositionable
Make Figure resizable but not repositionable [message #249027] Wed, 20 May 2009 17:36 Go to next message
Thomas Porcham is currently offline Thomas PorchamFriend
Messages: 14
Registered: July 2009
Junior Member
Hello,

I'm quite new to gef and draw2d.
I'm implementing a simple Form editor.

The figures use a XYLayout and the corresponding EditPolicy inherits from
XYLayoutEditPolicy.
All figures can be resized and their position can be changed. Works just
fine.

For some figures I would like to turn off the possibility to change the
position.
Is their a simple way to do this?

What I tried:
I can prevent changes to the x and y coordinates in the model, but the
figures can still be dragged around. After you release the mouse button
they flip back to their original position. Not an elegant solution :(

TIA,

Thomas
Re: Make Figure resizable but not repositionable [message #249032 is a reply to message #249027] Wed, 20 May 2009 20:04 Go to previous messageGo to next message
Ben Vitale is currently offline Ben VitaleFriend
Messages: 247
Registered: July 2009
Senior Member
One way to do it would be to override createChildEditPolicy(EditPart) in
your XYLayoutEditPolicy.

For the appropriate parts, return a subclass of ResizableEditPolicy
that overrides getMoveCommand(ChangeBoundsRequest) and returns
UnexecutableCommand.INSTANCE.

I haven't tried it but hope that helps.

Regards
Ben

Thomas Porcham wrote:
> Hello,
>
> I'm quite new to gef and draw2d.
> I'm implementing a simple Form editor.
>
> The figures use a XYLayout and the corresponding EditPolicy inherits
> from XYLayoutEditPolicy.
> All figures can be resized and their position can be changed. Works just
> fine.
>
> For some figures I would like to turn off the possibility to change the
> position.
> Is their a simple way to do this?
> What I tried:
> I can prevent changes to the x and y coordinates in the model, but the
> figures can still be dragged around. After you release the mouse button
> they flip back to their original position. Not an elegant solution :(
>
> TIA,
>
> Thomas
>
>
Re: Make Figure resizable but not repositionable [message #249034 is a reply to message #249032] Thu, 21 May 2009 17:37 Go to previous message
Thomas Porcham is currently offline Thomas PorchamFriend
Messages: 14
Registered: July 2009
Junior Member
Ben, thanks for your quick reply!
I tried your approach and it works. However, it still shows the "move and
flip back" behavior.

There is a method setDragAllowed(boolean draggable) in ResizableEditPolicy.
I used this method to turn dragging off.

public class SizeEditPolicy extends XYLayoutEditPolicy {

@Override
protected Command createChangeConstraintCommand(EditPart child,
Object constraint) {
ChangeSizePositionCommand command = new ChangeSizePositionCommand();
command.setModel(child.getModel());
command.setConstraint((Rectangle) constraint);
return command;
}

@Override
protected Command getCreateCommand(CreateRequest request) {
// TODO Auto-generated method stub
return null;
}

@Override
protected EditPolicy createChildEditPolicy(EditPart child) {
ResizableEditPolicy resizablePol = new ResizableEditPolicy();
resizablePol.setDragAllowed(false); //disable position changes
return resizablePol;
}
}

Thanks,

Thomas
Previous Topic:[Announce] GEF 3.5.0 I200905121850 is available
Next Topic:Display editparts on a ScrollingGraphicalViewer
Goto Forum:
  


Current Time: Fri Apr 19 22:38:46 GMT 2024

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

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

Back to the top