}
CellID cellID = new CellID(cellIDInt);
// Fetch the client-side Cell cache and find the Cell with the
// dropped CellID
WonderlandSession session = LoginManager.getPrimary().getPrimarySession();
CellCache cache = ClientContext.getCellCache(session);
if (cache == null) {
LOGGER.warning("Unable to find Cell cache for session " + session);
return;
}
Cell draggedCell = cache.getCell(cellID);
if (draggedCell == null) {
LOGGER.warning("Unable to find dragged Cell with ID " + cellID);
return;
}
// Find out what Cell ID this was dropped over. This will form the
// new parent. If the Cell is dropped over the world root, then set
// the CellID to InvalidCellID
CellID parentCellID = CellID.getInvalidCellID();
SortedTreeNode treeNode = (SortedTreeNode) path.getLastPathComponent();
Object userObject = treeNode.getUserObject();
Cell newParent = null;
if (userObject instanceof Cell && !(userObject instanceof EnvironmentCell)) {
parentCellID = ((Cell) userObject).getCellID();
newParent = (Cell) userObject;
if (draggedCell.equals(newParent) == true) {
// User dropped cell on itself, return !
return;
}
}
// Find the world transform of the new parent. If there is no new
// parent (e.g. if the Cell is to be placed at the world root), then
// use a null transform.
CellTransform newParentWorld = new CellTransform(null, null);
if (newParent != null) {
newParentWorld = newParent.getWorldTransform();
}
CellTransform newChildLocal = ScenegraphUtils.computeChildTransform(
newParentWorld, draggedCell.getWorldTransform());
// Send a message to the server indicating the change in the
// parent. We need to send this over the cell edit connection,
// rather than the cell connection.
CellEditChannelConnection connection =
(CellEditChannelConnection) session.getConnection(
CellEditConnectionType.CLIENT_TYPE);
connection.send(new CellReparentMessage(cellID, parentCellID, newChildLocal));
// Turn off the selected node border and repaint the tree.
dragOverTreeNode = null;