{
handle.clear();
}
else
{
final ElementType type = buttonToType.get( button );
handle.content( true, type );
}
}
catch( Exception e )
{
// Note that the EditFailedException is ignored here because the user has already
// been notified and likely has taken action that led to the exception (such as
// declining to make a file writable).
final EditFailedException editFailedException = EditFailedException.findAsCause( e );
if( editFailedException == null )
{
Sapphire.service( LoggingService.class ).log( e );
}
}
}
}
);
}
else if( style == Style.DROP_DOWN_LIST )
{
final Combo combo = new Combo( typeSelectorComposite, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY );
combo.setLayoutData( gdhfill() );
decorator.addEditorControl( combo );
actionPresentationKeyboard.attach( combo );
attachHelp( combo, property );
final Map<ElementType,Integer> typeToIndex = new HashMap<ElementType,Integer>();
final Map<Integer,ElementType> indexToType = new HashMap<Integer,ElementType>();
int index = 0;
for( ElementType type : allPossibleTypes )
{
final String label = type.getLabel( true, CapitalizationType.FIRST_WORD_ONLY, false );
combo.add( label );
typeToIndex.put( type, index );
indexToType.put( index, type );
index++;
}
updateUserInterfaceOp = new Runnable()
{
public void run()
{
if( Display.getCurrent() == null )
{
combo.getDisplay().asyncExec( this );
return;
}
final Element subModelElement = ( (ElementHandle<?>) property ).content();
final int index;
if( subModelElement == null )
{
index = -1;
}
else
{
index = typeToIndex.get( subModelElement.type() );
}
if( combo.getSelectionIndex() != index )
{
if( index == -1 )
{
combo.deselectAll();
}
else
{
combo.select( index );
}
}
combo.setEnabled( property.enabled() );
}
};
combo.addSelectionListener
(
new SelectionAdapter()
{
@Override
public void widgetSelected( final SelectionEvent event )
{
try
{
final ElementHandle<?> handle = (ElementHandle<?>) property;
final int index = combo.getSelectionIndex();
if( index == -1 )
{
handle.clear();
}
else
{
final ElementType type = indexToType.get( index );
handle.content( true, type );
}
}
catch( Exception e )
{