The use of Treeview is similar to that of tableview. The difference is that the implementation interfaces of contentprovider and labelprovider are different. The following is an example. I believe you can understand it.
Class kindlabelprovider extends labelprovider {
Public String gettext (Object OBJ ){
If (OBJ instanceof kind ){
Return obj. tostring ();
}
Return NULL;
}
Public Image getimage (Object OBJ ){
// String imagekey = isharedimages. img_obj_element;
If (OBJ instanceof kind ){
String imagekey = isharedimages. img_obj_folder;
Platformui. getworkbench (). get1_dimages (). getimage (imagekey );
}
Return NULL;
}
}
Class kindcontentprovider implements istructuredcontentprovider,
Itreecontentprovider {
Public object [] getelements (Object parent ){
If (parent instanceof kind ){
Return getchildren (parent );
}
Return NULL;
}
Public object getparent (Object child ){
If (Child instanceof node ){
Return (node) Child). getparent ();
}
Return NULL;
}
Public object [] getchildren (Object parent ){
If (parent instanceof kind ){
Arraylist children = (kind) parent). getchildren ();
Return children. toarray (new node [children. Size ()]);
}
Return new object [0];
}
Public Boolean haschildren (Object parent ){
If (parent instanceof kind)
Return (kind) parent). haschildren ();
Return false;
}
Public void dispose (){
// Todo auto-generated method stub
}
Public void inputchanged (viewer, object oldinput, object newinput ){
// Todo auto-generated method stub
}
}