OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

package org.openconcerto.modules.extensionbuilder.meu.actions;

import java.awt.Component;
import java.awt.Window;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

import org.openconcerto.modules.extensionbuilder.Extension;
import org.openconcerto.modules.extensionbuilder.list.EditableListPanel;

public class ActionListPanel extends EditableListPanel {

    private ActionMainPanel actionPanel;
    private Extension extension;

    public ActionListPanel(Extension extension, ActionMainPanel actionPanel) {
        super(new AllKnownActionsListModel(extension), "Actions", "Ajouter une action", true, true);
        this.extension = extension;
        this.actionPanel = actionPanel;
        this.list.setCellRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                value = ((ActionDescriptor) value).getId();
                return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            }
        });
    }

    @Override
    public void addNewItem() {
        ((AllKnownActionsListModel) this.dataModel).addAction();
    }

    @Override
    public void removeItem(Object item) {
        ((AllKnownActionsListModel) this.dataModel).removeElement(item);
        this.extension.removeCreateAction((ActionDescriptor) item);
    }

    @Override
    public void renameItem(Object item) {
        final ActionDescriptor e = (ActionDescriptor) item;
        final Window w = SwingUtilities.windowForComponent(this);
        final String s = (String) JOptionPane.showInputDialog(w, "Nouveau nom", "Renommer la liste", JOptionPane.PLAIN_MESSAGE, null, null, e.getId());
        if ((s != null) && (s.length() > 0)) {
            e.setId(s);
            reload();
        }
    }

    @Override
    public void itemSelected(Object item) {
        if (item != null) {
            this.actionPanel.setRightPanel(new JScrollPane(new ActionItemEditor((ActionDescriptor) item, this.extension)));
        } else {
            this.actionPanel.setRightPanel(new JPanel());
        }
    }

}