addControl( toolbar );
decorator.addEditorControl( toolbar );
}
final PossibleValuesService possibleValuesService = property.service( PossibleValuesService.class );
final ValueNormalizationService valueNormalizationService = property.service( ValueNormalizationService.class );
final MutableReference<List<PossibleValue>> possibleValuesRef = new MutableReference<List<PossibleValue>>();
final Runnable updateComboSelectionOp = new Runnable()
{
public void run()
{
if( PopUpListFieldPropertyEditorPresentation.this.updatingModel || combo.isDisposed() )
{
return;
}
final String text = valueNormalizationService.normalize( property.text() );
try
{
PopUpListFieldPropertyEditorPresentation.this.updatingEditor = true;
combo.setData( DATA_DEFAULT_VALUE, property.empty() );
if( text == null )
{
combo.deselectAll();
combo.setText( EMPTY_STRING );
}
else
{
final List<PossibleValue> possibleValues = possibleValuesRef.get();
final int possibleValuesCount = possibleValues.size();
int possibleValueIndex = -1;
for( int i = 0; i < possibleValuesCount && possibleValueIndex == -1; i++ )
{
if( equal( possibleValues.get( i ).value(), text ) )
{
possibleValueIndex = i;
}
}
if( PopUpListFieldPropertyEditorPresentation.this.style == PopUpListFieldStyle.STRICT )
{
if( possibleValueIndex == -1 )
{
if( possibleValues.size() == combo.getItemCount() )
{
combo.add( text );
}
else
{
final String existingNonConformingValue = combo.getItem( possibleValuesCount );
if( ! existingNonConformingValue.equals( text ) )
{
combo.setItem( possibleValuesCount, text );
}
}
possibleValueIndex = possibleValuesCount;
}
else if( possibleValuesCount < combo.getItemCount() )
{
combo.remove( possibleValuesCount );
}
}
if( possibleValueIndex != -1 )
{
if( combo.getSelectionIndex() != possibleValueIndex )
{
combo.setText( EMPTY_STRING );
combo.select( possibleValueIndex );
}
}
else
{
if( ! equal( valueNormalizationService.normalize( combo.getText() ), text ) )
{
combo.deselectAll();
combo.setText( text );
}
}