/** * Returns the tree lock object for the self tree. If the element is part of a content hierarchy, the parent's tree * lock is returned. * * @return the treelock object. */ public final Object getTreeLock() { final Section parent = getParentSection(); if ( parent != null ) { return parent.getTreeLock(); } return treeLock; }
/** * Unregisters the given element from its parent. If the element is already a direct child of this section, this * operation does nothing and returns 'true' to indicate that all the work is already done. * <p/> * This is a helper function and not meant to be used by the grand public. * * @param element * the element to be unregistered from its current parent. * @return true, if the element is a child of this section, false otherwise. */ protected boolean unregisterParent( final Element element ) { // remove the element from its old parent .. // this is the default AWT behaviour when adding Components to Container final Section parentSection = element.getParentSection(); if ( parentSection != null ) { if ( parentSection == this ) { // already a child, wont add twice ... return true; } parentSection.removeElement( element ); } return false; }
/** * Removes an element from the band. * * @param e * the element to be removed. * @throws NullPointerException * if the given element is null. */ public void removeElement( final Element e ) { if ( e == null ) { throw new NullPointerException(); } if ( e.getParentSection() != this ) { // this is none of my childs, ignore the request ... return; } if ( allElements == null ) { return; } e.setParent( null ); allElements.remove( e ); allElementsCached = null; notifyNodeChildRemoved( e ); }
/** * Removes an element from the band. * * @param e * the element to be removed. * @throws NullPointerException * if the given element is null. */ public void removeElement( final Element e ) { if ( e == null ) { throw new NullPointerException(); } if ( e.getParentSection() != this ) { // this is none of my childs, ignore the request ... return; } if ( allElements == null ) { return; } e.setParent( null ); // noinspection SuspiciousMethodCalls allElements.remove( e ); allElementsCached = null; notifyNodeChildRemoved( e ); }
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() ); }