OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 156
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.sales.pos.ui;
14
 package org.openconcerto.erp.core.sales.pos.ui;
15
 
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.ServerFinderConfig;
17
import org.openconcerto.erp.config.ServerFinderConfig;
18
import org.openconcerto.erp.config.ServerFinderPanel;
18
import org.openconcerto.erp.config.ServerFinderPanel;
19
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
19
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
20
import org.openconcerto.erp.core.sales.pos.io.ESCSerialPrinter;
20
import org.openconcerto.erp.core.sales.pos.io.ESCSerialPrinter;
21
import org.openconcerto.sql.model.DBRoot;
21
import org.openconcerto.sql.model.DBRoot;
22
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRowListRSH;
23
import org.openconcerto.sql.model.SQLRowListRSH;
24
import org.openconcerto.sql.model.SQLSelect;
24
import org.openconcerto.sql.model.SQLSelect;
25
import org.openconcerto.ui.DefaultGridBagConstraints;
25
import org.openconcerto.ui.DefaultGridBagConstraints;
26
import org.openconcerto.ui.JLabelBold;
26
import org.openconcerto.ui.JLabelBold;
27
 
27
 
28
import java.awt.Component;
28
import java.awt.Component;
29
import java.awt.Dimension;
29
import java.awt.Dimension;
30
import java.awt.GridBagConstraints;
30
import java.awt.GridBagConstraints;
31
import java.awt.GridBagLayout;
31
import java.awt.GridBagLayout;
32
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionListener;
33
import java.awt.event.ActionListener;
34
import java.awt.event.ComponentEvent;
34
import java.awt.event.ComponentEvent;
35
import java.awt.event.ComponentListener;
35
import java.awt.event.ComponentListener;
36
import java.awt.event.ItemEvent;
36
import java.awt.event.ItemEvent;
37
import java.awt.event.ItemListener;
37
import java.awt.event.ItemListener;
38
import java.util.ArrayList;
38
import java.util.ArrayList;
39
import java.util.List;
39
import java.util.List;
40
import java.util.Vector;
40
import java.util.Vector;
41
 
41
 
42
import javax.print.PrintService;
42
import javax.print.PrintService;
43
import javax.print.PrintServiceLookup;
43
import javax.print.PrintServiceLookup;
44
import javax.swing.ComboBoxModel;
44
import javax.swing.ComboBoxModel;
45
import javax.swing.DefaultComboBoxModel;
45
import javax.swing.DefaultComboBoxModel;
46
import javax.swing.DefaultListCellRenderer;
46
import javax.swing.DefaultListCellRenderer;
47
import javax.swing.JButton;
47
import javax.swing.JButton;
48
import javax.swing.JComboBox;
48
import javax.swing.JComboBox;
49
import javax.swing.JLabel;
49
import javax.swing.JLabel;
50
import javax.swing.JList;
50
import javax.swing.JList;
51
import javax.swing.JOptionPane;
51
import javax.swing.JOptionPane;
52
import javax.swing.JPanel;
52
import javax.swing.JPanel;
53
import javax.swing.JTabbedPane;
53
import javax.swing.JTabbedPane;
54
import javax.swing.JTextField;
54
import javax.swing.JTextField;
55
import javax.swing.SwingConstants;
55
import javax.swing.SwingConstants;
56
import javax.swing.SwingUtilities;
56
import javax.swing.SwingUtilities;
57
 
57
 
