Hi,

I have a large, structured tree of items on the server. I would like to allow users to add new items to it.

The example AsyncTreeGridExample suits perfectly. To this working example I have added following context menu function (stolen from ContextMenuTreeExample):
Code:
Menu contextMenu = new Menu();
MenuItem menuItemAddFile = new MenuItem();
menuItemAddFile.setText("Add file");
menuItemAddFile.setIcon(ExampleImages.INSTANCE.add());
menuItemAddFile.addSelectionHandler(new SelectionHandler<Item>() {
    @Override
    public void onSelection(SelectionEvent<Item> event) {
        FileModel sel = tree.getSelectionModel().getSelectedItem();
        if (sel != null) {
            String filename = "NewFile_" + DateTimeFormat.getFormat("yyyyMMdd-HHmmss").format(new Date()) + ".txt";
            FileModel child = new FileModel(filename, sel.getPath() + filename);
            child.setId(filename);
            store.add(sel, child);
            tree.setExpanded(sel, true);
        }
    }
});
contextMenu.add(menuItemAddFile);
tree.setContextMenu(contextMenu);
However adding new items works only to Folders and only if they are expanded.
  • If the folder is not expanded: How do I load its content from server before I add a new file to it?
  • Please help me get the combination of two working examples to work together.

M.