OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 96 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
76 ilm 1
/*
2
 * Créé le 1 juin 2012
3
 */
4
package org.openconcerto.modules.subscription.element;
5
 
6
import java.awt.Component;
7
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
9
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionListener;
11
 
12
import javax.swing.JCheckBox;
13
import javax.swing.JComponent;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16
import javax.swing.JTabbedPane;
17
import javax.swing.JTextField;
18
import javax.swing.SwingConstants;
19
 
20
import org.openconcerto.sql.element.BaseSQLComponent;
21
import org.openconcerto.sql.element.SQLElement;
22
import org.openconcerto.sql.sqlobject.ElementComboBox;
23
import org.openconcerto.ui.DefaultGridBagConstraints;
24
import org.openconcerto.ui.JDate;
25
import org.openconcerto.ui.component.ITextArea;
26
 
27
public class SubscriptionSQLComponent extends BaseSQLComponent {
28
 
29
    private static final long serialVersionUID = 4274010869219769289L;
30
 
31
    public SubscriptionSQLComponent(SQLElement element) {
32
        super(element);
33
    }
34
 
35
    @Override
36
    public void addViews() {
37
 
38
        this.setLayout(new GridBagLayout());
39
        final GridBagConstraints c = new DefaultGridBagConstraints();
40
        // Numéro
41
        c.weightx = 0;
42
        this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c);
43
        c.gridx++;
44
        c.weightx = 1;
45
        final JTextField textNumero = new JTextField(8);
46
        this.add(textNumero, c);
47
        // Date
48
        c.gridx++;
49
        c.weightx = 0;
50
        this.add(new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT), c);
51
        c.gridx++;
52
        c.weightx = 1;
53
        final JDate date = new JDate(true);
54
        this.add(date, c);
55
        // Libellé
56
        c.gridy++;
57
        c.gridx = 0;
58
        c.weightx = 0;
59
        this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
60
        c.gridx++;
61
        c.weightx = 1;
62
        c.gridwidth = 3;
63
        final JTextField textNom = new JTextField();
64
        this.add(textNom, c);
65
 
66
        // Libellé
67
        c.gridy++;
68
        c.gridx = 0;
69
        c.weightx = 0;
70
        c.gridwidth = 1;
71
        this.add(new JLabel(getLabelFor("INTITULE_FACTURE"), SwingConstants.RIGHT), c);
72
        c.gridx++;
73
        c.weightx = 1;
74
        c.gridwidth = 3;
75
        final JTextField intitule = new JTextField();
76
        this.add(intitule, c);
77
        this.addView(intitule, "INTITULE_FACTURE");
78
 
79
        // Description
80
        c.gridwidth = 1;
81
        c.gridy++;
82
        c.gridx = 0;
83
        c.weightx = 0;
84
        this.add(new JLabel(getLabelFor("DESCRIPTION"), SwingConstants.RIGHT), c);
85
        c.gridx++;
86
        c.weightx = 1;
87
        c.gridwidth = 3;
88
        final ITextArea textDescription = new ITextArea();
89
        this.add(textDescription, c);
90
 
91
        // Client
92
        c.gridwidth = 1;
93
        c.gridy++;
94
        c.gridx = 0;
95
        c.weightx = 0;
96
        this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c);
97
        c.gridx++;
98
        c.weightx = 1;
99
        c.gridwidth = 3;
100
        final ElementComboBox client = new ElementComboBox();
101
        this.add(client, c);
102
 
103
        //
104
        c.gridwidth = 4;
105
        c.gridx = 0;
106
        c.gridy++;
107
 
108
        c.weightx = 1;
109
        c.weighty = 1;
110
 
111
        final JTabbedPane tabbedPane = new JTabbedPane();
112
        tabbedPane.add("Facture", createTypeAboComponent("FACTURE", "ID_SAISIE_VENTE_FACTURE"));
113
        tabbedPane.add("Devis", createTypeAboComponent("DEVIS", "ID_DEVIS"));
114
        tabbedPane.add("Bon de commande", createTypeAboComponent("COMMANDE", "ID_COMMANDE_CLIENT"));
115
 
116
        this.add(tabbedPane, c);
117
 
118
        this.addView(textNumero, "NUMERO", REQ);
119
        this.addView(date, "DATE");
120
        this.addView(textNom, "NOM");
121
        this.addView(textDescription, "DESCRIPTION");
122
        this.addView(client, "ID_CLIENT");
123
 