58
public class ConfigCaissePanel extends JPanel {
58
public class ConfigCaissePanel extends JPanel {
59
 
59
 
60
    private final POSConfiguration configuration = POSConfiguration.getInstance();
60
    private final POSConfiguration configuration;
61
    private int userId;
61
    private int userId;
62
    private int societeId;
62
    private int societeId;
63
    private int caisseId;
63
    private int caisseId;
64
    private final ServerFinderPanel serverFinderPanel;
64
    private final ServerFinderPanel serverFinderPanel;
65
    private final JComboBox comboSociete;
65
    private final JComboBox comboSociete;
66
    private final JComboBox comboCaisse;
66
    private final JComboBox comboCaisse;
67
    private final JComboBox comboUtilisateur;
67
    private final JComboBox comboUtilisateur;
68
    private final TicketLineTable headerTable;
68
    private final TicketLineTable headerTable;
69
    private final TicketLineTable footerTable;
69
    private final TicketLineTable footerTable;
70
    private JTextField textTerminalCB;
70
    private JTextField textTerminalCB;
71
 
71
 
72
    // Ticket printers
72
    // Ticket printers
73
    private final TicketPrinterConfigPanel ticketPanel1;
73
    private final TicketPrinterConfigPanel ticketPanel1;
74
    private final TicketPrinterConfigPanel ticketPanel2;
74
    private final TicketPrinterConfigPanel ticketPanel2;
75
    // LCD
75
    // LCD
76
    private JComboBox comboLCDType;
76
    private JComboBox comboLCDType;
77
    private JTextField textLCDPort;
77
    private JTextField textLCDPort;
78
    private JTextField textLCDLine1;
78
    private JTextField textLCDLine1;
79
    private JTextField textLCDLine2;
79
    private JTextField textLCDLine2;
80
 
80
 
81
    public ConfigCaissePanel(final ServerFinderPanel serverFinderPanel) {
81
    public ConfigCaissePanel(final ServerFinderPanel serverFinderPanel) {
82
        this.serverFinderPanel = serverFinderPanel;
82
        this.serverFinderPanel = serverFinderPanel;
-
 
83
        try {
-
 
84
            this.configuration = POSConfiguration.setInstance();
-
 
85
        } catch (Exception e) {
-
 
86
            throw new IllegalStateException("Couldn't initialise POSConfiguration", e);
-
 
87
        }
83
 
88
 
84
        setOpaque(false);
89
        setOpaque(false);
85
 
90
 
86
        setLayout(new GridBagLayout());
91
        setLayout(new GridBagLayout());
87
        final GridBagConstraints c = new DefaultGridBagConstraints();
92
        final GridBagConstraints c = new DefaultGridBagConstraints();
88
        c.weighty = 0;
93
        c.weighty = 0;
89
        // Fichier
94
        // Fichier
90
        c.weightx = 0;
95
        c.weightx = 0;
91
        this.add(new JLabel("Fichier de configuration", SwingConstants.RIGHT), c);
96
        this.add(new JLabel("Fichier de configuration", SwingConstants.RIGHT), c);
92
        c.gridx++;
97
        c.gridx++;
93
        c.gridwidth = 3;
98
        c.gridwidth = 3;
94
        c.weightx = 1;
99
        c.weightx = 1;
95
        JTextField textConfigurationFile = new JTextField("");
100
        JTextField textConfigurationFile = new JTextField("");
96
        if (this.configuration.getConfigFile() != null) {
101
        if (this.configuration.getConfigFile() != null) {
97
            textConfigurationFile.setText(this.configuration.getConfigFile().getAbsolutePath());
102
            textConfigurationFile.setText(this.configuration.getConfigFile().getAbsolutePath());
98
        }
103
        }
99
        textConfigurationFile.setEditable(false);
104
        textConfigurationFile.setEditable(false);
100
        this.add(textConfigurationFile, c);
105
        this.add(textConfigurationFile, c);
101
 
106
 
102
        // Connexion
107
        // Connexion
103
        c.gridy++;
108
        c.gridy++;
104
        c.gridx = 0;
109
        c.gridx = 0;
105
        final JLabelBold titleConnexion = new JLabelBold("Connexion");
110
        final JLabelBold titleConnexion = new JLabelBold("Connexion");
106
        c.gridwidth = 2;
111
        c.gridwidth = 2;
107
        this.add(titleConnexion, c);
112
        this.add(titleConnexion, c);
108
        c.gridy++;
113
        c.gridy++;
109
        c.gridwidth = 1;
114
        c.gridwidth = 1;
110
        c.weightx = 0;
115
        c.weightx = 0;
111
        this.add(new JLabel("Société", SwingConstants.RIGHT), c);
116
        this.add(new JLabel("Société", SwingConstants.RIGHT), c);
112
        c.gridx++;
117
        c.gridx++;
113
        c.weightx = 1;
118
        c.weightx = 1;
114
        this.comboSociete = new JComboBox();
119
        this.comboSociete = new JComboBox();
115
        this.comboSociete.setRenderer(new DefaultListCellRenderer() {
120
        this.comboSociete.setRenderer(new DefaultListCellRenderer() {
116
            @Override
121
            @Override
117
            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
122
            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
118
                final SQLRow r = (SQLRow) value;
123
                final SQLRow r = (SQLRow) value;
119
                String label = "";
124
                String label = "";
120
                if (r != null) {
125
                if (r != null) {
121
                    label = r.getString("NOM") + " (" + r.getString("ID") + ")";
126
                    label = r.getString("NOM") + " (" + r.getString("ID") + ")";
122
                }
127
                }
123
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
128
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
124
            }
129
            }
125
        });
130
        });
126
        this.add(this.comboSociete, c);
131
        this.add(this.comboSociete, c);
127
        c.gridx = 0;
132
        c.gridx = 0;
128
        c.gridy++;
133
        c.gridy++;
129
        c.weightx = 0;
134
        c.weightx = 0;
130
        this.add(new JLabel("Caisse", SwingConstants.RIGHT), c);
135
        this.add(new JLabel("Caisse", SwingConstants.RIGHT), c);
131
        c.gridx++;
136
        c.gridx++;
132
        this.comboCaisse = new JComboBox();
137
        this.comboCaisse = new JComboBox();
133
        this.comboCaisse.setRenderer(new DefaultListCellRenderer() {
138
        this.comboCaisse.setRenderer(new DefaultListCellRenderer() {
134
            @Override
139
            @Override
135
            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
140
            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
136
                final SQLRow r = (SQLRow) value;
141
                final SQLRow r = (SQLRow) value;
137
                String label = "";
142
                String label = "";
138
                if (r != null) {
143
                if (r != null) {
139
                    label = r.getString("NOM") + " (" + r.getString("ID") + ")";
144
                    label = r.getString("NOM") + " (" + r.getString("ID") + ")";
140
                }
145
                }
141
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
146
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
142
            }
147
            }
143
        });
148
        });
144
        this.add(this.comboCaisse, c);
149
        this.add(this.comboCaisse, c);
145
        c.gridx = 0;
150
        c.gridx = 0;
146
        c.gridy++;
151
        c.gridy++;
147
        c.weightx = 0;
152
        c.weightx = 0;
148
        this.add(new JLabel("Utilisateur", SwingConstants.RIGHT), c);
153
        this.add(new JLabel("Utilisateur", SwingConstants.RIGHT), c);
149
        c.gridx++;
154
        c.gridx++;
150
        this.comboUtilisateur = new JComboBox();
155
        this.comboUtilisateur = new JComboBox();
151
        this.comboUtilisateur.setRenderer(new DefaultListCellRenderer() {
156
        this.comboUtilisateur.setRenderer(new DefaultListCellRenderer() {
152
            @Override
157
            @Override
153
            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
158
            public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
154
                final SQLRow r = (SQLRow) value;
159
                final SQLRow r = (SQLRow) value;
155
                String label = "";
160
                String label = "";
156
                if (r != null) {
161
                if (r != null) {
157
                    label = r.getString("NOM") + " " + r.getString("PRENOM") + " (" + r.getString("ID") + ")";
162
                    label = r.getString("NOM") + " " + r.getString("PRENOM") + " (" + r.getString("ID") + ")";
158
                }
163
                }
159
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
164
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
160
            }
165
            }
161
        });
166
        });
162
        this.add(this.comboUtilisateur, c);
167
        this.add(this.comboUtilisateur, c);
163
 
168
 
164
        // Ticket
169
        // Ticket
165
        final JLabelBold titleTicket = new JLabelBold("Ticket");
170
        final JLabelBold titleTicket = new JLabelBold("Ticket");
166
        c.gridwidth = 2;
171
        c.gridwidth = 2;
167
        c.gridx = 0;
172
        c.gridx = 0;
168
        c.gridy++;
173
        c.gridy++;
169
        c.weightx = 0;
174
        c.weightx = 0;
170
        this.add(titleTicket, c);
175
        this.add(titleTicket, c);
171
 
176
 
