Announcement Announcement Module
Collapse
No announcement yet.
Order of entities in ApplicationEntityTypesProcessor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Order of entities in ApplicationEntityTypesProcessor

    Is there any way to control the order of the entities that appear in GWT's left hand menu (proxy places list)?

    Tracing through code, I found ScaffoldApp.java's getTopPlaces() calls ApplicationEntityTypesProcessor.getAll(). However, the order of the entities in getAll() seems arbitrary -- it may be reverse of order in which entities were added. Worse, these methods return HashSet which does not guarantee iterator order will be the same over time.

    GUI design principles encourage consistent and logical arrangement of menus.

    Is there any way (perhaps an annotation) that I could use to customize the entity order?
    Unfortunately, ApplicationEntityTypesProcessor.java is one of those "DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO." files in ROO 1.1.1.

  • #2
    Modify the following class ${topLevelPackage}.client.scaffold. ScaffoldApp

    1) Change the return type of method getTopPlaces() from HashMap to List:
    2) Change definition of rtn from HashMap to List and change instance from hHshMap to ArrayList.
    3) Apply sort() method to types in for loop.
    protected List<ProxyListPlace> getTopPlaces() {
    Set<Class<? extends EntityProxy>> types = ApplicationEntityTypesProcessor.getAll();
    List<ProxyListPlace> rtn = new ArrayList<ProxyListPlace>(types.size());

    for (Class<? extends EntityProxy> type : sort(types)) {
    rtn.add(new ProxyListPlace(type));
    }

    return rtn;
    }
    4) Add static comparator to ScaffoldApp class:

    private static final Comparator<Class<? extends EntityProxy>> COMP =
    new Comparator<Class<? extends EntityProxy>>() {
    private final Map<Class<? extends EntityProxy>, Integer> MAP = new HashMap<Class<? extends EntityProxy>, Integer>();
    {
    // Populate MAP with you own proxy classes.
    MAP.put(AnimalProxy.class, 0);
    MAP.put(ExhibitProxy.class, 1);
    MAP.put(KeeperProxy.class, 2);
    }
    @Override
    public int compare(Class<? extends EntityProxy> p1, Class<? extends EntityProxy> p2) {
    return MAP.get(p1).compareTo(MAP.get(p2));
    }
    };
    5) Add sort method to ScaffoldApp class:
    private Set<Class<? extends EntityProxy>> sort(Set<Class<? extends EntityProxy>> in) {
    Set<Class<? extends EntityProxy>> out = new TreeSet<Class<? extends EntityProxy>>(COMP);
    out.addAll(in);
    return out;
    }
    This will now sort you entities in the left hand menu.

    Enjoy.

    Comment


    • #3
      Or simply replace the getTopPlaces() method in ${topLevelPackage}.client.scaffold.ScaffoldApp with this:
      protected List<ProxyListPlace> getTopPlaces() {
      List<ProxyListPlace> rtn = new ArrayList<ProxyListPlace>();
      rtn.add(new ProxyListPlace(AnimalProxy.class));
      rtn.add(new ProxyListPlace(ExhibitProxy.class));
      rtn.add(new ProxyListPlace(KeeperProxy.class));
      return rtn;
      }
      Remember to still change the return type of the method from HashMap to List else the order will still be random.

      Comment


      • #4
        Here the sort solution working with jsuas690 first solution :
        Code:
        	private Set<Class<? extends EntityProxy>> sort(Set<Class<? extends EntityProxy>> in) {
        		Set<Class<? extends EntityProxy>> out = new TreeSet<Class<? extends EntityProxy>>(COMP);
        		out.addAll(in);
        		return out;
        	}
        This allow to be compatible with new entities without having to change the sorting code.

        Comment

        Working...
        X