OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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