package data.stdforms;

import sale.*;

import data.*;
import data.swing.*;
import data.stdforms.singletableformsheet.*;

import util.swing.*;

import javax.swing.*;

import java.util.*;

/**
  * A FormSheet displaying the contents of a {@link Catalog}, {@link Stock} or {@link DataBasket}.
  *
  * <p>The FormSheet will comprise one table that renders the contents of the container to be displayed.
  * Additionally, there can be to extra buttons in the FormSheet's button bar that can be used to add or
  * remove records to/from the container. The actions linked to these buttons will be represented as
  * sub-processes to the process which displayed the FormSheet. The actual sub-process will be created by a
  * {@link EditButtonStrategy strategy object}.</p>
  *
  * <p>SingleTableFormSheets assume to be displayed at a {@link UIGate user interface gate}. However, if you
  * do not want to add editing capabilities, you may set this parameter to <code>null</code> and use the
  * FormSheet as you would any other FormSheet. If you need editing capabilities, you must set the FormSheet at
  * a UIGate.</p>
  *
  * <p>Various <code>create()</code> methods are offered that cover the entire spectrum of possible
  * SingleTableFormSheets. All you need to do is select the <code>create()</code> method that fits your purpose
  * and use it in your application.</p>
  *
  * @author Steffen Zschaler
  * @version 2.0 20/08/1999
  * @since v2.0
  */
public class SingleTableFormSheet extends FormSheet {

  /**
    * The button id that is used for the &quot;Add&quot; button.
    */
  public static final int BTNID_ADD = -100;

  /**
    * The button id that is used for the &quot;Remove&quot; button.
    */
  public static final int BTNID_REMOVE = -101;

  /**
    * Reference to the currently selected index.
    *
    * @serial
    */
  private int[] m_anSelection = new int[] { -1 };

  /**
    * The {@link TableModel} of the table displayed.
    */
  private transient util.swing.AbstractTableModel m_atmModel;

  /**
    * The {@link Gate} at which the FormSheet is being displayed.
    *
    * @serial
    */
  private UIGate m_uigGate;

  /**
    * Create a new SingleTableFormSheet. The &quot;{@link FormSheet#waitResponse}&quot; property will default
    * to true.
    *
    * <p>Instead of calling this method, call one of the <code>create()</code> methods provided.
    *
    * @param sCaption the FormSheet's caption.
    * @param uigGate the Gate at which the FormSheet is displayed.
    * @param fscc the content creator to be used to create the FormSheet's contents.
    */
  protected SingleTableFormSheet (String sCaption,
                                  UIGate uigGate,
                                  FormSheetContentCreator fscc) {
    super (sCaption,
           (JComponent) null,
           true);

    setGate (uigGate);

    // we call addContentCreator here to allow for m_anSelection to be initialized before.
    // We cannot give fscc as a parameter to the superclass constructor, as m_anSelection would then not
    // be initialized when the content creator is called to create the FormSheet's contents.
    addContentCreator (fscc);
  }

  /**
    * Set the gate at which to display the FormSheet. This will also move the FormSheet to that gate, i.e. make
    * the FormSheet the FormSheet of the given gate.
    *
    * @param uigGate the new Gate.
    *
    * @override Never
    *
    * @see UIGate#setFormSheet
    */
  public void setGate (UIGate uigGate) {
    if (m_uigGate != null) {
      m_uigGate.setFormSheet (null);
    }

    m_uigGate = uigGate;

    if (m_uigGate != null) {
      m_uigGate.setFormSheet (this);
    }
  }

  /**
    * Get the Gate this FormSheet is currently being displayed at.
    *
    * @override Never
    */
  public UIGate getGate() {
    return m_uigGate;
  }

  /**
    * Get the record currently selected.
    *
    * <p>The actual class of the record depends on the concrete type of
    * TableModel used. See the TableModel's <code>getRecord()</code> method for
    * details. To find out, which TableModel is used by your specific instance
    * of <code>SingleTableFormSheet</code> refer to the documentation of the
    * <code>create()</code> method you used to instantiate it.</p>
    */
  public Object getSelectedRecord() {
    return m_atmModel.getRecord (m_anSelection[0]);
  }

