2014-09-23 38 views
0

我有一个继承自CellTree的小部件。如果节点没有子元素,则可以打开此节点并显示"no data"标签。GWT-2.4.0,CellTree:从空节点删除“无数据”标签

enter image description here

我想看到不显示为空孩子的节点。

这就是我填充树的方式。我DictionaryTreeDataProvider类(相关部分):

public class DictionaryTreeDataProvider extends ListDataProvider<MValue> { 
    private final DictionariesServiceAsync service = GWT.create(DictionariesService.class); 

    ...  

    @Override 
    public void onRangeChanged(HasData<MValue> result) { 
     service.queryDictionaryValues(range, query, new AsyncCallback<SubsetResult<MValue>>() { 
      @Override 
      public void onFailure(Throwable t) { 
      } 

      @Override 
      public void onSuccess(SubsetResult<MValue> result) { 
       getList().clear(); 
       for (MValue value : result.items) { 
        getList().add(value); 
       } 
      } 
     }); 
    } 
} 

在服务器端,我让EJB调用填补SubsetResult。 我发现这个问题在GWT-2.5.0-rc2版本中修复(见https://groups.google.com/forum/#!topic/google-web-toolkit/d-rFUmyHTT4)。

似乎要做一个解决办法..


现在一切都OK,感谢@moutellou。 我照他建议:

... 
@Override 
public void onSuccess(SubsetResult<MValue> result) { 
    if (result.length == 0) { 
     updateRowCount(-1, true); 
     return; 
    } else { 
     for (MValue value : result.items) { 
      // some checks here 
      getList().add(value); 
     } 
    } 
} 
... 

enter image description here

+0

如何获取数据。你在使用AsyncDataProvider吗? – outellou 2014-09-23 15:40:15

+0

感谢您的评论。是的,我使用它,我已经更新了我的问题,谢谢。 – 2014-09-23 15:49:17

回答

1

这是我在我的DataProvider

//Fetch children 
    int size = children.size(); 
    if (size == 0) { 
    updateRowCount(-1, true); //Method called on AsyncDataProvider 
    return; 
    } 
+0

谢谢你的回答。现在我会尽力去做。 – 2014-09-23 15:53:40

+0

对不起,但你的解决方案不起作用.. – 2014-10-12 12:28:28

+0

对不起。: - )我不明白你的建议。现在一切正常。谢谢! – 2014-10-12 13:32:06

1

一些替代解决方案删除任何数据标签。可以定义扩展界面的界面CellTree.Resources。 在这个接口中必须指定CSS的路径,它覆盖所需的样式。

接口CellTree.Resources

public class CellTree extends AbstractCellTree implements HasAnimation, 
    Focusable { 
    ... 
    /** 
    * A ClientBundle that provides images for this widget. 
    */ 
    public interface Resources extends ClientBundle { 

    /** 
    * An image indicating a closed branch. 
    */ 
    @ImageOptions(flipRtl = true) 
    @Source("cellTreeClosedArrow.png") 
    ImageResource cellTreeClosedItem(); 

    /** 
    * An image indicating that a node is loading. 
    */ 
    @ImageOptions(flipRtl = true) 
    ImageResource cellTreeLoading(); 

    /** 
    * An image indicating an open branch. 
    */ 
    @ImageOptions(flipRtl = true) 
    @Source("cellTreeOpenArrow.png") 
    ImageResource cellTreeOpenItem(); 

    /** 
    * The background used for selected items. 
    */ 
    @ImageOptions(repeatStyle = RepeatStyle.Horizontal, flipRtl = true) 
    ImageResource cellTreeSelectedBackground(); 

    /** 
    * The styles used in this widget. 
    */ 
    @Source(Style.DEFAULT_CSS) 
    Style cellTreeStyle(); 
    } 
... 
} 

接口CustomCellTreeResources,基于CellTree.Resources

import com.google.gwt.resources.client.ClientBundle; 
import com.google.gwt.user.cellview.client.CellTree; 

public interface CustomCellTreeResources extends CellTree.Resources { 
    static final String STYLE_PATH = "components/common/client/static/custom-cell-tree.css"; 

    @Override 
    @ClientBundle.Source({CellTree.Style.DEFAULT_CSS, STYLE_PATH}) 
    CellTree.Style cellTreeStyle(); 
} 

重写规则:

.cellTreeEmptyMessage { 
    display: none; 
} 

创建一个实例:

private final static CellTree.Resources customCellTreeResources = 
    GWT.create(CustomCellTreeResources.class); 

接下来需要明确地将customCellTreeResources传递给CellTree类的构造函数。

消息不显示更多。

enter image description here

强制性:备案名单,即点击一个节点上之前之前,清单应清洗(getList().clear();):

@Override 
public void onRangeChanged(HasData<MValue> result) { 
    service.queryDictionaryValues(range, query, 
      new AsyncCallback<SubsetResult<MValue>>() { 
     @Override 
     public void onFailure(Throwable t) {} 
     @Override 
     public void onSuccess(SubsetResult<MValue> result) { 
      getList().clear(); 
      for (MValue value : result.items) { 
       getList().add(value); 
      } 
     } 
    }); 
} 
1

TreeViewModel,请确保isLeaf方法如果参数值没有孩子,则返回true。例如:

@Override 
public boolean isLeaf(Object value) { 
    if (value instanceof DepartmentDto) { 
     DepartmentDto department = (DepartmentDto) value; 
     return department.getEmployees().isEmpty(); 
    } else if (value instanceof EmployeeDto) { 
     return true; 
    } else { 
     return false; 
    } 
} 

在这种情况下,一个部门要声明自己作为叶子只有当它没有员工,员工将自己声明为叶,并默认为false。

请注意,许多值也是内部GWT节点。在这个例子中,它可能不一定只是DepartmentDtoEmployeeDto

+0

非常感谢您的回答! – 2017-12-15 02:54:27