Skip to content

Commit

Permalink
Moved grouping logic to NodeLibraryController.
Browse files Browse the repository at this point in the history
  • Loading branch information
stebanos committed Sep 18, 2012
1 parent 04cc258 commit 73ba692
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/main/java/nodebox/client/NodeBoxDocument.java
Expand Up @@ -1533,21 +1533,11 @@ public void deleteSelection() {

public void groupIntoNetwork(nodebox.graphics.Point pt) {
startEdits("Group Into Network Node");
String renderedChild = getActiveNetwork().getRenderedChildName();
cut();
Node subnet = controller.createNode(activeNetworkPath, Node.ROOT.withName("subnet"));
String subnetPath = Node.path(activeNetworkPath, subnet.getName());
List<Node> nodes = controller.pasteNodes(subnetPath, nodeClipboard.network, nodeClipboard.nodes);
for (Node node : nodes) {
controller.setNodePosition(Node.path(subnetPath, node.getName()), node.getPosition().moved(-4, -2));
if (node.getName().equals(renderedChild)) {
controller.setRenderedChild(subnetPath, node.getName());
break;
}
}
Node subnet = controller.groupIntoNetwork(activeNetworkPath, networkView.getSelectedNodes());
controller.setNodePosition(Node.path(activeNetworkPath, subnet.getName()), pt);
controller.setRenderedChild(activeNetworkPath, subnet.getName());
stopEdits();

setActiveNode(subnet);
networkView.updateAll();
networkView.select(subnet);
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/nodebox/node/NodeLibraryController.java
Expand Up @@ -146,6 +146,26 @@ public List<Node> pasteNodes(String parentPath, Node nodesParent, Iterable<Node>
return ImmutableList.copyOf(Iterables.skip(newParent.getChildren(), parent.getChildren().size()));
}

public Node groupIntoNetwork(String parentPath, Iterable<Node> nodes) {
Node parent = getNode(parentPath);
String renderedChild = parent.getRenderedChildName();
Node newParent = parent;
for (Node node : nodes) {
newParent = newParent.withChildRemoved(node.getName());
}
Node subnet = Node.ROOT
.withName(newParent.uniqueName("subnet"))
.withChildrenAdded(parent, nodes);
for (Node node : subnet.getChildren()) {
subnet = subnet.withChildReplaced(node.getName(), node.withPosition(node.getPosition().moved(-4, -2)));
if (node.getName().equals(renderedChild))
subnet = subnet.withRenderedChildName(node.getName());
}
newParent = newParent.withChildAdded(subnet);
replaceNodeInPath(parentPath, newParent);
return getNode(Node.path(parentPath, subnet.getName()));
}

public void removeNode(String parentPath, String nodeName) {
Node newParent = getNode(parentPath).withChildRemoved(nodeName);
replaceNodeInPath(parentPath, newParent);
Expand Down

0 comments on commit 73ba692

Please sign in to comment.