OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

package org.openconcerto.modules.extensionbuilder.list;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.openconcerto.modules.extensionbuilder.Extension;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.JLabelBold;

public class ListCreatePanel extends JPanel {

    private FieldDescSelector panel;

    public ListCreatePanel(final ListDescriptor n, final Extension extension) {
        this.setLayout(new GridBagLayout());
        GridBagConstraints c = new DefaultGridBagConstraints();
        c.gridwidth = 2;

        this.add(new JLabelBold(n.getId()), c);
        c.gridy++;
        c.gridwidth = 1;
        c.fill = GridBagConstraints.HORIZONTAL;
        this.add(new JLabel("Table principale", SwingConstants.RIGHT), c);
        c.gridx++;
        c.fill = GridBagConstraints.NONE;
        final JComboBox comboTable = new JComboBox(new AllTablesComboBoxModel(extension));
        this.add(comboTable, c);
        c.gridx = 0;
        c.gridy++;
        c.weightx = 1;
        c.weighty = 1;
        c.gridwidth = 2;
        c.fill = GridBagConstraints.BOTH;
        this.panel = new FieldDescSelector(n, extension);
        final String mainTable = n.getMainTable();
        if (mainTable == null && comboTable.getModel().getSize() > 0) {
            comboTable.setSelectedIndex(0);
            this.panel.setMainTable((String) comboTable.getModel().getElementAt(0));
        } else {
            comboTable.setSelectedItem(mainTable);
            this.panel.setMainTable(mainTable);
        }
        this.add(this.panel, c);

        comboTable.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                n.removeAllColumns();
                ListCreatePanel.this.panel.setMainTable((String) comboTable.getSelectedItem());
                extension.setChanged();
            }
        });

    }

}