1

我正在使用 vaadin 的 TreeTable 并尝试为我的行添加工具提示。这就是他们所说的应该这样做,但 propertyId 始终为空,所以我无法获得正确的列?是的,我也在 E​​clipse 调试器中运行它 =)

与这部分相关的代码:

private void init() {
    setDataSource();
    addGeneratedColumn("title", new TitleColumnGenerator());
    addGeneratedColumn("description", new DescriptionGenerator());
    setColumnExpandRatios();
    setItemDescriptionGenerator(new TooltipGenerator());
}

protected class TooltipGenerator implements ItemDescriptionGenerator{
        private static final long serialVersionUID = 1L;

        @Override
        public String generateDescription(Component source, Object itemId, Object propertyId) {
            TaskRow taskRow = (TaskRow)itemId;
            if("description".equals(propertyId)){
                return taskRow.getDescription();
            }else if("title".equals(propertyId)){
                return taskRow.getTitle();
            }else if("category".equals(propertyId)){
                return taskRow.getCategory().toString();
            }else if("operation".equals(propertyId)){
                return taskRow.getOperation().toString();
            }else if("resourcePointer".equals(propertyId)){
                return taskRow.getResourcePointer();
            }else if("taskState".equals(propertyId)){
                return taskRow.getTaskState().toString();
            }
            return null;
        }       
    }
4

1 回答 1

1

I have passed the source object as the itemId when adding an item to the tree.

Node node = ...;
Item item = tree.addItem(node);

this uses the object "node" as the id. Which then allows me to cast itemId as an instance of Node in the generateDescription method.

public String generateDescription(Component source, Object itemId, Object propertyId) {
    if (itemId instanceof Node) {
        Node node = (Node) itemId;
        ...

Maybe not the best solution, but it Works for me. Then again, I am adding items directly to the tree rather than using a DataContainer.

于 2015-04-02T01:22:02.330 回答