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.meu.actions;
2
 
3
import java.awt.Component;
4
import java.awt.Window;
5
 
6
import javax.swing.DefaultListCellRenderer;
7
import javax.swing.JList;
8
import javax.swing.JOptionPane;
9
import javax.swing.JPanel;
10
import javax.swing.JScrollPane;
11
import javax.swing.SwingUtilities;
12
 
13
import org.openconcerto.modules.extensionbuilder.Extension;
14
import org.openconcerto.modules.extensionbuilder.list.EditableListPanel;
15
 
16
public class ActionListPanel extends EditableListPanel {
17
 
181 ilm 18
    private ActionMainPanel actionPanel;
74 ilm 19
    private Extension extension;
20
 
181 ilm 21
    public ActionListPanel(Extension extension, ActionMainPanel actionPanel) {
22
        super(new AllKnownActionsListModel(extension), "Actions", "Ajouter une action", true, true);
74 ilm 23
        this.extension = extension;
181 ilm 24
        this.actionPanel = actionPanel;
25
        this.list.setCellRenderer(new DefaultListCellRenderer() {
74 ilm 26
            @Override
27
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
28
                value = ((ActionDescriptor) value).getId();
29
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
30
            }
31
        });
32
    }
33
 
34
    @Override
35
    public void addNewItem() {
181 ilm 36
        ((AllKnownActionsListModel) this.dataModel).addAction();
74 ilm 37
    }
38
 
39
    @Override
181 ilm 40
    public void removeItem(Object item) {
41
        ((AllKnownActionsListModel) this.dataModel).removeElement(item);
42
        this.extension.removeCreateAction((ActionDescriptor) item);
43
    }
44
 
45
    @Override
74 ilm 46
    public void renameItem(Object item) {
47
        final ActionDescriptor e = (ActionDescriptor) item;
48
        final Window w = SwingUtilities.windowForComponent(this);
49
        final String s = (String) JOptionPane.showInputDialog(w, "Nouveau nom", "Renommer la liste", JOptionPane.PLAIN_MESSAGE, null, null, e.getId());
50
        if ((s != null) && (s.length() > 0)) {
51
            e.setId(s);
181 ilm 52
            reload();
74 ilm 53
        }
54
    }
55
 
56
    @Override
57
    public void itemSelected(Object item) {
58
        if (item != null) {
181 ilm 59
            this.actionPanel.setRightPanel(new JScrollPane(new ActionItemEditor((ActionDescriptor) item, this.extension)));
74 ilm 60
        } else {
181 ilm 61
            this.actionPanel.setRightPanel(new JPanel());
74 ilm 62
        }
63
    }
64
 
65
}