contenprovider

引自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;
}

}

你可能感兴趣的:(eclipse,thread,UI)