OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 74 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
74 ilm 1
package org.openconcerto.modules.extensionbuilder.table;
2
 
3
import java.util.List;
4
 
5
import javax.swing.event.ChangeEvent;
6
import javax.swing.event.ChangeListener;
7
 
8
import org.openconcerto.modules.extensionbuilder.Extension;
9
import org.openconcerto.ui.DefaultListModel;
10
 
11
public class CreateTableListModel extends DefaultListModel implements ChangeListener {
12
 
13
    private Extension extension;
14
 
15
    CreateTableListModel(Extension extension) {
16
        this.extension = extension;
17
        loadContent(extension);
18
        this.extension.addChangeListener(this);
19
    }
20
 
21
    private void loadContent(Extension extension) {
22
        final List<TableDescritor> createTableList = extension.getCreateTableList();
23
        if (this.size() != createTableList.size()) {
24
            this.clear();
25
            this.addAll(createTableList);
26
        }
27
    }
28
 
29
    public void addNewTable() {
30
        // FIXME: ensure table does not exists
31
        final TableDescritor obj = new TableDescritor("TABLE_" + this.size());
32
        this.addElement(obj);
181 ilm 33
        this.extension.addCreateTable(obj);
74 ilm 34
    }
35
 
36
    @Override
37
    public boolean removeElement(Object obj) {
181 ilm 38
        this.extension.removeCreateTable((TableDescritor) obj);
74 ilm 39
        return super.removeElement(obj);
40
    }
41
 
42
    @Override
43
    public void stateChanged(ChangeEvent e) {
181 ilm 44
        this.loadContent(this.extension);
74 ilm 45
    }
46
 
47
}