0

から継承するウィジェットがありますCellTree。ノードに子要素がない場合、このノードを開いて"no data"ラベルを表示できます。

子のないノードが空として表示されることを望みます。

それが私が木を埋める方法です。私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を参照)。


@moutellou のおかげで、すべてが OK になりました。私は彼が提案したようにしました:

...
@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);
        }
    }
}
...
4

3 に答える 3

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クラス コンストラクターに渡す必要があります。

メッセージが表示されなくなりました。

必須: リストをファイリングする前、つまりノードをクリックする前に、リストを消去する必要があります( 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);
            }
        }
    });
}
于 2014-11-04T11:47:57.923 に答える
0

これは、DataProvider でデータなしラベルを削除した方法です

 //Fetch children
  int size = children.size();
  if (size == 0) {
     updateRowCount(-1, true); //Method called on AsyncDataProvider 
     return;
  }  
于 2014-09-23T15:51:50.410 に答える