Custom cell with table causes event problem in cellTable

94 views
Skip to first unread message

Musicman75

unread,
Mar 21, 2012, 10:22:04 AM3/21/12
to Google Web Toolkit
Hello,

I've a problem using a custom cell in a cellTable.
My custom renderer renders the data with templates and includes a
table.
On mouseOver the main cellTable highlights the row, but on mouseOver
on the included table, the highlight of the row gets lost.

How can I get the row highlighted even if I hover the internal table?

Thanks for help.



Here's a small example:

Playground.java (implementing EntryPoint):

----------
package com.heiler.playground.client;

import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.view.client.ListDataProvider;
import com.heiler.playground.shared.MainObject;

public class Playground implements EntryPoint {
@Override
public void onModuleLoad() {
ListDataProvider<MainObject> dataProvider = new
ListDataProvider<MainObject>();
for (int i = 0; i < 5; i++) {
dataProvider.getList().add(new MainObject(i));
}
CellTable<MainObject> mainTable = new CellTable<MainObject>();

Column<MainObject, String> idColumn = new Column<MainObject,
String>(
new TextCell()) {
@Override
public String getValue(MainObject object) {
return Integer.toString(object.getId());
}
};

Column<MainObject, MainObject> subColumn = new Column<MainObject,
MainObject>(
new CustomCell()) {
@Override
public MainObject getValue(MainObject object) {
return object;
}
};

mainTable.addColumn(idColumn, "ID");
mainTable.addColumn(subColumn, "Sub");

dataProvider.addDataDisplay(mainTable);
mainTable.setWidth("800px");

RootPanel.get().add(mainTable);
}
}

-------------------

CustomCell.java:

-------------------
package com.heiler.playground.client;

import java.util.List;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.client.SafeHtmlTemplates.Template;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.heiler.playground.shared.MainObject;
import com.heiler.playground.shared.SubObject;

public class CustomCell extends AbstractCell<MainObject> {
interface Template extends SafeHtmlTemplates {

@Template("<div cellspacing=\"0\" cellpadding=\"0\">")
SafeHtml stockInfoTableBegin();

@Template("</div>")
SafeHtml stockInfoTableEnd();

@Template("<div>")
SafeHtml stockInfoRowBegin();

@Template("</div>")
SafeHtml stockInfoRowEnd();

@Template("<div class=\"itemsTableWidget-StockInfoHeaderColumn\">{0}
</div>")
SafeHtml stockInfoColumn(String columnName);

@Template("<div class=\"itemsTableWidget-StockInfoDataColumn\">{0}</
div>")
SafeHtml stockInfoBodyData(String data);

@Template("<div class=\"itemsTableWidget-clearLayout\"></div>")
SafeHtml clearStockInfoLayout();

}

private static Template template = GWT.create(Template.class);

/**
* Creates and initializes new instance of this class.
*/
public CustomCell() {
super("click", "mouseover", "mouseout");
}

@Override
public void render(Cell.Context context, MainObject value,
SafeHtmlBuilder sb) {
if (value != null) {
renderStockInfo(context, value, sb);
}
}

private void renderStockInfo(Cell.Context context, MainObject value,
SafeHtmlBuilder sb) {
SubObject itemStockInfo = value.getSub();
List<String> columnNameList = value.getColumnNames();

// stockinfo row start

// table start
sb.append(template.stockInfoTableBegin());

// header start
sb.append(template.stockInfoRowBegin());
for (String columnName : columnNameList) {
sb.append(template.stockInfoColumn(columnName));
}
sb.append(template.stockInfoRowEnd());
// header end

// info rows
sb.append(template.stockInfoRowBegin());
sb.append(template.stockInfoBodyData(itemStockInfo.getMessage()));
sb.append(template.stockInfoRowEnd());

sb.append(template.stockInfoTableEnd());
// table end

sb.append(template.clearStockInfoLayout());
// container end
}

@Override
public void onBrowserEvent(Context context, Element parent,
MainObject value, NativeEvent event,
ValueUpdater<MainObject> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
EventTarget eventTarget = event.getEventTarget();
if (!Element.is(eventTarget)) {
return;
}

switch (DOM.eventGetType((Event) event)) {
case Event.ONCLICK:
GWT.log("onClick");
break;
case Event.ONMOUSEOUT:
GWT.log("onMouseOut");
break;
case Event.ONMOUSEOVER:
GWT.log("onMouseOver");
break;
default:
break;
}

}

}

----------------

MainObject.java (My root object contains a subObject):

----------------
package com.heiler.playground.shared;

import java.util.ArrayList;
import java.util.List;

public class MainObject {

Integer id;
String name = "MainObject";
SubObject sub;
String message = "This is the message of the main object";

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

List<String> columnNames = new ArrayList<String>();

public MainObject(int id) {
this.id = id;
this.sub = new SubObject(id);
columnNames.add("id");
columnNames.add("Name");
columnNames.add("Dat");
}

public List<String> getColumnNames() {
return columnNames;
}

public void setColumnNames(List<String> columnNames) {
this.columnNames = columnNames;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public SubObject getSub() {
return sub;
}

public void setSub(SubObject sub) {
this.sub = sub;
}

}

--------------------

SubObject.java:

--------------------
package com.heiler.playground.shared;

public class SubObject {

String name = "SubObject";
String dat = "Data";
Integer id = 10;
String message = "This is the message";

public SubObject(int id) {
this.id = id;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDat() {
return dat;
}

public void setDat(String dat) {
this.dat = dat;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

}

--------------------

Thomas Broyer

unread,
Mar 21, 2012, 11:44:01 AM3/21/12
to google-we...@googlegroups.com

Musicman75

unread,
Mar 23, 2012, 5:22:31 AM3/23/12
to Google Web Toolkit
Thanks a lot for your answer.

On 21 Mrz., 16:44, Thomas Broyer <t.bro...@gmail.com> wrote:
> Known issue, fixed in trunk:http://code.google.com/p/google-web-toolkit/issues/detail?id=5714&q=c...
> ...
>
> Erfahren Sie mehr »
Reply all
Reply to author
Forward
0 new messages