/**
  * Loads all of the children to initialize the view. This is called by the {@link #setParent}
  * method. Subclasses can reimplement this to initialize their child views in a different manner.
  * The default implementation creates a child view for each child element.
  *
  * @param f the view factory
  * @see #setParent
  */
 protected void loadChildren(ViewFactory f) {
   if (f == null) {
     // No factory. This most likely indicates the parent view
     // has changed out from under us, bail!
     return;
   }
   Element e = getElement();
   int n = e.getElementCount();
   if (n > 0) {
     View[] added = new View[n];
     for (int i = 0; i < n; i++) {
       added[i] = f.create(e.getElement(i));
     }
     replace(0, 0, added);
   }
 }
Ejemplo n.º 2
0
 /**
  * Updates the child views in response to receiving notification that the model changed, and there
  * is change record for the element this view is responsible for. This is implemented to assume
  * the child views are directly responsible for the child elements of the element this view
  * represents. The <code>ViewFactory</code> is used to create child views for each element
  * specified as added in the <code>ElementChange</code>, starting at the index specified in the
  * given <code>ElementChange</code>. The number of child views representing the removed elements
  * specified are removed.
  *
  * @param ec the change information for the element this view is responsible for. This should not
  *     be <code>null</code> if this method gets called
  * @param e the change information from the associated document
  * @param f the factory to use to build child views
  * @return whether or not the child views represent the child elements of the element this view is
  *     responsible for. Some views create children that represent a portion of the element they
  *     are responsible for, and should return false. This information is used to determine if
  *     views in the range of the added elements should be forwarded to or not
  * @see #insertUpdate
  * @see #removeUpdate
  * @see #changedUpdate
  * @since 1.3
  */
 protected boolean updateChildren(DocumentEvent.ElementChange ec, DocumentEvent e, ViewFactory f) {
   Element[] removedElems = ec.getChildrenRemoved();
   Element[] addedElems = ec.getChildrenAdded();
   View[] added = null;
   if (addedElems != null) {
     added = new View[addedElems.length];
     for (int i = 0; i < addedElems.length; i++) {
       added[i] = f.create(addedElems[i]);
     }
   }
   int nremoved = 0;
   int index = ec.getIndex();
   if (removedElems != null) {
     nremoved = removedElems.length;
   }
   replace(index, nremoved, added);
   return true;
 }