001    package edu.nrao.sss.catalog;
002    
003    /**
004     * A listener of changes to a catalog.  The monitored events are all related
005     * to the addition, removal, replacement, or movement of items and
006     * groups of catalog items.
007     * <p>
008     * <b>CVS Info:</b>
009     * <table style="margin-left:2em">
010     *   <tr><td>$Revision: 1356 $</td></tr>
011     *   <tr><td>$Date: 2008-06-17 16:36:05 -0600 (Tue, 17 Jun 2008) $</td></tr>
012     *   <tr><td>$Author: dharland $</td></tr>
013     * </table></p>
014     * 
015     * @author David M. Harland
016     * @since 2006-11-07
017     */
018    public interface CatalogListener<I extends CatalogItem<I>,
019                                     G extends CatalogItemGroup<I,G,C>,
020                                     C extends Catalog<I,G,C>>
021    {
022      /**
023       * Called after {@code newItem} was added to {@code catalog}.
024       * 
025       * @param catalog the catalog to which a new item was added.
026       * @param newItem the new item added to {@code catalog}.
027       * @param index the index at which the new item was added.
028       */
029      public void itemAdded(C catalog, I newItem, int index);
030    
031      /**
032       * Called after {@code formerItem} was removed from {@code catalog}.
033       * 
034       * @param catalog the catalog from which an item was removed.
035       * @param formerItem the item removed from {@code catalog}.
036       * @param index the index at which the former item had been located.
037       */
038      public void itemRemoved(C catalog, I formerItem, int index);
039    
040      /**
041       * Called after {@code item} was moved from one location to another
042       * within {@code catalog}.
043       * <p>
044       * It is anticipated that most implementations of
045       * {@code Catalog} will send this message only for the
046       * item that instigated the change in this list.  For example,
047       * if the last item of the list was moved to the first position in
048       * the list, only one message will be sent, even though every item
049       * of the list is now in a new position.  The message sent for this
050       * example would be for the item now in the first position.</p>
051       * 
052       * @param catalog the catalog in which movement occcurred.
053       * @param item the item whose position changed.
054       * @param fromIndex the position at which the item had been located.
055       * @param toIndex the position at which the item is now located.
056       */
057      public void itemMoved(C catalog, I item, int fromIndex, int toIndex);
058      
059      /**
060       * Called after the item located at {@code index} was replaced by
061       * another item.
062       * 
063       * @param catalog the catalog in which the replacement occurred.
064       * @param formerItem the item that had been located at {@code index}.
065       * @param newItem the item that is now located at {@code index}.
066       * @param index the position at which the replacement occurred.
067       */
068      public void itemReplaced(C catalog, I formerItem, I newItem, int index);
069      
070      /**
071       * Called after the items in this catalog were sorted.
072       * @param catalog the catalog whose items were sorted.
073       */
074      public void itemsSorted(C catalog);
075      
076      /**
077       * Called after {@code newGroup} was added to {@code catalog}.
078       * 
079       * @param catalog the catalog to which a new group was added.
080       * @param newGroup the new group added to {@code catalog}.
081       * @param index the index at which the new group was added.
082       */
083      public void groupAdded(C catalog, G newGroup, int index);
084    
085      /**
086       * Called after {@code formerGroup} was removed from {@code catalog}.
087       * 
088       * @param catalog the catalog from which a group was removed.
089       * @param formerGroup the group removed from {@code catalog}.
090       * @param index the index at which the former group had been located.
091       */
092      public void groupRemoved(C catalog, G formerGroup, int index);
093    
094      /**
095       * Called after {@code group} was moved from one location to another
096       * within {@code catalog}.
097       * <p>
098       * It is anticipated that most implementations of
099       * {@code Catalog} will send this message only for the
100       * group that instigated the change in this list.  For example,
101       * if the last group of the list was moved to the first position in
102       * the group, only one message will be sent, even though every group
103       * of the list is now in a new position.  The message sent for this
104       * example would be for the group now in the first position.</p>
105       * 
106       * @param catalog the catalog in which movement occcurred.
107       * @param group the group whose position changed.
108       * @param fromIndex the position at which the group had been located.
109       * @param toIndex the position at which the group is now located.
110       */
111      public void groupMoved(C catalog, G group, int fromIndex, int toIndex);
112      
113      /**
114       * Called after the group located at {@code index} was replaced by
115       * another group.
116       * 
117       * @param catalog the catalog in which the replacement occurred.
118       * @param formerGroup the group that had been located at {@code index}.
119       * @param newGroup the group that is now located at {@code index}.
120       * @param index the position at which the replacement occurred.
121       */
122      public void groupReplaced(C catalog, G formerGroup, G newGroup, int index);
123      
124      /**
125       * Called after the groups in this catalog were sorted.
126       * @param catalog the catalog whose groups were sorted.
127       */
128      public void groupsSorted(C catalog);
129    }