  /**
    * Convenience method Equivalent to:
    *
    * <pre>
    * {@link #addAddButton addAddButton} (ebsAdd);
    * {@link #addRemoveButton addRemoveButton} (ebsRemove);
    * </pre>
    *
    * <p>This method must be called from within a content creator if you need serializability.</p>
    *
    * @override Never
    */
  public void addEditingButtons (EditButtonStrategy ebsAdd,
                                 EditButtonStrategy ebsRemove) {
    addAddButton (ebsAdd);
    addRemoveButton (ebsRemove);
  }

  /**
    * Add to the FormSheet a button that will allow the user to add records to the container being displayed.
    *
    * <p>The button will by default have a caption of &quot;Add&quot; and a button id of {@link #BTNID_ADD}.
    * The button's action will trigger the sub-process defined by <code>ebsAdd</code>.</p>
    *
    * <p>This method must be called from within a content creator if you need serializability.</p>
    *
    * @param ebsAdd a strategy defining the sub-process to be used for adding a record. For a
    * SingleTableFormSheet displaying a Catalog, {@link AbstractAddCatalogItemStrategy} is already part of the
    * Framework.
    *
    * @override Never
    */
  public void addAddButton (final EditButtonStrategy ebsAdd) {
    removeButton (BTNID_ADD);

    addButton ("Add", BTNID_ADD, new sale.Action() {
      public void doAction (SaleProcess p, SalesPoint sp) {
        getGate().setNextTransition (ebsAdd.getEditProcess (SingleTableFormSheet.this, p, sp));
      }
    });
  }

  /**
    * Add to the FormSheet a button that will allow the user to remove the currently selected record from the
    * container being displayed.
    *
    * <p>The button will by default have a caption of &quot;Remove&quot; and a button id of
    * {@link #BTNID_REMOVE}. The button's action will trigger the sub-process defined by
    * <code>ebsRemove</code>.</p>
    *
    * <p>This method must be called from within a content creator if you need serializability.</p>
    *
    * @param ebsRemove a strategy defining the sub-process to be used for removing a record. For a
    * SingleTableFormSheet displaying a Catalog, {@link DefaultRemoveCatalogItemStrategy} is already part of
    * the Framework.
    *
    * @override Never
    */
  public void addRemoveButton (final EditButtonStrategy ebsRemove) {
    removeButton (BTNID_REMOVE);

    addButton ("Remove", BTNID_REMOVE, new sale.Action() {
      public void doAction (SaleProcess p, SalesPoint sp) {
        getGate().setNextTransition (ebsRemove.getEditProcess (SingleTableFormSheet.this, p, sp));
      }
    });
  }

  /**
    * Convenience method for removing the &quot;Add&quot; and the &quot;Remove&quot; button.
    *
    * @override Never
    */
  public void removeEditButtons() {
    removeButton (BTNID_REMOVE);
    removeButton (BTNID_ADD);
  }

  /**
    * Helper class forming the foundation of all SingleTableFormSheet content creators.
    *
    * @author Steffen Zschaler
    * @version 2.0 20/08/1999
    * @since v2.0
    */
  private static abstract class STFSContentCreator extends FormSheetContentCreator {

    /**
      * Set the given table to be the component of the given FormSheet. Also, link the FormSheet's selection
      * observer accordingly.
      *
      * @override Never
      */
    protected void setFormSheetComponent (SingleTableFormSheet stfs,
                                          JAbstractTable jat) {
      stfs.setComponent (new JScrollPane (jat));

      stfs.m_atmModel = (util.swing.AbstractTableModel) jat.getModel();
      jat.setSelectionObserver (stfs.m_anSelection);
    }
  }

