OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | 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.sales.pos.ui;
15
 
144 ilm 16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.Gestion;
132 ilm 18
import org.openconcerto.erp.core.sales.pos.POSConfiguration;
142 ilm 19
import org.openconcerto.erp.core.sales.pos.model.Client;
144 ilm 20
import org.openconcerto.erp.core.sales.pos.model.DBState;
21
import org.openconcerto.erp.core.sales.pos.model.ReceiptCode;
22
import org.openconcerto.erp.core.sales.pos.model.RegisterDB;
23
import org.openconcerto.erp.core.sales.pos.model.RegisterFiles;
24
import org.openconcerto.erp.core.sales.pos.model.RegisterLog;
25
import org.openconcerto.erp.core.sales.pos.model.RegisterState;
26
import org.openconcerto.erp.core.sales.pos.model.RegisterState.Status;
18 ilm 27
import org.openconcerto.erp.core.sales.pos.model.Ticket;
174 ilm 28
import org.openconcerto.erp.core.sales.pos.model.TicketItem;
156 ilm 29
import org.openconcerto.erp.utils.TM;
61 ilm 30
import org.openconcerto.sql.PropsConfiguration;
73 ilm 31
import org.openconcerto.sql.RemoteShell;
144 ilm 32
import org.openconcerto.sql.element.SQLElementDirectory;
61 ilm 33
import org.openconcerto.sql.model.SQLBase;
142 ilm 34
import org.openconcerto.sql.model.SQLRowAccessor;
144 ilm 35
import org.openconcerto.sql.model.SQLRowValues;
156 ilm 36
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
18 ilm 37
import org.openconcerto.sql.sqlobject.ElementComboBox;
38
import org.openconcerto.utils.ClassPathLoader;
39
import org.openconcerto.utils.ExceptionHandler;
144 ilm 40
import org.openconcerto.utils.cc.ExnTransformer;
18 ilm 41
 
142 ilm 42
import java.awt.Container;
67 ilm 43
import java.awt.Dimension;
149 ilm 44
import java.awt.Frame;
142 ilm 45
import java.awt.Point;
67 ilm 46
import java.awt.Toolkit;
142 ilm 47
import java.awt.event.MouseEvent;
18 ilm 48
import java.io.File;
144 ilm 49
import java.io.IOException;
18 ilm 50
import java.net.MalformedURLException;
144 ilm 51
import java.sql.SQLException;
52
import java.text.ParseException;
53
import java.util.EnumSet;
132 ilm 54
import java.util.List;
156 ilm 55
import java.util.Objects;
149 ilm 56
import java.util.Set;
144 ilm 57
import java.util.concurrent.Callable;
58
import java.util.concurrent.FutureTask;
59
import java.util.logging.Level;
156 ilm 60
import java.util.logging.Logger;
18 ilm 61
 
62
import javax.swing.JFrame;
67 ilm 63
import javax.swing.JOptionPane;
142 ilm 64
import javax.swing.JPanel;
18 ilm 65
import javax.swing.SwingUtilities;
66
import javax.swing.ToolTipManager;
67
 
144 ilm 68
import org.jdom2.JDOMException;
69
 
