PDA

View Full Version : ListField with EmptyText



A.Rothe
13 May 2013, 2:42 AM
My ListField hasn't displayed the empty text, which I had set. I have created a subclass to get the correct behaviour. I use GXT 2.2.5.



public class DefaultListView<M extends ModelData> extends ListView<M> {

private String emptyText;

public void setEmptyText(String emptyText) {
this.emptyText = emptyText;
}

@Override
public void refresh() {
super.refresh();

if (emptyText == null) {
emptyText = "&nbsp;";
}

if (getItemCount() == 0) {
el().setInnerHtml("<div class='x-view-empty'>" + emptyText + "</div>");
repaint();
}
}
}


The view class will set a new list content, if there are no items on the list. This class can be used as view of a ListField:



public class DefaultListField<D extends ModelData> extends ListField<D> {

public DefaultListField() {
listView = new DefaultListView<D>();
}

@Override
public DefaultListView<D> getListView() {
return (DefaultListView<D>) listView;
}

@Override
public void setEmptyText(String emptyText) {
super.setEmptyText(emptyText);
getListView().setEmptyText(emptyText);
}

@Override
protected void onRender(Element parent, int index) {
getListView().setEmptyText(emptyText);
super.onRender(parent, index);
}
}


I can replace the listView instance, because in the super constructor there is no further access to this member field.

The last step is to define a CSS class "x-view-empty":

.x-view-empty {
padding: 10px;
color: gray;
font: normal 11px tahoma, arial, helvetica, sans-serif;
}

This solution can also be used within DualListFields:



public class MyDualListField<D extends ModelData> extends DualListField<D> {

public MyDualListField() {
fields.clear();
fromField = new DefaultListField<D>();
fromField.setEmptyText("ho-ho-ho");
//...
}

}


Here is the result:

43742

Regards
Andre