GWT: Two CellList style overlapped even with different css resource - gwt

In my GWT application I have two CellLists. Each with a different style, like below:
public interface MyResources extends Resources
{
/**
* The styles used in this widget.
*/
#Override
#Source( "com/example/CellList.css" )
Style cellListStyle();
}
MyResources CELLLIST_RESOURCES = GWT.create( MyResources.class );
......
mylist=new CellList<MyProxy>( myCell, CELLLIST_RESOURCES );
Both CellLists have different css files. But when loaded I found, the style of both lists was same. This is strange, any ideas?

Just found this issue 6144, the solution is simple, just use different interface name each, i.e.
interface TableResources extends CellTable.Resources
{
#Source({"myCellTable.css"})
TableStyle cellTableStyle();
}

Related

How to set CSS Resource for DataGrid in UIBinder?

I have two questions.
Question #1. this question (post title) comes directly from the last comment from #Cataclysm on the first answer from here:
dataGrid = new DataGrid<T>(pageSize, resource), how to set CSS
Resource for UIBinder ?
I am attempting to style a DataGrid defined in a UIBinder:
<g:south size="400">
<c:DataGrid ui:field="documentDataTable" />
</g:south>
With this ClientBundle interface code:
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.cellview.client.DataGrid.Resources;
import com.google.gwt.user.cellview.client.DataGrid.Style;
/**
* Resources = "DataGrid.Resources"
* Style = "DataGrid.Style"
*
* http://federico.defaveri.org/?p=157
* https://code.google.com/p/google-web-toolkit/issues/detail?id=6144#c3
* https://stackoverflow.com/questions/7394151/datagrid-celltable-styling-frustration-overriding-row-styles/7395175#comment26605442_7395175
*/
public interface CustomDataGridResource extends Resources {
#Source({Style.DEFAULT_CSS, "css/CDD_DataGridStyle.css"})
CustomStyle dataGridStyle();
interface CustomStyle extends Style {
String dataGridHeader();
}
}
And CDD_DataGridStyle.css:
.dataGridHeader {
background-color: purple;
}
Using these references:
DataGrid / CellTable styling frustration -- overriding row styles
http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/cellview/client/DataGrid.html
http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/cellview/client/DataGrid.Style.html
http://crazygui.wordpress.com/2011/11/01/how-to-skin-a-gwt-celltable/
https://code.google.com/p/google-web-toolkit/issues/detail?id=6144#c3
From what I have understood from the answer to Reference 1, this resource style sheet is not "injected" like an ordinary client bundle, but rather should be passed in as a resource to a programmatically-instantiated data grid:
"To construct your newly-styled datagrid all you need to do is:
DataGridResource resource = GWT.create(DataGridResource.class);
dataGrid = new DataGrid<T>(pageSize, resource)"
Oddly, although I have a reference to the DataGrid #UIField, there does not appear to be any method in the DataGrid.java API documentation to "set" the resource (Hence the question as a repost of the last comment on this question about a DataGrid already defined in UIBinder -- DataGrid / CellTable styling frustration -- overriding row styles).
Question #2: What is the difference between DataGrid vs. CellTable, and which is the correct implementation syntax?
Why does the Google GWT API documentation for DataGrid.java (Reference 2) only detail a CellTable instantiation programmatically? I understand that DataGrid.java extends AbstractCellTable.java but why not use any of the seven DataGrid constructors in the API Example code?
To make matters more confusing, References 4 and 5 suggest that my client bundle interface should be extending CellTable.Resources, while Reference 1 suggests extending DataGrid.Resources (see also this link: http://federico.defaveri.org/?p=157).
I tried adapting the the "After" code example from the last post (#13) from Reference 5 but the nested interfaces threw an error:
public interface NxoCellTableResources extends CellTable.Resources {
public interface NormalStyle extends CellTable.Style {}
#Source({ CellTable.Style.DEFAULT_CSS, "NxoCellTable.css" })
public NormalStyle cellTableStyle();
}
public interface NxoCellTableThinResources extends CellTable.Resources {
public interface ThinStyle extends CellTable.Style {}
#Source({ CellTable.Style.DEFAULT_CSS, "NxoCellTable.css", "NxoCellTableThin.css" })
public ThinStyle cellTableStyle();
}
In summary, I am looking for the simplest way to style all elements in a DataGrid defined in a UIBinder with a clear explanation of which Resource syntax to use (DataGrid vs. CellTable). I am open to removing the reference from UIBinder and inserting programmatically into the view if necessary, thanks in advance!
Question 1:
Everything you said, is correct.
Make sure you pass provided=true to your DataGrid's UiField:
#UiField(provided = true)
DataGrid<MyDTO> dataGrid;
Then in the constructor you would create the DataGrid like this:
public MyView() {
CustomDataGridResource resource = GWT.create(CustomDataGridResource.class);
resource.dataGridStyle().ensureInjected();
dataGrid = new DataGrid<MyDTO>(pageSize, resource)"
binder.createAndBindUi(this);
}
Make sure you call ensureInjected() on the style.
Also if you have an Inject on your constructor.
You can pass the CustomDataGridresource and GWT.create() will be automatically called:
#Inject
public MyView(CustomDataGridResource resource) {
resource.dataGridStyle().ensureInjected();
dataGrid = new DataGrid<MyDTO>(pageSize, resource)"
binder.createAndBindUi(this);
}
Question 2:
Regarding the difference between CellTable and DataGrid refer to this thread:
https://groups.google.com/forum/#!topic/google-web-toolkit/PBhu6RtP4G8
Basically if you use LayoutPanels DataGrid is a good fit as it contains fixed headers and a scrollable content area. CellTable will also work with FlowPanel and normal Panels.
GWT has this documented here.
A good example can be found here.

how to disable mouse over highlighting of rows in celltable gwt

I want to disable the mouse highlighting of rows of a celltable.
This celltable is not a selectionmodel so I dont want the rows to get highlighted while mouse over event.
We are basically extending the CellTable Resources which contain the CssStyles of the CellTable so that we can custom define our own css styles. for more css classes check this link
public interface IMyResources extends CellTable.Resources {
interface IMyStyle extends CellTable.Style {
}
#Override
#Source({ CellTable.Style.DEFAULT_CSS, "MyStyleSheet.css" })
IMyStyle cellTableStyle();
}
MyStyleSheet.css CSS :
.hoveredRow {
background-color: none; //or just remove this but keep the class declaration
}
JAVA //dont forget add the resource.
CellTable<dataType> myCellTable = new CellTable<dataType>(15, GWT.create(IMYResources.class));

My custom css are not getting picked up completely

I have created a custom css for tree and other widgets.
I have made the following entry
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<stylesheet src="CustomStylesheet.css" />
But still only some of the styles are getting picked up and others don't. Has anyone faced a similar problem?
It will be either one of the below,
Either you have to use CSS Resource as mentioned by Andrew or you have missed Doctype declaration.
You can also visit this link: doctype explantion w.r.t to GWT
you should write the same style classnames with "com/google/gwt/user/cellview/client/CellTree.css" css file and you may change content css
pulic class MyClass extends Composite {
public interface MyResources extends CellTree.Resources {
#ImageResource.ImageOptions(flipRtl = true)
#Source("cellTreeClosedItem.gif")
ImageResource cellTreeClosedItem();
#ImageResource.ImageOptions(flipRtl = true)
#Source("cellTreeOpenItem.gif")
ImageResource cellTreeOpenItem();
#Override
#Source({"com/google/gwt/user/cellview/client/CellTree.css"})
CellTree.Style cellTreeStyle();
}
private MyResources res = GWT.create(MyResources.class);
public void onInitialize(){
cellTree = new CellTree(treeViewModel, null, res);
}
}

How to style GWT CellList?

I have a CellList that I want to style. I want to change the cursor style, the ugly color of a selected cell . I checked several questions and discussions on stack overflow,but none of them worked.
I checked these one:
CellList GWT CSS Style
How do I style a gwt 2.1 CellTables headers?
Her is my code:
public interface CellListResource extends CellList.Resources {
public static CellListResource INSTANCE = GWT.create(CellListResource.class);
interface CellListStyle extends CellList.Style {
}
#Source({CellList.Style.DEFAULT_CSS, "CellTableStyle.css"})
CellListStyle style();
}
public SearchViewImpl() {
CompanyCell companyCell = new CompanyCell();
//it doesn't work :S
companiesList = new CellList<Company>(companyCell, CellListResource.INSTANCE);
rootElement = ourUiBinder.createAndBindUi(this);
loadingImage.setVisible(false);
}
Am I missing something? I Cleared Browser cache, Restarted server, F5 F5 F5 .... F5 (pressed refresh again and again) and nothing ...!
Thanks for help in advance.
Besides injecting the CSS it's important that you call the CellListStyle style cellListStyle() and not just style():
public interface CellListResource extends CellList.Resources {
public static CellListResource INSTANCE = GWT.create(CellListResource.class);
interface CellListStyle extends CellList.Style {}
#Override
#Source("cellListStyle.css")
CellListStyle cellListStyle();
}
and then you do
CellListResource.INSTANCE.cellListStyle().ensureInjected();
companiesList = new CellList<Company>(companyCell, CellListResource.INSTANCE);
Make sure you inject the css resource.
CellTableResources.INSTANCE.cellTableStyle().ensureInjected();
myCellTable = new CellTable<T>(Integer.MAX_VALUE,CellTableResources.INSTANCE);
You can follow the following link
How do you change the mouse over highlighting?

Append custom style to a GWT CellTable (in this case all cells)

I have a case where I want to append
white-space: nowrap;
to the style of each cell in my CellTable. Currently it applies to all tables, but it would be nice to know both have to apply it for a specific CellTable, and all CellTables.
CellTables have their own CssResource. To override this style applied to all cells in a cellTable, create a new css file :
/* Incremental changes from CellTable.css */
.cellTableCell {
white-space: nowrap;
}
Then create your own CellTable.Resources interface :
public interface TableResources extends CellTable.Resources {
/**
* The styles applied to the table.
*/
interface TableStyle extends CellTable.Style {
}
#Override
#Source({ CellTable.Style.DEFAULT_CSS, "MyOwnCellTableStyleSheet.css" })
TableStyle cellTableStyle();
}
Finally, when creating your cellTable, use the constructor that lets you specify which Resources to use
CellTable<Object> myCellTable = new CellTable<Object>(15, GWT.create(TableResources.class));
For a working example, look at the Expenses sample provided in the GWT SDK.
Or you could do this the easy way:
CellTable<YourObj> yourTable = new CellTable<YourObj>();
yourTable.getElement().getStyle().setWhiteSpace(WhiteSpace.NOWRAP);
No css files, no weird boilerplate code.