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;
2
 
3
import javax.swing.JFrame;
4
import javax.swing.JOptionPane;
5
import javax.swing.event.ChangeEvent;
6
import javax.swing.event.ChangeListener;
7
 
8
import org.openconcerto.modules.extensionbuilder.list.EditableListPanel;
9
import org.openconcerto.ui.DefaultListModel;
10
 
11
public class ExtensionListModel extends DefaultListModel implements ChangeListener {
12
 
13
    private ExtensionListPanel moduleListPanel;
14
 
15
    ExtensionListModel(ExtensionListPanel moduleListPanel) {
16
        this.moduleListPanel = moduleListPanel;
17
    }
18
 
19
    public void fill(final EditableListPanel list) {
181 ilm 20
        addAll(this.moduleListPanel.getExtensionBuilderModule().getExtensions());
74 ilm 21
        final int size = this.getSize();
22
        if (size > 0) {
23
            final Object firstElement = firstElement();
24
            list.selectItem(firstElement);
25
        }
26
        for (int i = 0; i < size; i++) {
27
            Extension e = (Extension) this.get(i);
28
            e.addChangeListener(this);
29
        }
30
 
31
    }
32
 
33
    public void addNewModule() {
34
        final Extension e = new Extension("extension " + (this.size() + 1));
35
        this.addElement(e);
36
        e.addChangeListener(this);
37
    }
38
 
39
    @Override
40
    public void addElement(Object obj) {
41
        final Extension e = (Extension) obj;
181 ilm 42
        this.moduleListPanel.getExtensionBuilderModule().add(e);
74 ilm 43
        e.addChangeListener(this);
44
        super.addElement(obj);
45
    }
46
 
47
    @Override
48
    public boolean removeElement(Object obj) {
49
        final Extension extenstion = (Extension) obj;
50
        final int answer = JOptionPane.showConfirmDialog(new JFrame(), "Voulez vous vraiment supprimer l'extension " + extenstion.getName() + " ?", "Suppression", JOptionPane.YES_NO_OPTION);
51
        if (answer == JOptionPane.OK_OPTION) {
181 ilm 52
            this.moduleListPanel.getExtensionBuilderModule().remove(extenstion);
74 ilm 53
            extenstion.removeChangeListener(this);
54
            return super.removeElement(obj);
55
        }
56
        return false;
57
    }
58
 
59
    @Override
60
    public void stateChanged(ChangeEvent e) {
181 ilm 61
        this.moduleListPanel.modelChanged();
74 ilm 62
    }
63
 
64
}