123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- package com.vaadin.tests.components;
-
- import java.util.Arrays;
-
- import com.vaadin.data.Property.ValueChangeEvent;
- import com.vaadin.data.Property.ValueChangeListener;
- import com.vaadin.ui.AbsoluteLayout;
- import com.vaadin.ui.Button;
- import com.vaadin.ui.Button.ClickEvent;
- import com.vaadin.ui.GridLayout;
- import com.vaadin.ui.HasComponents.ComponentAttachEvent;
- import com.vaadin.ui.HasComponents.ComponentAttachListener;
- import com.vaadin.ui.Label;
- import com.vaadin.ui.Notification;
- import com.vaadin.ui.OptionGroup;
- import com.vaadin.ui.VerticalLayout;
-
- public class LayoutAttachListenerInfo extends TestBase {
-
- private VerticalLayout content = new VerticalLayout();
-
- @Override
- protected void setup() {
-
- OptionGroup layouts = new OptionGroup("Layouts",
- Arrays.asList("AbsoluteLayout", "OrderedLayout", "GridLayout"));
- layouts.select("AbsoluteLayout");
- layouts.setImmediate(true);
- layouts.addValueChangeListener(new ValueChangeListener() {
- @Override
- public void valueChange(ValueChangeEvent event) {
- if (event.getProperty().getValue().equals("AbsoluteLayout")) {
- testAbsoluteLayout();
- } else if (event.getProperty().getValue()
- .equals("OrderedLayout")) {
- testOrderedLayout();
- } else if (event.getProperty().getValue()
- .equals("GridLayout")) {
- testGridLayout();
- }
- }
- });
-
- addComponent(layouts);
- addComponent(content);
-
- testAbsoluteLayout();
- }
-
- @Override
- protected String getDescription() {
- return "When pressing the attach button a Label with the value \"X\" "
- + "should get added to the selected layout and a notification of the position"
- + " of the component should be visible";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return 6368;
- }
-
- private void testAbsoluteLayout() {
- content.removeAllComponents();
-
- final AbsoluteLayout a = new AbsoluteLayout();
- a.setWidth("300px");
- a.setHeight("300px");
- a.addComponentAttachListener(new ComponentAttachListener() {
- @Override
- public void componentAttachedToContainer(
- ComponentAttachEvent event) {
- AbsoluteLayout layout = (AbsoluteLayout) event.getContainer();
- AbsoluteLayout.ComponentPosition position = layout
- .getPosition(event.getAttachedComponent());
-
- getMainWindow().showNotification(
- "Attached to " + position.getCSSString(),
- Notification.TYPE_ERROR_MESSAGE);
- }
- });
- content.addComponent(a);
-
- content.addComponent(new Button("Attach label to layout",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- a.addComponent(new Label("X"), "top:50px;left:50px");
- }
- }));
- }
-
- private void testOrderedLayout() {
- content.removeAllComponents();
-
- final VerticalLayout v = new VerticalLayout();
- v.setWidth("300px");
- v.setHeight("300px");
- v.addComponentAttachListener(new ComponentAttachListener() {
- @Override
- public void componentAttachedToContainer(
- ComponentAttachEvent event) {
- VerticalLayout layout = (VerticalLayout) event.getContainer();
- getMainWindow().showNotification(
- "Attached to index " + layout.getComponentIndex(
- event.getAttachedComponent()),
- Notification.TYPE_ERROR_MESSAGE);
- }
- });
- content.addComponent(v);
-
- content.addComponent(new Button("Attach label to layout",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- v.addComponent(new Label("X"));
-
- }
- }));
- }
-
- private void testGridLayout() {
- content.removeAllComponents();
-
- final GridLayout g = new GridLayout(4, 4);
- g.setWidth("300px");
- g.setHeight("300px");
- g.setHideEmptyRowsAndColumns(true);
- g.addComponentAttachListener(new ComponentAttachListener() {
- @Override
- public void componentAttachedToContainer(
- ComponentAttachEvent event) {
- GridLayout layout = (GridLayout) event.getContainer();
- GridLayout.Area area = layout
- .getComponentArea(event.getAttachedComponent());
- getMainWindow().showNotification(
- "Attached to " + area.getColumn1() + ","
- + area.getRow1(),
- Notification.TYPE_ERROR_MESSAGE);
- }
- });
-
- content.addComponent(g);
-
- content.addComponent(new Button("Attach label to layout",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- g.addComponent(new Label("X"), 2, 3);
- }
- }));
- }
- }
|