Merge branch 'master' of github.com:systemed/potlatch2
[potlatch2.git] / net / systemeD / halcyon / connection / actions / MergeNodesAction.as
1 package net.systemeD.halcyon.connection.actions
2 {
3         import net.systemeD.halcyon.connection.*;
4
5
6         public class MergeNodesAction extends CompositeUndoableAction {
7         // Node2's tags are merged into node1, then node2 is deleted.       
8         private var node1:Node;
9         private var node2:Node;
10                 // ** FIXME: not at all elegant having these stuffed in static variables; we should probably use events instead
11         static public var lastTagsMerged:Boolean;
12                 static public var lastRelationsMerged:Boolean;
13     
14         public function MergeNodesAction(destnode:Node, sourcenode:Node) {
15             super("Merge nodes "+destnode.id+" "+sourcenode.id);
16             this.node1 = destnode;
17             this.node2 = sourcenode;
18             lastTagsMerged=false;
19             lastRelationsMerged=false;
20         }
21         
22         public override function doAction():uint {
23
24             super.clearActions();
25             node1.suspend();
26
27             lastTagsMerged=node1.mergeTags(node2,push);
28             node2.replaceWith(node1, push);
29             node2.remove(push);
30
31             super.doAction();
32             node1.resume();
33             
34             return SUCCESS;
35         }
36
37         public override function undoAction():uint {
38             node1.suspend();
39             super.undoAction();
40             node1.resume();
41             
42             return SUCCESS;
43         }
44         
45         public function mergeRelations():void {
46             for each (var r:Relation in node2.parentRelations) {
47                 // ** needs to copy roles as well
48                 if (r.findEntityMemberIndex(node1)==-1) {
49                     r.appendMember(new RelationMember(node1, ''), push);
50                     lastRelationsMerged=true;
51                 }
52             }
53         }
54     }
55
56 }