Skip to content
This repository was archived by the owner on Dec 31, 2020. It is now read-only.
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 lazylayouts-addon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vaadin.version>8.1.1</vaadin.version>
<vaadin.version>8.10.2</vaadin.version>
<vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>

<!-- ZIP Manifest fields -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.client.ui.VWindow;
import com.vaadin.client.ui.layout.MayScrollChildren;
import com.vaadin.client.ui.orderedlayout.VerticalLayoutConnector;
Expand All @@ -23,13 +24,14 @@
* Connector for LazyVerticalLayout
*/
@Connect(LazyVerticalLayout.class)
public class LazyVerticalLayoutConnector extends VerticalLayoutConnector implements LazyScrollListener {
public class LazyVerticalLayoutConnector extends VerticalLayoutConnector implements LazyScrollListener, PostLayoutListener {

private final static Logger LOGGER = Logger.getLogger(LazyVerticalLayoutConnector.class.getName());

private ComponentConnector scrollerFollowed;
private Element scrollingElement;
protected ComponentConnector scrollerFollowed;
protected Element scrollingElement;
protected boolean waitingResponse = false;
protected boolean mustRelayout = false;
private HandlerRegistration handlerRegistration;

/**
Expand All @@ -50,7 +52,7 @@ public void init() {
@Override
public void onUnregister() {

requestTimer.cancel();
//requestTimer.cancel();

removeScrollingHandlers();

Expand Down Expand Up @@ -90,35 +92,34 @@ public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
}

waitingResponse = false;

super.onConnectorHierarchyChange(event);
}

if(getParent() != null) {

@Override
public void postLayout() {
if(getParent() != null && mustRelayout) {
Widget indicator = getLazyLoadingIndicator();
if(indicator != null) {
indicator.getElement().getStyle().setOpacity(0.5);
}

// Verify that we do not need to continue loading after hierarchy change
if(scrollingElement != null) {
Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
if (!waitingResponse) {
if (checkIfLazyRequestRequired(scrollingElement)) {
sendLazyLoadRequest();
}
}
return false;
if(scrollingElement != null && getState().lazyLoading) {
if (!waitingResponse) {
if (checkIfLazyRequestRequired(scrollingElement)) {
sendLazyLoadRequest();
}
}, DELAYED_CHECK_AFTER_CHANGE_MS);
}
}
mustRelayout = false;
}
}

@Override
public void onStateChanged(StateChangeEvent event) {
if (event.hasPropertyChanged("childData")) {
mustRelayout = true;
}
super.onStateChanged(event);

if(event.hasPropertyChanged("lazyLoading")) {
Expand Down Expand Up @@ -211,16 +212,21 @@ protected boolean checkIfLazyRequestRequired(Element scrollingElement) {
* Sends lazy component loading request to server
*/
protected void sendLazyLoadRequest() {
if(!waitingResponse) {
if(!waitingResponse && LazyVerticalLayoutConnector.this.isEnabled()) {
waitingResponse = true;
// Delay so other signals will be sent before
requestTimer.schedule();
LOGGER.fine("Sending lazy loading request...");
Widget indicator = getLazyLoadingIndicator();
if (indicator != null) {
indicator.getElement().getStyle().setOpacity(1.0);
}
getRpcProxy(LazyLayoutServerRpc.class).onLazyLoadRequest();
}
}

/**
* Timer used to delay request until scrolling stops
*/
/*
protected class LazyRequestTimer extends Timer {

public final static int REQUEST_DELAY_TIMER_MS = 50;
Expand All @@ -247,12 +253,12 @@ public void run() {
};

protected LazyRequestTimer requestTimer = new LazyRequestTimer();

*/
/**
* Gets lazy loading indicator
* @return Loading indicator widget instance if defined
*/
private Widget getLazyLoadingIndicator() {
protected Widget getLazyLoadingIndicator() {
ComponentConnector connector = (ComponentConnector)getState().lazyLoadingIndicator;
if(connector == null) {
return null;
Expand Down