W dniu poniedziałek, 26 października 2015 15:24:54 UTC+1 użytkownik Jaron Shulver napisał:
Hi,I want to have a CellTree which expands when you click anywhere on the cell, not just on the icon.
I've found this in my project, but I don't remember even how it works:).
Especially curious is why did I use com.google.gwt.user.cellview.client package, probably I needed to override some protect method.
====
package com.google.gwt.user.cellview.client;
import java.util.ArrayList;
import com.google.gwt.dom.client.BrowserEvents;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.view.client.TreeViewModel;
public class MyCellTree extends CellTree {
public MyCellTree(TreeViewModel model, Object object,
Resources myresources, CellTreeMessages messages, int i) {
super(model, object, myresources, messages, i);
}
@Override
public void onBrowserEvent(Event event) {
String eventType = event.getType();
final boolean isMouseDown = BrowserEvents.MOUSEDOWN.equals(eventType);
if (isMouseDown)
{
final Element target = event.getEventTarget().cast();
ArrayList<Element> chain = new ArrayList<Element>();
collectElementChain2(chain, getElement(), target);
CellTreeNodeView<?> nodeView = findItemByChain2(chain, 0, rootNode);
if (nodeView != null)
{
if (!nodeView.isRootNode() && ! nodeView.getImageElement().isOrHasChild(target))
{
nodeView.setOpen(!nodeView.isOpen(), true);
return;
}
}
}
super.onBrowserEvent(event);
}
private void collectElementChain2(ArrayList<Element> chain, Element hRoot,
Element hElem) {
if ((hElem == null) || (hElem == hRoot)) {
return;
}
collectElementChain2(chain, hRoot, hElem.getParentElement());
chain.add(hElem);
}
private CellTreeNodeView<?> findItemByChain2(ArrayList<Element> chain,
int idx, CellTreeNodeView<?> parent) {
if (idx == chain.size()) {
return parent;
}
Element hCurElem = chain.get(idx);
for (int i = 0, n = parent.getChildCount(); i < n; ++i) {
CellTreeNodeView<?> child = parent.getChildNode(i);
if (child.getElement() == hCurElem) {
CellTreeNodeView<?> retItem = findItemByChain2(chain, idx + 1, child);
if (retItem == null) {
return child;
}
return retItem;
}
}
return findItemByChain2(chain, idx + 1, parent);
}
}
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment