Search code examples
javacssgwtgwt-celltablegwt-2.7

How to use CellTable.Style with GWT 2.7.0 without UiBinder?


I joined a GWT application project a few weeks ago. The codebase was started back in 2009. I am trying to replace a FlexTable with a CellTable so that I can take advantage of the sortable columns. The current version of GWT in the project is 2.7.0, but looking through the code, it looks like there are some features still used that have gone out of style. I am new to GWT, I could be wrong.

So far, things are functionally good. However, GWT seems to be overriding my attempts to update the CSS. I used the GWT dynatablerf sample as a model to add CSS to the CellTable. The TimeSlotWidget uses CellTable.Style:

  interface TableResources extends CellTable.Resources {
    @Override
    @Source(value = {CellTable.Style.DEFAULT_CSS, "CellTablePatch.css"})
    CellTable.Style cellTableStyle();
  }

And then applies it to the CellTable like this:

 table = new CellTable<TimeSlotListWidget.ScheduleRow>(ROWS_IN_A_DAY,
        GWT.<TableResources> create(TableResources.class));

I tried to use this approach in my code. I even omitted the CellTable.Style.DEFAULT_CSS from the value list and created my own CSS stylesheet which started as a copy of the GWT CellTable.css

I noticed that GWT TimeSlotListWidget sample has an ui.xml file with UIBinder. My project does not currently use UIBinder.

When I run my code, there is a <style> block inserted into the page that seems to be the standard GWT CellTable.css. Then directly after that, another <style> block is inserted with my CSS. And my CSS is not overriding the standard GWT CSS.

How can I keep the GWT CellTable.css from being inserted? Why is it being inserted?


Solution

  • The problem is that in your code, you reuse CellTable.Style, and two different ClientBundles have used the same type but each bound their own CSS to it.

    Instead, extend the CellTable.Style interface, and use that in your bundle:

    interface MyCellTableStyle extends CellTable.Style {}
    interface TableResources extends CellTable.Resources {
      @Override
      @Source(value = {CellTable.Style.DEFAULT_CSS, "CellTablePatch.css"})
      MyCellTableStyle cellTableStyle();
    }