OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.sales.pos.ui;
15
 
16
import org.openconcerto.erp.core.sales.pos.model.Article;
17
import org.openconcerto.erp.core.sales.pos.model.Categorie;
18
 
19
import java.util.ArrayList;
20
import java.util.List;
21
 
22
import javax.swing.ListModel;
23
import javax.swing.event.ListDataEvent;
24
import javax.swing.event.ListDataListener;
25
 
26
public class ArticleModel implements ListModel {
27
    private final List<Article> items = new ArrayList<Article>();
28
 
29
    private List<ListDataListener> listeners = new ArrayList<ListDataListener>();
30
 
31
    private Categorie categorie;
32
 
33
    @Override
34
    public void addListDataListener(ListDataListener l) {
35
        listeners.add(l);
36
    }
37
 
38
    @Override
39
    public Object getElementAt(int index) {
40
        return items.get(index);
41
    }
42
 
43
    @Override
44
    public int getSize() {
45
        return items.size();
46
    }
47
 
48
    @Override
49
    public void removeListDataListener(ListDataListener l) {
50
        listeners.remove(l);
51
    }
52
 
53
    public void setCategorie(Categorie c) {
54
        this.categorie = c;
55
        this.items.clear();
56
        if (c != null) {
57
            this.items.addAll(c.getArticles());
58
        }
59
        fire();
60
    }
61
 
62
    private void fire() {
63
        for (ListDataListener l : listeners) {
64
            l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, this.listeners.size()));
65
        }
66
    }
67
 
68
    public Categorie getRoot() {
69
        return this.categorie;
70
    }
71
}