package org.corpus_tools.annis.gui.admin.reflinks;

import com.vaadin.ui.Grid;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.components.grid.HeaderRow;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.corpus_tools.annis.gui.AnnisUI;
import org.corpus_tools.annis.gui.query_references.UrlShortener;
import org.corpus_tools.annis.gui.query_references.UrlShortenerEntry;

public class ReferenceLinkEditor extends Panel {

  private static final long serialVersionUID = 6191359393713574090L;
  private final Grid<UrlShortenerEntry> grid;
  private final TextField txtFilterId;

  public ReferenceLinkEditor() {
    grid = new Grid<>(UrlShortenerEntry.class);


    grid.setSizeFull();
    HeaderRow filterRow = grid.appendHeaderRow();
    
    txtFilterId = new TextField();
    txtFilterId.setPlaceholder("Filter by UUID");
    txtFilterId.setWidthFull();
    txtFilterId.addValueChangeListener((e) -> {
      refreshItems();
    });

    filterRow.getCell("id").setComponent(txtFilterId);

  }
  
  private void refreshItems() {
    if (getUI() instanceof AnnisUI) {
      AnnisUI annisUI = (AnnisUI) getUI();
      final UrlShortener shortener = annisUI.getUrlShortener();
      Stream<UrlShortenerEntry> items = shortener.list().stream();
      if(!txtFilterId.getValue().isEmpty()) {
        items = items.filter((item) -> item.getId().toString().contains(txtFilterId.getValue()));
      }
      grid.setItems(items.collect(Collectors.toList()));

    }
  }

  @Override
  public void attach() {
    super.attach();

    
    refreshItems();
    setContent(grid);
  }

}

@@ -67,15 +67,119 @@
 din.
-ui.Grid
+data.Binder;%0Aimport com.vaadin.data.Binder.Binding;%0Aimport com.vaadin.ui.Grid;%0Aimport com.vaadin.ui.Grid.Column
 ;%0Aim
@@ -284,16 +284,83 @@
 derRow;%0A
+import java.net.URI;%0Aimport java.util.Date;%0Aimport java.util.UUID;%0A
 import j
@@ -862,59 +862,1092 @@
 d%3C%3E(
-UrlShortenerEntry.class);%0A%0A%0A    grid.setSizeFull();
+);%0A    grid.setSizeFull();%0A    %0A    Binder%3CUrlShortenerEntry%3E binder = grid.getEditor().getBinder();%0A%0A    Column%3CUrlShortenerEntry, UUID%3E idColumn = grid.addColumn(UrlShortenerEntry::getId);%0A    idColumn.setCaption(%22UUID%22);%0A    TextField txtUUID = new TextField();%0A    Binding%3CUrlShortenerEntry, String%3E idBinding =%0A        binder.bind(txtUUID, entry -%3E entry.getId().toString()%0A            , (entry, value) -%3E %7B%0A              entry.setId(UUID.fromString(value));%0A    %7D);%0A    idColumn.setEditorBinding(idBinding);%0A    Column%3CUrlShortenerEntry, Date%3E createdColumn = grid.addColumn(UrlShortenerEntry::getCreated);%0A    createdColumn.setCaption(%22Timestamp%22);%0A    Column%3CUrlShortenerEntry, String%3E ownerColumn = grid.addColumn(UrlShortenerEntry::getOwner);%0A    ownerColumn.setCaption(%22Created by%22);%0A    Column%3CUrlShortenerEntry, URI%3E temporaryColumn =%0A        grid.addColumn(UrlShortenerEntry::getTemporaryUrl);%0A    temporaryColumn.setCaption(%22Temporary URL%22);%0A    Column%3CUrlShortenerEntry, URI%3E urlColumn = grid.addColumn(UrlShortenerEntry::getUrl);%0A    urlColumn.setCaption(%22URL%22);%0A    
 %0A   
@@ -2220,12 +2220,16 @@
 ell(
-%22
 id
-%22
+Column
 ).se

Create columns manually