Skip to content

Commit

Permalink
Fix resize at runtime for board (#55)
Browse files Browse the repository at this point in the history
* Remove row from board. Add docs.

Add documentation about nested rows.

* Fix resize at runtime for board
  • Loading branch information
rogozinds authored May 22, 2017
1 parent 18318d9 commit 8ae138c
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public BoardConnector() {
}
}

@Override
protected void init() {
super.init();
getLayoutManager().addElementResizeListener(getWidget().getElement(), e-> {
getWidget().redraw();
});
}

@Override
public BoardWidget getWidget() {
return (BoardWidget) super.getWidget();
Expand Down
11 changes: 11 additions & 0 deletions addon/src/main/java/com/vaadin/board/client/BoardWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ protected void add(Widget child, Element container) {
}
super.add(child, container);
}

private native void redraw(Element elem)/*-{
elem.redraw();
}-*/;

/**
* Calls the redraw of the Web Component board.
*/
public void redraw() {
this.redraw(getElement());
}
}
2 changes: 1 addition & 1 deletion addon/src/main/java/com/vaadin/board/client/RowWidget.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.vaadin.board.client;

import com.google.gwt.user.client.Element;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.FlowPanel;

public class RowWidget extends FlowPanel {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.vaadin.addon.board.testUI;

import com.vaadin.board.Board;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

public class BoardDynamicResizeUI extends AbstractTestUI {

@Override
protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
Board board = new Board();
board.setSizeFull();

Label lbl1 = new Label("Label 1");
Label lbl2 = new Label("Label 2");
Label lbl3 = new Label("Label 3");
board.addRow(lbl1, lbl2, lbl3);

Button button = new Button("resize");
button.addClickListener(e->{
board.setWidth("300px");
});
layout.addComponents(board, button);
setContent(layout);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.vaadin.addon.board.testbenchtests;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.WebElement;

import com.vaadin.addon.board.testUI.BoardDynamicResizeUI;
import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ButtonElement;

public class BoardDynamicResizeIT extends AbstractParallelTest {

@Override
protected Class<?> getUIClass() {
return BoardDynamicResizeUI.class;
}

@Test
public void basicLayout_boardTabletSize_twoRowsAndTwoItemsInRow() {
WebElement board = getDriver().findElement(By.tagName("vaadin-board"));
List<WebElement> rowChildren = board.findElements(By.xpath("//vaadin-board/vaadin-board-row/*"));
ButtonElement resizeButton = $(ButtonElement.class).caption("resize").first();
resizeButton.click();

Assert.assertEquals("Lbl1 should have same Y as the board Y coordinate",
board.getLocation().getY(), rowChildren.get(0).getLocation().getY());

Assert.assertEquals("Lbl2 should have Y == board.location + lbl1.height",
board.getLocation().getY() + rowChildren.get(0).getSize().getHeight(),
rowChildren.get(1).getLocation().getY());

Assert.assertEquals("Lbl3 should have Y == lbl2.location + lbl1.height + lbl2.height",
rowChildren.get(1).getLocation().getY() + rowChildren.get(2).getSize().getHeight(),
rowChildren.get(2).getLocation().getY());
}

}

0 comments on commit 8ae138c

Please sign in to comment.