Jackson Tale Jackson Tale - 1 month ago 7
Java Question

gwt - How does the inheritance work in gwt?

Forgive me if my question is too naive as I just started working with gwt.

I create a

gwt module
(let's say
) which has a number of DataGrid, buttons, etc. It works fine in the web page.

Then I am about to create the 2nd gwt module

They will not be on the same page ever, however,
is very similar with
as it just has an extra table and a button.

Now of course, I don't want to copy/paste code from
. Instead, I wish to reuse the code from Editor_A.

How can I do that?

How can I inherit from Editor_A and reuse most of its code with some modification to produce Editor_B?


This can solve your problem: You can create an additional Core module, which is responsible for your base custom widgets, Client-Side Utils etc. Then you should inherit Core module in your both modules. So in your case you can create Composite widget which is used by Editor_A, then in your latter module you can create your Editor_B by inheriting from Editor_A. And of course you can add some modifications to that from Editor_B class.

If you are using they in the same module, you can create one BaseEditor which is Editor_A in your case. And then:

public class Editor_B extends Editor_A{
    public Editor_B(){

    private void draw(){
   // here, add your extra table and button, to panel which're protected(public)

Apart from Java Inheritance be sure to configure GWT modules in the appropriate way, else the GWT Java to Javascript compiler will not find the relevant classes. Do this by modifying the module XML configuration to be something like this:

   <inherits name='com.google.gwt.user.User'/>
   <source path="widgets"/>