final boolean isLongString = property.definition().hasAnnotation( LongString.class );
final boolean isDeprecated = property.definition().hasAnnotation( Deprecated.class );
final boolean isReadOnly = ( property.definition().isReadOnly() || part.getRenderingHint( PropertyEditorDef.HINT_READ_ONLY, false ) );
final boolean isSensitiveData = property.definition().hasAnnotation( SensitiveData.class );
final SapphireActionGroup actions = getActions();
final SapphireActionHandler jumpActionHandler = actions.getAction( ACTION_JUMP ).getFirstActiveHandler();
final SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation( getActionPresentationManager() );
toolBarActionsPresentation.addFilter( createFilterByActionId( ACTION_ASSIST ) );
toolBarActionsPresentation.addFilter( createFilterByActionId( ACTION_JUMP ) );
actions.addFilter
(
new SapphireActionHandlerFilter()
{
@Override
public boolean check( final SapphireActionHandler handler )
{
final String actionId = handler.getAction().getId();
if( actionId.equals( ACTION_BROWSE ) && ( isReadOnly || suppressBrowseAction ) )
{
return false;
}
return true;
}
}
);
final boolean isActionsToolBarNeeded = toolBarActionsPresentation.hasActions();
final boolean isBrowseOnly = part.getRenderingHint( PropertyEditorDef.HINT_BROWSE_ONLY, false );
final Composite textFieldParent = createMainComposite
(
parent,
new CreateMainCompositeDelegate( part )
{
@Override
public boolean canScaleVertically()
{
return isLongString;
}
}
);
addControl( textFieldParent );
int textFieldParentColumns = 1;
if( isActionsToolBarNeeded ) textFieldParentColumns++;
if( isDeprecated ) textFieldParentColumns++;
textFieldParent.setLayout( glayout( textFieldParentColumns, 0, 0, 0, 0 ) );
final Composite nestedComposite = new Composite( textFieldParent, SWT.NONE );
nestedComposite.setLayoutData( isLongString ? gdfill() : gdvalign( gdhfill(), SWT.CENTER ) );
nestedComposite.setLayout( glspacing( glayout( 2, 0, 0 ), 2 ) );
addControl( nestedComposite );
final PropertyEditorAssistDecorator decorator = createDecorator( nestedComposite );
decorator.control().setLayoutData( gdvalign( gd(), SWT.TOP ) );
decorator.addEditorControl( nestedComposite );
final int style
= SWT.BORDER |
( isLongString ? SWT.MULTI | SWT.WRAP | SWT.V_SCROLL : SWT.NONE ) |
( ( isReadOnly || isBrowseOnly ) ? SWT.READ_ONLY : SWT.NONE ) |
( isSensitiveData ? SWT.PASSWORD : SWT.NONE );
this.textField = new Text( nestedComposite, style );
this.textField.setLayoutData( gdfill() );
decorator.addEditorControl( this.textField, true );
final Serialization serialization = property.definition().getAnnotation( Serialization.class );
final TextOverlayPainter.Controller textOverlayPainterController = new TextOverlayPainter.Controller()
{
@Override
public boolean isHyperlinkEnabled()
{
return ( jumpActionHandler == null ? false : jumpActionHandler.isEnabled() );
}
@Override
public void handleHyperlinkEvent()
{
if( jumpActionHandler != null )
{
jumpActionHandler.execute( TextFieldPropertyEditorPresentation.this );
}
}
@Override
public String overlay()
{
String def = property.disposed() ? null : property.getDefaultText();
if( def != null && isSensitiveData )
{
final StringBuilder buf = new StringBuilder();
for( int i = 0, n = def.length(); i < n; i++ )
{
buf.append( "\u25CF" );
}
def = buf.toString();
}
if( def == null && serialization != null )
{
def = serialization.primary();
}
return def;
}
};
TextOverlayPainter.install( this.textField, textOverlayPainterController );
if( isBrowseOnly || isReadOnly )
{
final Color bgcolor = new Color( this.textField.getDisplay(), 245, 245, 245 );
this.textField.setBackground( bgcolor );
this.textField.addDisposeListener
(
new DisposeListener()
{
public void widgetDisposed( final DisposeEvent event )
{
bgcolor.dispose();
}
}
);
}
final List<Control> relatedControls = new ArrayList<Control>();
this.textField.setData( RELATED_CONTROLS, relatedControls );
final Listener actionHandlerListener = new Listener()
{
@Override
public void handle( final Event event )
{
if( event instanceof PostExecuteEvent )
{
if( ! TextFieldPropertyEditorPresentation.this.textField.isDisposed() )
{
TextFieldPropertyEditorPresentation.this.textField.setFocus();
TextFieldPropertyEditorPresentation.this.textField.setSelection( 0, TextFieldPropertyEditorPresentation.this.textField.getText().length() );
}
}
}
};
for( SapphireAction action : actions.getActions() )
{
if( ! action.getId().equals( ACTION_ASSIST ) )
{
for( SapphireActionHandler handler : action.getActiveHandlers() )
{