Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8862981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:51:41+00:00 2026-06-14T15:51:41+00:00

Let’s say I have an object hierarchy like this: Account > Site > Supply

  • 0

Let’s say I have an object hierarchy like this:

Account > Site > Supply

An Account is an actual company, a Site is a building they have, and a Supply is either an ElecSupply or GasSupply. Supply is never instantiated and could be an abstract class in theory.

I am using Objectify for persistence, and have a page that displays the list of Supplies for each Site, regardless of whether they are an ElecSupply or GasSupply.

Now I am implementing the GWT Editor Framework and have come up against a problem with this polymorphic entity. How do I implement an Editor and set of sub-editors for an object like this?

@Entity
public class Supply implements Serializable
{
    @Id
    protected Long id;
    @Embedded
    protected List<BillingPeriod> billingPeriods = new ArrayList<BillingPeriod>();

    public Supply()
    {

    }
// ...
}

The subclasses: (ElecSupply has 5 unique fields and GasSupply has just one)

@Subclass
public class ElecSupply extends Supply implements Serializable
{
    private String profile;
    private String mtc;
    private String llf;
    private String area;
    private String core;

    public ElecSupply()
    {

    }
}

@Subclass
public class GasSupply extends Supply implements Serializable
{
    private String mpr;

    public GasSupply()
    {

    }
// ...
}

So I would like to know if anyone has any experience with this kind of structure? I have tried to make separate editors for ElecSupply and GasSupply, and then show or hide them as part of the edit page.

The other way I was thinking about doing it would be to have a single editor (for Supply), and then load different sub-editors depending on which type of object we are editing.

Any light shed will be gratefully received.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:51:43+00:00Added an answer on June 14, 2026 at 3:51 pm

    I’ve already been in this case, and I’ve implemented the following solution :

    • First create an generic utilitary class named AbstractSubTypeEditor which will activate a specific editor when you edit one of your subclass object :

      import com.google.gwt.editor.client.CompositeEditor;
      import com.google.gwt.editor.client.Editor;
      import com.google.gwt.editor.client.EditorDelegate;
      import com.google.gwt.editor.client.LeafValueEditor;
      
      public abstract class AbstractSubTypeEditor<T, C extends T, E extends Editor<C>> implements CompositeEditor<T, C, E>, LeafValueEditor<T> {
              private EditorChain<C, E> chain;
              private T currentValue;
              private final E subEditor;
      
              /**
               * Construct an AbstractSubTypeEditor backed by the given sub-Editor.
               *
               * @param subEditor the sub-Editor that will be attached to the Editor
               *          hierarchy
               */
              public AbstractSubTypeEditor(E subEditor) {
                      this.subEditor = subEditor;
              }
      
              /**
               * Returns the sub-Editor that the OptionalFieldEditor was constructed
               * with.
               *
               * @return an {@link Editor} of type E
               */
              public E createEditorForTraversal() {
                      return subEditor;
              }
      
              public void flush() {
                      currentValue = chain.getValue(subEditor);
              }
      
              /**
               * Returns an empty string because there is only ever one sub-editor used.
               */
              public String getPathElement(E subEditor) {
                      return "";
              }
      
              public T getValue() {
                      return currentValue;
              }
      
              public void onPropertyChange(String... paths) {
              }
      
              public void setDelegate(EditorDelegate<T> delegate) {
              }
      
              public void setEditorChain(EditorChain<C, E> chain) {
                      this.chain = chain;
              }
      
              public void setValue(T value, boolean instanceOf) {
                      if (currentValue != null && value == null) {
                              chain.detach(subEditor);
                      }
                      currentValue = value;
                      if (value != null && instanceOf) {
                              chain.attach((C)value, subEditor);
                      }
              }
      }
      
    • Now you can create an Editor for Supply, containing two sub-editors and two AbstractSubTypeEditor (one for each of your subtypes) :

      public class SupplyEditor extends Composite implements Editor<Supply> {
      
              public class ElecSupplyEditor implements Editor<ElecSupply> {
                      public final TextBox profile = new TextBox();
                      public final TextBox mtc = new TextBox();
                      public final TextBox llf = new TextBox();
                      public final TextBox area = new TextBox();
                      public final TextBox core = new TextBox();
              }
              @Ignore
              final ElecSupplyEditor elecSupplyEditor = new ElecSupplyEditor();
              @Path("")
              final AbstractSubTypeEditor<Supply, ElecSupply, ElecSupplyEditor> elecSupplyEditorWrapper = new AbstractSubTypeEditor<Supply, ElecSupply, SupplyEditor.ElecSupplyEditor>(elecSupplyEditor) {
                      @Override
                      public void setValue(final Supply value) {
                              setValue(value, value instanceof ElecSupply);
                              if (!(value instanceof ElecSupply)) {
                                      elecSupplyEditor.profile.setVisible(false);
                                      elecSupplyEditor.mtc.setVisible(false);
                                      elecSupplyEditor.llf.setVisible(false);
                                      elecSupplyEditor.area.setVisible(false);
                                      elecSupplyEditor.core.setVisible(false);
                              } else {
                                      elecSupplyEditor.profile.setVisible(true);
                                      elecSupplyEditor.mtc.setVisible(true);
                                      elecSupplyEditor.llf.setVisible(true);
                                      elecSupplyEditor.area.setVisible(true);
                                      elecSupplyEditor.core.setVisible(true);
                              }
                      }
              };
      
              public class GasSupplyEditor implements Editor<GasSupply> {
                      public final TextBox mpr = new TextBox();
              }
              @Ignore
              final GasSupplyEditor gasSupplyEditor = new GasSupplyEditor();
              @Path("")
              final AbstractSubTypeEditor<Supply, GasSupply, GasSupplyEditor> gasSupplyEditorWrapper = new AbstractSubTypeEditor<Supply, GasSupply, SupplyEditor.GasSupplyEditor>(gasSupplyEditor) {
                      @Override
                      public void setValue(final Supply value) {
                              setValue(value, value instanceof GasSupply);
                              if (!(value instanceof GasSupply)) {
                                      gasSupplyEditor.mpr.setVisible(false);
                              } else {
                                      gasSupplyEditor.mpr.setVisible(true);
                              }
                      }
              };
      
              public SupplyEditor () {
                      final VerticalPanel page = new VerticalPanel();
                      page.add(elecSupplyEditor.profile);
                      page.add(elecSupplyEditor.mtc);
                      page.add(elecSupplyEditor.llf);
                      page.add(elecSupplyEditor.area);
                      page.add(elecSupplyEditor.code);
                      page.add(gasSupplyEditor.mpr);
                      initWidget(page);
              }
      }
      

    This should show/hide your fields according to the subclass you are editing, and bind the properties to the good fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have this code: <p dataname=description> Hello this is a description. <a
Let's say I have some text as follows: do this, do that, then this,
Let's suppose that we have multi-site CMS and every website in this CMS having
Let's suppose I have an XML file like this: <?xml version=1.0 encoding=ISO-8859-1?> <MIDIFile> <Event>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.