GWT CellTree滚动到任意节点 [英] GWT CellTree scroll to arbitrary node

查看:56
本文介绍了GWT CellTree滚动到任意节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写某种对象浏览器,用文件夹组织。当用户选择列表中的某个文件夹时,我必须在树中展开适当的节点。
我在树中实现了树扩展,元素选择,但BUT扩展可能发生在超出可见区域的树的一部分(CellTree在ScrollPane中)。
所以,我确实有一个 TreeNode 的实例 - 如何以编程方式滚动以使其可见?

解决方案

目前的API无法实现,但您可以尝试,但我没有测试过,但应该是easy:


  1. 对于树中的每个对象渲染和不可见标记,标识这个对象,就像< input请确保您有一个 SelectionModel
  2. 当你设置你的NodeInfo等。
  3. 当你知道你想要滚动到的对象时,调用 yourSelectionModel.setSelected(object,true); 。这应该展开树并显示您选择的对象。

  4. 在此阶段,您要做的是:




 元素cellTreeElement = yourCellTree.getElement(); 
NodeList< Element> objectIds = cellTreeElement.getElementsByTagName(input);
for(int i = 0; i< elementsByTagName.getLength(); i ++)
{
Element e = objectIds .getItem(i);
if(e.getId()。equals(yourObjectId){
e.scrollIntoView();
}
}
pre>

很确定这应该工作得很好。


i'm coding some kind of objects browser, organized with folders. When user seslects some folder in the list i have to expand an appropriate node in a tree. I've implemented tree expand, element selection in tree, BUT expand might happen at a part of tree that is out of visible area (CellTree is on a ScrollPane). So, i do have an instace of TreeNode - how can i programmatically scroll to make it visible?

解决方案

It's not possible with the current API, but what you can try, and I haven't tested this, but should be easy:

  1. For each object in your tree render and invisible tag, identifying this object, like an <input type="hidden" id="yourObjectId"/>
  2. Make sure you have a SelectionModel when setting up your NodeInfo etc.
  3. When you know what object you want to scroll to, call yourSelectionModel.setSelected(object,true);. That should expand the tree and display your selected object.
  4. At this stage what you want to do is:

Element cellTreeElement = yourCellTree.getElement();
NodeList<Element> objectIds = cellTreeElement.getElementsByTagName("input");
for ( int i=0;i<elementsByTagName.getLength();i++ )
{
   Element e = objectIds .getItem( i );
   if (e.getId().equals( yourObjectId ) {
     e.scrollIntoView();
   }
}

Pretty sure this should work just fine.

这篇关于GWT CellTree滚动到任意节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