01: package org.drools.eclipse.flow.common.editor.core.command;
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.ElementConnection;
20: import org.drools.eclipse.flow.common.editor.core.ElementWrapper;
21: import org.drools.eclipse.flow.common.editor.core.ProcessWrapper;
22: import org.eclipse.gef.commands.Command;
23:
24: /**
25: * A command for splitting a connection.
26: *
27: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
28: */
29: public class SplitConnectionCommand extends Command {
30:
31: private ProcessWrapper parent;
32: private ElementWrapper oldSource;
33: private ElementWrapper oldTarget;
34: private ElementConnection oldConnection;
35: private ElementConnection secondConnection;
36: private ElementWrapper newElement;
37:
38: public void setNewSecondConnection(ElementConnection connection) {
39: if (connection == null) {
40: throw new IllegalArgumentException(
41: "new second connection cannot be null");
42: }
43: this .secondConnection = connection;
44: }
45:
46: public void execute() {
47: if (secondConnection == null) {
48: throw new IllegalStateException(
49: "new second connection is still null");
50: }
51: oldConnection.disconnect();
52: parent.addElement(newElement);
53: newElement.setParent(parent);
54: oldConnection.connect(oldSource, newElement);
55: secondConnection.connect(newElement, oldTarget);
56: }
57:
58: public void setParent(ProcessWrapper process) {
59: if (process == null) {
60: throw new IllegalArgumentException("process is null");
61: }
62: parent = process;
63: }
64:
65: public void setElementConnection(ElementConnection connection) {
66: if (connection == null) {
67: throw new IllegalArgumentException(
68: "Element connection is null");
69: }
70: this .oldConnection = connection;
71: oldSource = connection.getSource();
72: oldTarget = connection.getTarget();
73: }
74:
75: public void setNewElement(ElementWrapper newElement) {
76: if (newElement == null) {
77: throw new IllegalArgumentException("NewElement is null");
78: }
79: this .newElement = newElement;
80:
81: }
82:
83: public void undo() {
84: oldConnection.disconnect();
85: secondConnection.disconnect();
86: parent.removeElement(newElement);
87: newElement.setParent(null);
88: oldConnection.connect(oldSource, oldTarget);
89: }
90:
91: }
|