}
@Override
public void render()
{
final ActuatorPart part = part();
final ActuatorDef def = part.definition();
final SapphireActionGroup actions = part.getActions();
this.actionPresentationManager = new SapphireActionPresentationManager( this, actions );
final SapphireKeyboardActionPresentation keyboardActionPresentation = new SapphireKeyboardActionPresentation( this.actionPresentationManager );
final HorizontalAlignment hAlign = def.getHorizontalAlignment().content();
final int hAlignCode = ( hAlign == HorizontalAlignment.LEFT ? SWT.LEFT : ( hAlign == HorizontalAlignment.RIGHT ? SWT.RIGHT : SWT.CENTER ) );
final int hSpan = ( def.getSpanBothColumns().content() ? 2 : 1 );
if( hSpan == 1 )
{
final Label spacer = new Label( composite(), SWT.NONE );
spacer.setLayoutData( gd() );
spacer.setText( EMPTY_STRING );
register( spacer );
}
final ImageData image = part.image( 16 );
final Composite composite = new Composite( composite(), SWT.NONE );
composite.setLayoutData( gdhalign( gdhindent( gdhspan( gd(), hSpan ), 8 ), hAlignCode ) );
composite.setLayout( glayout( ( image == null ? 1 : 2 ), 0, 0 ) );
register( composite );
final Label imageControl;
if( image != null )
{
imageControl = new Label( composite, SWT.NONE );
imageControl.setImage( resources().image( image ) );
imageControl.setLayoutData( gdvalign( gd(), SWT.CENTER ) );
imageControl.setEnabled( part.enabled() );
}
else
{
imageControl = null;
}
final SapphireFormText text = new SapphireFormText( composite, SWT.NONE );
text.setLayoutData( gdvalign( gdhfill(), SWT.CENTER ) );
keyboardActionPresentation.attach( text );
String label = part.label( CapitalizationType.FIRST_WORD_ONLY );
label = ( label == null ? labelNotSpecified.text() : label );
final StringBuilder buf = new StringBuilder();
buf.append( "<form><p vspace=\"false\"><a href=\"action\" nowrap=\"true\">" );
buf.append( label );
buf.append( "</a></p></form>" );
text.setText( buf.toString(), true, false );
text.addHyperlinkListener
(
new HyperlinkAdapter()
{
@Override
public void linkActivated( final HyperlinkEvent event )
{
final SapphireActionHandler handler = part.handler();
if( handler != null )
{
handler.execute( ActuatorLinkPresentation.this );
}
}
}
);
text.setEnabled( part.enabled() );
attachPartListener
(
new Listener()
{
@Override
public void handle( final Event event )
{
if( event instanceof EnablementChangedEvent )
{
final boolean enabled = part.enabled();
if( imageControl != null )
{
imageControl.setEnabled( enabled );
}
text.setEnabled( enabled );
}
else if( event instanceof LabelChangedEvent )
{
final StringBuilder buf = new StringBuilder();
buf.append( "<form><p vspace=\"false\"><a href=\"action\" nowrap=\"true\">" );
buf.append( part.label( CapitalizationType.FIRST_WORD_ONLY ) );
buf.append( "</a></p></form>" );
text.setText( buf.toString(), true, false );
composite.getParent().layout( true, true );
}
else if( event instanceof ImageChangedEvent )
{
if( imageControl != null )
{
imageControl.setImage( resources().image( part.image( 16 ) ) );
}
}
}
}
);