01: package org.drools.eclipse.editors.rete.commands;
02:
03: import org.drools.reteoo.BaseVertex;
04: import org.eclipse.draw2d.geometry.Rectangle;
05:
06: import org.eclipse.gef.RequestConstants;
07: import org.eclipse.gef.commands.Command;
08: import org.eclipse.gef.requests.ChangeBoundsRequest;
09:
10: /**
11: * A command to move a vertex.
12: *
13: */
14: public class NodeSetConstraintCommand extends Command {
15:
16: /** Stores the new size and location. */
17: private final Rectangle newBounds;
18:
19: /** Stores the old size and location. */
20: private Rectangle oldBounds;
21:
22: /** A request to move/resize an edit part. */
23: private final ChangeBoundsRequest request;
24:
25: /** BaseVertex to manipulate. */
26: private final BaseVertex vertex;
27:
28: /**
29: * Create a command that can resize and/or move a vertex.
30: *
31: * @param vertex the vertex to manipulate
32: * @param req the move request
33: * @param newBounds the new location. size is ignored
34: * @throws IllegalArgumentException if any of the parameters is null
35: */
36: public NodeSetConstraintCommand(BaseVertex vertex,
37: ChangeBoundsRequest req, Rectangle newBounds) {
38: if (vertex == null || req == null || newBounds == null) {
39: throw new IllegalArgumentException();
40: }
41: this .vertex = vertex;
42: this .request = req;
43: this .newBounds = newBounds.getCopy();
44: }
45:
46: /* (non-Javadoc)
47: * @see org.eclipse.gef.commands.Command#canExecute()
48: */
49: public boolean canExecute() {
50: Object type = request.getType();
51: return (RequestConstants.REQ_MOVE.equals(type) || RequestConstants.REQ_MOVE_CHILDREN
52: .equals(type));
53: }
54:
55: /* (non-Javadoc)
56: * @see org.eclipse.gef.commands.Command#execute()
57: */
58: public void execute() {
59: oldBounds = new Rectangle(vertex.getLocation(), vertex
60: .getSize());
61: redo();
62: }
63:
64: /* (non-Javadoc)
65: * @see org.eclipse.gef.commands.Command#redo()
66: */
67: public void redo() {
68: vertex.setSize(newBounds.getSize());
69: vertex.setLocation(newBounds.getLocation());
70: }
71:
72: /* (non-Javadoc)
73: * @see org.eclipse.gef.commands.Command#undo()
74: */
75: public void undo() {
76: vertex.setSize(oldBounds.getSize());
77: vertex.setLocation(oldBounds.getLocation());
78: }
79: }
|