Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for alternative rowheight, e.g. Reindeer. For vaadin7 version #22

Open
wants to merge 2 commits into
base: 1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GridExtensionPack-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.vaadin.teemusa</groupId>
<artifactId>gridextensionpack-demo</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<name>GridExtensionPack Add-on Demo</name>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion GridExtensionPack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.vaadin.teemusa</groupId>
<artifactId>gridextensionpack</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<name>GridExtensionPack Add-on</name>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public interface WrappingClientRPC extends ClientRpc {

public void setWrapping(boolean enable);
public void setWrapping(boolean enable, int defaultRowHeight);

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@Connect(WrappingGrid.class)
public class WrappingGridConnector extends AbstractExtensionConnector {

protected static final int DEFAULT_HEIGHT = 38;
protected static int DEFAULT_HEIGHT = 38;

private static native double getWidth(Element e) /*-{
return e.offsetWidth;
Expand All @@ -42,7 +42,12 @@ private static native double getHeight(Element e) /*-{
private static native double getNaturalHeight(Element e) /*-{
var cssh = e.style.height;
e.style.height = "";
var h = e.offsetHeight;
var h = 0;
if(e.children.length > 0) {
h = e.children[0].offsetHeight;
} else {
h = e.offsetHeight;
}
e.style.height = cssh;
return h;
}-*/;
Expand Down Expand Up @@ -79,10 +84,12 @@ protected void extend(ServerConnector target) {
wrappingEnabled = false;
WrappingClientRPC rpc = new WrappingClientRPC() {
@Override
public void setWrapping(boolean enable) {
public void setWrapping(boolean enable, int defaultRowHeight) {
if (wrappingEnabled != enable) {
wrappingEnabled = enable;
DEFAULT_HEIGHT = defaultRowHeight;
if (enable) {
// Figure out default header height
applyStyle.execute(0);
} else {
disableWrapping();
Expand Down Expand Up @@ -147,9 +154,27 @@ public void execute(double timestamp) {
double[] heights = measureRowHeights();
double startY = setHeaderHeight(heights);
setBodyStartY(startY);
AnimationScheduler.get().requestAnimationFrame(applyScrollBarHeight);
}
};

/**
* Scroll bar height adjustment cannot be done in same animation frame
* hence create own animation frame for it
*/
private AnimationCallback applyScrollBarHeight = new AnimationCallback() {
@Override
public void execute(double timestamp) {
if (!wrappingEnabled) {
return;
}

double[] heights = measureRowHeights();
double startY = setHeaderHeight(heights);
adjustScrollBarHeight(startY);
}
};

/**
* Find maximum cell height per header row. A header row is at least as high
* as defined by {@link #DEFAULT_HEIGHT}.
Expand Down Expand Up @@ -196,32 +221,45 @@ private double setHeaderHeight(double[] rowHeights) {
* @param startY
* @return
*/
private double setBodyStartY(double startY) {
private void setBodyStartY(double startY) {


// Adjust body position
Element body = getGridPart("tbody");
body.getStyle().setMarginTop(startY, Unit.PX);

// Adjust deco position
for (Element e : getGridParts("div")) {
if (e.getClassName().contains("v-grid-header-deco")) {
e.getStyle().setHeight(startY, Unit.PX);
break;
}
}

// Adjust scrollbar position
for (Element e : getGridParts("div")) {
if (e.getClassName().contains("v-grid-scroller-vertical")) {
e.getStyle().setTop(startY, Unit.PX);
e.getStyle().setHeight(grid.getOffsetHeight() - startY, Unit.PX);
break;
}
}

// Adjust deco position
}

private void adjustScrollBarHeight(double startY) {
// Adjust scrollbar position
double scrollHeight = 0;

for (Element e : getGridParts("div")) {
if (e.getClassName().contains("v-grid-header-deco")) {
e.getStyle().setHeight(startY, Unit.PX);
if (e.getClassName().contains("v-grid-scroller-vertical")) {
double gridh = getGridPart("table").getParentElement().getOffsetHeight();
scrollHeight = gridh - startY;
e.getStyle().setHeight(scrollHeight, Unit.PX);
break;
}
}

return startY;
}

// Get elements in Grid by tag name relative to parent element
private Element[] getGridParts(String elem, Element parent) {
NodeList<Element> elems = parent.getElementsByTagName(elem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
@SuppressWarnings("serial")
public class WrappingGrid extends AbstractExtension {

static int defaultRowHeight = 38;

/**
* Constructor to create header wrapping extension for given Grid
* Constructor to create header wrapping extension for given Grid, uses header row height of the Valo theme
*
* @param grid The Grid where you want to apply header wrapping to
* @return
Expand All @@ -20,12 +22,26 @@ public static WrappingGrid extend(Grid grid) {
return g;
}

/**
* Constructor to create header wrapping extension for given Grid
*
* @param grid The Grid where you want to apply header wrapping to
* @param newDefaultRowHeight Header row height of the theme in px, e.g. Valo = 38, Reindeer = 21
* @return
*/
public static WrappingGrid extend(Grid grid, int newDefaultRowHeight) {
WrappingGrid g = new WrappingGrid();
defaultRowHeight = newDefaultRowHeight;
g.extend((AbstractClientConnector)grid);
return g;
}

/**
*
* @param enable Set header wrapping on/off true = on, false = off
*/
public void setWrapping(boolean enable) {
getRpcProxy(WrappingClientRPC.class).setWrapping(enable);
getRpcProxy(WrappingClientRPC.class).setWrapping(enable, defaultRowHeight);
}

}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ permanently ignored in your project. Do not worry, the project still works fine.

## Release notes

### Version 1.0.2
- New version of header wrapping extension
- Header wrapping can now be used with alternative header row heights with other
themes than Valo

### Version 1.0.1
- New version of header wrapping extension
- Header wrapping is now compatible with resizable columns
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.vaadin.teemusa</groupId>
<artifactId>gridextensionpack-root</artifactId>
<packaging>pom</packaging>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<name>GridExtensionPack Add-on Root Project</name>

<modules>
Expand Down