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

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

Introduction

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

Prototype

Object getChildValue(int index);

Source Link

Document

Get the value associated with a child node.

Usage

From source file:com.dingziran.effective.client.Showcase.java

License:Apache License

/**
   * This is the entry point method.//ww  w . j av  a2s .  c  o m
   */
public void onModuleLoad() {
    factory = GWT.create(Factory.class);
    eventBus = new SimpleEventBus();
    factory.initialize(eventBus);
    // Inject global styles.
    injectThemeStyleSheet();
    images.css().ensureInjected();

    // Initialize the constants.
    ShowcaseConstants constants = GWT.create(ShowcaseConstants.class);

    // Create the application shell.
    final SingleSelectionModel<ContentWidget> selectionModel = new SingleSelectionModel<ContentWidget>();
    final MainMenuTreeViewModel treeModel = new MainMenuTreeViewModel(constants, selectionModel);
    Set<ContentWidget> contentWidgets = treeModel.getAllContentWidgets();
    shell = new ShowcaseShell(treeModel);
    RootLayoutPanel.get().add(shell);

    final CellTree mainMenu = shell.getMainMenu();
    /*
        // Prefetch examples when opening the Category tree nodes.
        final List<Category> prefetched = new ArrayList<Category>();
        mainMenu.addOpenHandler(new OpenHandler<TreeNode>() {
          public void onOpen(OpenEvent<TreeNode> event) {
            Object value = event.getTarget().getValue();
            if (!(value instanceof Category)) {
              return;
            }
            
            Category category = (Category) value;
            if (!prefetched.contains(category)) {
              prefetched.add(category);
              Prefetcher.prefetch(category.getSplitPoints());
            }
          }
        });
            
        // Always prefetch.
        Prefetcher.start();
    */
    // Change the history token when a main menu item is selected.
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            ContentWidget selected = selectionModel.getSelectedObject();
            if (selected != null) {
                History.newItem(getContentWidgetToken(selected), true);
            }
        }
    });

    // Setup a history handler to reselect the associate menu item.
    final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() {
        public void onValueChange(ValueChangeEvent<String> event) {
            // Get the content widget associated with the history token.
            ContentWidget contentWidget = treeModel.getContentWidgetForToken(event.getValue());
            if (contentWidget == null) {
                return;
            }

            // Expand the tree node associated with the content.
            Category category = treeModel.getCategoryForContentWidget(contentWidget);
            TreeNode node = mainMenu.getRootTreeNode();
            int childCount = node.getChildCount();
            for (int i = 0; i < childCount; i++) {
                if (node.getChildValue(i) == category) {
                    node.setChildOpen(i, true, true);
                    break;
                }
            }

            // Select the node in the tree.
            selectionModel.setSelected(contentWidget, true);

            // Display the content widget.
            displayContentWidget(contentWidget);
        }
    };
    History.addValueChangeHandler(historyHandler);

    // Show the initial example.
    if (History.getToken().length() > 0) {
        History.fireCurrentHistoryState();
    } else {
        // Use the first token available.
        TreeNode root = mainMenu.getRootTreeNode();
        TreeNode category = root.setChildOpen(0, true);
        ContentWidget content = (ContentWidget) category.getChildValue(0);
        selectionModel.setSelected(content, true);
    }

    // Generate a site map.
    createSiteMap(contentWidgets);
}

From source file:com.github.gwt.sample.showcase.client.Showcase.java

License:Apache License

private void bindHistory(final SingleSelectionModel<Widget> selectionModel,
        final LeftMenuTreeViewModel treeModel) {

    // Setup a history handler to reselect the associate menu item.
    final CellTree mainMenu = showCase.getMainMenu();

    // Change the history token when a main menu item is selected.
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            Widget selected = selectionModel.getSelectedObject();
            if (selected != null) {
                History.newItem(selected.getTitle(), true);
            }//from ww w  . j  av  a2s  . c o  m
        }
    });

    final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() {
        public void onValueChange(ValueChangeEvent<String> event) {
            // Get the content widget associated with the history token.
            Widget contentWidget = treeModel.getWidget(event.getValue());
            if (contentWidget == null) {
                return;
            }

            // Expand the tree node associated with the content.
            LeftMenuTreeViewModel.Category category = treeModel.getCategoryForWidget(contentWidget);
            TreeNode node = mainMenu.getRootTreeNode();
            int childCount = node.getChildCount();
            for (int i = 0; i < childCount; i++) {
                if (node.getChildValue(i) == category) {
                    node.setChildOpen(i, true, true);
                    break;
                }
            }

            // Select the node in the tree.
            selectionModel.setSelected(contentWidget, true);

            // Display the content widget.
            displayContentWidget(contentWidget);
        }

        /**
         * Set the content to the {@link com.google.gwt.user.client.ui.Widget}.
         *
         * @param content the {@link com.google.gwt.user.client.ui.Widget} to display
         */
        private void displayContentWidget(Widget content) {
            if (content == null) {
                return;
            }

            showCase.setContent(content);
            Window.setTitle("Showcase of Features: " + content.getTitle());
        }
    };
    History.addValueChangeHandler(historyHandler);
}

