Search code examples
javaeclipsegwtgoogle-eclipse-plugin

Eclipse: Refactoring-renaming GWT uibinder java bean does not rename template ui.xml file


When using Eclipse Google plugin, when you create a gwt uibinder pair, you get a java bean file and its corresponding .ui.xml template file.

I believe I used to be able to do this in Eclipse Helios: Right-click on the java bean of a uibinder set, refactor to rename it, I could config the refactor dialog to also rename the .ui.xml template file.

Recently, I have been using Eclipse 3.7.0 and latest GPE. I am no longer able to do that. May be I forgot how to do it. Somebody please remind me how - thanks.

e.g. rename the uibinder pair

Hello.java, Hello.ui.xml

to

Bello.java, Bello.ui.xml

Perhaps, it had never been possible in the first place and I had remembered wrongly.


Solution

  • I've not noticed that capability, and I just tried it out, and renaming either the java or the ui.xml leaves you with an error until you rename the other file. Note that it isn't a given that the file.java code is mapped to file.ui.xml, since the design could use @UiTemplate to link file.java to somethingelse.ui.xml. That might be the reason for this not to work. Changing a ui.xml file name automatically like that could cause a big cascade of changes.

    But there is some refactoring.

    What the refactoring is capable of doing it tracking changes to @UiField names. If I rename (using Alt-R) a field in my file.java file that has been annotated with @UiField, the ui:field in the ui.xml file is changed as well.

    Now here's a tricky bit. Let's say I have foo.java, foo.ui.xml, and foo2.java, with foo2.java using the foo.ui.xml UI template (via the @UiTemplate annotation). The ui.xml file has a Button call bar, so each of foo.java and foo2.java have @UiField("bar") Button bar. Follow me so far?

    In Eclipse, I open foo.java, and using Alt-R I change bar to baz. The ui.xml file has its ui:field="bar" changed to ui:field="baz", and all annotations within foo.java that reference bar (such as @UiField and @UiHandler) are updated to reference baz. But the code in foo2.java is not changed, and there is now an error I need to fix. foo2.java still expects to see a button called bar inside of foo.ui.xml.

    Similarly, if I open foo2.java, and using Alt-R I change bar to baz, the ui:field="bar" in foo.ui.xml is not changed, and you now have an error.

    Not sure if any of this is documented somewhere. Maybe you vaguely remembered this refactoring.