private void enableButtons ( ) { final int itemCount = this . list . getTable ( ) . getItemCount ( ) ; final boolean hasElement = itemCount > 0 ; IStructuredSelection selection ; if ( hasElement ) { selection = this . list . getStructuredSelection ( ) ; final int selectionCount = selection . size ( ) ; if ( selectionCount <= 0 || selectionCount > itemCount ) { selection = null ; } } else { selection = null ; } this . removeButton . setEnabled ( selection != null ) ; this . clearButton . setEnabled ( hasElement ) ; if ( this . isSortedElements ) { final Object firstElement = selection != null ? this . list . getTable ( ) . getItem ( 0 ) . getData ( ) : null ; final Object lastElement = selection != null ? this . list . getTable ( ) . getItem ( this . list . getTable ( ) . getItemCount ( ) - 1 ) . getData ( ) : null ; final boolean isNotFirst = firstElement != null && selection != null && firstElement != selection . getFirstElement ( ) ; final boolean isNotLast = lastElement != null && selection != null && lastElement != selection . getFirstElement ( ) ; this . moveTopButton . setEnabled ( isNotFirst ) ; this . moveUpButton . setEnabled ( isNotFirst ) ; this . moveDownButton . setEnabled ( isNotLast ) ; this . moveBottomButton . setEnabled ( isNotLast ) ; } }
Enables the type conversion buttons based on selected items counts in the viewer .