172
        final JTabbedPane tabsTicket = new JTabbedPane();
177
        final JTabbedPane tabsTicket = new JTabbedPane();
173
        c.gridy++;
178
        c.gridy++;
174
        c.gridwidth = 2;
179
        c.gridwidth = 2;
175
        c.weightx = 0;
180
        c.weightx = 0;
176
        c.fill = GridBagConstraints.BOTH;
181
        c.fill = GridBagConstraints.BOTH;
177
        c.anchor = GridBagConstraints.NORTHWEST;
182
        c.anchor = GridBagConstraints.NORTHWEST;
178
        this.headerTable = new TicketLineTable();
183
        this.headerTable = new TicketLineTable();
179
        tabsTicket.addTab("Entête", this.headerTable);
184
        tabsTicket.addTab("Entête", this.headerTable);
180
        this.footerTable = new TicketLineTable();
185
        this.footerTable = new TicketLineTable();
181
        tabsTicket.addTab("Pied de page", this.footerTable);
186
        tabsTicket.addTab("Pied de page", this.footerTable);
182
        this.add(tabsTicket, c);
187
        this.add(tabsTicket, c);
183
 
188
 
184
        // Périphérique
189
        // Périphérique
185
        final JLabelBold titleImprimante = new JLabelBold("Périphériques");
190
        final JLabelBold titleImprimante = new JLabelBold("Périphériques");
186
        c.fill = GridBagConstraints.HORIZONTAL;
191
        c.fill = GridBagConstraints.HORIZONTAL;
187
        c.anchor = GridBagConstraints.WEST;
192
        c.anchor = GridBagConstraints.WEST;
188
        c.gridwidth = 2;
193
        c.gridwidth = 2;
189
        c.gridx = 0;
194
        c.gridx = 0;
190
        c.gridy++;
195
        c.gridy++;
191
        c.weightx = 0;
196
        c.weightx = 0;
192
        this.add(titleImprimante, c);
197
        this.add(titleImprimante, c);
193
        c.gridy++;
198
        c.gridy++;
194
        //
199
        //
195
        JTabbedPane tabs = new JTabbedPane();
200
        JTabbedPane tabs = new JTabbedPane();
196
        ticketPanel1 = new TicketPrinterConfigPanel();
201
        ticketPanel1 = new TicketPrinterConfigPanel();
197
        ticketPanel1.setOpaque(false);
202
        ticketPanel1.setOpaque(false);
198
        ticketPanel2 = new TicketPrinterConfigPanel();
203
        ticketPanel2 = new TicketPrinterConfigPanel();
199
        ticketPanel2.setOpaque(false);
204
        ticketPanel2.setOpaque(false);
200
        tabs.addTab("Imprimante ticket principale", ticketPanel1);
205
        tabs.addTab("Imprimante ticket principale", ticketPanel1);
201
        tabs.addTab("Imprimante ticket secondaire", ticketPanel2);
206
        tabs.addTab("Imprimante ticket secondaire", ticketPanel2);
202
        tabs.addTab("Terminal CB", createCreditCardPanel());
207
        tabs.addTab("Terminal CB", createCreditCardPanel());
203
        tabs.addTab("Afficheur LCD", createLCDPanel());
208
        tabs.addTab("Afficheur LCD", createLCDPanel());
204
        this.add(tabs, c);
209
        this.add(tabs, c);
205
        //
210
        //
206
 
211
 
207
        // Spacer
212
        // Spacer
208
        c.gridx = 0;
213
        c.gridx = 0;
209
        c.gridy++;
214
        c.gridy++;
210
        c.weighty = 1;
215
        c.weighty = 1;
211
        c.fill = GridBagConstraints.BOTH;
216
        c.fill = GridBagConstraints.BOTH;
212
        final JPanel spacer = new JPanel();
217
        final JPanel spacer = new JPanel();
213
        spacer.setOpaque(false);
218
        spacer.setOpaque(false);
214
        spacer.setPreferredSize(new Dimension(10, 10));
219
        spacer.setPreferredSize(new Dimension(10, 10));
215
 
220
 
216
        add(spacer, c);
221
        add(spacer, c);
217
 
222
 
218
        // Listeners
223
        // Listeners
219
        this.comboSociete.addItemListener(new ItemListener() {
224
        this.comboSociete.addItemListener(new ItemListener() {
220
 
225
 
221
            @Override
226
            @Override
222
            public void itemStateChanged(final ItemEvent e) {
227
            public void itemStateChanged(final ItemEvent e) {
223
                if (e.getStateChange() == ItemEvent.SELECTED) {
228
                if (e.getStateChange() == ItemEvent.SELECTED) {
224
                    ConfigCaissePanel.this.societeId = ((SQLRow) e.getItem()).getID();
229
                    ConfigCaissePanel.this.societeId = ((SQLRow) e.getItem()).getID();
225
                    reloadCaisses();
230
                    reloadCaisses();
226
                }
231
                }
227
            }
232
            }
228
        });
233
        });
229
        this.comboCaisse.addItemListener(new ItemListener() {
234
        this.comboCaisse.addItemListener(new ItemListener() {
230
            @Override
235
            @Override
231
            public void itemStateChanged(final ItemEvent e) {
236
            public void itemStateChanged(final ItemEvent e) {
232
                if (e.getStateChange() == ItemEvent.SELECTED) {
237
                if (e.getStateChange() == ItemEvent.SELECTED) {
233
                    ConfigCaissePanel.this.caisseId = ((SQLRow) e.getItem()).getID();
238
                    ConfigCaissePanel.this.caisseId = ((SQLRow) e.getItem()).getID();
234
                }
239
                }
235
            }
240
            }
236
        });
241
        });
237
        this.comboUtilisateur.addItemListener(new ItemListener() {
242
        this.comboUtilisateur.addItemListener(new ItemListener() {
238
            @Override
243
            @Override
239
            public void itemStateChanged(final ItemEvent e) {
244
            public void itemStateChanged(final ItemEvent e) {
240
                if (e.getStateChange() == ItemEvent.SELECTED) {
245
                if (e.getStateChange() == ItemEvent.SELECTED) {
241
                    ConfigCaissePanel.this.userId = ((SQLRow) e.getItem()).getID();
246
                    ConfigCaissePanel.this.userId = ((SQLRow) e.getItem()).getID();
242
                }
247
                }
243
            }
248
            }
244
        });
249
        });
