List of usage examples for com.google.gwt.user.cellview.client TreeNode setChildOpen
TreeNode setChildOpen(int index, boolean open, boolean fireEvents);
From source file:com.dingziran.effective.client.Showcase.java
License:Apache License
/** * This is the entry point method.//w ww . j av a2 s . co 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); }// ww w .j a v a 2 s . co 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.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);/* w w w . ja va2s. c o m*/ 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.code.tree.client.UpdatableTreeModel.java
License:Apache License
private NodeChildToClose searchTreeNode(TreeNode parent, UpdatableTreeNode nodeToCheck) { int childCount = parent.getChildCount(); for (int idx = 0; idx < childCount; idx++) { boolean leaveOpen = parent.isChildOpen(idx); TreeNode node = parent.setChildOpen(idx, true, false); if (!leaveOpen) parent.setChildOpen(idx, false, false); if (node != null) { UpdatableTreeNode utn = (UpdatableTreeNode) node.getValue(); NodeChildToClose nctc = null; if (nodeToCheck.getParent() == utn) { nctc = new NodeChildToClose(); nctc.node = parent;/*from ww w.j a v a 2 s . co m*/ nctc.childIndex = idx; return nctc; } else { if (node.getChildCount() > 0) { nctc = searchTreeNode(node, nodeToCheck); if (nctc != null) return nctc; } } } } return null; }
From source file:com.google.gwt.sample.showcase.client.Showcase.java
License:Apache License
/** * This is the entry point method.//from www .j a va2 s . com */ 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.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); }//w w w . j a v a2 s . com } }
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 ww.j a v a 2 s .c om*/ } } }
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 {/*from w w w . ja va 2 s .c om*/ 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();// w ww. jav a 2 s . c om return; } else { if (node.isChildOpen(i)) { TreeNode n = node.setChildOpen(i, true); if (n != null) openNodeContainingResource(n, resource, handler); } } } }
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 . j a va 2s.com } } } // 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; }