[ECLIPSERCP]populate a treeviewer using IAdapterFactory
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   david_vauquelin
Posted On:   Saturday, January 7, 2006 05:57 AM

Hello, i need help on my project based on rcp platform, i'd like to list my c: directory using a treeviewer and IAdapterFactory to populate it but nothing appears in my view here is my code, if somebody can help me with that. the code in my view to create the tree viewer : ... private TreeViewer treeViewer; private IAdapterFactory adapterFactory = new MyAdapterFactory(); public void createPartControl(Composite parent) { // TODO Auto-generated method stub treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); Platform.getAdapterManager().registerAdapters(adapterFactory, File.class); getSite().setSelectionProvider(treeViewer);    More>>

Hello, i need help on my project based on rcp platform, i'd like to list my c: directory using a treeviewer and IAdapterFactory to populate it but nothing appears in my view here is my code, if somebody can help me with that.
the code in my view to create the tree viewer :


			
...
private TreeViewer treeViewer;

private IAdapterFactory adapterFactory = new MyAdapterFactory();

public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
treeViewer = new TreeViewer(parent, SWT.BORDER
| SWT.MULTI | SWT.V_SCROLL);
Platform.getAdapterManager().registerAdapters(adapterFactory, File.class);
getSite().setSelectionProvider(treeViewer);
treeViewer.setLabelProvider(new WorkbenchLabelProvider());
treeViewer.setContentProvider(new BaseWorkbenchContentProvider());
treeViewer.setInput(new File("c:\"));
}
...


and the code to populate it :


			
import java.io.File;

import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;

public class MyAdapterFactory implements IAdapterFactory {

public MyAdapterFactory() {
super();
// TODO Auto-generated constructor stub
}

private IWorkbenchAdapter fileContentAdapter = new IWorkbenchAdapter() {

public Object getParent(Object o) {

return ((File)o).getParent();
}

public String getLabel(Object o) {

return ((File)o).getName();
}

public ImageDescriptor getImageDescriptor(Object object) {

return null;
}

public Object[] getChildren(Object o) {

Object[] kids = ((File)o).listFiles();
return kids == null ? new Object[0] : kids;
}

};

public Object getAdapter(Object adaptableObject, Class adapterType) {
// TODO Auto-generated method stub
if(adapterType == IWorkbenchAdapter.class &&
adaptableObject instanceof File)
return fileContentAdapter;
return null;
}

public Class[] getAdapterList() {
// TODO Auto-generated method stub
return new Class[] {IWorkbenchAdapter.class};
}


I think that the problem might come from the getLabel method but i don't know how to implement it to show something in my tree. I tried another solution implementing my own content provider and label provider and it works well using implementation of ITreeContentProvider and LabelProvider, but i'd like to do it this way caus i would be simpler for me after. Thanks for your answers and helping me.

   <<Less
About | Sitemap | Contact