245
    }
250
    }
246
 
251
 
247
    private Component createLCDPanel() {
252
    private Component createLCDPanel() {
248
        final JPanel p = new JPanel();
253
        final JPanel p = new JPanel();
249
        p.setOpaque(false);
254
        p.setOpaque(false);
250
 
255
 
251
        GridBagConstraints c = new DefaultGridBagConstraints();
256
        GridBagConstraints c = new DefaultGridBagConstraints();
252
        p.setLayout(new GridBagLayout());
257
        p.setLayout(new GridBagLayout());
253
        c.gridx = 0;
258
        c.gridx = 0;
254
        c.gridy++;
259
        c.gridy++;
255
        c.weightx = 0;
260
        c.weightx = 0;
256
        c.gridwidth = 1;
261
        c.gridwidth = 1;
257
        c.anchor = GridBagConstraints.EAST;
262
        c.anchor = GridBagConstraints.EAST;
258
        c.fill = GridBagConstraints.NONE;
263
        c.fill = GridBagConstraints.NONE;
259
        p.add(new JLabel("Type", SwingConstants.RIGHT), c);
264
        p.add(new JLabel("Type", SwingConstants.RIGHT), c);
260
        c.gridx++;
265
        c.gridx++;
261
        c.weightx = 0;
266
        c.weightx = 0;
262
        c.fill = GridBagConstraints.NONE;
267
        c.fill = GridBagConstraints.NONE;
263
        c.anchor = GridBagConstraints.WEST;
268
        c.anchor = GridBagConstraints.WEST;
264
        comboLCDType = new JComboBox(new String[] { "Port série", "Emulation imprimante" });
269
        comboLCDType = new JComboBox(new String[] { "Port série", "Emulation imprimante" });
265
 
270
 
266
        p.add(comboLCDType, c);
271
        p.add(comboLCDType, c);
267
        c.gridy++;
272
        c.gridy++;
268
        c.gridx = 0;
273
        c.gridx = 0;
269
        c.anchor = GridBagConstraints.EAST;
274
        c.anchor = GridBagConstraints.EAST;
270
        final JLabel labelType = new JLabel("Port", SwingConstants.RIGHT);
275
        final JLabel labelType = new JLabel("Port", SwingConstants.RIGHT);
271
        p.add(labelType, c);
276
        p.add(labelType, c);
272
        c.gridx++;
277
        c.gridx++;
273
        c.weightx = 1;
278
        c.weightx = 1;
274
        c.fill = GridBagConstraints.HORIZONTAL;
279
        c.fill = GridBagConstraints.HORIZONTAL;
275
 
280
 
276
        this.textLCDPort = new JTextField(20);
281
        this.textLCDPort = new JTextField(20);
277
        p.add(this.textLCDPort, c);
282
        p.add(this.textLCDPort, c);
278
        c.weightx = 0;
283
        c.weightx = 0;
279
        c.gridx++;
284
        c.gridx++;
280
        final JButton selectPortButton = new JButton("Sélectionner");
285
        final JButton selectPortButton = new JButton("Sélectionner");
281
        selectPortButton.addActionListener(new ActionListener() {
286
        selectPortButton.addActionListener(new ActionListener() {
282
 
287
 
283
            @Override
288
            @Override
284
            public void actionPerformed(ActionEvent e) {
289
            public void actionPerformed(ActionEvent e) {
285
                List<String> choices = new ArrayList<String>();
290
                List<String> choices = new ArrayList<String>();
286
                final String title;
291
                final String title;
287
                final String message;
292
                final String message;
288
                if (comboLCDType.getSelectedIndex() == 1) {
293
                if (comboLCDType.getSelectedIndex() == 1) {
289
                    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
294
                    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
290
                    for (PrintService printer : printServices) {
295
                    for (PrintService printer : printServices) {
291
                        choices.add(printer.getName());
296
                        choices.add(printer.getName());
292
                    }
297
                    }
293
                    title = "Afficheur LCD";
298
                    title = "Afficheur LCD";
294
                    message = "Choisissez l'imprimante correspondante à l'afficheur LCD";
299
                    message = "Choisissez l'imprimante correspondante à l'afficheur LCD";
295
                } else if (comboLCDType.getSelectedIndex() == 0) {
300
                } else if (comboLCDType.getSelectedIndex() == 0) {
296
                    choices.addAll(ESCSerialPrinter.getSerialPortNames());
301
                    choices.addAll(ESCSerialPrinter.getSerialPortNames());
297
                    title = "Port série";
302
                    title = "Port série";
298
                    message = "Choisissez le port série lié à l'afficheur LCD";
303
                    message = "Choisissez le port série lié à l'afficheur LCD";
299
                } else {
304
                } else {
300
                    return;
305
                    return;
301
                }
306
                }
302
                if (choices.isEmpty()) {
307
                if (choices.isEmpty()) {
303
                    return;
308
                    return;
304
                }
309
                }
305
                String s = (String) JOptionPane.showInputDialog(p, message, title, JOptionPane.PLAIN_MESSAGE, null, choices.toArray(), choices.get(0));
310
                String s = (String) JOptionPane.showInputDialog(p, message, title, JOptionPane.PLAIN_MESSAGE, null, choices.toArray(), choices.get(0));
306
 
311
 
307
                // If a string was returned
312
                // If a string was returned
308
                if ((s != null) && (s.length() > 0)) {
313
                if ((s != null) && (s.length() > 0)) {
309
                    textLCDPort.setText(s);
314
                    textLCDPort.setText(s);
310
                }
315
                }
311
 
316
 
312
            }
317
            }
313
        });
318
        });
314
        p.add(selectPortButton, c);
319
        p.add(selectPortButton, c);
315
 
320
 
316
        c.gridx = 0;
321
        c.gridx = 0;
317
        c.gridy++;
322
        c.gridy++;
318
        c.gridwidth = 3;
323
        c.gridwidth = 3;
319
        p.add(new JLabel("Message d'accueil de l'afficheur"), c);
324
        p.add(new JLabel("Message d'accueil de l'afficheur"), c);
320
        //
325
        //
321
        c.gridy++;
326
        c.gridy++;
322
        c.gridwidth = 1;
327
        c.gridwidth = 1;
323
        p.add(new JLabel("Ligne 1", SwingConstants.RIGHT), c);
328
        p.add(new JLabel("Ligne 1", SwingConstants.RIGHT), c);
324
        c.gridx++;
329
        c.gridx++;
325
        this.textLCDLine1 = new JTextField(20);
330
        this.textLCDLine1 = new JTextField(20);
326
        p.add(textLCDLine1, c);
331
        p.add(textLCDLine1, c);
327
 
332
 
328
        c.gridx = 0;
333
        c.gridx = 0;
329
        c.gridy++;
334
        c.gridy++;
330
        p.add(new JLabel("Ligne 2", SwingConstants.RIGHT), c);
335
        p.add(new JLabel("Ligne 2", SwingConstants.RIGHT), c);
331
        c.gridx++;
336
        c.gridx++;
332
        this.textLCDLine2 = new JTextField(20);
337
        this.textLCDLine2 = new JTextField(20);
333
        p.add(textLCDLine2, c);
338
        p.add(textLCDLine2, c);
334
 
339
 
335
        final JPanel spacer = new JPanel();
340
        final JPanel spacer = new JPanel();
336
        spacer.setOpaque(false);
341
        spacer.setOpaque(false);
337
        c.gridy++;
342
        c.gridy++;
338
        c.weighty = 1;
343
        c.weighty = 1;
339
        p.add(spacer, c);
344
        p.add(spacer, c);
340
        return p;
345
        return p;
341
    }
346
    }
