01: package org.drools.eclipse.flow.common.editor.policy;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import org.drools.eclipse.flow.common.editor.core.command.CreateBendpointCommand;
20: import org.drools.eclipse.flow.common.editor.core.command.DeleteBendpointCommand;
21: import org.drools.eclipse.flow.common.editor.core.command.MoveBendpointCommand;
22: import org.eclipse.draw2d.geometry.Point;
23: import org.eclipse.gef.commands.Command;
24: import org.eclipse.gef.editpolicies.BendpointEditPolicy;
25: import org.eclipse.gef.requests.BendpointRequest;
26:
27: /**
28: * Policy for bendpoints of connections.
29: *
30: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
31: */
32: public class ConnectionBendpointEditPolicy extends BendpointEditPolicy {
33:
34: protected Command getCreateBendpointCommand(BendpointRequest request) {
35: Point point = request.getLocation();
36: getConnection().translateToRelative(point);
37:
38: CreateBendpointCommand command = new CreateBendpointCommand();
39: command.setLocation(point);
40: command.setConnection(getHost().getModel());
41: command.setIndex(request.getIndex());
42:
43: return command;
44: }
45:
46: protected Command getDeleteBendpointCommand(BendpointRequest request) {
47: DeleteBendpointCommand command = new DeleteBendpointCommand();
48: command.setConnectionModel(getHost().getModel());
49: command.setIndex(request.getIndex());
50: return command;
51: }
52:
53: protected Command getMoveBendpointCommand(BendpointRequest request) {
54: Point location = request.getLocation();
55: getConnection().translateToRelative(location);
56:
57: MoveBendpointCommand command = new MoveBendpointCommand();
58: command.setConnectionModel(getHost().getModel());
59: command.setIndex(request.getIndex());
60: command.setNewLocation(location);
61:
62: return command;
63:
64: }
65: }
|