123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package com.vaadin.tests.components.table;
-
- import com.vaadin.data.Container;
- import com.vaadin.data.Item;
- import com.vaadin.data.Property;
- import com.vaadin.data.Property.ValueChangeEvent;
- import com.vaadin.data.util.IndexedContainer;
- import com.vaadin.server.VaadinRequest;
- import com.vaadin.tests.components.AbstractTestUI;
- import com.vaadin.ui.Button;
- import com.vaadin.ui.Button.ClickEvent;
- import com.vaadin.ui.CheckBox;
- import com.vaadin.ui.HorizontalLayout;
- import com.vaadin.ui.Table;
- import com.vaadin.ui.TextField;
- import com.vaadin.ui.VerticalLayout;
-
- public class Footer extends AbstractTestUI {
-
- @Override
- protected void setup(VaadinRequest request) {
- HorizontalLayout layout = new HorizontalLayout();
- layout.setSpacing(true);
-
- final Table table = new Table();
- table.setWidth("400px");
- table.setHeight("400px");
-
- table.setContainerDataSource(createContainer());
- table.setImmediate(true);
-
- table.setColumnCollapsingAllowed(true);
- table.setColumnReorderingAllowed(true);
-
- table.setFooterVisible(true);
-
- table.setColumnFooter("col1", "Footer1");
- table.setColumnFooter("col2", "Footer2");
- table.setColumnFooter("col3", "Footer3");
-
- table.setColumnAlignment("col2", Table.ALIGN_CENTER);
- table.setColumnAlignment("col3", Table.ALIGN_RIGHT);
-
- layout.addComponent(table);
-
- // Add some options to play with
- VerticalLayout options = new VerticalLayout();
- options.setSpacing(true);
-
- final CheckBox visible = new CheckBox("Footers Visible", true);
- visible.setImmediate(true);
- visible.addValueChangeListener(new Property.ValueChangeListener() {
- @Override
- public void valueChange(ValueChangeEvent event) {
- table.setFooterVisible(visible.getValue());
-
- }
- });
-
- options.addComponent(visible);
-
- final TextField footer1Value = new TextField(null, "Footer1");
- footer1Value.setImmediate(true);
- Button footer1Btn = new Button("Change", new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- table.setColumnFooter("col1",
- footer1Value.getValue() == null ? "" : footer1Value
- .getValue().toString());
- }
- });
- HorizontalLayout footer1 = new HorizontalLayout();
- footer1.addComponent(footer1Value);
- footer1.addComponent(footer1Btn);
- options.addComponent(footer1);
-
- final TextField footer2Value = new TextField(null, "Footer2");
- footer2Value.setImmediate(true);
- Button footer2Btn = new Button("Change", new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- table.setColumnFooter("col2",
- footer2Value.getValue() == null ? "" : footer2Value
- .getValue().toString());
- }
- });
- HorizontalLayout footer2 = new HorizontalLayout();
- footer2.addComponent(footer2Value);
- footer2.addComponent(footer2Btn);
- options.addComponent(footer2);
-
- final TextField footer3Value = new TextField(null, "Footer3");
- footer3Value.setImmediate(true);
- Button footer3Btn = new Button("Change", new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- table.setColumnFooter("col3",
- footer3Value.getValue() == null ? "" : footer3Value
- .getValue().toString());
- }
- });
- HorizontalLayout footer3 = new HorizontalLayout();
- footer3.addComponent(footer3Value);
- footer3.addComponent(footer3Btn);
- options.addComponent(footer3);
-
- layout.addComponent(options);
-
- addComponent(layout);
- }
-
- @Override
- public String getDescription() {
- return "Table with footer";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return 1553;
- }
-
- private Container createContainer() {
- IndexedContainer container = new IndexedContainer();
- container.addContainerProperty("col1", String.class, "");
- container.addContainerProperty("col2", String.class, "");
- container.addContainerProperty("col3", String.class, "");
-
- for (int i = 0; i < 100; i++) {
- Item item = container.addItem("item " + i);
- item.getItemProperty("col1").setValue("first" + i);
- item.getItemProperty("col2").setValue("middle" + i);
- item.getItemProperty("col3").setValue("last" + i);
- }
-
- return container;
- }
-
- }
|