}
@Override
public void render()
{
final TabGroupPart part = part();
final ListFactory<Presentation> pagesListFactory = ListFactory.start();
final TabFolder tabFolderControl = new TabFolder( composite(), SWT.TOP );
tabFolderControl.setLayoutData( gdhindent( gdhspan( ( part.getScaleVertically() ? gdfill() : gdhfill() ), 2 ), 9 ) );
register( tabFolderControl );
for( final TabGroupPagePart page : part.pages() )
{
final Composite tabControl = new Composite( tabFolderControl, SWT.NONE );
tabControl.setLayout( glayout( 2, 1, 10, 10, 10 ) );
final TabItem tab = new TabItem( tabFolderControl, SWT.NONE );
tab.setText( page.getLabel() );
tab.setControl( tabControl );
final Map<ImageDescriptor,Image> images = new HashMap<ImageDescriptor,Image>();
refreshTabImage( tab, page, images );
final Listener tabPartListener = new Listener()
{
@Override
public void handle( final Event event )
{
if( event instanceof LabelChangedEvent )
{
tab.setText( page.getLabel() );
}
else if( event instanceof ImageChangedEvent )
{
refreshTabImage( tab, page, images );
}
}
};
page.attach( tabPartListener );
tab.addDisposeListener
(
new DisposeListener()
{
public void widgetDisposed( final DisposeEvent event )
{
page.detach( tabPartListener );
for( Image image : images.values() )
{
image.dispose();
}
}
}
);
final Presentation presentation = page.createPresentation( this, tabControl );
pagesListFactory.add( presentation );
presentation.render();
}
tabFolderControl.setSelection( part.pages().indexOf( part.selection() ) );
tabFolderControl.addSelectionListener
(
new SelectionAdapter()
{
@Override
public void widgetSelected( final SelectionEvent event )
{
final int tabGroupPageIndex = tabFolderControl.getSelectionIndex();
part.select( part.pages().get( tabGroupPageIndex ) );
}
}
);
this.pages = pagesListFactory.result();