From source file:com.github.gwt.sample.showcase.client.Showcase.java

License:Apache License

private void showInitialExample(final SingleSelectionModel<Widget> selectionModel) {
    final CellTree mainMenu = showCase.getMainMenu();
    // Show the initial example.
    if (History.getToken().length() > 0) {
        History.fireCurrentHistoryState();
    } else {//from   ww  w  .j a v  a2 s . co  m

        // Use the first token available.
        TreeNode root = mainMenu.getRootTreeNode();
        TreeNode category = root.setChildOpen(0, true);
        Widget content = (Widget) category.getChildValue(0);
        selectionModel.setSelected(content, true);
    }
}

From source file:com.goodow.web.ui.client.nav.TagsUi.java

License:Apache License

private void openTreeNodeWhenSelected(final TreeNode parent, final String path) {
    logger.finest("openTreeNodeWhenSelected");
    for (int i = 0, len = parent.getChildCount(); i < len; i++) {
        com.goodow.web.mvp.shared.tree.TreeNodeProxy childNode = (com.goodow.web.mvp.shared.tree.TreeNodeProxy) parent
                .getChildValue(i);/*from w w w  .j  a  v a  2 s .  com*/
        String childId = childNode.getPath();
        if (path.startsWith(childId)) {
            TreeNode childOpen = parent.setChildOpen(i, true, true);
            if (childOpen != null && !path.equals(childId)) {
                openTreeNodeWhenSelected(childOpen, path);
            } else if (path.equals(childId)) {
                if (!selectionModel.isSelected(childNode)) {
                    selectionModel.setSelected(childNode, true);
                }
                continue;
            }
        } else {
            parent.setChildOpen(i, false, false);
        }
    }
}

From source file:com.google.gwt.sample.showcase.client.Showcase.java

License:Apache License

/**
 * This is the entry point method./* ww w .  j  a va 2s  . c  o  m*/
 */
public void onModuleLoad() {
    // Generate the source code and css for the examples
    GWT.create(GeneratorInfo.class);

    // Inject global styles.
    injectThemeStyleSheet();
    images.css().ensureInjected();

    // Initialize the constants.
    ShowcaseConstants constants = GWT.create(ShowcaseConstants.class);

    // Create the application shell.
    final SingleSelectionModel<ContentWidget> selectionModel = new SingleSelectionModel<ContentWidget>();
    final MainMenuTreeViewModel treeModel = new MainMenuTreeViewModel(constants, selectionModel);
    Set<ContentWidget> contentWidgets = treeModel.getAllContentWidgets();
    shell = new ShowcaseShell(treeModel);
    RootLayoutPanel.get().add(shell);

    // Prefetch examples when opening the Category tree nodes.
    final List<Category> prefetched = new ArrayList<Category>();
    final CellTree mainMenu = shell.getMainMenu();
    mainMenu.addOpenHandler(new OpenHandler<TreeNode>() {
        public void onOpen(OpenEvent<TreeNode> event) {
            Object value = event.getTarget().getValue();
            if (!(value instanceof Category)) {
                return;
            }

            Category category = (Category) value;
            if (!prefetched.contains(category)) {
                prefetched.add(category);
                Prefetcher.prefetch(category.getSplitPoints());
            }
        }
    });

    // Always prefetch.
    Prefetcher.start();

    // Change the history token when a main menu item is selected.
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            ContentWidget selected = selectionModel.getSelectedObject();
            if (selected != null) {
                History.newItem(getContentWidgetToken(selected), true);
            }
        }
    });

    // Setup a history handler to reselect the associate menu item.
    final ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>() {
        public void onValueChange(ValueChangeEvent<String> event) {
            // Get the content widget associated with the history token.
            ContentWidget contentWidget = treeModel.getContentWidgetForToken(event.getValue());
            if (contentWidget == null) {
                return;
            }

            // Expand the tree node associated with the content.
            Category category = treeModel.getCategoryForContentWidget(contentWidget);
            TreeNode node = mainMenu.getRootTreeNode();
            int childCount = node.getChildCount();
            for (int i = 0; i < childCount; i++) {
                if (node.getChildValue(i) == category) {
                    node.setChildOpen(i, true, true);
                    break;
                }
            }

            // Select the node in the tree.
            selectionModel.setSelected(contentWidget, true);

            // Display the content widget.
            displayContentWidget(contentWidget);
        }
    };
    History.addValueChangeHandler(historyHandler);

    // Show the initial example.
    if (History.getToken().length() > 0) {
        History.fireCurrentHistoryState();
    } else {
        // Use the first token available.
        TreeNode root = mainMenu.getRootTreeNode();
        TreeNode category = root.setChildOpen(0, true);
        ContentWidget content = (ContentWidget) category.getChildValue(0);
        selectionModel.setSelected(content, true);
    }

    // Generate a site map.
    createSiteMap(contentWidgets);
}

