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.table;
2
 
3
import java.awt.Dimension;
4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
6
import java.awt.Insets;
7
 
8
import javax.swing.JComponent;
9
import javax.swing.JLabel;
10
import javax.swing.JList;
11
import javax.swing.JPanel;
12
import javax.swing.JScrollPane;
13
import javax.swing.event.ListSelectionEvent;
14
import javax.swing.event.ListSelectionListener;
15
 
16
import org.openconcerto.modules.extensionbuilder.Extension;
17
import org.openconcerto.sql.model.SQLTable;
18
 
19
public class TableModifyLeftPanel extends JPanel {
20
    private final TableModifyMainPanel tableModifyMainPanel;
21
    private final Extension extension;
22
    private JList listTableModified;
23
    private JList listTableAll;
24
 
25
    TableModifyLeftPanel(Extension extension, TableModifyMainPanel tableModifyMainPanel) {
26
        this.extension = extension;
27
        this.tableModifyMainPanel = tableModifyMainPanel;
28
        this.setLayout(new GridBagLayout());
29
        final GridBagConstraints c = new GridBagConstraints();
30
        c.gridx = 0;
31
        c.gridy = 0;
32
        c.weightx = 1;
33
        c.fill = GridBagConstraints.HORIZONTAL;
34
        c.insets = new Insets(2, 2, 2, 0);
35
        this.add(new JLabel("Tables modifiées"), c);
36
 
37
        c.weighty = 1;
38
        c.fill = GridBagConstraints.BOTH;
39
        c.gridy++;
40
        c.insets = new Insets(0, 0, 0, 0);
41
        this.add(createModifiedTableList(extension), c);
42
        c.gridy++;
43
        c.weighty = 0;
44
        c.fill = GridBagConstraints.HORIZONTAL;
45
        c.insets = new Insets(2, 2, 2, 0);
46
        this.add(new JLabel("Toutes les tables"), c);
47
        c.weighty = 2;
48
        c.fill = GridBagConstraints.BOTH;
49
        c.gridy++;
50
        c.insets = new Insets(0, 0, 0, 0);
51
        this.add(createAllTableList(extension), c);
52
    }
53
 
54
    private JComponent createModifiedTableList(final Extension extension) {
55
        final ModifiedTableListModel dataModel = new ModifiedTableListModel(extension);
181 ilm 56
        this.listTableModified = new JList(dataModel);
57
        this.listTableModified.addListSelectionListener(new ListSelectionListener() {
74 ilm 58
 
59
            @Override
60
            public void valueChanged(ListSelectionEvent e) {
61
                if (!e.getValueIsAdjusting()) {
181 ilm 62
                    final TableDescritor tableDesc = (TableDescritor) TableModifyLeftPanel.this.listTableModified.getSelectedValue();
74 ilm 63
                    if (tableDesc != null) {
64
                        System.out.println("TableModifyLeftPanel.createModifiedTableList.valueChanged():" + tableDesc);
65
                        final TableModifyPanel p = new TableModifyPanel(extension.getSQLTable(tableDesc), tableDesc, extension, TableModifyLeftPanel.this);
181 ilm 66
                        TableModifyLeftPanel.this.tableModifyMainPanel.setRightPanel(p);
67
                        TableModifyLeftPanel.this.listTableAll.clearSelection();
74 ilm 68
                    }
69
                }
70
 
71
            }
72
        });
181 ilm 73
        final JScrollPane comp2 = new JScrollPane(this.listTableModified);
74 ilm 74
        comp2.setMinimumSize(new Dimension(250, 150));
75
        comp2.setPreferredSize(new Dimension(250, 150));
76
        return comp2;
77
    }
78
 
79
    private JComponent createAllTableList(final Extension extension) {
80
        final AllTableListModel dataModel = new AllTableListModel(extension);
181 ilm 81
        this.listTableAll = new JList(dataModel);
82
        this.listTableAll.addListSelectionListener(new ListSelectionListener() {
74 ilm 83
 
84
            @Override
85
            public void valueChanged(ListSelectionEvent e) {
86
                if (!e.getValueIsAdjusting()) {
181 ilm 87
                    final SQLTable table = (SQLTable) TableModifyLeftPanel.this.listTableAll.getSelectedValue();
74 ilm 88
                    if (table != null) {
89
                        System.out.println("TableModifyLeftPanel.createAllTableList.valueChanged():" + table);
90
                        final TableModifyPanel p = new TableModifyPanel(table, extension.getOrCreateTableDescritor(table.getName()), extension, TableModifyLeftPanel.this);
181 ilm 91
                        TableModifyLeftPanel.this.tableModifyMainPanel.setRightPanel(p);
92
                        TableModifyLeftPanel.this.listTableModified.clearSelection();
74 ilm 93
                    }
94
                }
95
 
96
            }
97
        });
181 ilm 98
        this.listTableAll.setCellRenderer(new SQLTableListCellRenderer());
99
        final JScrollPane comp2 = new JScrollPane(this.listTableAll);
74 ilm 100
        comp2.setMinimumSize(new Dimension(150, 150));
101
        comp2.setPreferredSize(new Dimension(150, 150));
102
        return comp2;
103
    }
104
 
105
    public void selectTable(String tableName) {
106
        System.out.println("TableModifyLeftPanel.selectTable():" + tableName);
107
        if (tableName != null) {
181 ilm 108
            TableDescritor tableDesc = this.extension.getOrCreateTableDescritor(tableName);
109
            final TableModifyPanel p = new TableModifyPanel(this.extension.getSQLTable(tableDesc), tableDesc, this.extension, TableModifyLeftPanel.this);
110
            this.tableModifyMainPanel.setRightPanel(p);
111
            this.listTableAll.clearSelection();
112
            this.listTableModified.clearSelection();
74 ilm 113
        }
114
    }
115
 
116
}