import org.eclipse.jface.viewers.TreeViewer; 展开树操作

import org.eclipse.jface.viewers.TreeViewer; 

public void init(){
  tree.setLabelProvider(new TreeLabelProvider1());
  tree.setContentProvider(new TreeContentProvider1());
  tree.setInput(data);
  tree.expandToLevel(2);//默认打开根目录
 }
tree.addSelectionChangedListener(new ISelectionChangedListener(){

			public void selectionChanged(SelectionChangedEvent event) {
				// TODO Auto-generated method stub
				StructuredSelection select=(StructuredSelection)event.getSelection();
				DialogRegion r = (DialogRegion)select.getFirstElement();
				text.setText(r.getRegionName());
				list.setVisible(false);
				targetregion = r;
				tree.expandToLevel(r, 2);//若为文件夹,则展开树
			}
			
		});

 

你可能感兴趣的:(eclipse)