342
 
347
 
343
    private JPanel createCreditCardPanel() {
348
    private JPanel createCreditCardPanel() {
344
        final JPanel p = new JPanel();
349
        final JPanel p = new JPanel();
345
        p.setOpaque(false);
350
        p.setOpaque(false);
346
        p.setLayout(new GridBagLayout());
351
        p.setLayout(new GridBagLayout());
347
        GridBagConstraints c = new DefaultGridBagConstraints();
352
        GridBagConstraints c = new DefaultGridBagConstraints();
348
 
353
 
349
        c.gridx = 0;
354
        c.gridx = 0;
350
        c.gridy++;
355
        c.gridy++;
351
        c.weightx = 0;
356
        c.weightx = 0;
352
        c.gridwidth = 1;
357
        c.gridwidth = 1;
353
        c.anchor = GridBagConstraints.EAST;
358
        c.anchor = GridBagConstraints.EAST;
354
        c.fill = GridBagConstraints.NONE;
359
        c.fill = GridBagConstraints.NONE;
355
        p.add(new JLabel("Port série", SwingConstants.RIGHT), c);
360
        p.add(new JLabel("Port série", SwingConstants.RIGHT), c);
356
        c.gridx++;
361
        c.gridx++;
357
        c.weightx = 1;
362
        c.weightx = 1;
358
        c.fill = GridBagConstraints.HORIZONTAL;
363
        c.fill = GridBagConstraints.HORIZONTAL;
359
 
364
 
360
        this.textTerminalCB = new JTextField(20);
365
        this.textTerminalCB = new JTextField(20);
361
        p.add(this.textTerminalCB, c);
366
        p.add(this.textTerminalCB, c);
362
        c.weightx = 0;
367
        c.weightx = 0;
363
        c.gridx++;
368
        c.gridx++;
364
        final JButton selectPortButton = new JButton("Sélectionner");
369
        final JButton selectPortButton = new JButton("Sélectionner");
365
        selectPortButton.addActionListener(new ActionListener() {
370
        selectPortButton.addActionListener(new ActionListener() {
366
 
371
 
367
            @Override
372
            @Override
368
            public void actionPerformed(ActionEvent e) {
373
            public void actionPerformed(ActionEvent e) {
369
                List<String> choices = new ArrayList<String>();
374
                List<String> choices = new ArrayList<String>();
370
                final String title;
375
                final String title;
371
                final String message;
376
                final String message;
372
 
377
 
373
                choices.addAll(ESCSerialPrinter.getSerialPortNames());
378
                choices.addAll(ESCSerialPrinter.getSerialPortNames());
374
                title = "Port série";
379
                title = "Port série";
375
                message = "Choisissez le port série lié au terminal CB";
380
                message = "Choisissez le port série lié au terminal CB";
376
                if (choices.isEmpty()) {
381
                if (choices.isEmpty()) {
377
                    return;
382
                    return;
378
                }
383
                }
379
                String s = (String) JOptionPane.showInputDialog(p, message, title, JOptionPane.PLAIN_MESSAGE, null, choices.toArray(), choices.get(0));
384
                String s = (String) JOptionPane.showInputDialog(p, message, title, JOptionPane.PLAIN_MESSAGE, null, choices.toArray(), choices.get(0));
380
                // If a string was returned
385
                // If a string was returned
381
                if ((s != null) && (s.length() > 0)) {
386
                if ((s != null) && (s.length() > 0)) {
382
                    textTerminalCB.setText(s);
387
                    textTerminalCB.setText(s);
383
                }
388
                }
384
            }
389
            }
385
        });
390
        });
386
        p.add(selectPortButton, c);
391
        p.add(selectPortButton, c);
387
 
392
 
388
        final JPanel spacer = new JPanel();
393
        final JPanel spacer = new JPanel();
389
        spacer.setOpaque(false);
394
        spacer.setOpaque(false);
390
        c.gridy++;
395
        c.gridy++;
391
        c.weighty = 1;
396
        c.weighty = 1;
392
        p.add(spacer, c);
397
        p.add(spacer, c);
393
 
398
 
394
        return p;
399
        return p;
395
    }
400
    }
396
 
401
 
