Example usage for com.google.gwt.user.cellview.client TreeNode isDestroyed

List of usage examples for com.google.gwt.user.cellview.client TreeNode isDestroyed

Introduction

In this page you can find the example usage for com.google.gwt.user.cellview.client TreeNode isDestroyed.

Prototype

boolean isDestroyed();

Source Link

Document

Check whether or not the current node is destroyed.

Usage

From source file:org.rstudio.studio.client.workbench.views.connections.ui.ObjectBrowser.java

License:Open Source License

public void update(Connection connection, String hint) {
    final Set<DatabaseObject> expandedNodes = new HashSet<DatabaseObject>();

    // if this update is for the currently visible connection in the model,
    // cache the set of expanded nodes for replay
    if (objects_ != null && connection == connection_) {
        TreeNode rootNode = objects_.getRootTreeNode();
        if (!objects_.getRootTreeNode().isDestroyed()) {
            for (int i = 0; i < rootNode.getChildCount(); i++) {
                if (rootNode.isChildOpen(i)) {
                    DatabaseObject node = (DatabaseObject) rootNode.getChildValue(i);
                    expandedNodes.add(node);
                }/*w w  w  .ja  va 2s  .c  om*/
            }
        }
    }

    // create tables model and widget
    objectsModel_ = new ObjectBrowserModel();

    // capture scroll position
    final int scrollPosition = scrollPanel_.getVerticalScrollPosition();

    // update the table then restore expanded nodes
    objectsModel_.update(connection, // connection 
            expandedNodes, new Command() { // table update completed, expand nodes
                @Override
                public void execute() {
                    TreeNode rootNode = objects_.getRootTreeNode();
                    if (!rootNode.isDestroyed()) {
                        for (int i = 0; i < rootNode.getChildCount(); i++) {
                            final DatabaseObject nodeVal = (DatabaseObject) (rootNode.getChildValue(i));
                            for (DatabaseObject expanded : expandedNodes) {
                                if (expanded.isEqualTo(nodeVal))
                                    rootNode.setChildOpen(i, true, false);
                            }
                        }
                    }
                }
            }, new Command() { // node expansion completed, restore scroll position
                @Override
                public void execute() {
                    // delay 100ms to allow expand animation to complete
                    new Timer() {

                        @Override
                        public void run() {
                            scrollPanel_.setVerticalScrollPosition(scrollPosition);
                        }

                    }.schedule(100);

                }
            });

    // create new widget
    objects_ = new CellTree(objectsModel_, null, RES, MESSAGES);

    // create the top level list of objects
    objects_.setDefaultNodeSize(Integer.MAX_VALUE);
    objects_.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
    objects_.setWidth("100%");

    // wrap in vertical panel to get correct scrollbar behavior
    VerticalPanel verticalWrapper = new VerticalPanel();
    verticalWrapper.setWidth("100%");
    verticalWrapper.add(objects_);

    scrollPanel_.setWidget(verticalWrapper);

    // cache connection
    connection_ = connection;
}