Exemplo n.º 1
0
  @SuppressWarnings("serial")
  private Component getTable() {
    List<UserOprYayasan> lm = GenericPersistence.findList(UserOprYayasan.class);

    dashboardPanels = new VerticalLayout();
    dashboardPanels.addStyleName("dashboard-panels");
    Responsive.makeResponsive(dashboardPanels);
    beans.setBeanIdProperty("id");
    beans.removeAllItems();
    if (lm != null) {
      beans.addAll(lm);
    } else {
      beans.addBean(new UserOprYayasan());
    }

    tabel.addGeneratedColumn(
        "aksi",
        new ColumnGenerator() {
          @Override
          public Object generateCell(Table source, Object itemId, Object columnId) {
            HorizontalLayout hl = new HorizontalLayout();
            Button edit = new Button(FontAwesome.EDIT);
            Button hapus = new Button(FontAwesome.TRASH_O);
            edit.addStyleName(ValoTheme.BUTTON_FRIENDLY);
            edit.addStyleName(ValoTheme.BUTTON_SMALL);
            hapus.addStyleName(ValoTheme.BUTTON_FRIENDLY);
            hapus.addStyleName(ValoTheme.BUTTON_SMALL);
            BeanItem<?> i = (BeanItem<?>) source.getContainerDataSource().getItem(itemId);
            final UserOprYayasan o = (UserOprYayasan) i.getBean();
            edit.addClickListener(
                new ClickListener() {
                  @Override
                  public void buttonClick(ClickEvent event) {
                    tambahUserYayasanbaru(o);
                  }
                });
            hl.addComponent(edit);
            hl.addComponent(hapus);
            return hl;
          }
        });
    tabel.setSizeFull();
    tabel.setImmediate(true);
    tabel.setSelectable(true);
    tabel.setContainerDataSource(beans);
    tabel.setRowHeaderMode(Table.RowHeaderMode.INDEX);
    tabel.setColumnHeader("useNnama", "NAMA PENGGUNA");
    tabel.setColumnHeader("nama", "NAMA");
    tabel.setColumnHeader("realName", "NAMA LENGKAP");
    tabel.setColumnHeader("registerDate", "TANGGAL REGISTRASI");
    tabel.setColumnHeader("email", "E-MAIL");
    tabel.setColumnHeader("lastSuccessfulLogin", "TERAKHIR LOGIN");
    tabel.setColumnHeader("aksi", "AKSI");
    tabel.setVisibleColumns(
        "aksi", "nama", "realName", "registerDate", "email", "lastSuccessfulLogin");
    dashboardPanels.addComponent(tabel);
    return dashboardPanels;
  }
Exemplo n.º 2
0
  @Override
  protected void init(VaadinRequest request) {
    setSizeFull();

    VerticalLayout layout = new VerticalLayout();

    List<Aircraft> message = aircraftService.list();
    Label label = new Label(message.toString());
    final TextField field = new TextField();
    Button button = new Button();

    button.addClickListener(
        new Button.ClickListener() {
          @Override
          public void buttonClick(Button.ClickEvent clickEvent) {
            aircraftService.create(field.getValue());
          }
        });
    HorizontalLayout fieldPanel = new HorizontalLayout();
    fieldPanel.addComponent(field);
    fieldPanel.addComponent(button);
    fieldPanel.addComponent(label);

    Table table = new Table();
    table.setRowHeaderMode(Table.RowHeaderMode.ID);
    table.setSizeFull();

    final BeanItemContainer<Booking> container = new BeanItemContainer<Booking>(Booking.class);
    container.addAll(bookingService.list());
    container.addNestedContainerProperty("flight.flightNumber");
    container.removeContainerProperty("flight");
    table.setContainerDataSource(container);

    HorizontalLayout toolbar = new HorizontalLayout();
    Button addButton = new Button("Add");
    addButton.addClickListener(
        new Button.ClickListener() {

          @Override
          public void buttonClick(Button.ClickEvent clickEvent) {
            FormLayout formLayout = new FormLayout();

            // Form for editing the bean
            final BeanFieldGroup<Booking> binder = new BeanFieldGroup<Booking>(Booking.class);
            binder.setBuffered(true);
            final Booking bean = new Booking();
            bean.setFlight(new Flight());
            binder.setItemDataSource(bean);
            formLayout.addComponent(binder.buildAndBind("Ticket", "ticket"));
            formLayout.addComponent(binder.buildAndBind("Flight Nr.", "flight.flightNumber"));

            Button save = new Button("Save");
            save.addClickListener(
                new Button.ClickListener() {
                  @Override
                  public void buttonClick(Button.ClickEvent event) {
                    try {
                      binder.commit();
                      container.addBean(bean);
                    } catch (FieldGroup.CommitException e) {
                      throw new RuntimeException(e.getMessage());
                    }
                  }
                });
            formLayout.addComponent(save);

            UI.getCurrent().addWindow(new Window("Edit Booking", formLayout));
          }
        });
    toolbar.addComponent(addButton);

    layout.addComponent(fieldPanel);
    layout.addComponent(toolbar);
    layout.addComponent(table);

    UI.getCurrent()
        .setErrorHandler(
            new ErrorHandler() {
              @Override
              public void error(com.vaadin.server.ErrorEvent event) {
                Notification.show(
                    event.getThrowable().getLocalizedMessage(), Notification.Type.ERROR_MESSAGE);
              }
            });
    setContent(layout);
  }