@@ -0,0 +1,3175 @@
+/*%0A * This Source Code Form is subject to the terms of the Mozilla Public%0A * License, v. 2.0. If a copy of the MPL was not distributed with this%0A * file, You can obtain one at http://mozilla.org/MPL/2.0/.%0A */%0Apackage net.localizethat.gui.models;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport javax.swing.AbstractListModel;%0Aimport javax.swing.MutableComboBoxModel;%0Aimport net.localizethat.model.Product;%0A%0A/**%0A *%0A * @author rpalomares%0A */%0Apublic class ProductListModel extends AbstractListModel%3CProduct%3E implements MutableComboBoxModel%3CProduct%3E %7B%0A    List%3CProduct%3E productList;%0A    int selectComboItem = -1;%0A%0A    public ProductListModel() %7B%0A        productList = new ArrayList%3C%3E(5);%0A    %7D%0A%0A    public ProductListModel(List%3CProduct%3E listSource) %7B%0A        productList = listSource;%0A    %7D%0A%0A    /**%0A     * Implements ListModel missing method%0A     * @return the list size%0A     */%0A    @Override%0A    public int getSize() %7B%0A        return productList.size();%0A    %7D%0A%0A    /**%0A     * Implements ListModel missing method%0A     * @param index index of the element to display%0A     * @return the element%0A     */%0A    @Override%0A    public Product getElementAt(int index) %7B%0A        return productList.get(index);%0A    %7D%0A%0A    @Override%0A    public void addElement(Product item) %7B%0A        productList.add(item);%0A        fireIntervalAdded(item, productList.size() -1, productList.size() -1);%0A    %7D%0A%0A    @Override%0A    public void removeElement(Object obj) %7B%0A        Product item = (Product) obj;%0A        int index = productList.indexOf(item);%0A        if (index != -1) %7B%0A            productList.remove(index);%0A            fireIntervalRemoved(item, index, index);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void insertElementAt(Product item, int index) %7B%0A        if (index %3E= 0 && index %3C productList.size()) %7B%0A            productList.add(index, item);%0A            fireIntervalAdded(item, index, index);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void removeElementAt(int index) %7B%0A        if (index %3E= 0 && index %3C productList.size()) %7B%0A            productList.remove(index);%0A            fireIntervalRemoved(index, index, index);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void setSelectedItem(Object anItem) %7B%0A        Product item = (Product) anItem;%0A        int index = productList.indexOf(item);%0A        if (index != -1) %7B%0A            selectComboItem = index;%0A            fireContentsChanged(item, index, index);%0A        %7D else %7B%0A            selectComboItem = -1;%0A        %7D%0A    %7D%0A%0A    @Override%0A    public Object getSelectedItem() %7B%0A        if (selectComboItem != -1) %7B%0A            return productList.get(selectComboItem);%0A        %7D else %7B%0A            return null;%0A        %7D%0A    %7D%0A%0A    public void clearAll() %7B%0A        int end = Math.max(0, productList.size() - 1);%0A        productList.clear();%0A        fireIntervalRemoved(this, 0, end);%0A    %7D%0A%0A    public void addAll(List%3CProduct%3E l) %7B%0A        // start marks the first element that will be added%0A        int start = productList.size();%0A        productList.addAll(l);%0A        // end marks the last element just added by above addAll%0A        int end = Math.max(0, productList.size() - 1);%0A        fireIntervalAdded(this, start, end);%0A    %7D%0A%7D%0A

Work In Progress - ProductListModel for JList and JComboBox models (corresponds to Issue #5)