397
    protected void reloadCaisses() {
402
    protected void reloadCaisses() {
398
        this.comboCaisse.setEnabled(false);
403
        this.comboCaisse.setEnabled(false);
399
        final int id = this.societeId;
404
        final int id = this.societeId;
400
        final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
405
        final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
401
        if (!config.isOnline()) {
406
        if (!config.isOnline()) {
402
            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
407
            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
403
            return;
408
            return;
404
        }
409
        }
405
 
410
 
406
        System.out.println("Reloading POS information from: " + config);
411
        System.out.println("Reloading POS information from: " + config);
407
        ComptaPropsConfiguration conf = config.createConf();
412
        ComptaPropsConfiguration conf = config.createConf();
408
        try {
413
        try {
409
            // Sociétés
414
            // Sociétés
410
            conf.setUpSocieteStructure(id);
415
            conf.setUpSocieteStructure(id);
411
            final SQLRow societe = conf.getRowSociete();
416
            final SQLRow societe = conf.getRowSociete();
412
            if (societe != null) {
417
            if (societe != null) {
413
                final String name = societe.getString("DATABASE_NAME");
418
                final String name = societe.getString("DATABASE_NAME");
414
                // Caisses
419
                // Caisses
415
                final SQLSelect sel = new SQLSelect();
420
                final SQLSelect sel = new SQLSelect();
416
                sel.addSelectStar(conf.getRootSociete().getTable("CAISSE"));
421
                sel.addSelectStar(conf.getRootSociete().getTable("CAISSE"));
417
                final List<SQLRow> caisses = SQLRowListRSH.execute(sel);
422
                final List<SQLRow> caisses = SQLRowListRSH.execute(sel);
418
                // Stock l'id de la caisse pour que la reslectionne soit correcte
423
                // Stock l'id de la caisse pour que la reslectionne soit correcte
419
                final int idCaisseToSelect = this.caisseId;
424
                final int idCaisseToSelect = this.caisseId;
420
                SwingUtilities.invokeLater(new Runnable() {
425
                SwingUtilities.invokeLater(new Runnable() {
421
                    @Override
426
                    @Override
422
                    public void run() {
427
                    public void run() {
423
                        ConfigCaissePanel.this.caisseId = idCaisseToSelect;
428
                        ConfigCaissePanel.this.caisseId = idCaisseToSelect;
424
                        if (caisses.isEmpty()) {
429
                        if (caisses.isEmpty()) {
425
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Pas de caisses définies dans la société " + name);
430
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Pas de caisses définies dans la société " + name);
426
                        }
431
                        }
427
                        ConfigCaissePanel.this.comboCaisse.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(caisses)));
432
                        ConfigCaissePanel.this.comboCaisse.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(caisses)));
428
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
433
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
429
                        ConfigCaissePanel.this.comboCaisse.setEnabled(true);
434
                        ConfigCaissePanel.this.comboCaisse.setEnabled(true);
430
                        final ComboBoxModel model = ConfigCaissePanel.this.comboCaisse.getModel();
435
                        final ComboBoxModel model = ConfigCaissePanel.this.comboCaisse.getModel();
431
                        final int stop = model.getSize();
436
                        final int stop = model.getSize();
432
                        if (stop > 0) {
437
                        if (stop > 0) {
433
                            // Force la reselection si la valeur n'existe plus,
438
                            // Force la reselection si la valeur n'existe plus,
434
                            // nécessité de recuperer l'id
439
                            // nécessité de recuperer l'id
435
                            ConfigCaissePanel.this.caisseId = ((SQLRow) model.getElementAt(0)).getID();
440
                            ConfigCaissePanel.this.caisseId = ((SQLRow) model.getElementAt(0)).getID();
436
                        }
441
                        }
437
                        for (int i = 0; i < stop; i++) {
442
                        for (int i = 0; i < stop; i++) {
438
                            final SQLRow r = (SQLRow) model.getElementAt(i);
443
                            final SQLRow r = (SQLRow) model.getElementAt(i);
439
                            if (r.getID() == idCaisseToSelect) {
444
                            if (r.getID() == idCaisseToSelect) {
440
                                ConfigCaissePanel.this.comboCaisse.setSelectedItem(r);
445
                                ConfigCaissePanel.this.comboCaisse.setSelectedItem(r);
441
                                break;
446
                                break;
442
                            }
447
                            }
443
                        }
448
                        }
444
                    }
449
                    }
445
 
450
 
446
                });
451
                });
447
            } else {
452
            } else {
448
                JOptionPane.showMessageDialog(this, "Impossible de trouver la société d'ID " + id);
453
                JOptionPane.showMessageDialog(this, "Impossible de trouver la société d'ID " + id);
449
            }
454
            }
450
        } catch (final Exception e) {
455
        } catch (final Exception e) {
451
            e.printStackTrace();
456
            e.printStackTrace();
452
        } finally {
457
        } finally {
453
            conf.destroy();
458
            conf.destroy();
454
        }
459
        }
455
    }
460
    }
456
 
461
 