From source file:org.eclipse.emf.eef.runtime.ui.gwt.editor.widget.EEFTreeViewer.java

License:Open Source License

public void expand(List<?> path) {
    TreeNode node = getRootTreeNode();
    if (node != null) {
        LOOP: for (int i = 0, size = path.size(); i < size; ++i) {
            Object segment = path.get(i);
            for (int j = 0, count = node.getChildCount(); j < count; ++j) {
                Object childValue = node.getChildValue(j);
                if (childValue.equals(segment)) {
                    node = node.setChildOpen(j, true);
                    continue LOOP;
                }/*from w  w w .java2 s  . c  o m*/
            }
            break;
        }
    }
}

From source file:org.gss_project.gss.web.client.CellTreeViewUtils.java

License:Open Source License

private void refreshNodeContainingResource(TreeNode node, RestResource resource) {
    int count = node.getChildCount();
    for (int i = 0; i < count; i++) {
        if (node.getChildValue(i).equals(resource)) {
            if (node.getChildValue(i) instanceof RestResourceWrapper
                    && ((RestResourceWrapper) node.getChildValue(i)).getResource().getFolders().size() == 0)
                return;
            node.setChildOpen(i, false, true);
            node.setChildOpen(i, true, true);
            return;
        } else if (node.isChildOpen(i)) {
            TreeNode n = node.setChildOpen(i, true);
            if (n != null)
                refreshNodeContainingResource(n, resource);
        }/*from  w  w  w.  j a v a2s . c om*/
    }

}

From source file:org.gss_project.gss.web.client.CellTreeViewUtils.java

License:Open Source License

void refreshNodeContainingResource(TreeNode node, String uri) {
    int count = node.getChildCount();
    for (int i = 0; i < count; i++) {
        if (node.isChildOpen(i)) {
            if (node.getChildValue(i) instanceof RestResource
                    && ((RestResource) node.getChildValue(i)).getUri().equals(uri)) {
                if (node.getChildValue(i) instanceof RestResourceWrapper
                        && ((RestResourceWrapper) node.getChildValue(i)).getResource().getFolders().size() == 0)
                    return;
                node.setChildOpen(i, false, true);
                node.setChildOpen(i, true, true);
                return;
            } else {
                TreeNode n = node.setChildOpen(i, true);
                if (n != null)
                    refreshNodeContainingResource(n, uri);
            }/*from w  w  w  . j  a  va 2  s  .com*/
        }
    }
}

From source file:org.gss_project.gss.web.client.CellTreeViewUtils.java

License:Open Source License

private void openNodeContainingResource(TreeNode node, RestResource resource) {
    int count = node.getChildCount();
    for (int i = 0; i < count; i++) {

        if (node.getChildValue(i).equals(resource)) {
            if (node.getChildValue(i) instanceof RestResourceWrapper
                    && ((RestResourceWrapper) node.getChildValue(i)).getResource().getFolders().size() == 0)
                return;
            node.setChildOpen(i, true, true);
            return;
        } else {/*  w  w w .j a v a2s  .c o  m*/
            if (node.isChildOpen(i)) {
                TreeNode n = node.setChildOpen(i, true);
                if (n != null)
                    openNodeContainingResource(n, resource);
            }
        }

    }
}

From source file:org.gss_project.gss.web.client.CellTreeViewUtils.java

License:Open Source License

private void openNodeContainingResource(TreeNode node, RestResource resource, RefreshHandler handler) {
    int count = node.getChildCount();
    for (int i = 0; i < count; i++) {
        if (node.getChildValue(i).equals(resource)) {
            if (node.getChildValue(i) instanceof RestResourceWrapper
                    && ((RestResourceWrapper) node.getChildValue(i)).getResource().getFolders().size() == 0)
                return;
            //node.setChildOpen(i, false, true);
            node.setChildOpen(i, true, true);
            handler.onRefresh();/*from   w w  w  .  ja  va2s .  co m*/
            return;
        } else {
            if (node.isChildOpen(i)) {
                TreeNode n = node.setChildOpen(i, true);
                if (n != null)
                    openNodeContainingResource(n, resource, handler);
            }
        }

    }
}