0

Is there a possibilty to create a certain number of windows in one screen. Each window has the same layout but different content. I would like to include a filter so that I can choose which window I would like to see. Right now I have a table with four entries. For each entry one window is generated, but that looks quite messy.

final int i = this.table.size();
    for (int h = 1; h <= i; h++) {
        final Window win = new Window("Window" + h, new SecondView());
        this.getParent().getUI().addWindow(win);
    }

Edit: The Starting point is as described. I have a table with content from a database. In this table i can select multiple rows. For each row a pre-defined window should open. In this window i have textFields, that should contain the values of the matching attributes from the selected row. In order to get a better structure i want to choose which window should be visbile.

  • What's messy with this solution? Looks OK for me. I would store the windows in a list/array, so you can select the one you wish, but otherwise... – André Schild Sep 24 '19 at 07:59
  • But how do i store those windows in list/array? –  Sep 24 '19 at 08:14
  • How do you decide to show or hide a window instance ? – Conffusion Sep 24 '19 at 08:36
  • What is your actual question? the one that you ask is already answered in your own question. If I had to guess, you want a Button which when clicked opens a window for each selected row of a Grid, with content respective to that row. Is that what you want? – kscherrer Sep 24 '19 at 12:40
  • @KasparScherrer that is correct, but it's no grid, it's a table. –  Sep 24 '19 at 12:54

3 Answers3

0
final int i = this.table.size();
List<Window> windowList= new LinkedList<>();
for (int h = 1; h <= i; h++) {
    Window win = new Window("Window" + h, new SecondView());
    windowList.add(win);
}

Then later on, you can itterate the list and do addWindow(...) or removeWindow(...)with the correct window instance

André Schild
  • 4,592
  • 5
  • 28
  • 42
0

Here is what you need to do:

1) fetch the selected items from the table. Not the amount of selected items, but the actual items - instances of Person if your table is of type Person.

2) iterate over these selected items.

2.a) For each item, create a new Window and pass that item into the constructor of your SecondView, so each SecondView can show values of that item or bind inputs to this bean.

2.b) Add that window to the UI


Since I am not very accustomed to the Table class I use a newer Grid instead in my example. I'm sure the table has some API to get the selected rows - use that instead.

Button openDetailWindowsButton = new Button("Open Details", click -> {
    Set<Person> selectedItems = grid.getSelectedItems();
    for (Person selectedItem : selectedItems) {
        Window win = new Window(selectedItem.getName(), new SecondView(selectedItem));
        this.getParent().getUI().addWindow(win);
    }
});
kscherrer
  • 5,486
  • 2
  • 19
  • 59
0

Thank you for your help, but meanwhile i found another solution.

private void button_buttonClick(final Button.ClickEvent event) {

    final int i = this.table.getSelectedItems().size() - 1;
    for(int h = 0; h <= i; h++) {
        final int personId = this.table.getSelectedItems().get(h).getBean().getId();
        final Window win = new Window("Person", new SecondView(personId));
        this.getUI().addWindow(win);
    }

That's the button click event.

And here is the constructor for my SecondView

public SecondView(final int personId) {
    super();
    this.initUI();
    final Person myPerson = new PersonDAO().find(personId);
    this.fieldGroup.setItemDataSource(myPerson);
}

The one last problem that i have, is that for every selected person/row each window shows seperately. My intent was to only show one window where i can select between the different selected persons/rows.

  • another solution? that's exactly what I was saying in my answer, adapted to use table instead of grid like I said. cheeky. – kscherrer Sep 24 '19 at 13:57
  • Also, is there a reason why you only pass id of the bean and not the bean itself? you have to reload that bean from the dao again this is so redundant. just pass the bean. And Lastly, your intent to only show one window should probably be in your question. This changes everything, the whole solution. cheers – kscherrer Sep 24 '19 at 13:59
  • @KasparScherrer my mistake, of course it's just an adpated solution. You are right, this step is not necessary. What can i do regarding the multi window problem? –  Sep 24 '19 at 14:08
  • Personally, I think it's a bad idea to make the user select another time in another table to finally see what he wants to see. If the user should be able to see only 1 item at a time, then make the table single-select. If the user should see multiple items at once, then show ALL selected items' details simultaneously in your `ARView` (or show multiple windows). – kscherrer Sep 24 '19 at 14:22
  • Anyways, to answer the question, in your already defined loop don't create new window but instead collect all selected items (beans) in a list. After the loop, create ONE new Window and pass the selected item-list as parameter into the `ARView`. How you structure that ARView is up to you, I would probably go with a verticallayout that has a component for each item. – kscherrer Sep 24 '19 at 14:22