Xcos: fix SuperBlock children ownership 68/18968/2
Clément DAVID [Thu, 26 Jan 2017 13:50:02 +0000 (14:50 +0100)]
The children should be referenced on move to avoid future deletion on
double-click. The PARENT_BLOCK property should also be updated ; on
deletion the unlink will thus not be performed on the temporary block.

Change-Id: I9406a29fa31bd095dcd67150f94c54c8733389e1

scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/BasicBlock.java

index 5db1015..7c4751c 100644 (file)
@@ -350,9 +350,15 @@ public class BasicBlock extends XcosCell implements Serializable {
         controller.getObjectProperty(modifiedBlock.getUID(), modifiedBlock.getKind(), ObjectProperties.DIAGRAM_CONTEXT, vStr);
         controller.setObjectProperty(getUID(), getKind(), ObjectProperties.DIAGRAM_CONTEXT, vStr);
 
+        // move the children to the parent
         VectorOfScicosID localChildren = new VectorOfScicosID();
-
         controller.getObjectProperty(modifiedBlock.getUID(), modifiedBlock.getKind(), ObjectProperties.CHILDREN, localChildren);
+        final int size = localChildren.size();
+        for (int i = 0; i < size; i++) {
+            long child = localChildren.get(i);
+            controller.referenceObject(child);
+            controller.setObjectProperty(child, controller.getKind(child), ObjectProperties.PARENT_BLOCK, getUID());
+        }
         controller.setObjectProperty(getUID(), getKind(), ObjectProperties.CHILDREN, localChildren);
 
         /*