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 java.awt.Component;
4
import java.awt.Window;
5
 
6
import javax.swing.DefaultListCellRenderer;
7
import javax.swing.ImageIcon;
8
import javax.swing.JLabel;
9
import javax.swing.JList;
10
import javax.swing.JOptionPane;
11
import javax.swing.JPanel;
12
import javax.swing.SwingUtilities;
13
 
14
import org.openconcerto.modules.extensionbuilder.list.EditableListPanel;
15
 
16
public class ExtensionMainListPanel extends EditableListPanel {
17
 
18
    private ExtensionListPanel moduleListPanel;
19
 
20
    ExtensionMainListPanel(final ExtensionListPanel moduleListPanel) {
21
        super(new ExtensionListModel(moduleListPanel), "Vos extensions", "Créer une extension");
22
        this.moduleListPanel = moduleListPanel;
23
        this.list.setFixedCellHeight(new JLabel("A").getPreferredSize().height + 8);
24
        this.list.setCellRenderer(new DefaultListCellRenderer() {
181 ilm 25
            @Override
74 ilm 26
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
27
                final JLabel listCellRendererComponent = (JLabel) super.getListCellRendererComponent(list, ((Extension) value).getName(), index, isSelected, cellHasFocus);
28
                Extension e = (Extension) value;
29
                if (e.isStarted()) {
30
                    listCellRendererComponent.setIcon(new ImageIcon(ExtensionMainListPanel.this.getClass().getResource("started.png")));
31
                }
32
                return listCellRendererComponent;
33
            }
34
 
35
        });
36
    }
37
 
38
    public void fill() {
181 ilm 39
        ((ExtensionListModel) this.dataModel).fill(this);
74 ilm 40
 
41
    }
42
 
43
    @Override
44
    public void addNewItem() {
181 ilm 45
        ((ExtensionListModel) this.dataModel).addNewModule();
74 ilm 46
    }
47
 
48
    @Override
49
    public void renameItem(Object item) {
50
        final Extension e = (Extension) item;
51
        final Window w = SwingUtilities.windowForComponent(this);
52
        final String s = (String) JOptionPane.showInputDialog(w, "Nouveau nom", "Renommer l'extension", JOptionPane.PLAIN_MESSAGE, null, null, e.getName());
53
        if ((s != null) && (s.length() > 0)) {
54
            e.setName(s);
55
        }
56
    }
57
 
58
    @Override
59
    public void removeItem(Object item) {
181 ilm 60
        ((ExtensionListModel) this.dataModel).removeElement(item);
74 ilm 61
    }
62
 
63
    @Override
64
    public void itemSelected(Object item) {
65
        if (item != null) {
181 ilm 66
            final ExtensionInfoPanel p = new ExtensionInfoPanel((Extension) item, this.moduleListPanel);
67
            this.moduleListPanel.setRightPanel(p);
74 ilm 68
        } else {
181 ilm 69
            this.moduleListPanel.setRightPanel(new JPanel());
74 ilm 70
        }
71
 
72
    }
73
 
74
    public void modelChanged() {
181 ilm 75
        this.list.invalidate();
76
        this.list.repaint();
74 ilm 77
    }
78
}