Search in sources :

Example 1 with PostLoadEvent

use of org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent in project che by eclipse.

the class TreeResourceRevealer method expand.

protected void expand(final ResourceNode parent, final Path segment, final boolean select, final AsyncCallback<ResourceNode> callback) {
    if (parent.getData().getLocation().equals(segment)) {
        if (select) {
            if (toSelect == null) {
                toSelect = new Node[] { parent };
            } else {
                final int index = toSelect.length;
                toSelect = copyOf(toSelect, index + 1);
                toSelect[index] = parent;
            }
            selectTask.delay(200);
        }
        callback.onSuccess(parent);
        return;
    }
    final HandlerRegistration[] handler = new HandlerRegistration[1];
    handler[0] = tree.getNodeLoader().addPostLoadHandler(new PostLoadHandler() {

        @Override
        public void onPostLoad(PostLoadEvent event) {
            if (!event.getRequestedNode().equals(parent)) {
                return;
            }
            if (handler[0] != null) {
                handler[0].removeHandler();
            }
            final List<Node> children = tree.getNodeStorage().getChildren(event.getRequestedNode());
            for (Node child : children) {
                if (child instanceof ResourceNode && ((ResourceNode) child).getData().getLocation().isPrefixOf(segment)) {
                    expand((ResourceNode) child, segment, select, callback);
                    return;
                }
            }
            callback.onFailure(new IllegalStateException("Not found"));
        }
    });
    tree.getNodeLoader().loadChildren(parent);
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) PostLoadEvent(org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) PostLoadHandler(org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent.PostLoadHandler) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Aggregations

HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 Node (org.eclipse.che.ide.api.data.tree.Node)1 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)1 PostLoadEvent (org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent)1 PostLoadHandler (org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent.PostLoadHandler)1