1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.ericmignot.modeler.action; |
19 |
| |
20 |
| import java.util.List; |
21 |
| |
22 |
| import org.ericmignot.modeler.data.Link; |
23 |
| import org.ericmignot.modeler.data.Model; |
24 |
| import org.ericmignot.modeler.data.SimplePoint; |
25 |
| import org.ericmignot.modeler.util.action.ActionException; |
26 |
| import org.ericmignot.modeler.util.action.NotifyableAction; |
27 |
| |
28 |
| public class SimplePointDeleteAction extends NotifyableAction |
29 |
| { |
30 |
| private SimplePoint target; |
31 |
| private Model model; |
32 |
| private List referencingBos; |
33 |
| private Link startLink; |
34 |
| private Link rootLink; |
35 |
| private Link removedLink; |
36 |
| |
37 |
2
| public SimplePointDeleteAction(SimplePoint target, Model model)
|
38 |
| { |
39 |
2
| this.target = target;
|
40 |
2
| this.model = model;
|
41 |
2
| this.referencingBos = model.getReferencingBos(target);
|
42 |
2
| this.startLink = this.getRemovedLinkToPoint();
|
43 |
2
| this.rootLink = model.getRootLink(this.startLink);
|
44 |
2
| this.removedLink = this.getRemovedLinkFromPoint();
|
45 |
| } |
46 |
| |
47 |
0
| public Link getStartLink()
|
48 |
| { |
49 |
0
| return this.startLink;
|
50 |
| } |
51 |
0
| public Link getRemovedLink()
|
52 |
| { |
53 |
0
| return this.removedLink;
|
54 |
| } |
55 |
| |
56 |
2
| public Object execute(Object actionParameter) throws ActionException
|
57 |
| { |
58 |
2
| this.model.removeBusinessObject(this.removedLink);
|
59 |
2
| this.model.removeBusinessObjectQuiet(this.target);
|
60 |
2
| this.startLink.setLinkEnd(this.removedLink.getLinkEnd());
|
61 |
2
| this.rootLink.removePoint(this.target.getCenter());
|
62 |
2
| return this.target;
|
63 |
| } |
64 |
| |
65 |
1
| public Object cancel(Object actionParameter) throws ActionException
|
66 |
| { |
67 |
1
| this.model.addBusinessObject(this.target);
|
68 |
1
| this.model.addBusinessObject(this.removedLink);
|
69 |
1
| this.startLink.setLinkEnd(this.target);
|
70 |
1
| this.rootLink.addPoint(this.target.getCenter());
|
71 |
1
| return this.target;
|
72 |
| } |
73 |
| |
74 |
2
| protected Link getRemovedLinkToPoint()
|
75 |
| { |
76 |
2
| for (int i=0; i<this.referencingBos.size(); i++)
|
77 |
| { |
78 |
2
| if (this.referencingBos.get(i) instanceof Link)
|
79 |
| { |
80 |
2
| Link link = (Link) this.referencingBos.get(i);
|
81 |
2
| if (link.getLinkEnd() == this.target)
|
82 |
| { |
83 |
2
| return link;
|
84 |
| } |
85 |
| } |
86 |
| } |
87 |
0
| return null;
|
88 |
| } |
89 |
2
| protected Link getRemovedLinkFromPoint()
|
90 |
| { |
91 |
4
| for (int i=0; i<this.referencingBos.size(); i++)
|
92 |
| { |
93 |
4
| if (this.referencingBos.get(i) instanceof Link)
|
94 |
| { |
95 |
4
| Link link = (Link) this.referencingBos.get(i);
|
96 |
4
| if (link.getLinkStart() == this.target)
|
97 |
| { |
98 |
2
| return link;
|
99 |
| } |
100 |
| } |
101 |
| } |
102 |
0
| return null;
|
103 |
| } |
104 |
| } |