PDA

View Full Version : Changing the font colour of a treenode



mtucker
19 Mar 2015, 9:08 AM
How would I change the font colour of a treenode in GXT 3? In GXT 2 you used a ModelStringProvider and could return HTML, but I can't find anything similar in 3.

I've tried using ValueProvider and returning SafeHtml, but that just calls the toString() method on the SafeHtml object.

mtucker
31 Mar 2015, 5:54 AM
Figured it out!

I needed to use SafeHtml for the ValueProvider and set the Tree cell to a SafeHtmlCell e.g.


tree=new Tree<NavigableModel<Integer>, SafeHtml>(treeStore, new ValueProvider<NavigableModel<Integer>, SafeHtml>() {
public SafeHtml getValue(NavigableModel<Integer> _model) {
SafeHtmlBuilder sb=new SafeHtmlBuilder();
if(_model==null) return sb.toSafeHtml();

if (!_model.getActive()) {
// My class to make the text red if this model isn't active
sb.appendHtmlConstant("<span class=\"item-deleted\">");
}

sb.appendEscaped((String)_model.get("name"));

if (!_model.getActive()) {
sb.appendHtmlConstant("</span>");
}
return(sb.toSafeHtml());
}
public void setValue(NavigableModel<Integer> object, SafeHtml value) {
}
public String getPath() {
return("name");
}
});

// Set the cell to SafeHtmlCell to use the SafeHtml returned by ValueProvider
tree.setCell(new SafeHtmlCell());


Hopefully this will help someone else.