Skip to content

Commit

Permalink
Revert Grid row height per section feature (#9823)
Browse files Browse the repository at this point in the history
Revert changes for #9425 (PRs #9810 and #9813) in the 8.1 branch.

This reverts commit bda7e54.
This reverts commit 1f87808.
  • Loading branch information
tsuoanttila authored and hesara committed Aug 16, 2017
1 parent 0f64ae4 commit df95222
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 193 deletions.
1 change: 0 additions & 1 deletion all/src/main/templates/release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ <h2 id="incompatible">Incompatible or Behavior-altering Changes in @version-mino
<li><tt>TreeGrid.createColumn()</tt> has an additional parameter.</li>
<li><tt>LocalDateTimeToDateConverter</tt> now uses <tt>ZoneId</tt> instead of <tt>ZoneOffset</tt>.</li>
<li><tt>FontAwesome</tt> icon alignment in <tt>ComboBox</tt> has changed in the theme.</li>
<li><tt>GridState</tt> variable <tt>rowHeight</tt> has replaced by three variables.</li>

<h2>For incompatible or behaviour-altering changes in 8.0, please see <a href="https://vaadin.com/download/release/8.0/8.0.0/release-notes.html#incompatible">8.0 release notes</a></h2>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.vaadin.client.connectors.grid.ColumnConnector.CustomColumn;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.ui.SimpleManagedLayout;
import com.vaadin.client.widget.escalator.RowContainer;
import com.vaadin.client.widget.grid.CellReference;
import com.vaadin.client.widget.grid.EventCellReference;
import com.vaadin.client.widget.grid.events.BodyClickHandler;
Expand Down Expand Up @@ -118,7 +117,6 @@ private void fireItemClick(CellReference<?> cell,
/* Child component list for HasComponentsConnector */
private List<ComponentConnector> childComponents;
private ItemClickHandler itemClickHandler = new ItemClickHandler();
private boolean rowHeightScheduled = false;

/**
* Gets the string identifier of the given column in this grid.
Expand Down Expand Up @@ -349,53 +347,19 @@ void updateHeader() {
grid.setHeaderVisible(state.visible);
}

@OnStateChange({ "bodyRowHeight", "headerRowHeight", "footerRowHeight" })
@OnStateChange("rowHeight")
void updateRowHeight() {
if (rowHeightScheduled) {
return;
}

Scheduler.get().scheduleFinally(() -> {
GridState state = getState();
if (getWidget().isAttached() && rowHeightNeedsReset()) {
getWidget().resetSizesFromDom();
}
updateContainerRowHeigth(getWidget().getEscalator().getBody(),
state.bodyRowHeight);
updateContainerRowHeigth(getWidget().getEscalator().getHeader(),
state.headerRowHeight);
updateContainerRowHeigth(getWidget().getEscalator().getFooter(),
state.footerRowHeight);
rowHeightScheduled = false;
});

rowHeightScheduled = true;
}

private boolean rowHeightNeedsReset() {
GridState state = getState();
// Body
boolean bodyAutoCalc = state.bodyRowHeight < 0;

// Header
boolean headerAutoCalc = state.headerRowHeight < 0;
boolean headerReset = headerAutoCalc && hasVisibleContent(state.header);

// Footer
boolean footerAutoCalc = state.footerRowHeight < 0;
boolean footerReset = footerAutoCalc && hasVisibleContent(state.footer);

return bodyAutoCalc || headerReset || footerReset;
}

private boolean hasVisibleContent(SectionState state) {
return state.visible && !state.rows.isEmpty();
}

private void updateContainerRowHeigth(RowContainer container,
double height) {
if (height >= 0) {
container.setDefaultRowHeight(height);
double rowHeight = getState().rowHeight;
if (rowHeight >= 0) {
getWidget().getEscalator().getHeader()
.setDefaultRowHeight(rowHeight);
getWidget().getEscalator().getBody().setDefaultRowHeight(rowHeight);
getWidget().getEscalator().getFooter()
.setDefaultRowHeight(rowHeight);
} else if (getWidget().isAttached()) {
// finally to make sure column sizes have been set before this
Scheduler.get()
.scheduleFinally(() -> getWidget().resetSizesFromDom());
}
}

Expand Down
4 changes: 2 additions & 2 deletions documentation/components/components-grid.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ Column<Person, LocalDateTime> bornColumn =
[classname]#ComponentRenderer#:: Renders a Vaadin [classname]#Component# in a column. Since components
are quite complex, the [classname]#ComponentRenderer# comes with possible performance issues.
To use it efficiently you should use as few nested components as possible. If the components used are
of a different size than the default row height, [methodname]#Grid.setBodyRowHeight()# can be used to adjust
of a different size than the default row height, [methodname]#Grid.setRowHeight()# can be used to adjust
the height of all rows in the Grid.

+
Expand All @@ -593,7 +593,7 @@ grid.addComponentColumn(person -> {
return button;
});
// make sure the buttons fit in the cells of the Grid
grid.setBodyRowHeight(40);
grid.setRowHeight(40);
----
+
Components will occasionally be generated again during runtime. If you have a state in your
Expand Down
98 changes: 6 additions & 92 deletions server/src/main/java/com/vaadin/ui/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -3012,113 +3012,27 @@ public HeightMode getHeightMode() {
}

/**
* Sets the height of body, header and footer rows. If -1 (default), the row
* height is calculated based on the theme for an empty row before the Grid
* is displayed.
* Sets the height of a row. If -1 (default), the row height is calculated
* based on the theme for an empty row before the Grid is displayed.
* <p>
* Note that all header, body and footer rows get the same height if
* explicitly set. In automatic mode, each section is calculated separately
* based on an empty row of that type.
*
* @see #setBodyRowHeight(double)
* @see #setHeaderRowHeight(double)
* @see #setFooterRowHeight(double)
*
* @param rowHeight
* The height of a row in pixels or -1 for automatic calculation
*/
public void setRowHeight(double rowHeight) {
setBodyRowHeight(rowHeight);
setHeaderRowHeight(rowHeight);
setFooterRowHeight(rowHeight);
}

/**
* Sets the height of a body row. If -1 (default), the row height is
* calculated based on the theme for an empty row before the Grid is
* displayed.
*
* @param rowHeight
* The height of a row in pixels or -1 for automatic calculation
* @since 8.1.2
*/
public void setBodyRowHeight(double rowHeight) {
getState().bodyRowHeight = rowHeight;
}

/**
* Sets the height of a header row. If -1 (default), the row height is
* calculated based on the theme for an empty row before the Grid is
* displayed.
*
* @param rowHeight
* The height of a row in pixels or -1 for automatic calculation
* @since 8.1.2
*/
public void setHeaderRowHeight(double rowHeight) {
getState().headerRowHeight = rowHeight;
getState().rowHeight = rowHeight;
}

/**
* Sets the height of a footer row. If -1 (default), the row height is
* calculated based on the theme for an empty row before the Grid is
* displayed.
* Returns the currently explicitly set row height or -1 if automatic.
*
* @param rowHeight
* The height of a row in pixels or -1 for automatic calculation
* @since 8.1.2
* @return explicitly set row height in pixels or -1 if in automatic mode
*/
public void setFooterRowHeight(double rowHeight) {
getState().footerRowHeight = rowHeight;
}

/**
* Returns the current body row height.-1 if row height is in automatic
* calculation mode.
*
* @see #getBodyRowHeight()
* @see #getHeaderRowHeight()
* @see #getFooterRowHeight()
*
* @return body row height
* @deprecated replaced by three separate row height controls
*/
@Deprecated
public double getRowHeight() {
return getBodyRowHeight();
}

/**
* Returns the current body row height. -1 if row height is in automatic
* calculation mode.
*
* @return body row height
* @since 8.1.2
*/
public double getBodyRowHeight() {
return getState(false).bodyRowHeight;
}

/**
* Returns the current header row height. -1 if row height is in automatic
* calculation mode.
*
* @return header row height
* @since 8.1.2
*/
public double getHeaderRowHeight() {
return getState(false).headerRowHeight;
}

/**
* Returns the current footer row height. -1 if row height is in automatic
* calculation mode.
*
* @return footer row height
* @since 8.1.2
*/
public double getFooterRowHeight() {
return getState(false).footerRowHeight;
return getState(false).rowHeight;
}

/**
Expand Down
21 changes: 3 additions & 18 deletions shared/src/main/java/com/vaadin/shared/ui/grid/GridState.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,11 @@ public class GridState extends AbstractSingleSelectState {
public boolean columnReorderingAllowed;

/**
* Explicit body row height in pixels for grid rows, or -1 to calculate
* Explicit row height in pixels for grid rows, or -1 to calculate
* automatically based on the theme.
*
* @since 8.1.2
* @since 8.1
*/
public double bodyRowHeight = -1;
public double rowHeight = -1;

/**
* Explicit body row height in pixels for grid rows, or -1 to calculate
* automatically based on the theme.
*
* @since 8.1.2
*/
public double headerRowHeight = -1;

/**
* Explicit body row height in pixels for grid rows, or -1 to calculate
* automatically based on the theme.
*
* @since 8.1.2
*/
public double footerRowHeight = -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,6 @@ private void createBodyMenu(MenuItem rowMenu) {
rowMenu.addItem("Deselect all", menuItem -> {
grid.getSelectionModel().deselectAll();
});

MenuItem rowHeight = rowMenu.addItem("Body Row Height", null);
Stream.of(-1, 20, 50, 100).forEach(i -> rowHeight.addItem("" + i,
menuItem -> grid.setBodyRowHeight(i)));
}

private void createSelectionMenu(MenuItem stateItem) {
Expand Down Expand Up @@ -644,10 +640,6 @@ private void createHeaderMenu(MenuItem headerMenu) {
headerMenu.addItem("Merge Header Cells [0,6..7]", menuItem -> {
mergeHeaderСells(0, "6+7", 6, 7);
});

MenuItem rowHeight = headerMenu.addItem("Header Row Height", null);
Stream.of(-1, 20, 50, 100).forEach(i -> rowHeight.addItem("" + i,
menuItem -> grid.setHeaderRowHeight(i)));
}

private void mergeHeaderСells(int rowIndex, String jointCellText,
Expand Down Expand Up @@ -711,10 +703,6 @@ private void createFooterMenu(MenuItem footerMenu) {
footerMenu.addItem("Merge Footer Cells [0,6..7]", menuItem -> {
mergeFooterСells(0, "6+7", 6, 7);
});

MenuItem rowHeight = footerMenu.addItem("Footer Row Height", null);
Stream.of(-1, 20, 50, 100).forEach(i -> rowHeight.addItem("" + i,
menuItem -> grid.setFooterRowHeight(i)));
}

/* DetailsGenerator related things */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,6 @@

public class GridRowHeightTest extends GridBasicsTest {

@Test
public void testSeparateRowHeights() {
selectMenuPath("Component", "Footer", "Add default footer row");

int initialHeaderHeight = getHeaderHeight();

Assert.assertNotEquals("Header height should not be 50px initially", 50,
initialHeaderHeight);

selectMenuPath("Component", "Body rows", "Body Row Height", "" + 100);
selectMenuPath("Component", "Header", "Header Row Height", "" + 20);
selectMenuPath("Component", "Footer", "Footer Row Height", "" + 50);

checkRowHeights(20, 100, 50);

selectMenuPath("Component", "Header", "Header Row Height", "" + -1);

checkRowHeights(initialHeaderHeight, 100, 50);
}

@Test
public void testRowHeights() {
selectMenuPath("Component", "Footer", "Add default footer row");
Expand Down

0 comments on commit df95222

Please sign in to comment.