Exemplo n.º 1
0
  @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());
  }
Exemplo n.º 2
0
  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();
  }
Exemplo n.º 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();
  }
Exemplo n.º 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)));
  }
Exemplo n.º 5
0
 public void edit(ClickEvent e) {
   edit(list.getValue());
 }
Exemplo n.º 6
0
 protected void adjustActionButtonState() {
   boolean hasSelection = list.getValue() != null;
   edit.setEnabled(hasSelection);
   delete.setEnabled(hasSelection);
 }
Exemplo n.º 7
0
 public void remove(ClickEvent e) {
   clientRepository.delete(list.getValue());
   list.setValue(null);
   listEntities();
 }
Exemplo n.º 8
0
 private void listPayees(String filterString) {
   payeeTable.setBeans(new ArrayList<>(service.findByName(filterString)));
 }
Exemplo n.º 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");
 }