Search code examples
gwtanchorcell

How can I render a ClickableTextCell as an anchor in a GWT CellTable?


I've got a CellTable with multiple columns in simple TextCell()s. Two of the columns are 'clickable' via the ClickableTextCell() class, but I want to change how they look. What's the easiest way to get the cell contents to resemble an anchor tag, while still using a cell in the table?

I've tried the following: 1. Implement a custom renderer to add anchor tags 2. Scouring Google looking for hints 3. Ignoring 'my library does it you just have to change your entire framework' links 4. Rolling my head across they keyboard

It's funny how annoying this simple change is turning out to be.

My current thought is to implement a custom AnchorCell type which puts in an Anchor widget instead of whatever it does in the other ones, but I'm not sure what all would need to be done.

Any help is appreciated.


Solution

  • As an example:

    public class MyClickableCellText extends ClickableTextCell {
    
        String style;   
        public MyClickableCellText()
        {
            super();
            style = "myClickableCellTestStyle";
        }
    
    
         @Override
          protected void render(Context context, SafeHtml value, SafeHtmlBuilder sb) {
            if (value != null) {
              sb.appendHtmlConstant("<div class=\""+style+"\">");
              sb.append(value);
              sb.appendHtmlConstant("</div>");
            }
          }
    
         public void addStyleName(String style)
         {
             this.style = style; 
         }
    
    
    }
    

    And the style (without the div, because you are hardcoding the style on it):

    .myClickableCellTestStyle{
        text-decoration:underline;
    
    }
    

    You can even create your own cell by not extending ClickableTextCell but extending AbstractCell (more powerful but need more explanation). Ask me if you need it!