Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » GEF ChangeConstraint Problem
GEF ChangeConstraint Problem [message #230488] Tue, 13 February 2007 00:13 Go to next message
Kathiravan  is currently offline Kathiravan Friend
Messages: 33
Registered: July 2009
Member
Hi ,

I am using GEF/Draw2d to create one of my custom plot view. I have a
data point which should be draggable inside the plot area. So i used
XYLayoutEditPolicy on the Parent of the data point which is a rectangle
with the XYLayout set on that.
I am not using the CreateCommand to create the data point. I have the
datapoints as the child of the plot area. I did create an object of the
data point on my own.
Now I can see the data point on the View, but it is not moving when i
drag that. I did implement the ChangeConstraintCommand but no use.

public class SetConstraintCommand extends
org.eclipse.gef.commands.Command {

private Rectangle oldBounds;

private Rectangle newBounds;

private ChangeBoundsRequest request;

private DataPoint part;

public SetConstraintCommand(DataPoint part, ChangeBoundsRequest
req,Rectangle newBounds) {

this.part = part;
this.request = req;
this.newBounds= newBounds;
setLabel("POINT_MOVE");
}

public boolean canExecute() {
System.out.println("Checking whether the ChangeConstraint can be
executed");
Object type = request.getType();
// make sure the Request is of a type we support:
return (RequestConstants.REQ_MOVE.equals(type)
|| RequestConstants.REQ_MOVE_CHILDREN.equals(type));
}

public void execute() {
oldBounds = new Rectangle(part.getLocation(),part.getSize());
redo();
}

public void redo() {
part.setSize(new Dimension(10,10));
part.setLocation(newBounds.getLocation());
}

public void setPoint(DataPoint part) {
this.part = part;
}

public void undo() {
part.setLocation(oldBounds.getLocation());
}

}

and on my PlotEditPart i added the

installEditPolicy(EditPolicy.LAYOUT_ROLE,new
DataPointXYLayoutEditPolicy());

and i used to create the command as follows..

protected Command createChangeConstraintCommand(ChangeBoundsRequest req,
EditPart part, Object constraint) {
System.out.println("createChangeConstraintCommand with Request");
return new SetConstraintCommand((BoundaryPoint) part.getModel(),
req,
(Rectangle) constraint);
}

But nothing happens when i click and drag the point. Any suggestions ?

Thanks in advance,
Kathir.
Re: GEF ChangeConstraint Problem [message #230553 is a reply to message #230488] Tue, 13 February 2007 08:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jakub.jurkiewicz.gmail.com

I cannot see what could be wrong, so could you post the code where you
create the data points on your own?

regards,
Jakub Jurkiewicz

kathir wrote:
> Hi ,
>
> I am using GEF/Draw2d to create one of my custom plot view. I have a
> data point which should be draggable inside the plot area. So i used
> XYLayoutEditPolicy on the Parent of the data point which is a rectangle
> with the XYLayout set on that.
> I am not using the CreateCommand to create the data point. I have the
> datapoints as the child of the plot area. I did create an object of the
> data point on my own.
> Now I can see the data point on the View, but it is not moving when i
> drag that. I did implement the ChangeConstraintCommand but no use.
>
> public class SetConstraintCommand extends
> org.eclipse.gef.commands.Command {
>
> private Rectangle oldBounds;
> private Rectangle newBounds;
> private ChangeBoundsRequest request;
>
> private DataPoint part;
> public SetConstraintCommand(DataPoint part, ChangeBoundsRequest
> req,Rectangle newBounds) {
> this.part = part;
> this.request = req;
> this.newBounds= newBounds;
> setLabel("POINT_MOVE");
> }
> public boolean canExecute() {
> System.out.println("Checking whether the ChangeConstraint can be
> executed");
> Object type = request.getType();
> // make sure the Request is of a type we support:
> return (RequestConstants.REQ_MOVE.equals(type)
> || RequestConstants.REQ_MOVE_CHILDREN.equals(type));
> }
>
> public void execute() {
> oldBounds = new Rectangle(part.getLocation(),part.getSize());
> redo();
> }
>
> public void redo() {
> part.setSize(new Dimension(10,10));
> part.setLocation(newBounds.getLocation());
> }
>
> public void setPoint(DataPoint part) {
> this.part = part;
> }
>
> public void undo() {
> part.setLocation(oldBounds.getLocation());
> }
>
> }
>
> and on my PlotEditPart i added the
>
> installEditPolicy(EditPolicy.LAYOUT_ROLE,new
> DataPointXYLayoutEditPolicy());
>
> and i used to create the command as follows..
>
> protected Command createChangeConstraintCommand(ChangeBoundsRequest req,
> EditPart part, Object constraint) {
> System.out.println("createChangeConstraintCommand with Request");
> return new SetConstraintCommand((BoundaryPoint) part.getModel(),
> req,
> (Rectangle) constraint);
> }
>
> But nothing happens when i click and drag the point. Any suggestions ?
>
> Thanks in advance,
> Kathir.
Re: GEF ChangeConstraint Problem [message #230586 is a reply to message #230553] Tue, 13 February 2007 17:56 Go to previous message
Kathiravan  is currently offline Kathiravan Friend
Messages: 33
Registered: July 2009
Member
Hi,
here is the createPartControl(Composite par) block in which i create a
single datapoint

createPartControl(Composite parent)
{
graphicalViewer = new GraphicalViewerImpl();

rootEditPart = new ScalableRootEditPart();

editPartFactory = new MyPlotEditPartFactory();

graphicalViewer.setRootEditPart(rootEditPart);

graphicalViewer.setEditPartFactory(editPartFactory);

graphicalViewer.createControl(parent);

plot = new MyPlot();

DataPoint point = new DataPoint(0,0); // I just created one data point
along the axis. The //
figure is a rectangle of 10,10 size.

plot.addPoint(point);

graphicalViewer.setContents(plot);

}

Now i can see the point in the view. But it is not draggable.

BR,
Kathir.

Jakub Jurkiewicz wrote:
> I cannot see what could be wrong, so could you post the code where you
> create the data points on your own?
>
> regards,
> Jakub Jurkiewicz
>
> kathir wrote:
>> Hi ,
>>
>> I am using GEF/Draw2d to create one of my custom plot view. I have a
>> data point which should be draggable inside the plot area. So i used
>> XYLayoutEditPolicy on the Parent of the data point which is a
>> rectangle with the XYLayout set on that.
>> I am not using the CreateCommand to create the data point. I have the
>> datapoints as the child of the plot area. I did create an object of
>> the data point on my own.
>> Now I can see the data point on the View, but it is not moving when i
>> drag that. I did implement the ChangeConstraintCommand but no use.
>>
>> public class SetConstraintCommand extends
>> org.eclipse.gef.commands.Command {
>>
>> private Rectangle oldBounds;
>> private Rectangle newBounds;
>> private ChangeBoundsRequest request;
>>
>> private DataPoint part;
>> public SetConstraintCommand(DataPoint part, ChangeBoundsRequest
>> req,Rectangle newBounds) {
>> this.part = part;
>> this.request = req;
>> this.newBounds= newBounds;
>> setLabel("POINT_MOVE");
>> }
>> public boolean canExecute() {
>> System.out.println("Checking whether the ChangeConstraint can
>> be executed");
>> Object type = request.getType();
>> // make sure the Request is of a type we support:
>> return (RequestConstants.REQ_MOVE.equals(type)
>> || RequestConstants.REQ_MOVE_CHILDREN.equals(type));
>> }
>>
>> public void execute() {
>> oldBounds = new Rectangle(part.getLocation(),part.getSize());
>> redo();
>> }
>>
>> public void redo() {
>> part.setSize(new Dimension(10,10));
>> part.setLocation(newBounds.getLocation());
>> }
>>
>> public void setPoint(DataPoint part) {
>> this.part = part;
>> }
>>
>> public void undo() {
>> part.setLocation(oldBounds.getLocation());
>> }
>>
>> }
>>
>> and on my PlotEditPart i added the
>>
>> installEditPolicy(EditPolicy.LAYOUT_ROLE,new
>> DataPointXYLayoutEditPolicy());
>>
>> and i used to create the command as follows..
>>
>> protected Command
>> createChangeConstraintCommand(ChangeBoundsRequest req,
>> EditPart part, Object constraint) {
>> System.out.println("createChangeConstraintCommand with Request");
>> return new SetConstraintCommand((BoundaryPoint)
>> part.getModel(), req,
>> (Rectangle) constraint);
>> }
>>
>> But nothing happens when i click and drag the point. Any suggestions ?
>>
>> Thanks in advance,
>> Kathir.
Previous Topic:Palette Name as shape label
Next Topic:GEF PrintAction
Goto Forum:
  


Current Time: Wed Apr 24 23:58:28 GMT 2024

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

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

Back to the top