Hi Jens,

Here's the full example of what I was trying to illustrate as it's probably 
unfair of me to have others expect that I'm setting everything up right 
from just the pseudo code alone:

public class GwtTest3 implements EntryPoint {
 public interface MyClientBundle extends ClientBundle{
public final static MyClientBundle INSTANCE = 
GWT.create(MyClientBundle.class);
 @Shared
@ImportedWithPrefix("global")
public interface GlobalCss extends CssResource{
public String genButton(); 
public String genButtonOther();
}
 /*
 * Global.css contains:
 * .genButton{
background: green;
}
.genButtonOther{
background: yellow;
}
 */
@Source("Global.css")
GlobalCss globalCss();
 public interface InitButtonCss extends CssResource{
public String initButton();
public String initButton2();
}
 /*
 * InitButton.css contains:
 * .initButton{
background: #66F;
}
.global-genButton.initButton2{
background: orange;
}
 */
@Import(GlobalCss.class)
@Source({"InitButton.css"})
InitButtonCss initButtonCss();
 public interface MyCss extends GlobalCss{
public String myButton();
}
 /*
 * My.css contains:
 * .myButton{
background: red;
}
 */
/*
 * Regardless of whether you use @Import on a CssResource that is extending 
another CssResource
 * you still need to specify the source of the extended CssResource or else 
 * gwt will error because it cannot find the selectors OR you would have to 
redefine all of the
 * selectors from the extended css in the child css. 
 * This occurs even if you use @NotStrict.
 */
@Import(GlobalCss.class)
/*
 * if specifying the source for this resource because it does not have the 
default name as well as
 * the extended css then order matters as it is the order in which gwt will 
generate the source 
 * into the final css
 */
@Source({"Global.css","My.css"}) //will cause duplicate insert of rules 
from Global.css
MyCss myCss();
}

/**
 * This is the entry point method.
 */
@Override
public void onModuleLoad() {
 MyClientBundle.INSTANCE.globalCss().ensureInjected();
 Button genButton = new Button("1.) add first buttons");
genButton.getElement().setAttribute("style", 
"position:absolute;top:50%;left:40%;");
 genButton.addClickHandler(new ClickHandler() {
 @Override
public void onClick(ClickEvent event) {
MyClientBundle.INSTANCE.initButtonCss().ensureInjected();
Button initButton = new Button("init button (overqualified)");
initButton.getElement().setAttribute("style", 
"position:absolute;top:60%;left:40%;");
initButton.addStyleName(MyClientBundle.INSTANCE.globalCss().genButton() + " 
" + MyClientBundle.INSTANCE.initButtonCss().initButton2());
 RootPanel.get().add(initButton);
 Button initButton2 = new Button("init button 2 (blue)");
initButton2.getElement().setAttribute("style", 
"position:absolute;top:70%;left:40%;");
initButton2.addStyleName(MyClientBundle.INSTANCE.globalCss().genButton() + 
" " + MyClientBundle.INSTANCE.initButtonCss().initButton());
 RootPanel.get().add(initButton2);
}
});
 RootPanel.get().add(genButton);
 
Button genButton2 = new Button("2.) add second button");
genButton2.getElement().setAttribute("style", 
"position:absolute;top:50%;left:60%;");
 genButton2.addClickHandler(new ClickHandler() {
 @Override
public void onClick(ClickEvent event) {
MyClientBundle.INSTANCE.myCss().ensureInjected();
Button myButton = new Button("My button");
myButton.getElement().setAttribute("style", 
"position:absolute;top:60%;left:60%;");
myButton.addStyleName(MyClientBundle.INSTANCE.globalCss().genButton() + " " 
+ MyClientBundle.INSTANCE.myCss().myButton());
 RootPanel.get().add(myButton);
}
});
 RootPanel.get().add(genButton2);
}
}

If you run it and click the 1st button then the 2nd button you'll see the 
background color of "init button 2 (blue)" change from blue to green.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to