  // JCatalogTable FormSheet creators

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a Catalog.
    *
    * <p>The FormSheet will contain a {@link JCatalogTable}, the individual records are
    * {@link CatalogItem CatalogItems}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>, the sorting
    * order defaults to the natural ordering of the CatalogItems. If <code>c</code> is a {@link Currency},
    * the {@link TableEntryDescriptor} defaults to a {@link DefaultCurrencyItemTED} using <code>c</code> to
    * format values. Otherwise, it defaults to a {@link DefaultCatalogItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param c the Catalog whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             Catalog c,
                                             UIGate uigGate) {
    return create (sCaption,
                   c,
                   uigGate,
                   null,
                   null,
                   ((c instanceof Currency)?
                    (new DefaultCurrencyItemTED ((Currency) c)):
                    (new DefaultCatalogItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a Catalog.
    *
    * <p>The FormSheet will contain a {@link JCatalogTable}, the individual records are
    * {@link CatalogItem CatalogItems}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>, the sorting
    * order defaults to the natural ordering of the CatalogItems.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param c the Catalog whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param ted a TableEntryDescriptor that can split individual CatalogItems into a table's cells. Must not
    * be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             Catalog c,
                                             UIGate uigGate,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   c,
                   uigGate,
                   null,
                   null,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a Catalog.
    *
    * <p>The FormSheet will contain a {@link JCatalogTable}, the individual records are
    * {@link CatalogItem CatalogItems}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>. If
    * <code>c</code> is a {@link Currency}, the {@link TableEntryDescriptor} defaults to a
    * {@link DefaultCurrencyItemTED} using <code>c</code> to format values. Otherwise, it defaults to a
    * {@link DefaultCatalogItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param c the Catalog whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the natural ordering of the CatalogItems will be followed.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             Catalog c,
                                             UIGate uigGate,
                                             Comparator cmp) {
    return create (sCaption,
                   c,
                   uigGate,
                   null,
                   cmp,
                   ((c instanceof Currency)?
                    (new DefaultCurrencyItemTED ((Currency) c)):
                    (new DefaultCatalogItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a Catalog.
    *
    * <p>The FormSheet will contain a {@link JCatalogTable}, the individual records are
    * {@link CatalogItem CatalogItems}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param c the Catalog whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the natural ordering of the CatalogItems will be followed.
    * @param ted a TableEntryDescriptor that can split individual CatalogItems into a table's cells. Must not
    * be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             Catalog c,
                                             UIGate uigGate,
                                             Comparator cmp,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   c,
                   uigGate,
                   null,
                   cmp,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a Catalog.
    *
    * <p>The FormSheet will contain a {@link JCatalogTable}, the individual records are
    * {@link CatalogItem CatalogItems}.</p>
    *
    * <p>The sorting order defaults to the natural ordering of the CatalogItems. If <code>c</code> is a
    * {@link Currency}, the {@link TableEntryDescriptor} defaults to a {@link DefaultCurrencyItemTED} using
    * <code>c</code> to format values. Otherwise, it defaults to a {@link DefaultCatalogItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param c the Catalog whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             Catalog c,
                                             UIGate uigGate,
                                             DataBasket db) {
    return create (sCaption,
                   c,
                   uigGate,
                   db,
                   null,
                   ((c instanceof Currency)?
                    (new DefaultCurrencyItemTED ((Currency) c)):
                    (new DefaultCatalogItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a Catalog.
    *
    * <p>The FormSheet will contain a {@link JCatalogTable}, the individual records are
    * {@link CatalogItem CatalogItems}.</p>
    *
    * <p>The sorting order defaults to the natural ordering of the CatalogItems.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param c the Catalog whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param ted a TableEntryDescriptor that can split individual CatalogItems into a table's cells. Must not
    * be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             Catalog c,
                                             UIGate uigGate,
                                             DataBasket db,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   c,
                   uigGate,
                   db,
                   null,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a Catalog.
    *
    * <p>The FormSheet will contain a {@link JCatalogTable}, the individual records are
    * {@link CatalogItem CatalogItems}.</p>
    *
    * <p>If <code>c</code> is a {@link Currency}, the {@link TableEntryDescriptor} defaults to a
    * {@link DefaultCurrencyItemTED} using <code>c</code> to format values. Otherwise, it defaults to a
    * {@link DefaultCatalogItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param c the Catalog whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the natural ordering of the CatalogItems will be followed.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             Catalog c,
                                             UIGate uigGate,
                                             DataBasket db,
                                             Comparator cmp) {
    return create (sCaption,
                   c,
                   uigGate,
                   db,
                   cmp,
                   ((c instanceof Currency)?
                    (new DefaultCurrencyItemTED ((Currency) c)):
                    (new DefaultCatalogItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a Catalog.
    *
    * <p>The FormSheet will contain a {@link JCatalogTable}, the individual records are
    * {@link CatalogItem CatalogItems}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param c the Catalog whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the natural ordering of the CatalogItems will be followed.
    * @param ted a TableEntryDescriptor that can split individual CatalogItems into a table's cells. Must not
    * be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             final Catalog c,
                                             UIGate uigGate,
                                             final DataBasket db,
                                             final Comparator cmp,
                                             final TableEntryDescriptor ted) {
    return new SingleTableFormSheet (sCaption,
                                     uigGate,
                                     new STFSContentCreator() {
      protected void createFormSheetContent (FormSheet fs) {
        JCatalogTable jct = new JCatalogTable (c,
                                               db,
                                               cmp,
                                               ted);

        setFormSheetComponent ((SingleTableFormSheet) fs, jct);
      }
    });
  }

  // JCountingStockTable FormSheet creators

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>, the sorting
    * order defaults to the natural ordering of the keys. Lines containing '0' in the &quot;Count&quot; column
    * will by default be hidden. If <code>cs</code> is a {@link MoneyBag}, the {@link TableEntryDescriptor}
    * defaults to a {@link DefaultMoneyBagItemTED} using <code>cs.getCatalog()</code> to format values.
    * Otherwise, it defaults to a {@link DefaultCountingStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate) {
    return create (sCaption,
                   cs,
                   uigGate,
                   null,
                   null,
                   false,
                   ((cs instanceof MoneyBag)?
                    (new DefaultMoneyBagItemTED ((Currency) cs.getCatalog (null))):
                    (new DefaultCountingStockItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>, the sorting
    * order defaults to the natural ordering of the keys. Lines containing '0' in the &quot;Count&quot; column
    * will by default be hidden.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param ted a TableEntryDescriptor that can split individual
    * {@link CountingStockTableModel.Record CountingStockTableModel records} into a table's cells. Must not be
    * <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   cs,
                   uigGate,
                   null,
                   null,
                   false,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>, the sorting
    * order defaults to the natural ordering of the keys. If <code>cs</code> is a {@link MoneyBag}, the
    * {@link TableEntryDescriptor} defaults to a {@link DefaultMoneyBagItemTED} using
    * <code>cs.getCatalog()</code> to format values. Otherwise, it defaults to a
    * {@link DefaultCountingStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param fShowZeros if false, lines containing a '0' in the &quot;Count&quot; field will be hidden.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             boolean fShowZeros) {
    return create (sCaption,
                   cs,
                   uigGate,
                   null,
                   null,
                   fShowZeros,
                   ((cs instanceof MoneyBag)?
                    (new DefaultMoneyBagItemTED ((Currency) cs.getCatalog (null))):
                    (new DefaultCountingStockItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>, the sorting
    * order defaults to the natural ordering of the keys.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param fShowZeros if false, lines containing a '0' in the &quot;Count&quot; field will be hidden.
    * @param ted a TableEntryDescriptor that can split individual
    * {@link CountingStockTableModel.Record CountingStockTableModel records} into a table's cells. Must not be
    * <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             boolean fShowZeros,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   cs,
                   uigGate,
                   null,
                   null,
                   fShowZeros,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>. Lines
    * containing '0' in the &quot;Count&quot; column will by default be hidden. If <code>cs</code> is a
    * {@link MoneyBag}, the {@link TableEntryDescriptor} defaults to a {@link DefaultMoneyBagItemTED} using
    * <code>cs.getCatalog()</code> to format values. Otherwise, it defaults to a
    * {@link DefaultCountingStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the records will be ordered by their keys.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             Comparator cmp) {
    return create (sCaption,
                   cs,
                   uigGate,
                   null,
                   cmp,
                   false,
                   ((cs instanceof MoneyBag)?
                    (new DefaultMoneyBagItemTED ((Currency) cs.getCatalog (null))):
                    (new DefaultCountingStockItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>. Lines
    * containing '0' in the &quot;Count&quot; column will by default be hidden.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the records will be ordered by their keys.
    * @param ted a TableEntryDescriptor that can split individual
    * {@link CountingStockTableModel.Record CountingStockTableModel records} into a table's cells. Must not be
    * <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             Comparator cmp,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   cs,
                   uigGate,
                   null,
                   cmp,
                   false,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>. If
    * <code>cs</code> is a {@link MoneyBag}, the {@link TableEntryDescriptor} defaults to a
    * {@link DefaultMoneyBagItemTED} using <code>cs.getCatalog()</code> to format values. Otherwise, it
    * defaults to a {@link DefaultCountingStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the records will be ordered by their keys.
    * @param fShowZeros if false, lines containing a '0' in the &quot;Count&quot; field will be hidden.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             Comparator cmp,
                                             boolean fShowZeros) {
    return create (sCaption,
                   cs,
                   uigGate,
                   null,
                   cmp,
                   fShowZeros,
                   ((cs instanceof MoneyBag)?
                    (new DefaultMoneyBagItemTED ((Currency) cs.getCatalog (null))):
                    (new DefaultCountingStockItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the records will be ordered by their keys.
    * @param fShowZeros if false, lines containing a '0' in the &quot;Count&quot; field will be hidden.
    * @param ted a TableEntryDescriptor that can split individual
    * {@link CountingStockTableModel.Record CountingStockTableModel records} into a table's cells. Must not be
    * <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             Comparator cmp,
                                             boolean fShowZeros,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   cs,
                   uigGate,
                   null,
                   cmp,
                   fShowZeros,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The sorting order defaults to the natural ordering of the keys. Lines containing '0' in the
    * &quot;Count&quot; column will by default be hidden. If <code>cs</code> is a {@link MoneyBag}, the
    * {@link TableEntryDescriptor} defaults to a {@link DefaultMoneyBagItemTED} using
    * <code>cs.getCatalog()</code> to format values. Otherwise, it defaults to a
    * {@link DefaultCountingStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             DataBasket db) {
    return create (sCaption,
                   cs,
                   uigGate,
                   db,
                   null,
                   false,
                   ((cs instanceof MoneyBag)?
                    (new DefaultMoneyBagItemTED ((Currency) cs.getCatalog (db))):
                    (new DefaultCountingStockItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The sorting order defaults to the natural ordering of the keys. Lines containing '0' in the
    * &quot;Count&quot; column will by default be hidden.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param ted a TableEntryDescriptor that can split individual
    * {@link CountingStockTableModel.Record CountingStockTableModel records} into a table's cells. Must not be
    * <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             DataBasket db,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   cs,
                   uigGate,
                   db,
                   null,
                   false,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The sorting order defaults to the natural ordering of the keys. If <code>cs</code> is a
    * {@link MoneyBag}, the {@link TableEntryDescriptor} defaults to a {@link DefaultMoneyBagItemTED} using
    * <code>cs.getCatalog()</code> to format values. Otherwise, it defaults to a
    * {@link DefaultCountingStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param fShowZeros if false, lines containing a '0' in the &quot;Count&quot; field will be hidden.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             DataBasket db,
                                             boolean fShowZeros) {
    return create (sCaption,
                   cs,
                   uigGate,
                   db,
                   null,
                   fShowZeros,
                   ((cs instanceof MoneyBag)?
                    (new DefaultMoneyBagItemTED ((Currency) cs.getCatalog (db))):
                    (new DefaultCountingStockItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>The sorting order defaults to the natural ordering of the keys.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param fShowZeros if false, lines containing a '0' in the &quot;Count&quot; field will be hidden.
    * @param ted a TableEntryDescriptor that can split individual
    * {@link CountingStockTableModel.Record CountingStockTableModel records} into a table's cells. Must not be
    * <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             DataBasket db,
                                             boolean fShowZeros,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   cs,
                   uigGate,
                   db,
                   null,
                   fShowZeros,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>Lines containing '0' in the &quot;Count&quot; column will by default be hidden. If <code>cs</code> is
    * a {@link MoneyBag}, the {@link TableEntryDescriptor} defaults to a {@link DefaultMoneyBagItemTED} using
    * <code>cs.getCatalog()</code> to format values. Otherwise, it defaults to a
    * {@link DefaultCountingStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the records will be ordered by their keys.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             DataBasket db,
                                             Comparator cmp) {
    return create (sCaption,
                   cs,
                   uigGate,
                   db,
                   cmp,
                   false,
                   ((cs instanceof MoneyBag)?
                    (new DefaultMoneyBagItemTED ((Currency) cs.getCatalog (db))):
                    (new DefaultCountingStockItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>Lines containing '0' in the &quot;Count&quot; column will by default be hidden.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the records will be ordered by their keys.
    * @param ted a TableEntryDescriptor that can split individual
    * {@link CountingStockTableModel.Record CountingStockTableModel records} into a table's cells. Must not be
    * <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             DataBasket db,
                                             Comparator cmp,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   cs,
                   uigGate,
                   db,
                   cmp,
                   false,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * <p>If <code>cs</code> is a {@link MoneyBag}, the {@link TableEntryDescriptor} defaults to a
    * {@link DefaultMoneyBagItemTED} using <code>cs.getCatalog()</code> to format values. Otherwise, it
    * defaults to a {@link DefaultCountingStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the records will be ordered by their keys.
    * @param fShowZeros if false, lines containing a '0' in the &quot;Count&quot; field will be hidden.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             CountingStock cs,
                                             UIGate uigGate,
                                             DataBasket db,
                                             Comparator cmp,
                                             boolean fShowZeros) {
    return create (sCaption,
                   cs,
                   uigGate,
                   db,
                   cmp,
                   fShowZeros,
                   ((cs instanceof MoneyBag)?
                    (new DefaultMoneyBagItemTED ((Currency) cs.getCatalog (db))):
                    (new DefaultCountingStockItemTED())));
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a CountingStock.
    *
    * <p>The FormSheet will contain a {@link JCountingStockTable}, the individual records are
    * {@link CountingStockTableModel.Record CountingStockTableModel records}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param cs the CountingStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the records will be ordered by their keys.
    * @param fShowZeros if false, lines containing a '0' in the &quot;Count&quot; field will be hidden.
    * @param ted a TableEntryDescriptor that can split individual
    * {@link CountingStockTableModel.Record CountingStockTableModel records} into a table's cells. Must not be
    * <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             final CountingStock cs,
                                             UIGate uigGate,
                                             final DataBasket db,
                                             final Comparator cmp,
                                             final boolean fShowZeros,
                                             final TableEntryDescriptor ted) {
    return new SingleTableFormSheet (sCaption,
                                     uigGate,
                                     new STFSContentCreator() {
      protected void createFormSheetContent (FormSheet fs) {
        JCountingStockTable jcst = new JCountingStockTable (cs,
                                                            db,
                                                            cmp,
                                                            fShowZeros,
                                                            ted);
        setFormSheetComponent ((SingleTableFormSheet) fs, jcst);
      }
    });
  }

  // JStoringStockTable FormSheet creators

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a StoringStock.
    *
    * <p>The FormSheet will contain a {@link JStoringStockTable}, the individual records are
    * {@link StockItem StockItems}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>, the sorting
    * order defaults to the natural ordering of the StockItems. The {@link TableEntryDescriptor} defaults to a
    * {@link DefaultStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param ss the StoringStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             StoringStock ss,
                                             UIGate uigGate) {
    return create (sCaption,
                   ss,
                   uigGate,
                   null,
                   null,
                   new DefaultStockItemTED());
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a StoringStock.
    *
    * <p>The FormSheet will contain a {@link JStoringStockTable}, the individual records are
    * {@link StockItem StockItems}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>, the sorting
    * order defaults to the natural ordering of the StockItems.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param ss the StoringStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param ted a TableEntryDescriptor that can split individual {@link StockItem StockItems} into a table's
    * cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             StoringStock ss,
                                             UIGate uigGate,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   ss,
                   uigGate,
                   null,
                   null,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a StoringStock.
    *
    * <p>The FormSheet will contain a {@link JStoringStockTable}, the individual records are
    * {@link StockItem StockItems}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>. The
    * {@link TableEntryDescriptor} defaults to a {@link DefaultStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param ss the StoringStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the natural order of the StockItems will be applied.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             StoringStock ss,
                                             UIGate uigGate,
                                             Comparator cmp) {
    return create (sCaption,
                   ss,
                   uigGate,
                   null,
                   cmp,
                   new DefaultStockItemTED());
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a StoringStock.
    *
    * <p>The FormSheet will contain a {@link JStoringStockTable}, the individual records are
    * {@link StockItem StockItems}.</p>
    *
    * <p>The {@link DataBasket} used to determine visibility will default to <code>null</code>.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param ss the StoringStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the natural order of the StockItems will be applied.
    * @param ted a TableEntryDescriptor that can split individual {@link StockItem StockItems} into a table's
    * cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             StoringStock ss,
                                             UIGate uigGate,
                                             Comparator cmp,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   ss,
                   uigGate,
                   null,
                   cmp,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a StoringStock.
    *
    * <p>The FormSheet will contain a {@link JStoringStockTable}, the individual records are
    * {@link StockItem StockItems}.</p>
    *
    * <p>The sorting order defaults to the natural ordering of the StockItems. The {@link TableEntryDescriptor}
    * defaults to a {@link DefaultStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param ss the StoringStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             StoringStock ss,
                                             UIGate uigGate,
                                             DataBasket db) {
    return create (sCaption,
                   ss,
                   uigGate,
                   db,
                   null,
                   new DefaultStockItemTED());
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a StoringStock.
    *
    * <p>The FormSheet will contain a {@link JStoringStockTable}, the individual records are
    * {@link StockItem StockItems}.</p>
    *
    * <p>The sorting order defaults to the natural ordering of the StockItems.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param ss the StoringStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param ted a TableEntryDescriptor that can split individual {@link StockItem StockItems} into a table's
    * cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             StoringStock ss,
                                             UIGate uigGate,
                                             DataBasket db,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   ss,
                   uigGate,
                   db,
                   null,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a StoringStock.
    *
    * <p>The FormSheet will contain a {@link JStoringStockTable}, the individual records are
    * {@link StockItem StockItems}.</p>
    *
    * <p>The {@link TableEntryDescriptor} defaults to a {@link DefaultStockItemTED}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param ss the StoringStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the natural order of the StockItems will be applied.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             StoringStock ss,
                                             UIGate uigGate,
                                             DataBasket db,
                                             Comparator cmp) {
    return create (sCaption,
                   ss,
                   uigGate,
                   db,
                   cmp,
                   new DefaultStockItemTED());
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a StoringStock.
    *
    * <p>The FormSheet will contain a {@link JStoringStockTable}, the individual records are
    * {@link StockItem StockItems}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param ss the StoringStock whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param db the DataBasket that is used to determine visibility of items.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * the natural order of the StockItems will be applied.
    * @param ted a TableEntryDescriptor that can split individual {@link StockItem StockItems} into a table's
    * cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             final StoringStock ss,
                                             UIGate uigGate,
                                             final DataBasket db,
                                             final Comparator cmp,
                                             final TableEntryDescriptor ted) {
    return new SingleTableFormSheet (sCaption,
                                     uigGate,
                                     new STFSContentCreator() {
      protected void createFormSheetContent (FormSheet fs) {
        JStoringStockTable jsst = new JStoringStockTable (ss,
                                                          db,
                                                          cmp,
                                                          ted);
        setFormSheetComponent ((SingleTableFormSheet) fs, jsst);
      }
    });
  }

  // JDataBasketTable FormSheet creators

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a DataBasket.
    *
    * <p>The FormSheet will contain a {@link JDataBasketTable}, the individual records are
    * {@link DataBasketEntry DataBasketEntries}.</p>
    *
    * <p>The default is to show all entries and apply no grouping. The default sorting order sorts entries by
    * their main keys and then by their secondary keys.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param db the DataBasket whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param ted a TableEntryDescriptor that can split individual {@link DataBasketEntry DataBasketEntries}
    * into a table's cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             DataBasket db,
                                             UIGate uigGate,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   db,
                   uigGate,
                   DataBasketConditionImpl.ALL_ENTRIES,
                   null,
                   null,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a DataBasket.
    *
    * <p>The FormSheet will contain a {@link JDataBasketTable}, the individual records are
    * {@link DataBasketEntry DataBasketEntries}.</p>
    *
    * <p>The default is to show all entries and apply no grouping.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param db the DataBasket whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * entries will be sorted first by their main and then by their secondary keys.
    * @param ted a TableEntryDescriptor that can split individual {@link DataBasketEntry DataBasketEntries}
    * into a table's cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             DataBasket db,
                                             UIGate uigGate,
                                             Comparator cmp,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   db,
                   uigGate,
                   DataBasketConditionImpl.ALL_ENTRIES,
                   null,
                   cmp,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a DataBasket.
    *
    * <p>The FormSheet will contain a {@link JDataBasketTable}, the individual records are
    * {@link DataBasketEntry DataBasketEntries}.</p>
    *
    * <p>The default is to show all entries. The default sorting order sorts entries by their main keys and
    * then by their secondary keys.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param db the DataBasket whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param dbeg a grouper that can be used to combine several entries into one for display.
    * @param ted a TableEntryDescriptor that can split individual {@link DataBasketEntry DataBasketEntries}
    * into a table's cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             DataBasket db,
                                             UIGate uigGate,
                                             DataBasketEntryGrouper dbeg,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   db,
                   uigGate,
                   DataBasketConditionImpl.ALL_ENTRIES,
                   dbeg,
                   null,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a DataBasket.
    *
    * <p>The FormSheet will contain a {@link JDataBasketTable}, the individual records are
    * {@link DataBasketEntry DataBasketEntries}.</p>
    *
    * <p>The default is to show all entries.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param db the DataBasket whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param dbeg a grouper that can be used to combine several entries into one for display.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * entries will be sorted first by their main and then by their secondary keys.
    * @param ted a TableEntryDescriptor that can split individual {@link DataBasketEntry DataBasketEntries}
    * into a table's cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             DataBasket db,
                                             UIGate uigGate,
                                             DataBasketEntryGrouper dbeg,
                                             Comparator cmp,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   db,
                   uigGate,
                   DataBasketConditionImpl.ALL_ENTRIES,
                   dbeg,
                   cmp,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a DataBasket.
    *
    * <p>The FormSheet will contain a {@link JDataBasketTable}, the individual records are
    * {@link DataBasketEntry DataBasketEntries}.</p>
    *
    * <p>The default is to apply no grouping. The default sorting order sorts entries by
    * their main keys and then by their secondary keys.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param db the DataBasket whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param dbc a condition specifying the entries to be displayed.
    * @param ted a TableEntryDescriptor that can split individual {@link DataBasketEntry DataBasketEntries}
    * into a table's cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             DataBasket db,
                                             UIGate uigGate,
                                             DataBasketCondition dbc,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   db,
                   uigGate,
                   dbc,
                   null,
                   null,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a DataBasket.
    *
    * <p>The FormSheet will contain a {@link JDataBasketTable}, the individual records are
    * {@link DataBasketEntry DataBasketEntries}.</p>
    *
    * <p>The default is to apply no grouping.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param db the DataBasket whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param dbc a condition specifying the entries to be displayed.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * entries will be sorted first by their main and then by their secondary keys.
    * @param ted a TableEntryDescriptor that can split individual {@link DataBasketEntry DataBasketEntries}
    * into a table's cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             DataBasket db,
                                             UIGate uigGate,
                                             DataBasketCondition dbc,
                                             Comparator cmp,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   db,
                   uigGate,
                   dbc,
                   null,
                   cmp,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a DataBasket.
    *
    * <p>The FormSheet will contain a {@link JDataBasketTable}, the individual records are
    * {@link DataBasketEntry DataBasketEntries}.</p>
    *
    * <p>The default sorting order sorts entries by their main keys and then by their secondary keys.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param db the DataBasket whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param dbc a condition specifying the entries to be displayed.
    * @param dbeg a grouper that can be used to combine several entries into one for display.
    * @param ted a TableEntryDescriptor that can split individual {@link DataBasketEntry DataBasketEntries}
    * into a table's cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             DataBasket db,
                                             UIGate uigGate,
                                             DataBasketCondition dbc,
                                             DataBasketEntryGrouper dbeg,
                                             TableEntryDescriptor ted) {
    return create (sCaption,
                   db,
                   uigGate,
                   dbc,
                   dbeg,
                   null,
                   ted);
  }

  /**
    * Create and return a new SingleTableFormSheet that will display the contents of a DataBasket.
    *
    * <p>The FormSheet will contain a {@link JDataBasketTable}, the individual records are
    * {@link DataBasketEntry DataBasketEntries}.</p>
    *
    * @param sCaption the caption of the new FormSheet.
    * @param db the DataBasket whose contents are to be displayed.
    * @param uigGate the gate at which to display the FormSheet. May be <code>null</code> only if no editing is
    * performed through the FormSheet.
    * @param dbc a condition specifying the entries to be displayed.
    * @param dbeg a grouper that can be used to combine several entries into one for display.
    * @param cmp a comparator defining the order in which to display the individual items. If <code>null</code>
    * entries will be sorted first by their main and then by their secondary keys.
    * @param ted a TableEntryDescriptor that can split individual {@link DataBasketEntry DataBasketEntries}
    * into a table's cells. Must not be <code>null</code>.
    */
  public static SingleTableFormSheet create (String sCaption,
                                             final DataBasket db,
                                             UIGate uigGate,
                                             final DataBasketCondition dbc,
                                             final DataBasketEntryGrouper dbeg,
                                             final Comparator cmp,
                                             final TableEntryDescriptor ted) {
    return new SingleTableFormSheet (sCaption,
                                     uigGate,
                                     new STFSContentCreator() {
      protected void createFormSheetContent (FormSheet fs) {
        JDataBasketTable jdbt = new JDataBasketTable (db,
                                                      dbc,
                                                      dbeg,
                                                      cmp,
                                                      ted);
        setFormSheetComponent ((SingleTableFormSheet) fs, jdbt);
      }
    });
  }
}