/** * Adds a source as child of this source. All {@link DockAction DockActions} * of <code>source</code> will be presented as actions of this source.<br> * Note: creating circles or adding a source more than once will lead to * unspecified behavior. * @param source the new child */ public void add( DockActionSource source ){ SeparatorSource separator = new SeparatorSource( source ); sources.add( source ); sources.add( separator ); separators.add( separator ); if( !listeners.isEmpty() ){ source.addDockActionSourceListener( listener ); separator.addDockActionSourceListener( listener ); } int index = getDockActionCountUntil( sources.size()-2, false ); int length = source.getDockActionCount(); if( length > 0 ) fireAdded( index, index+length-1 ); updateSeparators(); }
/** * Removes <code>source</code> from this {@link MultiDockActionSource}. * @param source the child to remove */ public void remove( DockActionSource source ){ int index = sources.indexOf( source ); if( index < 0 ) return; SeparatorSource separator = (SeparatorSource)sources.get( index+1 ); int actionIndex = getDockActionCountUntil( index, false ); int length = source.getDockActionCount(); sources.remove( index+1 ); sources.remove( index ); separators.remove( separator ); if( !listeners.isEmpty() ){ source.removeDockActionSourceListener( listener ); separator.removeDockActionSourceListener( listener ); } if( length > 0 ){ fireRemoved( actionIndex, index+length-1 ); } updateSeparators(); }
/** * Ensures that all separators which must be visible are really visible. */ private void updateSeparators(){ int size = separators.size(); int index = 0; for( SeparatorSource source : separators ){ source.update( ++index == size ); } }
/** * Removes all children of this source. */ public void removeAll(){ int length = getDockActionCount(); if( !listeners.isEmpty() ){ for( SeparatorSource source : separators ){ source.removeDockActionSourceListener( listener ); } for( DockActionSource source : sources ){ source.removeDockActionSourceListener( listener ); } } separators.clear(); sources.clear(); if( length > 0 ){ fireRemoved( 0, length-1 ); } }
public void update( boolean last ){ if( !separateSources || last ) remove( SeparatorAction.SEPARATOR ); else if( predecessor.getDockActionCount() > 0 && getDockActionCount() == 0 ) add( SeparatorAction.SEPARATOR ); } }