01: package net.refractions.udig.printing.ui.internal.editor.commands;
02:
03: import java.util.Iterator;
04:
05: import net.refractions.udig.printing.model.Box;
06: import net.refractions.udig.printing.model.Connection;
07: import net.refractions.udig.printing.model.ModelFactory;
08: import net.refractions.udig.printing.ui.internal.Messages;
09:
10: import org.eclipse.gef.commands.Command;
11:
12: public class ConnectionCreateCommand extends Command {
13:
14: private Box source;
15: private Box target;
16: private Connection connection;
17:
18: public ConnectionCreateCommand(Box source) {
19: super ();
20: if (source == null) {
21: throw new IllegalArgumentException(
22: Messages.ConnectionCreateCommand_error_sourceNull);
23: }
24: this .source = source;
25: }
26:
27: public boolean canExecute() {
28: if (source.equals(target)) {
29: return false;
30: }
31: Iterator iter = source.getSourceConnections().iterator();
32: while (iter.hasNext()) {
33: Connection connection = (Connection) iter.next();
34:
35: if (connection.getTarget().equals(target)) {
36: return false;
37: }
38: }
39: return true;
40: }
41:
42: public void execute() {
43: connection = ModelFactory.eINSTANCE.createConnection();
44: connection.setSource(source);
45: connection.setTarget(target);
46: }
47:
48: public void redo() {
49: connection.reconnect();
50: }
51:
52: public void setTarget(Box target) {
53: if (target == null) {
54: throw new IllegalArgumentException(
55: Messages.ConnectionCreateCommand_error_targetNull);
56: }
57: this .target = target;
58: }
59:
60: public void undo() {
61: connection.disconnect();
62: }
63: }
|