124
        // Codé mais jamais lancé.. a verifier: nom des champs
125
    }
126
 
127
    private Component createTypeAboComponent(String type, String idName) {
128
        final String fieldCreate = "CREATE_" + type;
129
        final String fieldStart = "DATE_DEBUT_" + type;
130
        final String fieldStop = "DATE_FIN_" + type;
131
        final String fieldPeriodicity = "NB_MOIS_" + type;
132
 
133
        final JPanel panel = new JPanel();
134
        panel.setOpaque(false);
135
 
136
        panel.setLayout(new GridBagLayout());
137
        final GridBagConstraints c = new DefaultGridBagConstraints();
138
 
139
        // Checkbox
140
        c.gridx = 1;
141
        c.weightx = 1;
142
        final JCheckBox check = new JCheckBox(getLabelFor(fieldCreate));
143
        check.setOpaque(false);
144
        panel.add(check, c);
145
 
146
        // Item
147
        c.gridx = 0;
148
        c.gridy++;
149
        c.weightx = 0;
150
        panel.add(new JLabel(getLabelFor(idName), SwingConstants.RIGHT), c);
151
        c.gridx++;
152
        c.weightx = 1;
153
        final ElementComboBox item = new ElementComboBox();
154
        // SQLElement elt =
155
        // Configuration.getInstance().getDirectory().getElement(getTable().getForeignTable(idName));
156
        // ComboSQLRequest req = new ComboSQLRequest(elt.getComboRequest(true),
157
        // Arrays.asList(elt.getTable().getField("NUMERO"), elt.getTable().getField("ID_CLIENT")));
158
        // item.init(elt, req);
159
        panel.add(item, c);
160
 
161
        // Start
162
        c.gridx = 0;
163
        c.gridy++;
164
        c.weightx = 0;
165
        c.fill = GridBagConstraints.HORIZONTAL;
166
        panel.add(new JLabel(getLabelFor(fieldStart), SwingConstants.RIGHT), c);
167
        c.gridx++;
168
        c.weightx = 1;
169
        c.fill = GridBagConstraints.NONE;
170
        final JDate startDate = new JDate(true);
171
        panel.add(startDate, c);
172
 
173
        // Stop
174
        c.gridx = 0;
175
        c.gridy++;
176
        c.weightx = 0;
177
        c.fill = GridBagConstraints.HORIZONTAL;
178
        panel.add(new JLabel(getLabelFor(fieldStop), SwingConstants.RIGHT), c);
179
        c.gridx++;
180
        c.weightx = 1;
181
        final JDate stopDate = new JDate(true);
182
        c.fill = GridBagConstraints.NONE;
183
        panel.add(stopDate, c);
184
 
185
        // Periodicity
186
        c.gridx = 0;
187
        c.gridy++;
188
        c.weightx = 0;
189
        c.fill = GridBagConstraints.HORIZONTAL;
190
        panel.add(new JLabel(getLabelFor(fieldPeriodicity), SwingConstants.RIGHT), c);
191
        c.gridx++;
192
        c.weightx = 1;
193
        c.fill = GridBagConstraints.NONE;
194
        final JTextField textPeriod = new JTextField(5);
195
        panel.add(textPeriod, c);
196
 
197
        check.addActionListener(new ActionListener() {
198
 
199
            @Override
200
            public void actionPerformed(ActionEvent e) {
201
                setFieldEnabled(item, startDate, stopDate, textPeriod, check.isSelected());
202
            }
203
        });
204
 
205
        this.addView(check, fieldCreate);
206
        this.addView(item, idName);
207
        this.addView(startDate, fieldStart);
208
        this.addView(stopDate, fieldStop);
209
        this.addView(textPeriod, fieldPeriodicity);
210
 
211
        setFieldEnabled(item, startDate, stopDate, textPeriod, false);
212
        return panel;
213
    }
214
 
215
    // @Override
216
    // protected SQLRowValues createDefaults() {
217
    // SQLRowValues rowVals = new SQLRowValues(getTable());
218
    // return super.createDefaults();
219
    // }
220
 
221
    public void setFieldEnabled(JComponent item, JComponent startDate, JComponent stopDate, JComponent textPeriod, boolean b) {
222
        System.err.println(b);
223
        Thread.dumpStack();
224
        item.setEnabled(b);
225
        startDate.setEnabled(b);
226
        stopDate.setEnabled(b);
227
        textPeriod.setEnabled(b);
228
    }
229
}