public static void delete(JoeTree tree, OutlineLayoutManager layout, boolean deleteMode) {
		Node youngestNode = tree.getYoungestInSelection();
		
		if (youngestNode == null) {
			return;
		}
		
		Node parent = youngestNode.getParent();
		CompoundUndoableReplace undoable = new CompoundUndoableReplace(parent, deleteMode);
		
		int startDeleting = 0;
		if (tree.isWholeDocumentSelected()) {
			// Abort if the doc is empty.
			if (tree.isDocumentEmpty()) {
				return;
			}
			
			// Swap in a new node for the first node since a doc always has at least one child of root.
			Node newNode = new NodeImpl(tree,"");
			newNode.setDepth(0);
			undoable.addPrimitive(new PrimitiveUndoableReplace(parent, youngestNode, newNode));
			
			startDeleting++;
		}
		
		// Iterate over the remaining selected nodes deleting each one
		JoeNodeList nodeList = tree.getSelectedNodes();
		int deleteCount = 0;
		for (int i = startDeleting, limit = nodeList.size(); i < limit; i++) {
			Node node = nodeList.get(i);
			
			// Abort if node is not editable
			if (!node.isEditable()) {
				continue;
			}
			
			undoable.addPrimitive(new PrimitiveUndoableReplace(parent, node, null));
			deleteCount++;
		}
		
		if (!undoable.isEmpty()) {
			if (deleteCount == 1) {
				undoable.setName("Delete Node");
			} else {
				undoable.setName(new StringBuffer().append("Delete ").append(deleteCount).append(" Nodes").toString());
			}
			tree.getDocument().getUndoQueue().add(undoable);
			undoable.redo();
		}
		
		return;
	}