Skip to content

Commit

Permalink
Server Log: Show Tail button does not scroll to bottom #731
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaurite committed Apr 28, 2018
1 parent 53aa124 commit 26b5eb1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.haulmont.cuba.web.toolkit.ui.client.scrollboxlayout;

import com.google.gwt.user.client.Element;
import com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout;
import com.haulmont.cuba.web.toolkit.ui.client.cssactionslayout.CubaCssActionsLayoutConnector;
import com.haulmont.cuba.web.toolkit.ui.client.cubascrollboxlayout.CubaScrollBoxLayoutServerRpc;
import com.haulmont.cuba.web.toolkit.ui.client.cubascrollboxlayout.CubaScrollBoxLayoutState;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.SimpleManagedLayout;
import com.vaadin.shared.ui.Connect;

Expand All @@ -40,12 +40,33 @@ public CubaScrollBoxLayoutWidget getWidget() {
@Override
public void layout() {
CubaScrollBoxLayoutWidget widget = getWidget();
Element element = widget.getElement();

element.setScrollTop(getState().scrollTop);
element.setScrollLeft(getState().scrollLeft);
widget.setScrollTop(getState().scrollTop);
widget.setScrollLeft(getState().scrollLeft);

widget.onScrollHandler = (scrollTop, scrollLeft) ->
getRpcProxy(CubaScrollBoxLayoutServerRpc.class).setScroll(scrollTop, scrollLeft);
widget.onScrollHandler = (scrollTop, scrollLeft) -> {
if (getState().scrollChangeMode.equals(CubaScrollBoxLayoutState.DEFERRED_MODE)) {
getRpcProxy(CubaScrollBoxLayoutServerRpc.class).setDeferredScroll(scrollTop, scrollLeft);
} else {
getRpcProxy(CubaScrollBoxLayoutServerRpc.class).setDelayedScroll(scrollTop, scrollLeft);
}
};
}

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);

if (stateChangeEvent.hasPropertyChanged("scrollTop")) {
getWidget().setScrollTop(getState().scrollTop);
}

if (stateChangeEvent.hasPropertyChanged("scrollLeft")) {
getWidget().setScrollLeft(getState().scrollLeft);
}

if (stateChangeEvent.hasPropertyChanged("scrollChangeMode")) {
getWidget().setScrollChangeMode(getState().scrollChangeMode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,41 @@
package com.haulmont.cuba.web.toolkit.ui.client.scrollboxlayout;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.haulmont.cuba.web.toolkit.ui.client.cssactionslayout.CubaCssActionsLayoutWidget;
import com.haulmont.cuba.web.toolkit.ui.client.cubascrollboxlayout.CubaScrollBoxLayoutState;

import java.util.function.BiConsumer;

public class CubaScrollBoxLayoutWidget extends CubaCssActionsLayoutWidget {

private static final int TIMEOUT = 250;

protected int scrollTop = 0;
protected int scrollLeft = 0;

public BiConsumer<Integer, Integer> onScrollHandler;

protected String scrollChangeMode;

protected Timer scrollBoxStateTrigger = new Timer() {

@Override
public void run() {
if (isAttached()) {
updateScrollState();
}
}
};

protected void updateScrollState() {
if (onScrollHandler != null) {
onScrollHandler.accept(scrollTop, scrollLeft);
}
}

protected CubaScrollBoxLayoutWidget() {
DOM.sinkEvents(getElement(), Event.ONKEYDOWN | Event.ONSCROLL);
}
Expand All @@ -45,13 +67,35 @@ public void onBrowserEvent(Event event) {
int scrollLeft = element.getScrollLeft();

if (this.scrollTop != scrollTop || this.scrollLeft != scrollLeft) {
if (onScrollHandler != null) {
onScrollHandler.accept(scrollTop, scrollLeft);
}

this.scrollTop = scrollTop;
this.scrollLeft = scrollLeft;

if (CubaScrollBoxLayoutState.DEFERRED_MODE.equals(scrollChangeMode)) {
updateScrollState();
} else {
scrollBoxStateTrigger.cancel();
scrollBoxStateTrigger.schedule(TIMEOUT);
}
}
}
}

public void setScrollChangeMode(String scrollChangeMode) {
this.scrollChangeMode = scrollChangeMode;
}

public void setScrollTop(int scrollTop) {
this.scrollTop = scrollTop;

scrollBoxStateTrigger.cancel();
getElement().setScrollTop(scrollTop);
}

public void setScrollLeft(int scrollLeft) {
this.scrollLeft = scrollLeft;

scrollBoxStateTrigger.cancel();
getElement().setScrollLeft(scrollLeft);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public void handleAction(Object sender, Object target) {

downloadButton.setDescription("CTRL-SHIFT-D");
showTailButton.setDescription("CTRL-SHIFT-S");

logContainer.unwrapComposition(CubaScrollBoxLayout.class).setDelayed(true);
}

private void refreshHostInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ public class CubaScrollBoxLayout extends CubaCssActionsLayout {
protected CubaScrollBoxLayoutServerRpc serverRpc;

public CubaScrollBoxLayout() {
serverRpc = (scrollTop, scrollLeft) -> {
getState().scrollTop = scrollTop;
getState().scrollLeft = scrollLeft;
serverRpc = new CubaScrollBoxLayoutServerRpc() {
@Override
public void setDeferredScroll(int scrollTop, int scrollLeft) {
getState().scrollTop = scrollTop;
getState().scrollLeft = scrollLeft;
}

@Override
public void setDelayedScroll(int scrollTop, int scrollLeft) {
getState().scrollTop = scrollTop;
getState().scrollLeft = scrollLeft;
}
};
registerRpc(serverRpc);
}
Expand All @@ -41,6 +50,11 @@ protected CubaScrollBoxLayoutState getState(boolean markAsDirty) {
return (CubaScrollBoxLayoutState) super.getState(markAsDirty);
}

public void setDelayed(boolean delayed) {
getState().scrollChangeMode = delayed ?
CubaScrollBoxLayoutState.DELAYED_MODE : CubaScrollBoxLayoutState.DEFERRED_MODE;
}

public void setScrollTop(int scrollTop) {
if (getState(false).scrollTop != scrollTop) {
getState().scrollTop = scrollTop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
public interface CubaScrollBoxLayoutServerRpc extends ServerRpc {

@Delayed(lastOnly = true)
void setScroll(int scrollTop, int scrollLeft);
void setDeferredScroll(int scrollTop, int scrollLeft);

void setDelayedScroll(int scrollTop, int scrollLeft);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

public class CubaScrollBoxLayoutState extends CubaCssActionsLayoutState {

public static final String DELAYED_MODE = "DELAYED"; // send after 200ms delay
public static final String DEFERRED_MODE = "DEFERRED"; // send only with changes from other components

public int scrollTop = 0;
public int scrollLeft = 0;

public String scrollChangeMode = DEFERRED_MODE;
}

0 comments on commit 26b5eb1

Please sign in to comment.