コード例 #1
0
  @Override
  protected void setup() {
    // Multiselect
    Table t = new Table("Multiselect");
    addComponent(t);
    t.setSelectable(false);
    t.setMultiSelect(true);
    t.setPageLength(5);
    t.addContainerProperty("Name", String.class, null);
    Set<Object> selected = new HashSet<>();
    for (int i = 0; i < 30; i++) {
      Item item = t.addItem(i);
      item.getItemProperty("Name").setValue("Name " + i);
      if (i % 2 == 0) {
        selected.add(i);
      }
    }
    t.setValue(selected);

    // Singleselect
    t = new Table("Singleselect");
    addComponent(t);
    t.setSelectable(false);
    t.setMultiSelect(false);
    t.setPageLength(5);
    t.addContainerProperty("Name", String.class, null);
    for (int i = 0; i < 30; i++) {
      Item item = t.addItem(i);
      item.getItemProperty("Name").setValue("Name " + i);
    }
    t.setValue(3);
  }
  private void blinkTable() {
    final Table table = new Table();
    table.setPageLength(5);
    table.addContainerProperty(new Object(), String.class, null);

    for (int i = 0; i < 50; i++) {
      table.addItem(new Object[] {"Row"}, new Object());
    }

    System.out.println("adding component");
    addComponent(table);

    new Thread() {
      @Override
      public void run() {
        getSession().lock();
        try {
          Thread.sleep(500);
          access(
              new Runnable() {
                @Override
                public void run() {
                  System.out.println("removing component");
                  removeComponent(table);
                  button.setCaption(SUCCESS_CAPTION);
                }
              });
        } catch (InterruptedException e) {
          e.printStackTrace();
        } finally {
          getSession().unlock();
        }
      }
    }.start();
  }
コード例 #3
0
  @Override
  protected void setup(VaadinRequest request) {
    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();

    final Table table = new Table();
    table.setColumnReorderingAllowed(true);
    table.setSizeFull();

    BeanItemContainer<TestItem> cont = new BeanItemContainer<>(TestItem.class);

    for (int i = 0; i < ROW_COUNT; i++) {
      TestItem ti = new TestItem();
      ti.setValue1("Value1_" + i);
      ti.setValue2("Value2_" + (ROW_COUNT - i));
      ti.setValue3("Value3_" + i);
      ti.setValue4("Value4_" + (ROW_COUNT - i));
      ti.setValue5("Value5_" + i);
      cont.addBean(ti);
    }

    table.setContainerDataSource(cont);
    table.setImmediate(true);
    table.setSelectable(true);
    table.setMultiSelect(false);

    table.setPageLength(10);
    table.setDragMode(Table.TableDragMode.ROW);

    table.setDropHandler(
        new DropHandler() {
          @Override
          public void drop(DragAndDropEvent dragAndDropEvent) {}

          @Override
          public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
          }
        });

    table.addColumnReorderListener(
        new ColumnReorderListener() {

          @Override
          public void columnReorder(ColumnReorderEvent event) {
            System.out.println("columnReorder");
          }
        });

    table.addHeaderClickListener(
        new HeaderClickListener() {

          @Override
          public void headerClick(HeaderClickEvent event) {
            System.out.println("Header was clicked");
          }
        });

    layout.addComponent(table);

    addComponent(layout);
  }