0

I have a CellTable where I want to add several links to a row when I click an add button. Right now Im facing the problem that when I click the add button the link will be added to all rows in that column. Somehow it feels like I only can add things to columns.

// shows project column
    final MultipleLinkTextCell projectCell = new MultipleLinkTextCell();
    final Column<Booking, String> projectColumn = new Column<Booking, String>(
        projectCell) {

    @Override
    public String getValue(Booking project) {
       return "";
    }

    };
    getView().getTimeTable().addColumn(projectColumn, "Tasks");

An Example with Buttons

 @Override
protected void render(com.google.gwt.cell.client.Cell.Context context,
    SafeHtml data, SafeHtmlBuilder sb) {
String string = "";
for (int i = 0; i < value; i++) {
    string += "<button type=\"button\" style=\" height:20px; width:22px\">";
}

sb.appendHtmlConstant(string);
if (data != null) {
    sb.append(data);

}
}

Im thinking about to use the Anchor widget because I can handle the placemanager from gwtp with it. But still I dont know how to add widgets to a specific row.

//Update: I did it like this now, it works, but its better to use the revealmanager. The hardcoded link is kinda bad because I always need to change the reference to the link when I change the webserver. I get a string with several values splitted by a commar.

   @Override
protected void render(com.google.gwt.cell.client.Cell.Context context,
    SafeHtml data, SafeHtmlBuilder sb) {
String stringData = data.asString();
String[] splitResult = stringData.split(",");
for (int i = 0; i < splitResult.length; i++) {
    if (!splitResult[i].equals("")) {
    sb.appendHtmlConstant("<div><a href=\"http://127.0.0.1:8888/gwtpTimeTracking.html?gwt.codesvr=127.0.0.1:9997#project;projectid="+splitResult[i].substring(0, 7)+"\">"
        + splitResult[i].substring(0, 7) + "</a></div>");
    }
}
kArvee
  • 84
  • 1
  • 11

1 Answers1

0

You can't use any Widgets in CellWidgets.
However you can create your custom cell that mimics it or create an ActionCell and add a VaueUpdater that fires a PlaceRequest Event.

For adding the link to a specific row you have to add a field (i..e List<String> links) to your DTO that is rendered in your CellTable. When you click on the "Add" button you have to modify the field of the specific DTO in your list.

MyDTO obj = // get the specific DTO from the DataProvider
obj.setLinks(LIST OF LINKS);

In the render method of your custom cell you check the field (i..e links) and either render out the links or not.

Where does the value data in your render method come from ?

Ümit
  • 17,379
  • 7
  • 55
  • 74
  • how can I check the links in the render method? In my column I have to return a single string. – kArvee Jun 17 '13 at 08:38
  • if you override the `render` method of your custom `Cell` one parameter is the String that has to be rendered. You can check if that's not null/not empty and then render a link otherwise render nothing. – Ümit Jun 17 '13 at 09:00
  • hm ok, I updated my code. It works for me but I'm not really happy about that. – kArvee Jun 17 '13 at 10:34
  • A couple of things 1.) Instead of returning a String you can returns a String[] or a DTO (contains url, title, etc) in your `Cell`. 2.) you can use relative links instead of the absolute link. 3.) You can inject a `PlaceManager` into your custom `Cell` and construct the url. – Ümit Jun 17 '13 at 11:20
  • I returned a DTO. It works :) But another Question: How can I use the placemanager in my custom Cell? I mean I cant just write it in the href or sth? – kArvee Jun 17 '13 at 12:16
  • add the `PlaceManager` as a constructor parameter to your custom `Cell` and store it in a field. Then you can access it in your `render` method and create the proper URL and use setHref to set the URL. – Ümit Jun 17 '13 at 13:11
  • Okay thank you for your time :) Everything works alright. I even added buttons to each link which trigger a fieldupdater to reveal a new presenter to edit the link value. – kArvee Jun 17 '13 at 14:26