2014-09-23 37 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