Hi!
I have a databound treeGrid (parent type) where it is possible to drag and drop nodes (in the same folder or into different folders). Before the drop become effective, I need to do some server-side checks. I want the move to be done only if the check is OK. So I implemented a dropHandler but it does not work. Tree.move(TreeNode, TreeNode, Integer) method seem to work only in different folders and to ignore the move index...
Can anyone give me some help?
My env :
SmartGWT 5.1p-20171219
GWT 2.7
Firefox 38.2.1 ESR
I have a databound treeGrid (parent type) where it is possible to drag and drop nodes (in the same folder or into different folders). Before the drop become effective, I need to do some server-side checks. I want the move to be done only if the check is OK. So I implemented a dropHandler but it does not work. Tree.move(TreeNode, TreeNode, Integer) method seem to work only in different folders and to ignore the move index...
Can anyone give me some help?
Code:
final ResultTree tree = new ResultTree(); tree.setModelType(TreeModelType.PARENT); [...] this.treeGrid.setDataProperties(tree); this.treeGrid.setDataSource(dataSource); this.treeGrid.setAutoFetchData(true); this.treeGrid.setSaveLocally(false); this.treeGrid.setCanReorderRecords(true); this.treeGrid.setDragDataAction(DragDataAction.MOVE); this.treeGrid.setCanAcceptDroppedRecords(true); [...] this.treeGrid.addFolderDropHandler(new FolderDropHandler() { @Override public void onFolderDrop(final FolderDropEvent event) { if (event.getNodes() != null && event.getNodes().length > 0) { final TreeNode movedNode = event.getNodes()[0]; final String sourceParentId = movedNode.getAttribute("parentId"); final Record targetParentNode = event.getFolder(); final String targetParentId = targetParentNode.getAttribute("id"); final Integer moveIndex = event.getIndex(); RestRequest.doGet(myPath, myResource + movedNode.getAttribute("id") + "/in/" + targetParentId + "/at/" + moveIndex, new RequestCallback() { @Override public void onError(final Request request, final Throwable exception) { SC.warn("Error while performing request to move an item in tree."); } @Override public void onResponseReceived(final Request request, final Response response) { if (response.getStatusCode() != Response.SC_OK) { final String httpResponseText = response.getText(); final JSONValue body = JSONParser.parseStrict(httpResponseText); final JSONObject resp = body.isObject().get("response").isObject(); final String errorMessage = resp.get("errors").isString().stringValue(); SC.warn(errorMessage); } else { this.treeGrid.getTree().move(movedNode, (TreeNode) targetParentNode, moveIndex); } } }); event.cancel(); } } });
My env :
SmartGWT 5.1p-20171219
GWT 2.7
Firefox 38.2.1 ESR
Comment