@PostConstruct
  protected void init() {
    list.setHeight(25, Unit.PERCENTAGE);
    addComponent(
        new MVerticalLayout(new MHorizontalLayout(addNew, edit, delete), list)
        // .expand(list)
        );

    listEntities();
    list.addMValueChangeListener(e -> adjustActionButtonState());
  }
  private void listEntities() {
    // A dead simple in memory listing would be:
    list.setBeans(clientRepository.findAll());

    // Lazy binding with SortableLazyList: memory and query efficient
    // connection from Vaadin Table to Spring Repository
    // Note that fetching strategies can be given to MTable constructor as well.
    // Use this approach if you expect you'll have lots of data in your
    // table.

    /*list.setBeans(new SortableLazyList<>(
            // entity fetching strategy
            (firstRow, asc, sortProperty) -> clientRepository.findAllBy(
                    new PageRequest(
                            firstRow / PAGE_SIZE,
                            PAGE_SIZE,
                            asc ? Sort.Direction.ASC : Sort.Direction.DESC,
                            // fall back to id as "natural order"
                            sortProperty == null ? "id" : sortProperty
                    )
            ),
            // count fetching strategy
            () -> (int) clientRepository.count(),
            PAGE_SIZE
    ));*/
    adjustActionButtonState();
  }
Example #3
0
  @PostConstruct
  public void init() {

    /*
     * Add value change listener to table that opens the selected Payee into
     * an editor.
     */
    payeeTable.addMValueChangeListener(
        new MValueChangeListener<Payee>() {

          @Override
          public void valueChange(MValueChangeEvent<Payee> event) {
            editPayee(event.getValue());
          }
        });

    /*
           * Configure the filter input and hook to text change events to
           * repopulate the table based on given filter. Text change
           * events are sent to the server when e.g. user holds a tiny pause
           * while typing or hits enter.
           *
          filter.setInputPrompt("Filter Payees...");
          filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
              @Override
              public void textChange(FieldEvents.TextChangeEvent textChangeEvent) {
                  listPayees(textChangeEvent.getText());
              }
          });
    */

    /* "Responsive Web Design" can be done with plain Java as well. Here we
     * e.g. do selective layouting and configure visible columns in
     * table based on available width */
    layout();
    adjustTableColumns();
    /* If you wish the UI to adapt on window resize/page orientation
     * change, hook to BrowserWindowResizeEvent */
    UI.getCurrent().setResizeLazy(true);
    Page.getCurrent()
        .addBrowserWindowResizeListener(
            new Page.BrowserWindowResizeListener() {
              @Override
              public void browserWindowResized(
                  Page.BrowserWindowResizeEvent browserWindowResizeEvent) {
                adjustTableColumns();
                layout();
              }
            });
    listPayees();
  }
Example #4
0
  // Controller methods.
  //
  // In a big project, consider using separate controller/presenter
  // for improved testability. MVP is a popular pattern for large
  // Vaadin applications.
  private void listPayees() {
    // filtered by authorized user from Bluemix SSO
    try {
      Subject s = WSSubject.getCallerSubject();

      if (s != null) {
        Set<Principal> principals = s.getPrincipals();
        if (principals != null && principals.size() > 0) {
          authname = principals.iterator().next().getName();
        }
      }

    } catch (Exception exc) {
      authname = "bad stuff";
    }
    tservice.updateTransactions(authname);
    payeeTable.setBeans(new ArrayList<>(service.findByName(authname)));
  }
 public void edit(ClickEvent e) {
   edit(list.getValue());
 }
 protected void adjustActionButtonState() {
   boolean hasSelection = list.getValue() != null;
   edit.setEnabled(hasSelection);
   delete.setEnabled(hasSelection);
 }
 public void remove(ClickEvent e) {
   clientRepository.delete(list.getValue());
   list.setValue(null);
   listEntities();
 }
Example #8
0
 private void listPayees(String filterString) {
   payeeTable.setBeans(new ArrayList<>(service.findByName(filterString)));
 }
Example #9
0
 /**
  * Similarly to layouts, we can adapt component configurations based on the client details. Here
  * we configure visible columns so that a sane amount of data is displayed for various devices.
  */
 private void adjustTableColumns() {
   payeeTable.setVisibleColumns("name", "account");
   payeeTable.setColumnHeaders("Name", "Account");
 }