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 1, 2018
1 parent b5128ea commit 6c80e40
Showing 1 changed file with 49 additions and 3 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,22 +18,26 @@
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.core.client.Scheduler;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Style.BorderStyle;
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.ui.Composite;
import com.google.gwt.user.client.ui.RequiresResize;
Expand Down Expand Up @@ -141,7 +145,7 @@ public void run()
});

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

// create the top level list of objects
objects_.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
Expand All @@ -153,7 +157,6 @@ public void run()
objectsWrapper_.add(objects_);

scrollPanel_.setWidget(objectsWrapper_);

// cache connection
connection_ = connection;
}
Expand All @@ -163,6 +166,48 @@ 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(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 (!StringUtil.equals(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(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 @@ -261,4 +306,5 @@ private void hideUnmatchedElements(Element ele)
private VerticalPanel objectsWrapper_;
private ObjectBrowserModel objectsModel_;
private Connection connection_;
private HandlerRegistration registration_;
}

0 comments on commit 6c80e40

Please sign in to comment.