int limit = Math.min( historyList.size( ), historyIndex + MAX_ENTRIES + 1 ); for ( int i = historyIndex + 1; i < limit; i++ )
for ( int i = historyIndex + 1, j = 0; i < historyList.size( ) && j < MAX_ENTRIES; i++ )
	public ToolBar createHistoryControls( ToolBar historyBar,			ToolBarManager manager )	{		historyToolbar = manager;		/**		 * Superclass of the two for-/backward actions for the history.		 */		abstract class HistoryNavigationAction extends Action				implements					IMenuCreator		{			private Menu lastMenu;			protected final static int MAX_ENTRIES = 5;			HistoryNavigationAction( )			{				super( "", IAction.AS_DROP_DOWN_MENU ); //$NON-NLS-1$			}			public IMenuCreator getMenuCreator( )			{				return this;			}			public void dispose( )			{				if ( lastMenu != null )				{					lastMenu.dispose( );					lastMenu = null;				}			}			public Menu getMenu( Control parent )			{				if ( lastMenu != null )				{					lastMenu.dispose( );				}				lastMenu = new Menu( parent );				createEntries( lastMenu );				return lastMenu;			}			public Menu getMenu( Menu parent )			{				return null;			}			protected void addActionToMenu( Menu parent, IAction action )			{				ActionContributionItem item = new ActionContributionItem( action );				item.fill( parent, -1 );			}			protected abstract void createEntries( Menu menu );		}		/**		 * Menu entry for the toolbar dropdowns. Instances are direct-jump		 * entries in the navigation history.		 */		class HistoryItemAction extends Action		{			private final int index;			HistoryItemAction( int index, String label )			{				super( label, IAction.AS_PUSH_BUTTON );				this.index = index;			}			public void run( )			{				if ( isCurrentEntryAvailable( index ) )				{					jumpToHistory( index );				}			}		}		HistoryNavigationAction backward = new HistoryNavigationAction( ) {			public void run( )			{				int index = historyIndex - 1;				while ( !isCurrentEntryAvailable( index ) )				{					index--;				}				jumpToHistory( index );			}			public boolean isEnabled( )			{				boolean enabled = historyIndex > 0;				if ( enabled )				{					int index = historyIndex - 1;					setToolTipText( isCurrentEntryAvailable( index )							? Messages.getFormattedString( "SubtaskHistory.Tooltip.Back", //$NON-NLS-1$									getItemText( index ) ) : "" ); //$NON-NLS-1$				}				return enabled;			}			protected void createEntries( Menu menu )			{				int limit = Math.max( 0, historyIndex - MAX_ENTRIES );				for ( int i = historyIndex - 1; i >= limit; i-- )				{					IAction action = new HistoryItemAction( i, getItemText( i ) );					addActionToMenu( menu, action );				}			}		};		backward.setText( Messages.getString( "SubtaskHistory.Text.Back" ) ); //$NON-NLS-1$		backward.setActionDefinitionId( "org.eclipse.ui.navigate.backwardHistory" ); //$NON-NLS-1$		backward.setImageDescriptor( ImageDescriptor.createFromURL( UIHelper.getURL( UIHelper.IMAGE_NAV_BACKWARD ) ) );		backward.setDisabledImageDescriptor( ImageDescriptor.createFromURL( UIHelper.getURL( UIHelper.IMAGE_NAV_BACKWARD_DIS ) ) );		historyToolbar.add( backward );		HistoryNavigationAction forward = new HistoryNavigationAction( ) {			public void run( )			{				int index = historyIndex + 1;				while ( !isCurrentEntryAvailable( index ) )				{					index++;				}				jumpToHistory( index );			}			public boolean isEnabled( )			{				boolean enabled = historyIndex < historyList.size( ) - 1;				if ( enabled )				{					int index = historyIndex + 1;					setToolTipText( isCurrentEntryAvailable( index )							? Messages.getFormattedString( "SubtaskHistory.Tooltip.Forward", //$NON-NLS-1$									getItemText( index ) ) : "" ); //$NON-NLS-1$				}				return enabled;			}			protected void createEntries( Menu menu )			{				int limit = Math.min( historyList.size( ), historyIndex						+ MAX_ENTRIES + 1 );				for ( int i = historyIndex + 1; i < limit; i++ )				{					IAction action = new HistoryItemAction( i, getItemText( i ) );					addActionToMenu( menu, action );				}			}		};		forward.setText( Messages.getString( "SubtaskHistory.Text.Forward" ) ); //$NON-NLS-1$		forward.setActionDefinitionId( "org.eclipse.ui.navigate.forwardHistory" ); //$NON-NLS-1$		forward.setImageDescriptor( ImageDescriptor.createFromURL( UIHelper.getURL( UIHelper.IMAGE_NAV_FORWARD ) ) );		forward.setDisabledImageDescriptor( ImageDescriptor.createFromURL( UIHelper.getURL( UIHelper.IMAGE_NAV_FORWARD_DIS ) ) );		historyToolbar.add( forward );		return historyBar;	}