final PropertyEditorAssistDecorator decorator = new PropertyEditorAssistDecorator( part, property, typeSelectorComposite );
decorator.control().setLayoutData( gdhindent( gdvalign( gd(), ( style == Style.DROP_DOWN_LIST ? SWT.TOP : SWT.CENTER ) ), ( showLabel ? 3 : 0 ) ) );
if( style == Style.RADIO_BUTTONS )
{
final RadioButtonsGroup radioButtonsGroup = new RadioButtonsGroup( typeSelectorComposite, false );
radioButtonsGroup.setLayoutData( gdhfill() );
final Map<ElementType,Button> typeToButton = new HashMap<ElementType,Button>();
final Map<Button,ElementType> buttonToType = new HashMap<Button,ElementType>();
for( final ElementType type : allPossibleTypes )
{
final String label = type.getLabel( true, CapitalizationType.FIRST_WORD_ONLY, false );
final Button button = radioButtonsGroup.addRadioButton( label );
typeToButton.put( type, button );
buttonToType.put( button, type );
decorator.addEditorControl( button );
actionPresentationKeyboard.attach( button );
attachHelp( button, property );
}
final Button noneButton = radioButtonsGroup.addRadioButton( noneSelection.text() );
noneButton.setVisible( false );
decorator.addEditorControl( noneButton );
actionPresentationKeyboard.attach( noneButton );
attachHelp( noneButton, property );
updateUserInterfaceOp = new Runnable()
{
public void run()
{
if( Display.getCurrent() == null )
{
radioButtonsGroup.getDisplay().asyncExec( this );
return;
}
final Element subModelElement = ( (ElementHandle<?>) property ).content();
final Button button;
if( subModelElement == null )
{
button = noneButton;
noneButton.setVisible( true );
}
else
{
button = typeToButton.get( subModelElement.type() );
noneButton.setVisible( false );
}
if( radioButtonsGroup.getSelection() != button )
{
radioButtonsGroup.setSelection( button );
}
radioButtonsGroup.setEnabled( property.enabled() );
}
};
radioButtonsGroup.addSelectionListener
(
new SelectionAdapter()
{
@Override
public void widgetSelected( final SelectionEvent event )
{
try
{
final ElementHandle<?> handle = (ElementHandle<?>) property;
final Button button = radioButtonsGroup.getSelection();
if( button == noneButton )
{
handle.clear();
}