457
    public void loadConfiguration() {
462
    public void loadConfiguration() {
458
 
463
 
459
        final POSConfiguration configuration = this.configuration;
464
        final POSConfiguration configuration = this.configuration;
460
        // Terminal CB
465
        // Terminal CB
461
        this.textTerminalCB.setText(configuration.getCreditCardPort());
466
        this.textTerminalCB.setText(configuration.getCreditCardPort());
462
        // Afficheur LCD
467
        // Afficheur LCD
463
        final String lcdType = configuration.getLCDType();
468
        final String lcdType = configuration.getLCDType();
464
        if (lcdType.equals("serial")) {
469
        if (lcdType.equals("serial")) {
465
            this.comboLCDType.setSelectedIndex(0);
470
            this.comboLCDType.setSelectedIndex(0);
466
        } else {
471
        } else {
467
            this.comboLCDType.setSelectedIndex(1);
472
            this.comboLCDType.setSelectedIndex(1);
468
        }
473
        }
469
 
474
 
470
        this.textLCDPort.setText(configuration.getLCDPort());
475
        this.textLCDPort.setText(configuration.getLCDPort());
471
        this.textLCDLine1.setText(configuration.getLCDLine1());
476
        this.textLCDLine1.setText(configuration.getLCDLine1());
472
        this.textLCDLine2.setText(configuration.getLCDLine2());
477
        this.textLCDLine2.setText(configuration.getLCDLine2());
473
 
478
 
474
        this.userId = configuration.getUserID();
479
        this.userId = configuration.getUserID();
475
        this.societeId = configuration.getCompanyID();
480
        this.societeId = configuration.getCompanyID();
476
        this.caisseId = configuration.getPosID();
481
        this.caisseId = configuration.getPosID();
477
        this.headerTable.fillFrom(configuration.getHeaderLines());
482
        this.headerTable.fillFrom(configuration.getHeaderLines());
478
        this.footerTable.fillFrom(configuration.getFooterLines());
483
        this.footerTable.fillFrom(configuration.getFooterLines());
479
        this.ticketPanel1.setConfiguration(configuration.getTicketPrinterConfiguration1());
484
        this.ticketPanel1.setConfiguration(configuration.getTicketPrinterConfiguration1());
480
        this.ticketPanel2.setConfiguration(configuration.getTicketPrinterConfiguration2());
485
        this.ticketPanel2.setConfiguration(configuration.getTicketPrinterConfiguration2());
481
 
486
 
482
        addComponentListener(new ComponentListener() {
487
        addComponentListener(new ComponentListener() {
483
            @Override
488
            @Override
484
            public void componentHidden(final ComponentEvent event) {
489
            public void componentHidden(final ComponentEvent event) {
485
            }
490
            }
486
 
491
 
487
            @Override
492
            @Override
488
            public void componentMoved(final ComponentEvent event) {
493
            public void componentMoved(final ComponentEvent event) {
489
            }
494
            }
490
 
495
 
491
            @Override
496
            @Override
492
            public void componentResized(final ComponentEvent event) {
497
            public void componentResized(final ComponentEvent event) {
493
            }
498
            }
494
 
499
 
495
            @Override
500
            @Override
496
            public void componentShown(final ComponentEvent event) {
501
            public void componentShown(final ComponentEvent event) {
497
                final Thread t = new Thread(new Runnable() {
502
                final Thread t = new Thread(new Runnable() {
498
 
503
 
499
                    @Override
504
                    @Override
500
                    public void run() {
505
                    public void run() {
501
                        ConfigCaissePanel.this.comboSociete.setEnabled(false);
506
                        ConfigCaissePanel.this.comboSociete.setEnabled(false);
502
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(false);
507
                        ConfigCaissePanel.this.comboUtilisateur.setEnabled(false);
503
                        ConfigCaissePanel.this.comboCaisse.setEnabled(false);
508
                        ConfigCaissePanel.this.comboCaisse.setEnabled(false);
504
                        final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
509
                        final ServerFinderConfig config = ConfigCaissePanel.this.serverFinderPanel.createServerFinderConfig();
505
                        if (!config.isOnline()) {
510
                        if (!config.isOnline()) {
506
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
511
                            JOptionPane.showMessageDialog(ConfigCaissePanel.this, "Impossible de se connecter au serveur");
507
                            return;
512
                            return;
508
                        }
513
                        }
509
                        final ComptaPropsConfiguration server = config.createConf();
514
                        final ComptaPropsConfiguration server = config.createConf();
510
                        try {
515
                        try {
511
                            final DBRoot root = server.getRoot();
516
                            final DBRoot root = server.getRoot();
512
 
517
 
513
                            // Sociétés
518
                            // Sociétés
514
                            SQLSelect sel = new SQLSelect();
519
                            SQLSelect sel = new SQLSelect();
515
                            sel.addSelectStar(root.findTable("SOCIETE_COMMON"));
520
                            sel.addSelectStar(root.findTable("SOCIETE_COMMON"));
516
                            final List<SQLRow> societes = SQLRowListRSH.execute(sel);
521
                            final List<SQLRow> societes = SQLRowListRSH.execute(sel);
517
 
522
 
518
                            // Utilisateurs
523
                            // Utilisateurs
519
                            sel = new SQLSelect();
524
                            sel = new SQLSelect();
520
                            sel.addSelectStar(root.findTable("USER_COMMON"));
525
                            sel.addSelectStar(root.findTable("USER_COMMON"));
521
                            final List<SQLRow> utilisateurs = SQLRowListRSH.execute(sel);
526
                            final List<SQLRow> utilisateurs = SQLRowListRSH.execute(sel);
522
 
527
 
523
                            SwingUtilities.invokeLater(new Runnable() {
528
                            SwingUtilities.invokeLater(new Runnable() {
524
                                @Override
529
                                @Override
525
                                public void run() {
530
                                public void run() {
526
                                    ConfigCaissePanel.this.comboSociete.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(societes)));
531
                                    ConfigCaissePanel.this.comboSociete.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(societes)));
527
                                    ConfigCaissePanel.this.comboUtilisateur.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(utilisateurs)));
532
                                    ConfigCaissePanel.this.comboUtilisateur.setModel(new DefaultComboBoxModel(new Vector<SQLRow>(utilisateurs)));
528
 
533
 
529
                                    ConfigCaissePanel.this.comboSociete.setEnabled(true);
534
                                    ConfigCaissePanel.this.comboSociete.setEnabled(true);
530
                                    ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
535
                                    ConfigCaissePanel.this.comboUtilisateur.setEnabled(true);
531
 
536
 
532
                                    // Societe
537
                                    // Societe
533
                                    ComboBoxModel model = ConfigCaissePanel.this.comboSociete.getModel();
538
                                    ComboBoxModel model = ConfigCaissePanel.this.comboSociete.getModel();
534
                                    int stop = model.getSize();
539
                                    int stop = model.getSize();
535
                                    boolean societeFound = false;
540
                                    boolean societeFound = false;
536
                                    for (int i = 0; i < stop; i++) {
541
                                    for (int i = 0; i < stop; i++) {
537
                                        final SQLRow r = (SQLRow) model.getElementAt(i);
542
                                        final SQLRow r = (SQLRow) model.getElementAt(i);
538
                                        if (r.getID() == ConfigCaissePanel.this.societeId) {
543
                                        if (r.getID() == ConfigCaissePanel.this.societeId) {
539
                                            ConfigCaissePanel.this.comboSociete.setSelectedItem(r);
544
                                            ConfigCaissePanel.this.comboSociete.setSelectedItem(r);
540
                                            ConfigCaissePanel.this.societeId = r.getID();
545
                                            ConfigCaissePanel.this.societeId = r.getID();
541
                                            societeFound = true;
546
                                            societeFound = true;
542
                                            break;
547
                                            break;
543
                                        }
548
                                        }
544
                                    }
549
                                    }
545
 
550
 
546
                                    if (!societeFound && stop > 0) {
551
                                    if (!societeFound && stop > 0) {
547
                                        ConfigCaissePanel.this.comboSociete.setSelectedItem(model.getElementAt(0));
552
                                        ConfigCaissePanel.this.comboSociete.setSelectedItem(model.getElementAt(0));
548
                                        ConfigCaissePanel.this.societeId = ((SQLRow) model.getElementAt(0)).getID();
553
                                        ConfigCaissePanel.this.societeId = ((SQLRow) model.getElementAt(0)).getID();
549
                                    }
554
                                    }
550
                                    // Utilisateur
555
                                    // Utilisateur
551
                                    model = ConfigCaissePanel.this.comboUtilisateur.getModel();
556
                                    model = ConfigCaissePanel.this.comboUtilisateur.getModel();
552
                                    stop = model.getSize();
557
                                    stop = model.getSize();
553
                                    boolean utilisateurFound = false;
558
                                    boolean utilisateurFound = false;
554
                                    for (int i = 0; i < stop; i++) {
559
                                    for (int i = 0; i < stop; i++) {
555
                                        final SQLRow r = (SQLRow) model.getElementAt(i);
560
                                        final SQLRow r = (SQLRow) model.getElementAt(i);
556
                                        if (r.getID() == ConfigCaissePanel.this.userId) {
561
                                        if (r.getID() == ConfigCaissePanel.this.userId) {
557
                                            ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(r);
562
                                            ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(r);
558
                                            ConfigCaissePanel.this.userId = r.getID();
563
                                            ConfigCaissePanel.this.userId = r.getID();
559
                                            utilisateurFound = true;
564
                                            utilisateurFound = true;
560
                                            break;
565
                                            break;
561
                                        }
566
                                        }
562
                                    }
567
                                    }
563
 
568
 
564
                                    if (!utilisateurFound && stop > 0) {
569
                                    if (!utilisateurFound && stop > 0) {
565
                                        ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(model.getElementAt(0));
570
                                        ConfigCaissePanel.this.comboUtilisateur.setSelectedItem(model.getElementAt(0));
566
                                        ConfigCaissePanel.this.userId = ((SQLRow) model.getElementAt(0)).getID();
571
                                        ConfigCaissePanel.this.userId = ((SQLRow) model.getElementAt(0)).getID();
567
                                    }
572
                                    }
568
                                    final Thread t = new Thread() {
573
                                    final Thread t = new Thread() {
569
                                        public void run() {
574
                                        public void run() {
570
                                            reloadCaisses();
575
                                            reloadCaisses();
571
                                        };
576
                                        };
572
                                    };
577
                                    };
573
                                    t.start();
578
                                    t.start();
574
 
579
 
575
                                }
580
                                }
576
 
581
 
577
                            });
582
                            });
578
 
583
 
579
                        } catch (final Exception e) {
584
                        } catch (final Exception e) {
580
                            e.printStackTrace();
585
                            e.printStackTrace();
581
                        } finally {
586
                        } finally {
582
                            server.destroy();
587
                            server.destroy();
-
 
588
                            server.tearDownLogging(true);
583
                        }
589
                        }
584
                    }
590
                    }
585
                });
591
                });
586
                t.setDaemon(true);
592
                t.setDaemon(true);
587
                t.start();
593
                t.start();
588
            }
594
            }
