javagwtcelltable

GWT Create column with custom cell type


I'm trying to use the code from https://stackoverflow.com/a/6966235/1339354 in my project. I defined the following class:

public class SeoClickableCell extends AbstractCell<WebmasterObject> {

public SeoClickableCell() {
    super("click", "keydown");
}

@Override
public void render(Context context, WebmasterObject value, SafeHtmlBuilder sb) {
     if (value != null) {
         sb.appendHtmlConstant("<a href='javascript:;'>");
         sb.appendEscaped(value.getName());
         sb.appendHtmlConstant("</a>");
     }
}

@Override
public void onBrowserEvent(Context context, Element parent, WebmasterObject value, NativeEvent event, ValueUpdater<WebmasterObject> valueUpdater) {
    if (value == null)
        return;

    super.onBrowserEvent(context, parent, value, event, valueUpdater);
    if ("click".equals(event.getType())) {
        //TODO
    }
}

};

But I'm trying to create a custom column in my CellTable. but the following code:

final SeoClickableCell cell = new SeoClickableCell();
    Column<WebmasterObject, String> nameColumn = new Column<WebmasterObject, String>(cell) {
        @Override
        public String getValue(WebmasterObject WebmasterObject) {
            return WebmasterObject.getName();
        }
    };

Tells me:

The constructor Column(SeoClickableCell) is undefined

And that I should make SeoClickableCell implement Cell or change the type of "cell".

I'm not sure if I'm grasping correctly the procedure to make custom cells/columns, so any help would be appreciated.


Solution

  • I solved it changing the type and implementation of SeoClickableCell to this:

    public class SeoClickableCell extends AbstractCell<String> {
    
    public SeoClickableCell() {
        super("click", "keydown");
    }
    
    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
         if (value != null) {
             sb.appendHtmlConstant("<a href='javascript:;'>");
             sb.appendEscaped(value);
             sb.appendHtmlConstant("</a>");
         }
    }
    
    @Override
    public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) {
        if (value == null)
            return;
    
        super.onBrowserEvent(context, parent, value, event, valueUpdater);
        if ("click".equals(event.getType())) {
            //TODO
        }
    }
    

    };

    and making the column like this:

    final SeoClickableCell cell = new SeoClickableCell();
        Column<WebmasterObject, String> nameColumn = new Column<WebmasterObject, String>(cell) {
            @Override
            public String getValue(WebmasterObject wbo) {
                return wbo.getName();
            }
        };