123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- package com.vaadin.tests.components.table;
-
- import java.text.DecimalFormat;
-
- import com.vaadin.tests.components.AbstractTestCase;
- import com.vaadin.ui.Button;
- import com.vaadin.ui.HorizontalLayout;
- import com.vaadin.ui.HorizontalSplitPanel;
- import com.vaadin.ui.Label;
- import com.vaadin.ui.LegacyWindow;
- import com.vaadin.ui.VerticalLayout;
- import com.vaadin.v7.ui.Table;
-
- public class TableToggleVisibility extends AbstractTestCase {
-
- private static final int[] LENGTHS = { 20, 22, 10 };
-
- @Override
- public void init() {
-
- DecimalFormat format = new DecimalFormat("000");
- Table[] tables = new Table[3];
- Button[] buttons = new Button[3];
-
- VerticalLayout leftComponent = new VerticalLayout();
- leftComponent.setMargin(true);
- leftComponent.setSpacing(true);
-
- // Toolbar with buttons to hide or show lists
-
- HorizontalLayout toolBar = new HorizontalLayout();
- toolBar.setSpacing(true);
- toolBar.setMargin(true);
-
- leftComponent.addComponent(toolBar);
- leftComponent.setExpandRatio(toolBar, 0.0f);
-
- // List of trucks -----------------------
-
- tables[0] = new Table("Trucks");
- tables[0].addContainerProperty("Brand", String.class, null);
- tables[0].addContainerProperty("Model", String.class, null);
- tables[0].addContainerProperty("License Plate", String.class, null);
-
- for (int i = 1; i < LENGTHS[0]; i++) {
- tables[0].addItem(
- new Object[] { "MAN", "XYZ", "1-ABC-" + format.format(i) },
- Integer.valueOf(i));
- }
- tables[0].setPageLength(LENGTHS[0]);
-
- tables[0].setWidth("100%");
- tables[0].setHeight("100%");
- tables[0].setSelectable(true);
-
- leftComponent.addComponent(tables[0]);
- leftComponent.setExpandRatio(tables[0], 1.0f);
-
- // List of trailers ----------------------
-
- tables[1] = new Table("Trailers");
- tables[1].addContainerProperty("Type", String.class, null);
- tables[1].addContainerProperty("License Plate", String.class, null);
- for (int i = 1; i < LENGTHS[1]; i++) {
- tables[1].addItem(
- new Object[] { "Cooler", "1-QQQ-" + format.format(i) },
- Integer.valueOf(i));
- }
- tables[1].setPageLength(LENGTHS[1]);
-
- tables[1].setWidth("100%");
- tables[1].setHeight("100%");
- tables[1].setSelectable(true);
-
- leftComponent.addComponent(tables[1]);
- leftComponent.setExpandRatio(tables[1], 1.0f);
-
- // List of drivers ------------------------
-
- tables[2] = new Table("Drivers");
- tables[2].addContainerProperty("First Name", String.class, null);
- tables[2].addContainerProperty("Last Name", String.class, null);
- tables[2].addContainerProperty("HR ID", String.class, null);
- for (int i = 1; i < LENGTHS[2]; i++) {
- tables[2].addItem(
- new Object[] { "King", "Vabis", "HR-" + format.format(i) },
- Integer.valueOf(i));
- }
- tables[2].setPageLength(LENGTHS[2]);
-
- tables[2].setWidth("100%");
- tables[2].setHeight("100%");
- tables[2].setSelectable(true);
-
- leftComponent.addComponent(tables[2]);
- leftComponent.setExpandRatio(tables[2], 1.0f);
-
- leftComponent.setWidth("100%");
-
- HorizontalSplitPanel split = new HorizontalSplitPanel();
- split.setFirstComponent(leftComponent);
-
- VerticalLayout rightComponent = new VerticalLayout();
- rightComponent.setMargin(true);
- rightComponent.addComponent(new Label("Left blank!"));
- split.setSecondComponent(rightComponent);
-
- split.setSizeFull();
-
- VerticalLayout mainLayout = new VerticalLayout();
- mainLayout.setSizeFull();
- mainLayout.addComponent(split);
- mainLayout.setExpandRatio(split, 1.0f);
-
- LegacyWindow mainWindow = new LegacyWindow("Visibilitybug Application",
- mainLayout);
- mainWindow.setSizeFull();
-
- setMainWindow(mainWindow);
-
- // complete toolbar
-
- for (int i = 0; i < buttons.length; i++) {
- buttons[i] = new ToggleButton(tables[i]);
- toolBar.addComponent(buttons[i]);
- }
-
- }
-
- // Button to switch the visibility of a table.
-
- private static class ToggleButton extends Button {
-
- private Table table;
-
- private ToggleButton(Table table) {
- this.table = table;
-
- setCaption("- " + table.getCaption());
-
- addClickListener(event -> {
- boolean wasVisible = ToggleButton.this.table.isVisible();
-
- ToggleButton.this.table.setVisible(!wasVisible);
- setCaption((wasVisible ? "+ " : "- ")
- + ToggleButton.this.table.getCaption());
- setDescription(
- (wasVisible ? "Show " : "Hide ") + "the list with "
- + ToggleButton.this.table.getCaption());
- });
- }
- }
-
- @Override
- protected String getDescription() {
- return "Test for hiding and showing tables. Click a button to show/hide one of the tables. The tables are all 100% wide and should be rendered the same way after being hidden and shown again.";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return 6494;
- }
-
- }
|