Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Help with ITreePathContentProvider and ItreePathLabelProvider.
Help with ITreePathContentProvider and ItreePathLabelProvider. [message #485043] Thu, 10 September 2009 11:00 Go to next message
ali Mising name is currently offline ali Mising nameFriend
Messages: 38
Registered: July 2009
Member
Hello all,

I'm trying to evaluate the ITreePathContentProvider and
ItreePathLabelProvider, but haven’t been able to find any examples or get
them to work with a TreeView using guesswork.

Does anyone know of any good example code that demonstrated a viewer using
TreePaths?

Ali.
Re: Help with ITreePathContentProvider and ItreePathLabelProvider. [message #485585 is a reply to message #485043] Sun, 13 September 2009 23:32 Go to previous messageGo to next message
Wim Jongman is currently offline Wim JongmanFriend
Messages: 423
Registered: July 2009
Senior Member
Hi Ali,

This uses a threepathcontentprovider



package org.eclipse.jface.snippets.viewers;

import java.io.File;
import java.util.ArrayList;

import org.eclipse.jface.viewers.ITreePathContentProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* @author Wim Jongman, Industrial-TSI & Remain
*
*/
public class TreePathSnippet {

public TreePathSnippet(Shell shell) {
shell.setBounds(10, 10, 280, 200);
shell.setLayout(new GridLayout(1, true));
final Composite sc = new Composite(shell, SWT.NONE);
sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
sc.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR _WHITE));
sc.setLayout(new GridLayout(1, true));

final TreeViewer v = new TreeViewer(sc, SWT.BORDER);
v.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

v.setContentProvider(new ITreePathContentProvider() {

public void inputChanged(Viewer viewer, Object oldInput,
Object newInput) {

}

public void dispose() {
}

public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}

public boolean hasChildren(TreePath path) {
if (((File) path.getLastSegment()).isDirectory())
return true;
return false;
}

public TreePath[] getParents(Object element) {

ArrayList<File> files = new ArrayList<File>();
File elm = (File) element;
while (elm.getParentFile() != null) {
files.add(elm.getParentFile());
elm = elm.getParentFile();
}
return new TreePath[] { new TreePath(files.toArray()) };
}

public Object[] getChildren(TreePath parentPath) {
return ((File) parentPath.getLastSegment()).listFiles();
}
});


v.setInput(File.listRoots());
}

public static void main(String[] args) {
Display display = new Display();
try {
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new TreePathSnippet(shell);
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}

display.dispose();

}

}



> Hello all,
>
> I'm trying to evaluate the ITreePathContentProvider and
> ItreePathLabelProvider, but haven?t been able to find any examples or get
> them to work with a TreeView using guesswork.
>
> Does anyone know of any good example code that demonstrated a viewer using
> TreePaths?
>
> Ali.
icon4.gif  Re: Help with ITreePathContentProvider and ItreePathLabelProvider. [message #899168 is a reply to message #485585] Mon, 30 July 2012 18:56 Go to previous message
Libor Jelinek is currently offline Libor JelinekFriend
Messages: 143
Registered: January 2012
Location: Prague, Czech Rep.
Senior Member

Hi Wim!
First off - thanks your this snippet! But getParents() is never called (at least in my case). Is it a bug or intention?

Thanks
Libor
Previous Topic:Remove Mac Application Menu in RCP application
Next Topic:CNF adding Undo and Redo actions
Goto Forum:
  


Current Time: Thu Apr 25 11:09:18 GMT 2024

Powered by FUDForum. Page generated in 0.03049 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top