On Dec 21, 2:33 am, Dazza <dazzacoll...@gmail.com> wrote:
> I have an existing GWT project that uses
> StyleInjector.injectStylesheet and StyleInjector.setContents from the
> GWT Incubator.  I have upgraded to GWT 2.0 and see that StyleInjector
> is now an official GWT class.  Unfortunately the two methods I am
> using (injectStylesheet and setContents) are now deprecated and I am
> not sure how best to replace their usage.

As said in the JavaDoc, the problem is that they cannot be guaranteed
to work the way they should in all browsers in all cases.

> On initial display of the page I call StyleInjector.injectStylesheet
> to inject some CSS styles with values specific to the data displayed.
> At a later point when I refresh the data I need to change the CSS
> style values, so I call StyleInjector.setContents which replaces the
> styles I originally created.  I may end up replacing the CSS styles
> thousands of times in the course of a user session.

Wow! you'd probably better use a single stylesheet and do the switch
by setting a class in the document's body or other container element
and using descendant selectors.
I.e., instead of switching between those two rules with setContents:
  .data { color: red; }
  .data { color: blue; }
you'd better use a single stylesheet with those 2 rules
  .red .data { color: red; }
  .blue .data { color: blue; }
and just change a container element's class:
  myRootPanel.setStyleName("blue"); // will replace the previous "red"
value
or, if you have other classes on the root panel:
  myRootPanel.removeStyleName("red");
  myRootPanel.addStyleName("blue");
Or you can use Document.get().getBody().set/add/removeClassName(), if
you have several root panels for instance.

--

You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.


Reply via email to