18 ilm 70
public class CaisseFrame extends JFrame {
156 ilm 71
    private final POSConfiguration posConf;
144 ilm 72
    private final ComptaPropsConfiguration conf;
73
    private final RegisterFiles files;
74
    private final RegisterDB registerDB;
142 ilm 75
    final CaissePanel mainPanel;
18 ilm 76
 
156 ilm 77
    CaisseFrame(final POSConfiguration posConf, final ComptaPropsConfiguration conf, final RegisterFiles files, final RegisterDB registerDB) throws Exception {
78
        this.posConf = posConf;
144 ilm 79
        this.conf = conf;
80
        this.files = files;
81
        this.registerDB = registerDB;
142 ilm 82
        this.mainPanel = new CaissePanel(this);
83
        setContentPane(mainPanel);
18 ilm 84
        setFocusable(true);
85
    }
86
 
156 ilm 87
    public final POSConfiguration getPOSConf() {
88
        return this.posConf;
89
    }
90
 
144 ilm 91
    public final ComptaPropsConfiguration getConf() {
92
        return this.conf;
93
    }
94
 
95
    public final RegisterFiles getFiles() {
96
        return this.files;
97
    }
98
 
99
    public final RegisterDB getDB() {
100
        return this.registerDB;
101
    }
102
 
18 ilm 103
    public static void main(String[] args) {
142 ilm 104
        System.setProperty(SQLRowAccessor.ACCESS_DB_IF_NEEDED_PROP, "true");
18 ilm 105
        try {
106
            System.out.println("Lancement du module de caisse");
107
            ToolTipManager.sharedInstance().setInitialDelay(0);
132 ilm 108
            RemoteShell.startDefaultInstance(null, null);
61 ilm 109
 
110
            System.setProperty(PropsConfiguration.REDIRECT_TO_FILE, "true");
111
            System.setProperty(SQLBase.ALLOW_OBJECT_REMOVAL, "true");
112
 
113
            ExceptionHandler.setForceUI(true);
114
            ExceptionHandler.setForumURL("http://www.openconcerto.org/forum");
144 ilm 115
            ExceptionHandler.setThrowableHandler(Gestion.createDefaultThrowableHandler());
18 ilm 116
            // SpeedUp Linux
117
            System.setProperty("sun.java2d.pmoffscreen", "false");
80 ilm 118
            System.setProperty(SQLBase.STRUCTURE_USE_XML, "true");
61 ilm 119
            System.setProperty(PropsConfiguration.REDIRECT_TO_FILE, "true");
156 ilm 120
            final POSConfiguration posConf = POSConfiguration.setInstance();
121
            if (posConf.isUsingJPos()) {
18 ilm 122
                ClassPathLoader c = ClassPathLoader.getInstance();
123
                try {
156 ilm 124
                    final List<String> posDirectories = posConf.getJPosDirectories();
132 ilm 125
                    for (String posDirectory : posDirectories) {
126
                        if (posDirectory != null && !posDirectory.trim().isEmpty()) {
127
                            c.addJarFromDirectory(new File(posDirectory.trim()));
128
                        }
18 ilm 129
                    }
130
                } catch (MalformedURLException e) {
131
                    e.printStackTrace();
132
                }
133
                c.load();
134
 
135
            }
156 ilm 136
            final ComptaPropsConfiguration conf = posConf.createConnexion();
144 ilm 137
 
156 ilm 138
            final int userID = posConf.getUserID();
139
            final int posID = posConf.getPosID();
140
            final RegisterFiles registerFiles = new RegisterFiles(posConf.getRootDir(), true, posConf.getPosID());
141
            final RegisterDB registerDB = new RegisterDB(conf.getDirectory(), conf.getProductInfo(), posConf.getPosID());
142
            // check if register exists
143
            final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(new SQLRowValues(registerDB.getRegisterTable()));
144
            if (fetcher.fetchOne(posID) == null) {
145
                SwingUtilities.invokeLater(() -> {
146
                    JOptionPane.showMessageDialog(null, TM.tr("register.missing", posID), TM.tr("register.missing.title"), JOptionPane.ERROR_MESSAGE);
147
                });
148
                posConf.closeConnexion();
149
                return;
150
            }
149 ilm 151
            // check before changing any state
152
            final boolean quit = registerDB.fetchRegisterState().checkIfMoved();
153
            if (quit) {
156 ilm 154
                quit(posConf);
149 ilm 155
                return;
156
            }
157
 
156 ilm 158
            final Logger logger = POSConfiguration.getLogger();
159
            final RegisterState reconciledState;
160
            try {
161
                reconciledState = registerFiles.doWithLock(new ExnTransformer<RegisterFiles, RegisterState, Exception>() {
162
                    @Override
163
                    public RegisterState transformChecked(RegisterFiles input) throws Exception {
164
                        return reconcileFSandDB(posConf, conf.getDirectory(), input, registerDB);
144 ilm 165
                    }
156 ilm 166
                });
167
            } catch (ReconcileException re) {
168
                logger.log(Level.WARNING, "States couldn’t be reconciled, local : " + re.getLocalState() + ", remote : " + re.getRemoteState(), re);
169
                final String generalMsg;
170
                boolean onlyOptionPane = false;
171
                if (re instanceof OutsideMeddlingException) {
172
                    generalMsg = TM.tr("register.notReconciled.outsideMeddling") + '\n';
173
                    onlyOptionPane = true;
174
                } else if (re instanceof ResumeException) {
175
                    generalMsg = TM.tr("register.notReconciled.resumeFailed") + '\n';
176
                } else {
177
                    generalMsg = "";
144 ilm 178
                }
156 ilm 179
                final String message = TM.getTM().trM("register.notReconciled." + re.getTranslationKey(), "localDate", re.getLocalState().copyDate(), "remoteDate", re.getRemoteState().copyDate());
180
                if (onlyOptionPane) {
181
                    SwingUtilities.invokeLater(() -> {
182
                        JOptionPane.showMessageDialog(null, generalMsg + message, TM.tr("register.notReconciled.title"), JOptionPane.ERROR_MESSAGE);
183
                    });
184
                } else {
185
                    ExceptionHandler.handle(generalMsg + message, re);
186
                }
187
                // ATTN this calls ComptaPropsConfiguration.tearDownLogging(), so even syserr is
188
                // closed.
189
                posConf.closeConnexion();
190
                return;
191
            } catch (Exception e) {
192
                throw new IOException("Couldn't reconcile local and remote state", e);
193
            }
194
            logger.log(Level.INFO, "FS and DB states reconciled : {0}", reconciledState);
144 ilm 195
 
196
            System.setProperty("awt.useSystemAAFontSettings", "on");
197
            System.setProperty("swing.aatext", "true");
198
            System.setProperty(ElementComboBox.CAN_MODIFY, "true");
199
 
200
            RegisterState state = reconciledState;
201
            if (reconciledState.getStatus() == Status.CLOSED) {
202
                final FutureTask<Boolean> askUserCallable = new FutureTask<>(new Callable<Boolean>() {
203
                    @Override
204
                    public Boolean call() throws Exception {
205
                        final int ans = JOptionPane.showConfirmDialog(null, "La caisse n’est pas ouverte, voulez-vous l’ouvrir ?", "Caisse fermée", JOptionPane.YES_NO_OPTION);
206
                        return ans == JOptionPane.YES_OPTION;
207
 
208
                    }
209
                });
210
                SwingUtilities.invokeLater(askUserCallable);
211
                final boolean userAgreed = askUserCallable.get();
212
                if (userAgreed) {
213
                    final RegisterLog newLog = registerFiles.open(userID, registerDB);
214
                    state = newLog.getRegisterState();
215
                }
216
            }
217
            if (state.getStatus() != Status.OPEN) {
156 ilm 218
                logger.log(Level.FINE, "State not open ({0}), exiting", state);
219
                posConf.closeConnexion();
144 ilm 220
                return;
221
            }
156 ilm 222
            logger.log(Level.INFO, "FS and DB states open, opening UI");
144 ilm 223
 
18 ilm 224
            SwingUtilities.invokeLater(new Runnable() {
225
                public void run() {
226
 
227
                    try {
156 ilm 228
                        CaisseFrame f = new CaisseFrame(posConf, conf, registerFiles, registerDB);
18 ilm 229
                        f.setUndecorated(true);
230
                        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
231
 
232
                        f.pack();
151 ilm 233
                        if (System.getProperty("os.name").toLowerCase().startsWith("mac os x")) {
234
                            f.setLocation(0, 24);
235
                        } else {
236
                            f.setLocation(0, 0);
237
                        }
67 ilm 238
                        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
156 ilm 239
                        if (posConf.getScreenWidth() > 0 && posConf.getScreenHeight() > 0) {
240
                            f.setSize(new Dimension(posConf.getScreenWidth() - f.getX(), posConf.getScreenHeight() - f.getY()));
83 ilm 241
                        } else {
151 ilm 242
                            f.setSize(new Dimension(screenSize.getSize().width - f.getX(), screenSize.getSize().height - f.getY()));
83 ilm 243
                        }
18 ilm 244
                        System.out.println("Affichage de l'interface");
245
                        f.setVisible(true);
174 ilm 246
                        if (screenSize.getWidth() < 1024 || screenSize.getHeight() < 720) {
67 ilm 247
                            JOptionPane.showMessageDialog(f,
174 ilm 248
                                    "La résolution de votre écran est trop faible.\nLa largeur doit être au minium de 1024 pixels.\nLa hauteur doit être au minium de 720 pixels.");
67 ilm 249
                        }
83 ilm 250
                    } catch (Throwable e) {
251
                        // Catch throwable to be able to see NoClassDefFound and other hard issues
18 ilm 252
                        ExceptionHandler.handle("Erreur d'initialisation de la caisse (main)", e);
253
                    }
254
 
255
                }
256
            });
83 ilm 257
        } catch (Throwable e) {
258
            // Catch throwable to be able to see NoClassDefFound and other hard issues
18 ilm 259
            ExceptionHandler.handle("Erreur d'initialisation de la caisse", e);
260
        }
261
    }
262
 
156 ilm 263
    public static class ReconcileException extends IllegalStateException {
264
        private RegisterState localState, remoteState;
265
        private final String translationKey;
266
 
267
        protected ReconcileException(final String msg, final String key) {
268
            this(msg, key, null);
269
        }
270
 
271
        protected ReconcileException(final String msg, final String key, final Throwable cause) {
272
            super(Objects.requireNonNull(msg, "message"), cause);
273
            this.translationKey = Objects.requireNonNull(key, "translation key");
274
        }
275
 
276
        public final RegisterState getLocalState() {
277
            return this.localState;
278
        }
279
 
280
        public final RegisterState getRemoteState() {
281
            return this.remoteState;
282
        }
283
 
284
        public final String getTranslationKey() {
285
            return this.translationKey;
286
        }
287
 
288
        protected final ReconcileException init(final RegisterState localState, final RegisterState remoteState) {
289
            this.localState = Objects.requireNonNull(localState, "local state");
290
            this.remoteState = Objects.requireNonNull(remoteState, "remote state");
291
            return this;
292
        }
293
    }
294
 
295
    // the FS and/or DB states were modified outside of this software.
296
    public static final class OutsideMeddlingException extends ReconcileException {
297
        protected OutsideMeddlingException(final String msg, final String key) {
298
            super(msg, key);
299
        }
300
    }
301
 
302
    // the opening or closure was interrupted, the process was resumed but it failed.
303
    public static final class ResumeException extends ReconcileException {
304
        protected ResumeException(final String msg, final String key, final Throwable cause) {
305
            super(msg, key, Objects.requireNonNull(cause, "missing cause"));
306
        }
307
    }
308
 
309
    /*
310
     * List of translations keys.
311
     */
312
    private static final String unknownTK = "unknown";
313
    // localOpen
314
    private static final String open_datesMismatch = "open.datesMismatch";
315
    private static final String localOpen_remoteClosed = "localOpen_remoteClosed";
316
    private static final String localOpen_remoteMissing = "localOpen_remoteMissing";
317
    // remoteOpen
318
    private static final String localMissing_remoteReopen = "localMissing_remoteReopen";
319
    private static final String localOpenFailed_remoteOpen = "localOpenFailed_remoteOpen";
320
    private static final String localClosed_remoteCloseFailed = "localClosed_remoteCloseFailed";
321
    private static final String localClosed_remoteOpen_datesMismatch = "localClosed_remoteOpen.datesMismatch";
322
    // both closed
323
    private static final String localMissing_remoteClosed = "localMissing_remoteClosed";
324
    private static final String closed_datesMismatch = "closed.datesMismatch";
325
    private static final String localClosed_remoteMissing = "localClosed_remoteMissing";
326
 
327
    private static RegisterState reconcileFSandDB(final POSConfiguration posConf, final SQLElementDirectory dir, final RegisterFiles files, final RegisterDB registerDB)
144 ilm 328
            throws IOException, JDOMException, ParseException, SQLException {
329
 
330
        // *** find local and remote states
331
        final RegisterLog lastLog = files.getLastLog();
332
        POSConfiguration.getLogger().log(Level.CONFIG, "Found last log {0}", lastLog);
333
 
334
        RegisterState localState;
335
        if (lastLog == null) {
336
            final List<File> remainingReceipts = ReceiptCode.getReceiptsToImport(files.getPosID());
337
            localState = new RegisterState(remainingReceipts.isEmpty() ? Status.CLOSED : Status.OBSOLETE, null);
338
        } else {
339
            localState = lastLog.getRegisterState();
340
        }
341
        POSConfiguration.getLogger().log(Level.CONFIG, "FS state {0}", localState);
342
 
343
        final DBState fetchedState = registerDB.fetchRegisterState();
344
        RegisterState remoteState = fetchedState.getRegisterState();
345
        POSConfiguration.getLogger().log(Level.CONFIG, "DB state {0}", fetchedState);
346
 
347
        // *** import remaining obsolete receipts
348
        if (localState.getStatus() == Status.OBSOLETE) {
349
            if (remoteState.hasDate())
350
                throw new IllegalStateException("There remains obsolete receipts but DB can no longer import them : " + remoteState);
156 ilm 351
            final List<Ticket> allTickets = posConf.allTickets();
144 ilm 352
            POSConfiguration.getLogger().log(Level.INFO, "{0} obsolete receipt(s) will be stored in the DB", allTickets.size());
156 ilm 353
            posConf.commitAll(allTickets);
144 ilm 354
            final List<File> remainingReceipts = ReceiptCode.getReceiptsToImport(files.getPosID());
355
            if (!remainingReceipts.isEmpty())
356
                throw new IllegalStateException("Not all obsolete receipts could be imported : " + remainingReceipts);
357
            localState = new RegisterState(Status.CLOSED, null);
358
            POSConfiguration.getLogger().log(Level.FINE, "All obsolete receipts have been stored in the DB");
359
        }
360
        final EnumSet<Status> validStatus = EnumSet.of(Status.OPEN, Status.CLOSED);
361
        if (!validStatus.contains(localState.getStatus()))
362
            throw new IllegalStateException("Unexpected local status :" + localState);
363
        if (!validStatus.contains(remoteState.getStatus()))
364
            throw new IllegalStateException("Unexpected remote status :" + remoteState);
365
 
366
        // *** reconcile if possible
367
        if (!localState.equals(remoteState)) {
368
            POSConfiguration.getLogger().log(Level.INFO, "Different FS and DB state, will try to reconcile\nFS " + localState + " with\nDB " + remoteState);
156 ilm 369
            final int userID = posConf.getUserID();
144 ilm 370
 
371
            // OK because of the check above
372
            final boolean localOpen = localState.getStatus() == Status.OPEN;
373
            final boolean remoteOpen = remoteState.getStatus() == Status.OPEN;
374
            // Time line
375
            // 0
376
            // Open DB
377
            // 1
378
            // Open Local
379
            // 2
380
            // Create tickets...
381
            // 3
382
            // Close Local
383
            // 4
384
            // Close DB
385
            // 5
386
            // Open DB
387
            // 6
388
            // Open Local
389
            // 7
390
            try {
391
                if (localOpen) {
392
                    if (remoteOpen) {
156 ilm 393
                        throw new OutsideMeddlingException("Both open with but with different dates", open_datesMismatch);
144 ilm 394
                    } else {
395
                        // DB is at 0 or 5, local is at 2
156 ilm 396
                        throw new OutsideMeddlingException("local is open but the DB isn't", remoteState.hasDate() ? localOpen_remoteClosed : localOpen_remoteMissing);
144 ilm 397
                    }
398
                } else if (remoteOpen) {
399
                    assert remoteState.hasDate() : "Remote state open without date : " + remoteState;
400
                    final SQLRowValues lastClosure = fetchedState.getLastClosureEntry();
401
                    final java.util.Date lastClosureDate = lastClosure == null ? null : lastClosure.getDate("DATE").getTime();
402
                    if (!localState.hasDate()) {
403
                        // at 1
404
                        // MAYBE allow it for new install, for now the receipts must be copied
405
                        // over
406
                        if (lastClosureDate != null)
156 ilm 407
                            throw new OutsideMeddlingException("DB was closed and now open, but local log is missing", localMissing_remoteReopen);
144 ilm 408
                        try {
409
                            localState = files.open(userID, fetchedState).getRegisterState();
410
                        } catch (Exception e) {
156 ilm 411
                            throw new ResumeException("The local opening (following the already open DB) failed", localOpenFailed_remoteOpen, e);
144 ilm 412
                        }
413
                    } else if (remoteState.compareDateTo(lastLog.getFirstRegisterEvent().getDate()) == 0) {
414
                        // at 4
415
                        try {
156 ilm 416
                            remoteState = registerDB.close(posConf, files.getLastLog()).getRegisterState();
144 ilm 417
                        } catch (Exception e) {
156 ilm 418
                            throw new ResumeException("The closure of the DB (following the already closed local) failed", localClosed_remoteCloseFailed, e);
144 ilm 419
                        }
420
                    } else if (lastClosureDate != null && localState.compareDateTo(lastClosureDate) == 0) {
421
                        // at 6, TODO factor with above
422
                        try {
423
                            localState = files.open(userID, fetchedState).getRegisterState();
424
                        } catch (Exception e) {
156 ilm 425
                            throw new ResumeException("The local opening (following the already open DB) failed", localOpenFailed_remoteOpen, e);
144 ilm 426
                        }
427
                    } else {
428
                        // DB is at 1, local is between 4 and 6
156 ilm 429
                        throw new OutsideMeddlingException("DB was opened for a different date", localClosed_remoteOpen_datesMismatch);
144 ilm 430
                    }
431
                } else {
156 ilm 432
                    assert !localOpen && !remoteOpen;
144 ilm 433
                    if (!localState.hasDate()) {
434
                        assert remoteState.hasDate() : "Both closed with no dates, but not equal";
435
                        // DB is at 5, local is at 0
436
                        // MAYBE allow it for new install, for now the receipts must be copied
437
                        // over
156 ilm 438
                        throw new OutsideMeddlingException("DB was opened and closed, but local log is missing", localMissing_remoteClosed);
144 ilm 439
                    } else if (remoteState.hasDate()) {
440
                        // DB is at 5, local is at 5 but not for the same day
441
                        assert remoteState.compareDateTo(localState) != 0 : "Both closed with equal dates, but not equal";
156 ilm 442
                        throw new OutsideMeddlingException("DB was opened and closed for a different date", closed_datesMismatch);
144 ilm 443
                    } else {
444
                        // DB is at 0, local is between 4 and 6
156 ilm 445
                        throw new OutsideMeddlingException("DB was never opened but local was closed", localClosed_remoteMissing);
144 ilm 446
                    }
447
                }
156 ilm 448
            } catch (ReconcileException e) {
449
                throw e.init(localState, remoteState);
144 ilm 450
            } catch (Exception e) {
156 ilm 451
                throw new ReconcileException("Unknown exception", unknownTK, e).init(localState, remoteState);
144 ilm 452
            }
453
        }
454
        if (!remoteState.equals(localState))
455
            throw new IllegalStateException("Unexpected state");
456
        return remoteState;
457
    }
458
 
156 ilm 459
    static public void quit(final POSConfiguration posConf) {
149 ilm 460
        POSConfiguration.getLogger().log(Level.INFO, "User exit");
156 ilm 461
        posConf.closeConnexion();
149 ilm 462
        Frame[] l = Frame.getFrames();
463
        for (int i = 0; i < l.length; i++) {
464
            Frame f = l[i];
465
            System.err.println(f.getName() + " " + f + " Displayable: " + f.isDisplayable() + " Valid: " + f.isValid() + " Active: " + f.isActive());
466
        }
467
        Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
468
        for (Thread thread : threadSet) {
469
            if (!thread.isDaemon()) {
470
                System.err.println(thread.getName() + " " + thread.getId() + " not daemon");
471
            }
472
        }
473
    }
474
 
475
    @Override
476
    public void dispose() {
156 ilm 477
        quit(this.posConf);
149 ilm 478
        // Fermeture
479
        this.getControler().setLCD("   CAISSE FERMEE    ", "", 0);
480
        super.dispose();
481
    }
482
 
18 ilm 483
    public void showMenu() {
484
        System.out.println("CaisseFrame.showMenu()");
142 ilm 485
        final CaisseMenuPanel panel = new CaisseMenuPanel(this);
149 ilm 486
        showPanel(panel);
487
        this.getControler().setLCD("OpenConcerto", "Menu", 0);
142 ilm 488
 
149 ilm 489
    }
490
 
151 ilm 491
    public void showPanel(final JPanel panel) {
149 ilm 492
        this.invalidate();
493
        final int x = (getWidth() - panel.getPreferredSize().width) / 2;
494
        final int y = 100;
495
        final POSGlassPane glassPane2 = new POSGlassPane(panel, x, y) {
142 ilm 496
            @Override
497
            public void mousePressed(MouseEvent e) {
498
                Point containerPoint = SwingUtilities.convertPoint(this, e.getPoint(), panel);
499
                if (containerPoint.x < 0 || containerPoint.x > panel.getWidth() || containerPoint.y < 0 || containerPoint.y > panel.getHeight()) {
500
                    setGlassPane(new JPanel());
501
                    getGlassPane().setVisible(false);
502
                }
503
                super.mousePressed(e);
504
            }
505
 
506
        };
507
        this.setGlassPane(glassPane2);
508
        this.getGlassPane().setVisible(true);
18 ilm 509
        this.validate();
510
        this.repaint();
511
    }
512
 
174 ilm 513
    public void showPriceEditor(TicketItem item, CaisseControler caisseControler) {
142 ilm 514
        getControler().disableBarcodeReader();
515
        System.out.println("CaisseFrame.showPriceEditor()");
18 ilm 516
        this.invalidate();
174 ilm 517
        final PriceEditorPanel panel = new PriceEditorPanel(this, item);
142 ilm 518
 
519
        final POSGlassPane glassPane2 = new POSGlassPane(panel, (getWidth() - panel.getPreferredSize().width) / 2, 100) {
520
            @Override
521
            public void mousePressed(MouseEvent e) {
522
                Point containerPoint = SwingUtilities.convertPoint(this, e.getPoint(), panel);
523
                if (containerPoint.x < 0 || containerPoint.x > panel.getWidth() || containerPoint.y < 0 || containerPoint.y > panel.getHeight()) {
524
                    setGlassPane(new JPanel());
525
                    getGlassPane().setVisible(false);
526
                    getControler().enableBarcodeReader();
527
 
528
                }
529
                super.mousePressed(e);
530
            }
531
 
532
        };
533
        this.setGlassPane(glassPane2);
534
        this.getGlassPane().setVisible(true);
18 ilm 535
        this.validate();
536
        this.repaint();
142 ilm 537
 
18 ilm 538
    }
539
 
142 ilm 540
    public void showCaisse() {
541
        getControler().enableBarcodeReader();
542
        setGlassPane(new JPanel());
543
        getGlassPane().setVisible(false);
544
 
545
        System.out.println("CaisseFrame.showCaisse()");
546
        this.setContentPane(this.mainPanel);
547
        this.getControler().setLCD("OpenConcerto", "Caisse", 0);
548
        this.getControler().setLCDDefaultDisplay(5);
549
    }
550
 
18 ilm 551
    public void showTickets(Ticket t) {
552
        System.out.println("CaisseFrame.showMenu()");
142 ilm 553
        final ListeDesTicketsPanel panel = new ListeDesTicketsPanel(this);
18 ilm 554
        panel.setSelectedTicket(t);
555
        this.setContentPane(panel);
556
    }
557
 
132 ilm 558
    public CaisseControler getControler() {
142 ilm 559
        return this.mainPanel.getControler();
132 ilm 560
    }
142 ilm 561
 
562
    public void showClients() {
563
        System.out.println("CaisseFrame.showClients()");
564
        final ListeDesClientsPanel panel = new ListeDesClientsPanel(this);
565
        this.setContentPane(panel);
566
    }
567
 
568
    public void setClient(Client client) {
569
        System.err.println("CaisseFrame.setClient() " + client.getFullName());
570
        this.getControler().setClient(client);
571
 
572
    }
573
 
574
    @Override
575
    public void setContentPane(Container contentPane) {
576
        this.invalidate();
577
        setGlassPane(new JPanel());
578
        getGlassPane().setVisible(false);
579
        super.setContentPane(contentPane);
580
        this.validate();
581
        this.repaint();
582
    }
174 ilm 583
 
584
    public void showPostalCodeFrame(CaissePanel caissePanel) {
585
        System.out.println("CaisseFrame.showPostalCodeFrame()");
586
        this.invalidate();
587
        final PostalCodeEditorPanel panel = new PostalCodeEditorPanel(this, caissePanel);
588
        final POSGlassPane glassPane2 = new POSGlassPane(panel, (getWidth() - panel.getPreferredSize().width) / 2, 100);
589
        this.setGlassPane(glassPane2);
590
        this.getGlassPane().setVisible(true);
591
        this.validate();
592
        this.repaint();
593
 
594
    }
18 ilm 595
}