OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 93 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.customerrelationship.customer.ui;
15
 
16
import org.openconcerto.erp.core.common.ui.ITextComboVilleTableCellEditor;
73 ilm 17
import org.openconcerto.erp.core.common.ui.VilleTableCellRenderer;
18
import org.openconcerto.map.model.Ville;
18 ilm 19
import org.openconcerto.sql.Configuration;
20
import org.openconcerto.sql.element.SQLElement;
21
import org.openconcerto.sql.model.SQLRowValues;
22
import org.openconcerto.sql.view.list.RowValuesTable;
23
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
24
import org.openconcerto.sql.view.list.RowValuesTableModel;
25
import org.openconcerto.sql.view.list.RowValuesTableRenderer;
26
import org.openconcerto.sql.view.list.SQLTableElement;
27
import org.openconcerto.ui.DefaultGridBagConstraints;
41 ilm 28
import org.openconcerto.ui.table.XTableColumnModel;
18 ilm 29
 
30
import java.awt.GridBagConstraints;
31
import java.awt.GridBagLayout;
41 ilm 32
import java.util.HashMap;
18 ilm 33
import java.util.List;
41 ilm 34
import java.util.Map;
18 ilm 35
import java.util.Vector;
36
 
37
import javax.swing.JPanel;
38
import javax.swing.JScrollPane;
39
import javax.swing.ToolTipManager;
40
 
41
public class AdresseClientItemTable extends JPanel {
42
    private RowValuesTable table;
83 ilm 43
    private SQLTableElement type, dest, rue, cedex, ville, province, pays, email;
18 ilm 44
    private RowValuesTableModel model;
45
    private SQLRowValues defaultRowVals;
46
 
47
    public AdresseClientItemTable() {
48
        init();
49
        uiInit();
50
        this.defaultRowVals = new SQLRowValues(getSQLElement().getTable());
51
        this.defaultRowVals.put("PAYS", "France");
52
    }
53
 
54
    /**
55
     *
56
     */
57
    protected void init() {
58
 
59
        final SQLElement e = getSQLElement();
60
 
61
        final List<SQLTableElement> list = new Vector<SQLTableElement>();
62
 
63
        // Destinataire
83 ilm 64
        this.type = new SQLTableElement(e.getTable().getField("TYPE"));
65
        list.add(this.type);
66
 
67
        // Destinataire
41 ilm 68
        this.dest = new SQLTableElement(e.getTable().getField("DEST"));
69
        list.add(this.dest);
18 ilm 70
 
71
        // Rue
72
        this.rue = new SQLTableElement(e.getTable().getField("RUE"));
73
        list.add(this.rue);
74
 
75
        // Ville
73 ilm 76
        this.ville = new SQLTableElement(e.getTable().getField("VILLE"), Ville.class, new ITextComboVilleTableCellEditor()) {
77
            @Override
78
            public void setValueFrom(SQLRowValues row, Object value) {
79
 
80
                if (value != null) {
81
                    Ville v = (Ville) value;
82
                    row.put("CODE_POSTAL", v.getCodepostal());
83
                    row.put("VILLE", v.getName());
84
                } else {
85
                    row.put("CODE_POSTAL", "");
86
                    row.put("VILLE", "");
87
                }
88
                fireModification(row);
89
            }
90
        };
91
        this.ville.setRenderer(new VilleTableCellRenderer());
18 ilm 92
        list.add(this.ville);
93
 
94
        // has cedex
83 ilm 95
        // this.hasCedex = new SQLTableElement(e.getTable().getField("HAS_CEDEX"));
96
        // list.add(this.hasCedex);
18 ilm 97
 
98
        // cedex
99
        this.cedex = new SQLTableElement(e.getTable().getField("CEDEX"));
100
        list.add(this.cedex);
101
 
83 ilm 102
        // Province
103
        this.province = new SQLTableElement(e.getTable().getField("PROVINCE"));
104
        list.add(this.province);
105
 
106
        // Pays
107
        this.pays = new SQLTableElement(e.getTable().getField("PAYS"));
108
        list.add(this.pays);
109
 
110
        // Emails
111
        this.email = new SQLTableElement(e.getTable().getField("EMAIL_CONTACT"));
112
        list.add(this.email);
113
 
18 ilm 114
        this.model = new RowValuesTableModel(e, list, e.getTable().getField("VILLE"));
115
 
116
        this.table = new RowValuesTable(this.model, null, true);
41 ilm 117
 
118
        setColumnVisible(this.model.getColumnForField("DEST"), false);
119
 
120
        for (String string : visibilityMap.keySet()) {
121
            setColumnVisible(this.model.getColumnForField(string), visibilityMap.get(string));
122
        }
123
 
18 ilm 124
        ToolTipManager.sharedInstance().unregisterComponent(this.table);
125
        ToolTipManager.sharedInstance().unregisterComponent(this.table.getTableHeader());
126
    }
127
 
41 ilm 128
    protected void setColumnVisible(int col, boolean visible) {
129
        if (col >= 0) {
130
            XTableColumnModel columnModel = this.table.getColumnModel();
131
            columnModel.setColumnVisible(columnModel.getColumnByModelIndex(col), visible);
132
        }
133
    }
134
 
135
    private static Map<String, Boolean> visibilityMap = new HashMap<String, Boolean>();
136
 
137
    public static Map<String, Boolean> getVisibilityMap() {
138
        return visibilityMap;
139
    }
140
 
18 ilm 141
    /**
142
     *
143
     */
144
    protected void uiInit() {
145
        // Ui init
146
        this.setLayout(new GridBagLayout());
147
        final GridBagConstraints c = new DefaultGridBagConstraints();
148
        c.weightx = 1;
149
 
150
        final JPanel control = new RowValuesTableControlPanel(this.table);
151
 
152
        this.add(control, c);
153
 
154
        c.gridy++;
155
        c.fill = GridBagConstraints.BOTH;
156
        c.weightx = 1;
157
        c.weighty = 1;
158
 
159
        this.add(new JScrollPane(this.table), c);
160
        this.table.setDefaultRenderer(Long.class, new RowValuesTableRenderer());
161
    }
162
 
163
    public SQLElement getSQLElement() {
164
        return Configuration.getInstance().getDirectory().getElement("ADRESSE");
165
    }
166
 
167
    public void updateField(String field, int id) {
168
        this.table.updateField(field, id);
169
    }
170
 
171
    public RowValuesTable getRowValuesTable() {
172
        return this.table;
173
    }
174
 
175
    public void insertFrom(String field, int id) {
176
        this.table.insertFrom(field, id);
177
 
178
    }
179
 
180
    public RowValuesTableModel getModel() {
181
        return this.table.getRowValuesTableModel();
182
    }
183
 
184
    public void refreshTable() {
185
        this.table.repaint();
186
    }
187
 
188
    public SQLRowValues getDefaultRowValues() {
189
 
190
        return this.defaultRowVals;
191
    }
192
}