Getting access to the BaseTabComponent

I was wondering if there was a straightforward mechanism to get to the BaseTabComponent for a Dockable. We use Marathon as an automated test driver and to ease development have named all of our components under test. For selecting tabs in a stack dock station, we set the name of the BaseTabComponent. Apparently we had directly hacked this into the previous version of dock frames and so lost that when we recently upgraded to 1.1.1. I would prefer to do this is in a more sustainable manner, so if there is a good mechanism for doing this, could you let me know.

Thanks as usual for all of your work.

I would not call it straight forward, but you could put a wrapper around the factory that creates these BaseTabComponents. The factory knows for which Dockable it creates the tab, so you could set a name there (or store the tabs in a map if desired).

… and yes, the factory may create tabs that are actually never shown. The framework does not much care about efficiency, correctness is more important.

A wrapper factory could look like this:


import javax.swing.JFrame;
import javax.swing.border.Border;

import bibliothek.extension.gui.dock.theme.EclipseTheme;
import bibliothek.extension.gui.dock.theme.eclipse.stack.EclipseTabPane;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.ArchGradientPainter;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.BorderedComponent;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.InvisibleTab;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.InvisibleTabPane;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.TabComponent;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.TabPainter;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.TabPanePainter;
import bibliothek.gui.DockController;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.SingleCDockable;
import bibliothek.gui.dock.common.intern.CDockable;
import bibliothek.gui.dock.common.intern.CommonDockable;
import bibliothek.gui.dock.common.theme.ThemeMap;

public class BaseTabCatcher {
	public static void main( String[] args ){
		JFrame frame = new JFrame();
		frame.setExtendedState( JFrame.EXIT_ON_CLOSE );
		CControl control = new CControl( frame );
		
		TabPainter painter = new BaseTabNamingFactory( ArchGradientPainter.FACTORY );
		control.putProperty( EclipseTheme.TAB_PAINTER, painter );
		control.setTheme( ThemeMap.KEY_ECLIPSE_THEME );
		frame.add( control.getContentArea() );
		
		DefaultSingleCDockable content = new DefaultSingleCDockable( "hello", "Hello" );
		control.addDockable( content );
		content.setVisible( true );
		
		frame.setBounds( 20, 20, 400, 400 );
		frame.setVisible( true );
	}
	
	private static class BaseTabNamingFactory implements TabPainter{
		private TabPainter delegate;
		
		public BaseTabNamingFactory( TabPainter delegate ){
			this.delegate = delegate;
		}
		
		@Override
		public TabPanePainter createDecorationPainter( EclipseTabPane pane ){
			return delegate.createDecorationPainter( pane );
		}
		
		@Override
		public InvisibleTab createInvisibleTab( InvisibleTabPane pane, Dockable dockable ){
			return delegate.createInvisibleTab( pane, dockable );
		}
		
		@Override
		public TabComponent createTabComponent( EclipseTabPane pane, Dockable dockable ){
			TabComponent component = delegate.createTabComponent( pane, dockable );

			String name = null;
			
			// TabComponent is a BaseTabComponent
			if( dockable instanceof CommonDockable ){
				CDockable cdockable = ((CommonDockable)dockable).getDockable();
				if( cdockable instanceof SingleCDockable ){
					name = ((SingleCDockable)cdockable).getUniqueId();
				}
			}
			
			System.out.println( "created with name: " + name );
			component.getComponent().setName( name );
			return component;
		}
		
		@Override
		public Border getFullBorder( BorderedComponent owner, DockController controller, Dockable dockable ){
			return delegate.getFullBorder( owner, controller, dockable );
		}
	}
}