引自http://lggege.iteye.com/category/28438?show_full=true
为了在公司看的方便故贴过来
package cn.iwoo.treeviewer.provider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.progress.DeferredTreeContentManager;
/**
* @author lggege
*/
public class PendingLazyContentProvider implements ITreeContentProvider {
private DeferredTreeContentManager manager;
@Override
public Object[] getChildren(Object parentElement) {
return manager.getChildren(parentElement);
}
@Override
public boolean hasChildren(Object element) {
return true;
}
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof PendingTreeNode) {
return ((PendingTreeNode) inputElement).getChildren().toArray();
}
return new Object[0];
}
@Override
public Object getParent(Object element) {
return ((TreeNode) element).getParent();
}
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (manager == null) {
manager = new DeferredTreeContentManager(this, (TreeViewer) viewer);
}
}
}
package cn.iwoo.treeviewer.provider;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.progress.IElementCollector;
/**
* @author lggege
*/
public class PendingTreeNode extends TreeNode implements IDeferredWorkbenchAdapter {
public PendingTreeNode(Object value) {
super(value);
}
@Override
public void fetchDeferredChildren(Object object, IElementCollector collector,
IProgressMonitor monitor) {
PendingTreeNode parent = (PendingTreeNode) object;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
PendingTreeNode node1 = new PendingTreeNode("1");
parent.addChild(node1);
collector.add(node1, monitor);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
PendingTreeNode node2 = new PendingTreeNode("2");
parent.addChild(node2);
collector.add(node2, monitor);
}
@Override
public ISchedulingRule getRule(Object object) {
return null;
}
@Override
public boolean isContainer() {
return false;
}
@Override
public Object[] getChildren(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
return null;
}
@Override
public String getLabel(Object o) {
return null;
}
@Override
public Object getParent(Object o) {
return null;
}
}
分享到:
相关推荐
使用自定义ContentProvider实现 SQLite 跨应用数据共享,使用文章地址: http://blog.csdn.net/lablenet/article/details/48030993 的下一篇
在Android开发中,ContentProvider是四大组件之一,它充当了数据共享和访问的桥梁,使得应用程序间的数据交换变得可能。这篇博文将深入探讨ContentProvider的学习,让我们一起深入了解这个关键组件。...
在我们使用Android Studio时,创建一个类是继承于Android中已有的类时,我们会对原有类中的方法进行重载,Android Studio为我们提供了快捷的插入重载的方法,便于开发、减轻了工作量。 当我们继承一个Android中已有...