Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage of custom grid #96

Closed
stefanuebe opened this issue Mar 29, 2022 · 3 comments
Closed

Allow usage of custom grid #96

stefanuebe opened this issue Mar 29, 2022 · 3 comments

Comments

@stefanuebe
Copy link

Currently the model uses an instance of GridEx, which seems not to add any additional functionality. We would like to use a SelectionGrid instead (or some other custom grid, which provides additional functionality).

To allow that, the simples solution would be to use the normal Grid instead of GridEx and add a "createGrid" method to the base class, which can be overridden by any subclass.

Something like this:

  public TwinColGrid(final ListDataProvider<T> dataProvider, String caption) {
    available = new TwinColModel<>(createGrid(true), "twincol-grid-available");
    selection = new TwinColModel<>(createGrid(false),"twincol-grid-selection");
    ...
  }

  protected Grid<T> createGrid(boolean available) {
     return new GridEx<>();
  }

    private static final class TwinColModel<T> implements Serializable {
      final Grid<T> grid;
      ...

      TwinColModel(String className, Grid<T> grid) {
         this.grid = grid;
      }
@javier-godoy javier-godoy self-assigned this Mar 29, 2022
@javier-godoy javier-godoy added this to Inbox (needs triage) in Flowing Code Addons (legacy) via automation Mar 29, 2022
@javier-godoy
Copy link
Member

Makes sense.

@javier-godoy
Copy link
Member

Currently the model uses an instance of GridEx, which seems not to add any additional functionality

GridEx is used for "publishing" the protected method createSortingComparator which is required in order to support ordered values (#66) because this addon is compatible with Vaadin 14+ and thus we cannot use ListDataView. I'll duplicate the code from Grid::createSortingComparator as that preserves the current behavior. (createSortingComparator is not final, thus it's possible that a subclass of Grid want to override it, although it doesn't seem likely).

Add a "createGrid" method to the base class, which can be overridden by any subclass.

That approach entails calling overridable methods from the constructor (see https://stackoverflow.com/a/3404369/1297272).
Instead, I'll add a constructor that receives a Supplier<Grid<T>> (the same supplier instantiates both grids) and another constructor that receives two Grid<T> instances (one for each side).

@javier-godoy
Copy link
Member

Released in v2.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants