Skip to content

Commit

Permalink
scroll down after clicking Show More; fixes #2211
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcphers committed Mar 5, 2018
1 parent 9f935f6 commit 2c49f68
Showing 1 changed file with 63 additions and 4 deletions.
@@ -1,7 +1,7 @@
/*
* ObjectBrowser.java
*
* Copyright (C) 2009-17 by RStudio, Inc.
* Copyright (C) 2009-18 by RStudio, Inc.
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
Expand All @@ -18,20 +18,30 @@
import java.util.HashSet;
import java.util.Set;

import org.rstudio.core.client.StringUtil;
import org.rstudio.core.client.dom.DomUtils;
import org.rstudio.core.client.widget.SimplePanelWithProgress;
import org.rstudio.studio.client.common.Value;
import org.rstudio.studio.client.workbench.views.connections.model.Connection;
import org.rstudio.studio.client.workbench.views.connections.model.DatabaseObject;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.event.dom.client.ScrollEvent;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.i18n.client.LocalizableResource.DefaultLocale;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.resources.client.ImageResource.ImageOptions;
import com.google.gwt.user.cellview.client.CellTree;
import com.google.gwt.user.cellview.client.CellTree.CellTreeMessages;
import com.google.gwt.user.cellview.client.TreeNode;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RequiresResize;
import com.google.gwt.user.client.ui.ScrollPanel;
Expand Down Expand Up @@ -138,10 +148,9 @@ public void run()
});

// create new widget
objects_ = new CellTree(objectsModel_, null, RES, MESSAGES);
objects_ = new CellTree(objectsModel_, null, RES, MESSAGES, 512);

// create the top level list of objects
objects_.setDefaultNodeSize(Integer.MAX_VALUE);
objects_.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
objects_.setWidth("100%");

Expand All @@ -151,7 +160,6 @@ public void run()
objectsWrapper_.add(objects_);

scrollPanel_.setWidget(objectsWrapper_);

// cache connection
connection_ = connection;
}
Expand All @@ -161,6 +169,56 @@ public void onResize()
{
}

@Override
public void onAttach()
{
// this works around an issue in CellTree; it has a "Show more" link which
// displays when there are more than defaultNodeSize items, but clicking
// on it causes the hosting scroll panel to jump to the top. unfortunately
// neither this link nor its activation is visible, so listen for clicks
// on the link in the capture phase and scroll the user to the bottom when
// expansion is complete.
registration_ = Event.addNativePreviewHandler(new NativePreviewHandler()
{
@Override
public void onPreviewNativeEvent(NativePreviewEvent event)
{
// look only for click events
if (event.getTypeInt() != Event.ONMOUSEDOWN)
return;

// look only for those that are targeted at the Show More button
Element target = Element.as(event.getNativeEvent().getEventTarget());
if (target.getTagName().toLowerCase() != "a")
return;
if (!target.getInnerText().equals("Show more"))
return;

// if we got here, the user has clicked Show More, so scroll to the
// bottom when they're done
final Value<HandlerRegistration> registration =
new Value<HandlerRegistration>(null);
registration.setValue(scrollPanel_.addScrollHandler(new ScrollHandler()
{
@Override
public void onScroll(ScrollEvent e)
{
scrollPanel_.scrollToBottom();
registration.getValue().removeHandler();
}
}));
}
});
super.onAttach();
}

@Override
public void onDetach()
{
registration_.removeHandler();
super.onDetach();
}

public interface Resources extends CellTree.Resources {

@Source("zoomDataset_2x.png")
Expand Down Expand Up @@ -216,4 +274,5 @@ public interface TableBrowserMessages extends CellTreeMessages {
private VerticalPanel objectsWrapper_;
private ObjectBrowserModel objectsModel_;
private Connection connection_;
private HandlerRegistration registration_;
}

0 comments on commit 2c49f68

Please sign in to comment.