Changeset 5234

Show
Ignore:
Timestamp:
08/21/08 10:28:00 (3 months ago)
Author:
joonas.lehtinen@…
Message:

Fixes #1995: Cannot add items to IndexedContainer when using filters

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/com/itmill/toolkit/data/util/IndexedContainer.java

    r5186 r5234  
    4444        Cloneable, Container.Filterable { 
    4545 
    46     /* Internal structure *************************************************** */ 
     46    /* Internal structure */ 
    4747 
    4848    /** 
     
    115115    private HashSet filters; 
    116116 
    117     /* Container constructors *********************************************** */ 
     117    /* Container constructors */ 
    118118 
    119119    public IndexedContainer() { 
     
    128128    } 
    129129 
    130     /* Container methods **************************************************** */ 
     130    /* Container methods */ 
    131131 
    132132    /** 
     
    136136     *  
    137137     * @param itemId 
    138      *                the ID of the Item to retrieve. 
     138     *            the ID of the Item to retrieve. 
    139139     * @return the Item with the given ID or <code>null</code> if the Item is 
    140140     *         not found in the list 
     
    181181     *  
    182182     * @param id 
    183      *                the ID of the Property. 
     183     *            the ID of the Property. 
    184184     * @return Type of the requested Property 
    185185     */ 
     
    190190    /** 
    191191     * Gets the Property identified by the given Item ID and Property ID from 
    192      * the lsit. If the list does not contain the Property, <code>null</code> 
    193      * is returned. 
     192     * the lsit. If the list does not contain the Property, <code>null</code> is 
     193     * returned. 
    194194     *  
    195195     * @param itemId 
    196      *                the ID of the Item which contains the requested Property. 
     196     *            the ID of the Item which contains the requested Property. 
    197197     * @param propertyId 
    198      *                the ID of the Property to retrieve. 
     198     *            the ID of the Property to retrieve. 
    199199     * @return Property with the given ID or <code>null</code> 
    200200     *  
     
    230230     *  
    231231     * @param itemId 
    232      *                the ID the of Item to be tested for. 
    233      * @return <code>true</code> if the operation succeeded, 
    234      *         <code>false</code> if not 
     232     *            the ID the of Item to be tested for. 
     233     * @return <code>true</code> if the operation succeeded, <code>false</code> 
     234     *         if not 
    235235     */ 
    236236    public boolean containsId(Object itemId) { 
     
    246246     *  
    247247     * @param propertyId 
    248      *                the ID of the new Property. 
     248     *            the ID of the new Property. 
    249249     * @param type 
    250      *                the Data type of the new Property. 
     250     *            the Data type of the new Property. 
    251251     * @param defaultValue 
    252      *                the value all created Properties are initialized to. 
    253      * @return <code>true</code> if the operation succeeded, 
    254      *         <code>false</code> if not 
     252     *            the value all created Properties are initialized to. 
     253     * @return <code>true</code> if the operation succeeded, <code>false</code> 
     254     *         if not 
    255255     */ 
    256256    public boolean addContainerProperty(Object propertyId, Class type, 
     
    291291     * </p> 
    292292     *  
    293      * @return <code>true</code> if the operation succeeded, 
    294      *         <code>false</code> if not 
     293     * @return <code>true</code> if the operation succeeded, <code>false</code> 
     294     *         if not 
    295295     */ 
    296296    public boolean removeAllItems() { 
     
    312312     * Creates a new Item into the list, and assign it an automatic ID. The new 
    313313     * ID is returned, or <code>null</code> if the operation fails. After a 
    314      * successful call you can use the 
    315      * {@link #getItem(Object ItemId) <code>getItem</code>}method to fetch the 
    316      * Item. 
     314     * successful call you can use the {@link #getItem(Object ItemId) 
     315     * <code>getItem</code>}method to fetch the Item. 
    317316     *  
    318317     * @return ID of the newly created Item, or <code>null</code> in case of a 
     
    337336     *  
    338337     * @param itemId 
    339      *                the ID of the Item to be created. 
     338     *            the ID of the Item to be created. 
    340339     * @return Created new Item, or <code>null</code> in case of a failure 
    341340     */ 
     
    355354        itemIds.add(itemId); 
    356355        items.put(itemId, new Hashtable()); 
    357         final Item item = getItem(itemId); 
     356        final Item item = new IndexedContainerItem(itemId); 
    358357        if (filteredItemIds != null) { 
    359358            if (passesFilters(item)) { 
     
    372371     *  
    373372     * @param itemId 
    374      *                the ID of the Item to remove. 
    375      * @return <code>true</code> if the operation succeeded, 
    376      *         <code>false</code> if not 
     373     *            the ID of the Item to remove. 
     374     * @return <code>true</code> if the operation succeeded, <code>false</code> 
     375     *         if not 
    377376     */ 
    378377    public boolean removeItem(Object itemId) { 
     
    396395     *  
    397396     * @param propertyId 
    398      *                the ID of the Property to remove. 
    399      * @return <code>true</code> if the operation succeeded, 
    400      *         <code>false</code> if not 
     397     *            the ID of the Property to remove. 
     398     * @return <code>true</code> if the operation succeeded, <code>false</code> 
     399     *         if not 
    401400     */ 
    402401    public boolean removeContainerProperty(Object propertyId) { 
     
    422421    } 
    423422 
    424     /* Container.Ordered methods ******************************************** */ 
     423    /* Container.Ordered methods */ 
    425424 
    426425    /** 
     
    468467     *  
    469468     * @param itemId 
    470      *                the ID of an Item in the list. 
     469     *            the ID of an Item in the list. 
    471470     * @return ID of the next Item or <code>null</code> 
    472471     */ 
     
    501500     *  
    502501     * @param itemId 
    503      *                the ID of an Item in the list. 
     502     *            the ID of an Item in the list. 
    504503     * @return ID of the previous Item or <code>null</code> 
    505504     */ 
     
    532531     *  
    533532     * @param itemId 
    534      *                the ID of an Item in the list. 
     533     *            the ID of an Item in the list. 
    535534     * @return <code>true</code> if the Item is first in the list, 
    536535     *         <code>false</code> if not 
     
    553552     *  
    554553     * @param itemId 
    555      *                the ID of an Item in the list. 
     554     *            the ID of an Item in the list. 
    556555     * @return <code>true</code> if the Item is last in the list, 
    557556     *         <code>false</code> if not 
     
    614613     * @return ID in the given index. 
    615614     * @param index 
    616      *                Index of the requested ID in the container. 
     615     *            Index of the requested ID in the container. 
    617616     */ 
    618617    public Object getIdByIndex(int index) { 
     
    637636 
    638637    /** 
    639      * Gets the index of an id. The following is true for the index: 0 <= index < 
    640      * size(). 
     638     * Gets the index of an id. The following is true for the index: 0 <= index 
     639     * < size(). 
    641640     *  
    642641     * @return Index of the Item or -1 if the Item is not in the container. 
    643642     * @param itemId 
    644      *                ID of an Item in the collection 
     643     *            ID of an Item in the collection 
    645644     */ 
    646645    public int indexOfId(Object itemId) { 
     
    700699    } 
    701700 
    702     /* Event notifiers ****************************************************** */ 
     701    /* Event notifiers */ 
    703702 
    704703    /** 
     
    749748         */ 
    750749        private static final long serialVersionUID = 3832616279386372147L; 
    751         private int addedItemIndex; 
     750        private final int addedItemIndex; 
    752751 
    753752        private ItemSetChangeEvent(IndexedContainer source, int addedItemIndex) { 
     
    778777 
    779778    /** 
    780      * An <code>event</code> object specifying the Propery in a list whose 
    781      * value has changed. 
     779     * An <code>event</code> object specifying the Propery in a list whose value 
     780     * has changed. 
    782781     *  
    783782     * @author IT Mill Ltd. 
     
    813812     *  
    814813     * @param listener 
    815      *                the new Listener to be registered. 
     814     *            the new Listener to be registered. 
    816815     */ 
    817816    public void addListener(Container.PropertySetChangeListener listener) { 
     
    826825     *  
    827826     * @param listener 
    828      *                the listener to be removed. 
     827     *            the listener to be removed. 
    829828     */ 
    830829    public void removeListener(Container.PropertySetChangeListener listener) { 
     
    838837     *  
    839838     * @param listener 
    840      *                the listener to be added. 
     839     *            the listener to be added. 
    841840     */ 
    842841    public void addListener(Container.ItemSetChangeListener listener) { 
     
    851850     *  
    852851     * @param listener 
    853      *                the listener to be removed. 
     852     *            the listener to be removed. 
    854853     */ 
    855854    public void removeListener(Container.ItemSetChangeListener listener) { 
     
    863862     *  
    864863     * @param listener 
    865      *                the new Listener to be registered 
     864     *            the new Listener to be registered 
    866865     */ 
    867866    public void addListener(Property.ValueChangeListener listener) { 
     
    876875     *  
    877876     * @param listener 
    878      *                the listener to be removed. 
     877     *            the listener to be removed. 
    879878     */ 
    880879    public void removeListener(Property.ValueChangeListener listener) { 
     
    888887     *  
    889888     * @param source 
    890      *                the IndexedContainerProperty object. 
     889     *            the IndexedContainerProperty object. 
    891890     */ 
    892891    private void firePropertyValueChange(IndexedContainerProperty source) { 
     
    942941     *  
    943942     * @param addedItemIndex 
    944      *                index of new item if change event was an item addition 
     943     *            index of new item if change event was an item addition 
    945944     */ 
    946945    private void fireContentsChange(int addedItemIndex) { 
     
    960959     *  
    961960     * @param propertyId 
    962      *                the ID of the Property to add. 
     961     *            the ID of the Property to add. 
    963962     * @param itemId 
    964      *                the ID of the Item . 
     963     *            the ID of the Item . 
    965964     * @param listener 
    966      *                the listener to be added. 
     965     *            the listener to be added. 
    967966     */ 
    968967    private void addSinglePropertyChangeListener(Object propertyId, 
     
    993992     *  
    994993     * @param propertyId 
    995      *                the ID of the Property to remove. 
     994     *            the ID of the Property to remove. 
    996995     * @param itemId 
    997      *                the ID of the Item. 
     996     *            the ID of the Item. 
    998997     * @param listener 
    999      *                the listener to be removed. 
     998     *            the listener to be removed. 
    1000999     */ 
    10011000    private void removeSinglePropertyChangeListener(Object propertyId, 
     
    10231022    } 
    10241023 
    1025     /* Internal Item and Property implementations *************************** */ 
     1024    /* Internal Item and Property implementations */ 
    10261025 
    10271026    /* 
     
    10301029     *  
    10311030     * @version @VERSION@ 
     1031     *  
    10321032     * @since 3.0 
    10331033     */ 
     
    10441044         *  
    10451045         * @param itemId 
    1046          *                the Item ID of the new Item. 
     1046         *            the Item ID of the new Item. 
    10471047         */ 
    10481048        private IndexedContainerItem(Object itemId) { 
     
    10611061         *  
    10621062         * @param id 
    1063          *                the identifier of the Property to get. 
     1063         *            the identifier of the Property to get. 
    10641064         * @return the Property with the given ID or <code>null</code> 
    10651065         */ 
     
    11181118         *  
    11191119         * @param obj 
    1120          *                an object to compare with this object 
     1120         *            an object to compare with this object 
    11211121         * @return <code>true</code> if the given object is the same as this 
    11221122         *         object, <code>false</code> if not 
     
    11911191         *  
    11921192         * @param itemId 
    1193          *                the ID of the Item to connect the new Property to. 
     1193         *            the ID of the Item to connect the new Property to. 
    11941194         * @param propertyId 
    1195          *                the Property ID of the new Property. 
     1195         *            the Property ID of the new Property. 
    11961196         * @param host 
    1197          *                the list that contains the Item to contain the new 
    1198          *                Property. 
     1197         *            the list that contains the Item to contain the new 
     1198         *            Property. 
    11991199         */ 
    12001200        private IndexedContainerProperty(Object itemId, Object propertyId) { 
     
    12101210        /** 
    12111211         * Returns the type of the Property. The methods <code>getValue</code> 
    1212          * and <code>setValue</code> must be compatible with this type: one 
    1213          * must be able to safely cast the value returned from 
    1214          * <code>getValue</code> to the given type and pass any variable 
    1215          * assignable to this type as a parameter to <code>setValue</code. 
     1212         * and <code>setValue</code> must be compatible with this type: one must 
     1213         * be able to safely cast the value returned from <code>getValue</code> 
     1214         * to the given type and pass any variable assignable to this type as a 
     1215         * parameter to <code>setValue</code. 
    12161216         *  
    12171217         * @return the type of the Property. 
     
    12311231 
    12321232        /** 
    1233          * <p> 
    1234          * Tests if the Property is in read-only mode. In read-only mode calls 
    1235          * to the method <code>setValue</code> will throw 
    1236          * <code>ReadOnlyException</code> s and will not modify the value of 
    1237          * the Property. 
    1238          * </p> 
     1233         * <p> Tests if the Property is in read-only mode. In read-only mode 
     1234         * calls to the method <code>setValue</code> will throw 
     1235         * <code>ReadOnlyException</code> s and will not modify the value of the 
     1236         * Property. </p> 
    12391237         *  
    12401238         * @return <code>true</code> if the Property is in read-only mode, 
     
    12491247         *  
    12501248         * @param newStatus 
    1251          *                the new read-only status of the Property. 
     1249         *            the new read-only status of the Property. 
    12521250         */ 
    12531251        public void setReadOnly(boolean newStatus) { 
     
    12621260         * Sets the value of the Property. By default this method will try to 
    12631261         * assign the value directly, but if it is unassignable, it will try to 
    1264          * use the <code>String</code> constructor of the internal data type 
    1265          * to assign the value, 
     1262         * use the <code>String</code> constructor of the internal data type to 
     1263         * assign the value, 
    12661264         *  
    12671265         * @param newValue 
    1268          *                the New value of the Property. This should be 
    1269          *                assignable to the Property's internal type or support 
    1270          *                <code>toString</code>. 
     1266         *            the New value of the Property. This should be assignable 
     1267         *            to the Property's internal type or support 
     1268         *            <code>toString</code>. 
    12711269         *  
    12721270         * @throws Property.ReadOnlyException 
    1273          *                 if the object is in read-only mode 
     1271         *             if the object is in read-only mode 
    12741272         * @throws Property.ConversionException 
    1275          *                 if <code>newValue</code> can't be converted into 
    1276          *                 the Property's native type directly or through 
    1277          *                 <code>String</code> 
     1273         *             if <code>newValue</code> can't be converted into the 
     1274         *             Property's native type directly or through 
     1275         *             <code>String</code> 
    12781276         */ 
    12791277        public void setValue(Object newValue) 
     
    13151313         * method if the Property is not in read-only mode. 
    13161314         *  
    1317          * @return <code>String</code> representation of the value stored in 
    1318          *         the Property 
     1315         * @return <code>String</code> representation of the value stored in the 
     1316         *         Property 
    13191317         */ 
    13201318        public String toString() { 
     
    13441342         *  
    13451343         * @param obj 
    1346          *                an object to compare with this object 
     1344         *            an object to compare with this object 
    13471345         * @return <code>true</code> if the given object is the same as this 
    13481346         *         object, <code>false</code> if not 
     
    13631361         *  
    13641362         * @param listener 
    1365          *                the new Listener to be registered. 
     1363         *            the new Listener to be registered. 
    13661364         * @see com.itmill.toolkit.data.Property.ValueChangeNotifier#addListener(ValueChangeListener) 
    13671365         */ 
     
    13741372         *  
    13751373         * @param listener 
    1376          *                listener to be removed 
     1374         *            listener to be removed 
    13771375         * @see com.itmill.toolkit.data.Property.ValueChangeNotifier#removeListener(ValueChangeListener) 
    13781376         */ 
     
    14311429     * (non-Javadoc) 
    14321430     *  
    1433      * @see com.itmill.toolkit.data.Container.Sortable#getSortableContainerPropertyIds() 
     1431     * @see 
     1432     * com.itmill.toolkit.data.Container.Sortable#getSortableContainerPropertyIds 
     1433     * () 
    14341434     */ 
    14351435    public Collection getSortableContainerPropertyIds() { 
     
    15001500     *  
    15011501     * @throws CloneNotSupportedException 
    1502      *                 if an object cannot be cloned. . 
     1502     *             if an object cannot be cloned. . 
    15031503     */ 
    15041504    public Object clone() throws CloneNotSupportedException {