OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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.element;
15
 
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.element.SQLElement;
18
import org.openconcerto.sql.model.SQLRowValues;
19
import org.openconcerto.sql.view.list.RowValuesTable;
20
import org.openconcerto.sql.view.list.RowValuesTableControlPanel;
21
import org.openconcerto.sql.view.list.RowValuesTableModel;
22
import org.openconcerto.sql.view.list.RowValuesTableRenderer;
23
import org.openconcerto.sql.view.list.SQLTableElement;
151 ilm 24
import org.openconcerto.ui.FormatEditor;
25
import org.openconcerto.utils.FormatGroup;
26
import org.openconcerto.utils.convertor.DateToSQLConvertor;
18 ilm 27
 
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
30
import java.io.File;
151 ilm 31
import java.text.DateFormat;
32
import java.util.Date;
18 ilm 33
import java.util.List;
34
import java.util.Vector;
35
 
36
import javax.swing.JPanel;
37
import javax.swing.JScrollPane;
38
import javax.swing.ToolTipManager;
39
 
40
public class ContactItemTable extends JPanel {
41
 
42
    private RowValuesTable table;
43
    final RowValuesTableControlPanel comp;
44
 
45
    public ContactItemTable(SQLRowValues defaultRow) {
21 ilm 46
        this(defaultRow, Configuration.getInstance().getDirectory().getElement(defaultRow.getTable()));
47
    }
48
 
49
    private ContactItemTable(SQLRowValues defaultRow, SQLElement elt) {
83 ilm 50
        this.setOpaque(false);
18 ilm 51
        this.setLayout(new GridBagLayout());
52
        GridBagConstraints c = new GridBagConstraints();
53
        c.gridwidth = 1;
54
        c.gridheight = 1;
55
        c.gridx = 0;
56
        c.gridy = 0;
57
        c.fill = GridBagConstraints.HORIZONTAL;
58
        c.weightx = 1;
59
        c.weighty = 0;
60
 
61
        List<SQLTableElement> list = new Vector<SQLTableElement>();
62
        SQLTableElement tableElementTitre = new SQLTableElement(elt.getTable().getField("ID_TITRE_PERSONNEL"));
63
        list.add(tableElementTitre);
64
 
65
        SQLTableElement tableElementNom = new SQLTableElement(elt.getTable().getField("NOM"));
66
        list.add(tableElementNom);
67
 
68
        SQLTableElement tableElementPrenom = new SQLTableElement(elt.getTable().getField("PRENOM"));
69
        list.add(tableElementPrenom);
70
 
71
        SQLTableElement tableElementFonction = new SQLTableElement(elt.getTable().getField("FONCTION"));
72
        list.add(tableElementFonction);
73
 
132 ilm 74
        if (elt.getTable().contains("SERVICE")) {
75
            SQLTableElement tableElementService = new SQLTableElement(elt.getTable().getField("SERVICE"));
76
            list.add(tableElementService);
77
        }
78
 
18 ilm 79
        SQLTableElement tableElementTel = new SQLTableElement(elt.getTable().getField("TEL_DIRECT"));
80
        list.add(tableElementTel);
81
 
82
        SQLTableElement tableElementFax = new SQLTableElement(elt.getTable().getField("FAX"));
83
        list.add(tableElementFax);
84
 
85
        SQLTableElement tableElementTelP = new SQLTableElement(elt.getTable().getField("TEL_MOBILE"));
86
        list.add(tableElementTelP);
87
 
88
        SQLTableElement tableElementMail = new SQLTableElement(elt.getTable().getField("EMAIL"));
89
        list.add(tableElementMail);
90
 
94 ilm 91
        if (elt.getTable().contains("TYPE")) {
92
            SQLTableElement tableElementType = new SQLTableElement(elt.getTable().getField("TYPE"));
93
            list.add(tableElementType);
94
        }
95
 
96
        if (elt.getTable().contains("PAYS")) {
97
            SQLTableElement tableElementPays = new SQLTableElement(elt.getTable().getField("PAYS"));
98
            list.add(tableElementPays);
99
        }
100
 
93 ilm 101
        if (elt.getTable().contains("ENVOI_RAPPORT_MAIL")) {
102
            SQLTableElement tableElementEnvoiMail = new SQLTableElement(elt.getTable().getField("ENVOI_RAPPORT_MAIL"));
103
            list.add(tableElementEnvoiMail);
104
 
105
        }
106
 
107
        if (elt.getTable().contains("NO_MAILING")) {
108
            SQLTableElement tableElementNoMailing = new SQLTableElement(elt.getTable().getField("NO_MAILING"));
109
            list.add(tableElementNoMailing);
110
        }
111
 
151 ilm 112
        if (elt.getTable().contains("DATE_NAISSANCE")) {
113
            list.add(new SQLTableElement(elt.getTable().getField("DATE_NAISSANCE")) {
114
                private final DateToSQLConvertor conv = new DateToSQLConvertor();
115
                {
116
                    this.setEditor(new FormatEditor(
117
                            new FormatGroup(DateFormat.getDateInstance(DateFormat.SHORT), DateFormat.getDateInstance(DateFormat.MEDIUM), DateFormat.getDateInstance(DateFormat.LONG))));
118
                }
119
 
120
                @Override
121
                public Object convertEditorValueToModel(Object value, SQLRowValues row) {
122
                    return this.conv.convert((Date) value);
123
                }
124
            });
125
        }
18 ilm 126
        final RowValuesTableModel model = new RowValuesTableModel(elt, list, elt.getTable().getField("NOM"), false, defaultRow);
127
 
73 ilm 128
        this.table = new RowValuesTable(model, new File(Configuration.getInstance().getConfDir(), "Table" + File.separator + "Table_Contact.xml"));
18 ilm 129
        ToolTipManager.sharedInstance().unregisterComponent(this.table);
130
        ToolTipManager.sharedInstance().unregisterComponent(this.table.getTableHeader());
131
        this.comp = new RowValuesTableControlPanel(this.table);
132
        this.add(this.comp, c);
133
 
134
        c.gridy++;
135
        c.fill = GridBagConstraints.BOTH;
136
        c.weightx = 1;
137
        c.weighty = 1;
138
        this.add(new JScrollPane(this.table), c);
139
        this.table.setDefaultRenderer(Long.class, new RowValuesTableRenderer());
140
    }
141
 
142
    public void updateField(String field, int id) {
143
        this.table.updateField(field, id);
144
    }
145
 
73 ilm 146
    public void insertFrom(String field, SQLRowValues row) {
147
        this.table.insertFrom(field, row);
148
    }
149
 
18 ilm 150
    public void insertFrom(String field, int id) {
151
        this.table.insertFrom(field, id);
152
    }
153
 
154
    public RowValuesTableModel getModel() {
155
        return this.table.getRowValuesTableModel();
156
    }
157
 
158
    public void setEditable(boolean b) {
159
        this.comp.setEditable(b);
160
        this.table.setEditable(b);
161
    }
162
 
163
}