589
        });
595
        });
590
    }
596
    }
591
 
597
 
592
    public void dumpConfiguration() {
598
    public void dumpConfiguration() {
593
        System.out.println("Societe: id:" + this.societeId);
599
        System.out.println("Societe: id:" + this.societeId);
594
        System.out.println("Caisse: id:" + this.caisseId);
600
        System.out.println("Caisse: id:" + this.caisseId);
595
        System.out.println("Utilisateur:  id:" + this.userId);
601
        System.out.println("Utilisateur:  id:" + this.userId);
596
    }
602
    }
597
 
603
 
598
    public void saveConfiguration() {
604
    public void saveConfiguration() {
599
        final POSConfiguration configuration = this.configuration;
605
        final POSConfiguration configuration = this.configuration;
600
        this.ticketPanel1.commitValues();
606
        this.ticketPanel1.commitValues();
601
        this.ticketPanel2.commitValues();
607
        this.ticketPanel2.commitValues();
602
        configuration.setUserID(this.userId);
608
        configuration.setUserID(this.userId);
603
        configuration.setCompanyID(this.societeId);
609
        configuration.setCompanyID(this.societeId);
604
        configuration.setPosID(this.caisseId);
610
        configuration.setPosID(this.caisseId);
605
        configuration.setHeaderLines(this.headerTable.getLines());
611
        configuration.setHeaderLines(this.headerTable.getLines());
606
        configuration.setFooterLines(this.footerTable.getLines());
612
        configuration.setFooterLines(this.footerTable.getLines());
607
        // Terminal CB
613
        // Terminal CB
608
        configuration.setCreditCardPort(this.textTerminalCB.getText());
614
        configuration.setCreditCardPort(this.textTerminalCB.getText());
609
        // LCD
615
        // LCD
610
        final int selectedIndex = this.comboLCDType.getSelectedIndex();
616
        final int selectedIndex = this.comboLCDType.getSelectedIndex();
611
        if (selectedIndex == 0) {
617
        if (selectedIndex == 0) {
612
            configuration.setLCDType("serial");
618
            configuration.setLCDType("serial");
613
        } else {
619
        } else {
614
            configuration.setLCDType("printer");
620
            configuration.setLCDType("printer");
615
        }
621
        }
616
        configuration.setLCDPort(this.textLCDPort.getText());
622
        configuration.setLCDPort(this.textLCDPort.getText());
617
        configuration.setLCDLine1(this.textLCDLine1.getText());
623
        configuration.setLCDLine1(this.textLCDLine1.getText());
618
        configuration.setLCDLine2(this.textLCDLine2.getText());
624
        configuration.setLCDLine2(this.textLCDLine2.getText());
619
        // Save
625
        // Save
620
        configuration.saveConfiguration();
626
        configuration.saveConfiguration();
621
    }
627
    }
622
}
628
}