1

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.

Community
  • 1
  • 1
Shadark
  • 499
  • 1
  • 7
  • 18
  • Why don't you want to make `SeoClickableCell implements Cell` ? What is ther hierarchy of `AbstractCell` ? – Gaël J Oct 27 '15 at 12:19
  • Because if I make `public class SeoClickableCell extends AbstractCell implements Cell {` , Java tells me that I can't implement interface Cell more than once. If I make both of them implement X no errors are found, but then I should make my original code something like `Column nameColumn = new Column(cell) {` and I'm not sure if that's what I need. – Shadark Oct 27 '15 at 12:25
  • That's strange because `AbstractCell` implements `Cell`... Which version of GWT are you using ? – Philippe Gonday Oct 27 '15 at 14:52
  • @philfr49 That's because the OP is now trying to extend `AbstractCell` **and** implement `Cell` which doesn't work. It's either or. – Baz Oct 27 '15 at 16:46
  • @philfr49 I'm using GWT 2.6.0. And yes, the header of `AbstractCell` is `public abstract class AbstractCell implements Cell`, so I understand that I shouldn't make my class implement Cell because it's already implemented. My question now is how to make a custom Column using that class. – Shadark Oct 28 '15 at 08:13

1 Answers1

1

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();
        }
    };
Shadark
  • 499
  • 1
  • 7
  • 18