if ( event.getSelection() instanceof IStructuredSelection )
{
Object obj = ( ( IStructuredSelection ) event.getSelection() ).getFirstElement();
if ( treeViewer.getExpandedState( obj ) )
{
treeViewer.collapseToLevel( obj, 1 );
}
else if ( ( ( ITreeContentProvider ) treeViewer.getContentProvider() ).hasChildren( obj ) )
{
treeViewer.expandToLevel( obj, 1 );
}