/** * Adds a report element to the band. * * @param element * the element that should be added * @throws NullPointerException * if the given element is null * @throws IllegalArgumentException * if the position is invalid, either negative or greater than the number of elements in this band or if the * given element is a parent of this element. */ public void addElement( final Element element ) { addElement( getElementCount(), element ); }
/** * Returns a string representation of the band, useful mainly for debugging purposes. * * @return a string representation of this band. */ public String toString() { final StringBuilder b = new StringBuilder( 100 ); b.append( this.getClass().getName() ); b.append( "={name=\"" ); b.append( getName() ); b.append( "\", size=\"" ); b.append( getElementCount() ); b.append( "\", layout=\"" ); b.append( getStyle().getStyleProperty( BandStyleKeys.LAYOUT ) ); b.append( "\"}" ); return b.toString(); }
public static Band findGeneratedContent( final Band band ) { final Band generatedContentInternal = findGeneratedContentInternal( band ); if ( generatedContentInternal != null ) { generatedContentInternal.clear(); return generatedContentInternal; } if ( band.getElementCount() == 0 ) { return band; } return null; }
/** * Internal function that collects all elements of a given band with a given name. * * @param band * the band from which elements should be collected. * @param element * the name of the element to collect. * @param collector * the list of results. */ private static void performFindElement( final Band band, final String element, final ArrayList<Element> collector ) { final int count = band.getElementCount(); final Element[] buffer = band.getElementArray(); for ( int i = 0; i < count; i++ ) { final Element e = buffer[i]; if ( e.getName().equals( element ) ) { collector.add( e ); } if ( e instanceof Band ) { performFindElement( (Band) e, element, collector ); } } }
throw new IllegalArgumentException( "Position < 0" ); if ( position > getElementCount() ) { throw new IllegalArgumentException( "Position < 0" );
public void setElementAt( final int position, final Element element ) { if ( position < 0 ) { throw new IllegalArgumentException( "Position < 0" ); } if ( position >= getElementCount() ) { throw new IllegalArgumentException( "Position >= size" ); } if ( element == null ) { throw new NullPointerException( "Band.addElement(...): element is null." ); } validateLooping( element ); if ( unregisterParent( element ) ) { return; } if ( allElements == null ) { throw new IllegalStateException( "The throws above should have caught that state" ); } // add the element, update the childs Parent and the childs stylesheet. final Element o = allElements.set( position, element ); o.setParent( null ); allElementsCached = null; // then add the parents, or the band's parent will be unregistered .. registerAsChild( element ); notifyNodeChildRemoved( o ); notifyNodeChildAdded( element ); }
private boolean isEmptyRootBand( final Band band ) { if ( band.getName().startsWith( Band.ANONYMOUS_BAND_PREFIX ) == false ) { return false; } if ( band.getName().startsWith( Element.ANONYMOUS_ELEMENT_PREFIX ) == false ) { return false; } if ( band.getElementCount() != 0 ) { return false; } if ( band instanceof RootLevelBand ) { final RootLevelBand rlb = (RootLevelBand) band; if ( rlb.getSubReportCount() > 0 ) { return false; } } final ElementStyleSheet styleSheet = band.getStyle(); if ( isStyleSheetEmpty( styleSheet ) ) { return true; } return false; }
public void testAddElements() { Band band = new Band(); try { band.addElements( null ); fail( "should throw exception" ); } catch ( NullPointerException e ) { // expected } Element elem = mock( Element.class ); List<Element> elements = new ArrayList<Element>(); elements.add( elem ); band.addElements( elements ); assertEquals( 1, band.getElementCount() ); assertEquals( elem, band.getElement( 0 ) ); }
public void testGetElement() { Band band = new Band(); try { band.getElement( null ); fail( "should throw exception" ); } catch ( NullPointerException e ) { // expected } Element elem = mock( Element.class ); doReturn( "test_name" ).when( elem ).getName(); band.addElement( elem ); assertEquals( 1, band.getElementCount() ); assertEquals( elem, band.getElement( "test_name" ) ); }
public void testAddElement() { final Band b = new Band(); assertTrue( b.getElementCount() == 0 ); b.addElement( 0, new Element() ); assertTrue( b.getElementCount() == 1 ); b.addElement( new Element() ); assertTrue( b.getElementCount() == 2 ); b.addElement( 0, new Element() ); assertTrue( b.getElementCount() == 3 ); b.addElement( 2, new Element() ); assertTrue( b.getElementCount() == 4 ); try { b.addElement( 5, new Element() );
public void testSetElementAt() { Band band = new Band(); band.addElement( mock( Element.class ) ); Element elem = mock( Element.class ); try { band.setElementAt( -1, elem ); fail( "should throw exception" ); } catch ( IllegalArgumentException e ) { // expected } try { band.setElementAt( 10, elem ); fail( "should throw exception" ); } catch ( IllegalArgumentException e ) { // expected } try { band.setElementAt( 0, null ); fail( "should throw exception" ); } catch ( NullPointerException e ) { // expected } band.setElementAt( 0, elem ); assertEquals( 1, band.getElementCount() ); assertEquals( elem, band.getElement( 0 ) ); assertEquals( band, elem.getParentSection() ); }
if ( band.getElementCount() == 0 ) { inlineContainer = new Band(); inlineContainer.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, "inline" ); final Element maybeInlineContainer = (Element) band.getElement( band.getElementCount() - 1 ); if ( maybeInlineContainer == inlineContainer ) {
if ( band instanceof Band ) { final Band b = (Band) band; if ( b.getElementCount() > 0 ) { return false;
public void testBandCreate() { Band b = new Band(); assertNotNull( b.getDataSource() ); assertNotNull( b.getStyle() ); assertNotNull( b.getName() ); assertTrue( b.isVisible() ); assertNull( b.getParent() ); assertNotNull( b.getElementArray() ); assertTrue( b.getElementCount() == 0 ); assertTrue( b.getElementType() instanceof BandType ); assertFalse( b.isPagebreakBeforePrint() ); assertFalse( b.isPagebreakAfterPrint() ); InstanceID id = new InstanceID(); b = new Band( id ); assertNotNull( b.getTreeLock() ); assertEquals( id, b.getTreeLock() ); assertTrue( b.getElementType() instanceof BandType ); assertFalse( b.isPagebreakBeforePrint() ); assertFalse( b.isPagebreakAfterPrint() ); b = new Band( true, true ); assertTrue( b.getElementType() instanceof BandType ); assertTrue( b.isPagebreakBeforePrint() ); assertTrue( b.isPagebreakAfterPrint() ); }