import java.awt.Image;import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;public class TestMain
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("List Viewer Example");
shell.setBounds(100, 100, 300, 200);
shell.setLayout(new FillLayout()); final ListViewer lv = new ListViewer(shell, SWT.SINGLE);
lv.setContentProvider(new ArrayContentProvider());
lv.setLabelProvider(new PersonListLabelProvider());
lv.setInput(Person.example()); shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose(); }}class Person
{
public String firstName = "John";
public String lastName = "Doe";
public int age = 37;
public Person[] children = new Person[0];
public Person parent = null; public Person(String firstName, String lastName, int age)
{
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
} public Person(String firstName, String lastName, int age, Person[] children)
{
this(firstName, lastName, age);
this.children = children;
for (int i = 0; i < children.length; i++)
{
children[i].parent = this;
}
} public static Person[] example()
{
return new Person[] {
new Person("Dan", "Rubel", 41, new Person[] {
new Person("Beth", "Rubel", 11),
new Person("David", "Rubel", 6) }),
new Person("Eric", "Clayberg", 42, new Person[] {
new Person("Lauren", "Clayberg", 9),
new Person("Lee", "Clayberg", 7) }),
new Person("Mike", "Taylor", 55) };
} public String toString()
{
return firstName + " " + lastName;
}
}class PersonListLabelProvider extends LabelProvider
{
public String getText(Object element)
{
Person person = (Person) element;
return person.firstName + " " + person.lastName;
}
}