I have a GWT 1.7 application and I want to upgrade it to GWT 2 Milestone 2. The application uses 2 big external CSS files. In GWT 1.7 I had a public folder and put both the CSS files in the folder and my application compiled and worked fine. Now for GWT 2 I have created a ResourceBundle class and put all image sprites and CSS as follows:
public interface ResourceBundle extends ClientBundle {
public static final ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);
#Source("com/web/tech/public/stylesheet1.css")
public Css stylesheet1();
#Source("com/web/tech/public/stylesheet2.css")
public Css stylesheet2();
#Source("com/docobo/keswick/keswickweb/public/images/organisnew.gif")
public ImageResource add_org();
.....
}
The Css class is an empty class extending CssResource :
public interface Css extends CssResource{
}
Then in my onModuleLoad() I use :
StyleInjector.inject(ResourceBundle.INSTANCE.stylesheet1().getText());
StyleInjector.inject(ResourceBundle.INSTANCE.stylesheet2().getText());
When I compile I get the following error:
Rebinding com.docobo.keswick.keswickweb.client.ClientResources.ResourceBundle
Invoking <generate-with class='com.google.gwt.resources.rebind.context.InlineClientBundleGenerator'/>
Creating assignment for gxt_gray()
Replacing CSS class names
[ERROR] The following unobfuscated classes were present in a strict CssResource:
[ERROR] x-tab-scroller-left
[ERROR] x-tab-strip-disabled
[ERROR] ......loads of other styles
Fix by adding String accessor method(s) to the CssResource interface for obfuscated classes, or using an #external declaration for unobfuscated classes.
Following the above instruction when I use #external above all my style classes inside the CSS file I get the following error :
[ERROR] Generator 'com.google.gwt.resources.rebind.context.InlineClientBundleGenerator' threw threw an exception while rebinding 'com.docobo.keswick.keswickweb.client.ClientResources.ResourceBundle'
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
at java.lang.String.substring(Unknown Source)
at com.google.gwt.resources.css.GenerateCssAst$GenerationHandler.ignorableAtRule(GenerateCssAst.java:236)
at org.w3c.flute.parser.Parser.atRuleDeclaration(Parser.java:1178)
at org.w3c.flute.parser.Parser.ignoreStatement(Parser.java:622)
at org.w3c.flute.parser.Parser.parserUnit(Parser.java:452)
at org.w3c.flute.parser.Parser.parseStyleSheet(Parser.java:107)
at org.w3c.flute.parser.Parser.parseStyleSheet(Parser.java:119)
at com.google.gwt.resources.css.GenerateCssAst.exec(GenerateCssAst.java:663)
at com.google.gwt.resources.rg.CssResourceGenerator.prepare(CssResourceGenerator.java:506)
at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.initAndPrepare(AbstractClientBundleGenerator.java:531)
at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.initAndPrepare(AbstractClientBundleGenerator.java:502)
at com.google.gwt.resources.rebind.context.AbstractClientBundleGenerator.generate(AbstractClientBundleGenerator.java:179)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:49)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:108)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:54)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:154)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:143)
at com.google.gwt.dev.Precompile$DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(Precompile.java:315)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:107)
at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.process(AbstractCompiler.java:161)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:84)
at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.compile(AbstractCompiler.java:196)
at com.google.gwt.dev.jdt.AbstractCompiler$CompilerImpl.access$300(AbstractCompiler.java:70)
at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:481)
at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:113)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:49)
at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:415)
at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:32)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:507)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:408)
at com.google.gwt.dev.Compiler.run(Compiler.java:194)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:145)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:89)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:83)
at com.google.gwt.dev.Compiler.main(Compiler.java:152)
Try with #NotStrict. Example:
#NotStrict
#Source("com/web/tech/public/stylesheet1.css")
public Css stylesheet1();
Got it solved.
As pointed out by Thomas#Google Groups --> The #external must not be put "above" the style
http://code.google.com/p/google-web-toolkit/wiki/CssResource#External...
The example from this link, the css will look like :
#external .legacySelectorA, .legacySelectorB;
.obfuscated .legacySelectorA { .... }
.obfuscated .legacySelectorB { .... }
/* #external also accepts tail-globs */
#external .myProject-*;
.myProject-text {}
.myProject-foo {}
Related
Often people ask AspectJ questions like this one, so I want to answer it in a place I can easily link to later.
I have this marker annotation:
package de.scrum_master.app;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
#Inherited
#Retention(RetentionPolicy.RUNTIME)
public #interface Marker {}
Now I annotate an interface and/or methods like this:
package de.scrum_master.app;
#Marker
public interface MyInterface {
void one();
#Marker void two();
}
Here is a little driver application which also implements the interface:
package de.scrum_master.app;
public class Application implements MyInterface {
#Override
public void one() {}
#Override
public void two() {}
public static void main(String[] args) {
Application application = new Application();
application.one();
application.two();
}
}
Now when I define this aspect, I expect that it gets triggered
for each constructor execution of an annotated class and
for each execution of an annotated method.
package de.scrum_master.aspect;
import de.scrum_master.app.Marker;
public aspect MarkerAnnotationInterceptor {
after() : execution((#Marker *).new(..)) && !within(MarkerAnnotationInterceptor) {
System.out.println(thisJoinPoint);
}
after() : execution(#Marker * *(..)) && !within(MarkerAnnotationInterceptor) {
System.out.println(thisJoinPoint);
}
}
Unfortunately the aspect prints nothing, just as if class Application and method two() did not have any #Marker annotation. Why does AspectJ not intercept them?
The problem here is not AspectJ but the JVM. In Java, annotations on
interfaces,
methods or
other annotations
are never inherited by
implementing classes,
overriding methods or
classes using annotated annotations.
Annotation inheritance only works from classes to subclasses, but only if the annotation type used in the superclass bears the meta annotation #Inherited, see JDK JavaDoc.
AspectJ is a JVM language and thus works within the JVM's limitations. There is no general solution for this problem, but for specific interfaces or methods you wish to emulate annotation inheritance for, you can use a workaround like this:
package de.scrum_master.aspect;
import de.scrum_master.app.Marker;
import de.scrum_master.app.MyInterface;
/**
* It is a known JVM limitation that annotations are never inherited from interface
* to implementing class or from method to overriding method, see explanation in
* JDK API.
* <p>
* Here is a little AspectJ trick which does it manually.
*
*/
public aspect MarkerAnnotationInheritor {
// Implementing classes should inherit marker annotation
declare #type: MyInterface+ : #Marker;
// Overriding methods 'two' should inherit marker annotation
declare #method : void MyInterface+.two() : #Marker;
}
Please note: With this aspect in place, you can remove the (literal) annotations from the interface and from the annotated method because AspectJ's ITD (inter-type definition) mechanics adds them back to the interface plus to all implementing/overriding classes/methods.
Now the console log when running the Application says:
execution(de.scrum_master.app.Application())
execution(void de.scrum_master.app.Application.two())
By the way, you could also embed the aspect right into the interface so as to have everything in one place. Just be careful to rename MyInterface.java to MyInterface.aj in order to help the AspectJ compiler to recognise that it has to do some work here.
package de.scrum_master.app;
public interface MyInterface {
void one();
void two();
// Cannot omit 'static' here due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=571104
public static aspect MarkerAnnotationInheritor {
// Implementing classes should inherit marker annotation
declare #type: MyInterface+ : #Marker;
// Overriding methods 'two' should inherit marker annotation
declare #method : void MyInterface+.two() : #Marker;
}
}
Update 2021-02-11: Someone suggested an edit to the latter solution, saying that the aspect MarkerAnnotationInheritor nested inside interface MyInterface is implicitly public static, so the modifiers in the aspect declaration could be omitted. In principle this is true, because members (methods, nested classes) of interfaces are always public by default and a non-static inner class definition would not make sense inside an interface either (there is no instance to bind it to). I like to be explicit in my sample code, though, because not all Java developers might know these details.
Furthermore, currently the AspectJ compiler in version 1.9.6 throws an error if we omit static. I have just created AspectJ issue #571104 for this problem.
I'm new to Dagger 2, trying to port a (quite) complex application to it.
We have several dependencies on 'common' libraries (shared with other projects). Those 'common' libraries sometimes depend on other 'common' libraries. Each library exposes a module.
An example:
#Module
public class JsonModule {
#Provides
public Mapper provideMapper(ObjectMapper objectMapper) {
return new DefaultMapper(objectMapper);
}
#Provides
public ObjectMapper provideObjectMapper() {
return ObjectMapperFactory.build();
}
}
Our HttpModule depends on the JsonModule:
#Module(includes = {JsonModule.class})
public class HttpModule {
public HttpHelper provideHttpHelper(ObjectMapper objectMapper) {
return new DefaultHttpHelper(objectMapper);
}
}
Finally in my application, I depend on both these modules:
#Module(includes = {JsonModule.class, HttpModule.class})
public class MyAppModule {
public Service1 provideService1(ObjectMapper objectMapper) {
return new DefaultService1(objectMapper);
}
public Service2 provideService2(Mapper mappper) {
return new DefaultService2(mappper);
}
}
I then have 1 component that depends on my MyAppModule:
#Component(modules = MyAppModule.class)
#Singleton
public interface MyAppComponent {
public Service2 service2();
}
Unfortunately, when I compile the project, I get a Dagger compiler error:
[ERROR] com.company.json.Mapper is bound multiple times:
[ERROR] #Provides com.company.json.Mapper com.company.json.JsonModule.provideMapper(com.company.json.ObjectMapper)
[ERROR] #Provides com.company.json.Mapper com.company.json.JsonModule.provideMapper(com.company.json.ObjectMapper)
What am I doing wrong? Is it wrong to depend on a module twice in the same dependency graph?
In your MyAppModule you shouldn't include JsonModule, it is included by dagger implicitly. When including HttpModule dagger will automatically include all modules which HttpModule includes (in your case that is JsonModule).
It seems like the problem is related to our project's situation:
the common projects combine Groovy and Java
the common projects are built using Gradle
the application project combines Groovy and Java
the application project was built using Maven and the groovy-eclipse-compiler
Basicly: I blame the groovy-eclipse-compiler for now. I converted the project to Gradle, and everything works now.
I am trying to use the custom styling as shown here (https://code.google.com/p/mgwt/wiki/Styling):
public class MGWTColorTheme implements MGWTTheme {
private MGWTClientBundle bundle;
public MGWTColorTheme() {
if (MGWT.getOsDetection().isIOs()) {
if (MGWT.getOsDetection().isRetina()) {
bundle = (MGWTColorBundleRetina) GWT.create(MGWTColorBundleRetina.class);
} else {
bundle = (MGWTColorBundleNonRetina) GWT.create(MGWTColorBundleNonRetina.class);
}
} else {
bundle = (MGWTColorBundleNonRetina) GWT.create(MGWTColorBundleNonRetina.class);
}
}
#Override
public MGWTClientBundle getMGWTClientBundle() {
return bundle;
}
}
and
MGWTStyle.setTheme(new MGWTColorTheme());
When I load my app I get the following error:
Rebinding com.googlecode.mgwt.ui.client.theme.mgwt.MGWTColorBundleNonRetina
Invoking generator com.google.gwt.resources.rebind.context.InlineClientBundleGenerator
Creating assignment for getButtonBarCss()
Replacing CSS class names
The following unobfuscated classes were present in a strict CssResource:
text
Fix by adding String accessor method(s) to the CssResource interface for obfuscated classes, or using an #external declaration for unobfuscated classes.
This looks like you are using a broken theme which has css classes present in the css files that are not declared in the java interfaces.
If you want to get started with mgwt styling you can easily clone the themebase project and start from there:
https://code.google.com/p/mgwt/source/checkout?repo=themebase
I'm trying to create my custom TabLayoutPanel extension, my code is following:
public class ExpandableTabLayoutPanel extends TabLayoutPanel {
#UiConstructor
public ExpandableTabLayoutPanel(double barHeight, Unit barUnit) {
super(barHeight, barUnit);
addExpandableBehaviour();
}
private addExpandableBehaviour(){
//...
}
}
And here I invoke it from UIBinder:
<a:ExpandableTabLayoutPanel barHeight="20" barUnit="PX">
<a:tab>
<a:header>header</a:header>
<a:AdvancedRichTextArea styleName="{style.area}" ui:field="area"/>
</a:tab>
</a:ExpandableTabLayoutPanel>
(I was forced by error messages to use a:tab/a:header instead of g:tab/g:header even if I don't have tab and header defined in my a: package/workspace, but that's probably not the issue)
If #UiConstructor annotation is present over ExpandableTabLayoutPanel like in the listing, I'm getting strange error:
[ERROR] [gwtreproduce] - <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> missing required attribute(s): arg1 barHeight Element <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> (:13)
When I disable #UiConstructor, I'm getting even stranger error:
[ERROR] [gwtreproduce] - Errors in 'generated://E6338B946DFB2D28988DA492134093C7/reproduce/client/TestView_TestViewUiBinderImpl.java' : [ERROR] [gwtreproduce] - Line 33: Type mismatch: cannot convert from TabLayoutPanel to ExpandableTabLayoutPanel
What am I doing wrong with extending TabLayoutPanel?
And side question: how it is possible that TabLayoutPanel constructor isn't annotated with #UiConstructor and can be used in UiBinder (how UiBinder knows which constructor to invoke)?
for you side question : you have to add (provided=true) to the UiField annotation of your widget. Then in the code, set the instance yourself, before createAndBindUi() call like this :
class Whaoo extends Composite{
/* with 'provided', UiBinder don't call any constructor */
#UiField(provided = true)
final Great foo;
interface WhaooUiBinder extends
UiBinder<Widget, Whaoo> {}
private static WhaooUiBinder uiBinder =
GWT.create(WhaooUiBinder.class);
public Whaoo() {
// initialize "provided" before createAndBindUi call
foo = new Great(String bar, int pouet);
initWidget(uiBinder.createAndBindUi(this));
}
}
every one!
I'm having a compilation problem in my GWT app which is divided in 3 modules:
App-core: containing the main classes without an entry point,
App-A and App-B: inherit from App-core, and containing there specific classes with an entry point in each submodule.
I'm using GIN to inject classes instances in every module:
in App-core:
public interface App-coreGinjector extends Ginjector {
EventBus getEventBus();
Provider<LoginPagePresenter> getLoginPagePresenter();
...
}
App-coreModule extends AbstractPresenterModule {
protected void configureCore() {
install(new DefaultModule(App-corePlaceManager.class));
bindConstant().annotatedWith(DefaultPlace.class).to(LoginPagePresenter.NAME_TOKEN);
...
bind(AuthenticationManager.class).to(AuthenticationManagerImpl.class);
bindPresenter(LoginPagePresenter.class, LoginPagePresenter.MyView.class,
LoginPageView.class, LoginPagePresenter.MyProxy.class);
}
in App-A:
#GinModules({ App-AModule.class })
public interface App-AGinjector extends App-coreGinjector {
MyApp-AScreen getMyApp-AScreen();
...
}
public class App-AModule extends App-coreModule {
#Override
protected void configure() {
configureCore();
...
//Here we bind the App-A classes inheriting from App-core classes
bind(App-coreScreenManager.class).to(App-AcreenManager.class).in(Singleton.class);
...
//Here we bind the specific App=A classes
}
And we do the same thing in App-B
The maven compilation is successful for the App-A, but it fail for the App-B, with this message:
[ERROR] Errors in 'C:\workspace\App-core\client\gin\App-coreGinjectorImpl.java'
[ERROR] Line 790: Rebind result 'com.gwtplatform.mvp.client.proxy.PlaceManager' must be a class
[ERROR] Line 818: Rebind result 'lu.sfeir.grh.client.authentication.AuthenticationManager' must be a class
[ERROR] Line 1047: Rebind result 'lu.sfeir.grh.client.login.LoginPagePresenter.MyView' must be a class
[ERROR] Line 2359: Rebind result 'com.google.gwt.event.shared.EventBus' cannot be abstract
[ERROR] Cannot proceed due to previous errors
So the weird part int all this is that this error come from the shared module between these two submodules, witch is the binding of the LoginPagePresenter and the AuthentificationManager, but we have this compilation error just in one sub module.
So if someone had this king of problems I'm waiting for his precious help ^^
Ah! if you want some precisions , don't be shy!!
In GWTP 0.7 and all EventBus instances are changed from
com.google.gwt.event.shared.EventBus;
to
com.google.web.bindery.event.shared.EventBus
If you are using GWTP 0.6 you have to change them back...