callback.onNodeAvailable(closest);
return;
}
// Get the directory that contains the path.
final PathUtil dirPath = PathUtil.createExcludingLastN(path, 1);
// Request the node and its parents, starting from the closest node.
/*
* TODO: We should revisit deep linking in the file tree and possible only show
* the directory that is deep linked. Otherwise, we may have to load a lot of parent
* directories when deep linking to a very deep directory.
*/
GetDirectoryImpl getDirectoryAndPath = GetDirectoryImpl.make()
.setPath(dirPath.getPathString())
.setDepth(FrontendConstants.DEFAULT_FILE_TREE_DEPTH)
.setRootId(fileTreeModel.getLastAppliedTreeMutationRevision());
// Include the root path so we load parent directories leading up to the file.
//.setRootPath(closest.getNodePath().getPathString());
appContext.getFrontendApi().GET_DIRECTORY.send(
getDirectoryAndPath, new ApiCallback<GetDirectoryResponse>() {
@Override
public void onMessageReceived(GetDirectoryResponse response) {
DirInfo baseDir = response.getBaseDirectory();
if (baseDir == null) {
/*
* The folder was most probably deleted before the server received our request.
* We should receive a tango notification to update the client.
*/
return;
}
FileTreeNode incomingSubtree = FileTreeNode.transform(baseDir);
fileTreeModel.replaceNode(
new PathUtil(response.getPath()), incomingSubtree, response.getRootId());
// Check if the node now exists.
FileTreeNode child = fileTreeModel.getWorkspaceRoot().findChildNode(path);
if (child == null) {
callback.onNodeUnavailable();
} else {
callback.onNodeAvailable(child);
}
}
@Override
public void onFail(FailureReason reason) {
Log.error(getClass(), "Failed to retrieve directory path "
+ dirPath.getPathString());
// Update the callback.
callback.onError(reason);
}
});