OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 177 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 182
Line 1... Line 1...
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-2019 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.
Line 126... Line 126...
126
        final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
126
        final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
127
        final StringSelection data = new StringSelection(s);
127
        final StringSelection data = new StringSelection(s);
128
        clipboard.setContents(data, data);
128
        clipboard.setContents(data, data);
129
    }
129
    }
130
 
130
 
-
 
131
    static public Future<Boolean> handle(Component comp, String msg, Throwable originalExn) {
-
 
132
        return handle(comp, msg, null, originalExn);
-
 
133
    }
-
 
134
 
131
    /**
135
    /**
132
     * Display the passed message. Note: this method doesn't block.
136
     * Display the passed message. Note: this method doesn't block.
133
     * 
137
     * 
134
     * @param comp the modal parent of the error window.
138
     * @param comp the modal parent of the error window.
135
     * @param msg the message to display.
139
     * @param msg the message to display.
-
 
140
     * @param title the title, can be <code>null</code>.
136
     * @param originalExn the cause, can be <code>null</code>.
141
     * @param originalExn the cause, can be <code>null</code>.
137
     * @return a future completed when the error is handled (e.g. the user clicked on the dialog),
142
     * @return a future completed when the error is handled (e.g. the user clicked on the dialog),
138
     *         <code>false</code> if the error couldn't be displayed to the user.
143
     *         <code>false</code> if the error couldn't be displayed to the user.
139
     */
144
     */
140
    static public Future<Boolean> handle(Component comp, String msg, Throwable originalExn) {
145
    static public Future<Boolean> handle(Component comp, String msg, String title, Throwable originalExn) {
141
        final Future<Boolean> res;
146
        final Future<Boolean> res;
142
        if (tHandler != null && tHandler.handle(msg, originalExn)) {
147
        if (tHandler != null && tHandler.handle(msg, originalExn)) {
143
            res = TRUE_FUTURE;
148
            res = TRUE_FUTURE;
144
        } else {
149
        } else {
145
            res = new ExceptionHandler(comp, msg, originalExn, false).display();
150
            res = new ExceptionHandler(comp, msg, title, originalExn, false).display();
146
        }
151
        }
147
        assert res != null;
152
        assert res != null;
148
        return res;
153
        return res;
149
    }
154
    }
150
 
155
 
Line 163... Line 168...
163
     * @param msg the message to display.
168
     * @param msg the message to display.
164
     * @param originalExn the cause, can be <code>null</code>.
169
     * @param originalExn the cause, can be <code>null</code>.
165
     * @return an exception.
170
     * @return an exception.
166
     */
171
     */
167
    static public RuntimeException die(String msg, Throwable originalExn) {
172
    static public RuntimeException die(String msg, Throwable originalExn) {
168
        final ExceptionHandler res = new ExceptionHandler(null, msg, originalExn);
173
        final ExceptionHandler res = new ExceptionHandler(null, msg, null, originalExn);
169
        res.display();
174
        res.display();
170
        return res;
175
        return res;
171
    }
176
    }
172
 
177
 
173
    static public RuntimeException die(String msg) {
178
    static public RuntimeException die(String msg) {
Line 178... Line 183...
178
        return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
183
        return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
179
    }
184
    }
180
 
185
 
181
    // the comp on which to display the popup, may be null
186
    // the comp on which to display the popup, may be null
182
    private final Component comp;
187
    private final Component comp;
-
 
188
    private final String title;
183
    private final boolean quit;
189
    private final boolean quit;
184
    protected static AtomicInteger openedWindows = new AtomicInteger(0);
190
    protected static AtomicInteger openedWindows = new AtomicInteger(0);
185
    private static boolean forceUI;
191
    private static boolean forceUI;
186
    private static boolean submitErrorAuto = false;
192
    private static boolean submitErrorAuto = false;
187
 
193
 
Line 239... Line 245...
239
            }
245
            }
240
        }
246
        }
241
        return Boolean.FALSE;
247
        return Boolean.FALSE;
242
    }
248
    }
243
 
249
 
244
    protected final void showMsg(final String msg, final boolean quit) {
250
    protected final void showMsg(String msg, final boolean quit) {
-
 
251
        if (msg == null) {
-
 
252
            msg = "";
-
 
253
        }
245
        final JPanel p = new JPanel();
254
        final JPanel p = new JPanel();
246
        p.setLayout(new GridBagLayout());
255
        p.setLayout(new GridBagLayout());
247
        final GridBagConstraints c = new GridBagConstraints();
256
        final GridBagConstraints c = new GridBagConstraints();
248
        c.insets = new Insets(10, 10, 10, 10);
257
        c.insets = new Insets(10, 10, 10, 10);
249
        c.gridx = 0;
258
        c.gridx = 0;
Line 404... Line 413...
404
        p.add(closePanel, c);
413
        p.add(closePanel, c);
405
 
414
 
406
        final Window window = this.comp == null ? null : SwingUtilities.getWindowAncestor(this.comp);
415
        final Window window = this.comp == null ? null : SwingUtilities.getWindowAncestor(this.comp);
407
        final JDialog f;
416
        final JDialog f;
408
        if (window instanceof Frame) {
417
        if (window instanceof Frame) {
409
            f = new JDialog((Frame) window, "Erreur", true);
418
            f = new JDialog((Frame) window, this.getTitle(), true);
410
        } else {
419
        } else {
411
            f = new JDialog((Dialog) window, "Erreur", true);
420
            f = new JDialog((Dialog) window, this.getTitle(), true);
412
        }
421
        }
413
        f.setContentPane(p);
422
        f.setContentPane(p);
414
        f.pack();
423
        f.pack();
415
        f.setSize(780, 580);
424
        f.setSize(780, 580);
416
        f.setMinimumSize(new Dimension(380, 380));
425
        f.setMinimumSize(new Dimension(380, 380));
Line 449... Line 458...
449
    /**
458
    /**
450
     * Affiche l'erreur et quitte.
459
     * Affiche l'erreur et quitte.
451
     * 
460
     * 
452
     * @param comp the component upon which to display the popup.
461
     * @param comp the component upon which to display the popup.
453
     * @param msg le message d'erreur à afficher.
462
     * @param msg le message d'erreur à afficher.
-
 
463
     * @param title the title, can be <code>null</code>.
454
     * @param cause la cause de l'exception (peut être <code>null</code>).
464
     * @param cause la cause de l'exception (peut être <code>null</code>).
455
     */
465
     */
456
    private ExceptionHandler(Component comp, String msg, Throwable cause) {
466
    private ExceptionHandler(Component comp, String msg, String title, Throwable cause) {
457
        this(comp, msg, cause, true);
467
        this(comp, msg, title, cause, true);
458
    }
468
    }
459
 
469
 
460
    /**
470
    /**
461
     * Affiche l'erreur et quitte suivant l'option passée.
471
     * Affiche l'erreur et quitte suivant l'option passée.
462
     * 
472
     * 
463
     * @param comp the component upon which to display the popup.
473
     * @param comp the component upon which to display the popup.
464
     * @param msg the error message to display.
474
     * @param msg the error message to display.
-
 
475
     * @param title the title, can be <code>null</code>.
465
     * @param cause the cause of the exception (maybe <code>null</code>).
476
     * @param cause the cause of the exception (maybe <code>null</code>).
466
     * @param quit if the VM must exit.
477
     * @param quit if the VM must exit.
467
     */
478
     */
468
    private ExceptionHandler(Component comp, String msg, Throwable cause, boolean quit) {
479
    private ExceptionHandler(Component comp, String msg, String title, Throwable cause, boolean quit) {
469
        super(msg, cause);
480
        super(msg, cause);
470
        this.comp = comp;
481
        this.comp = comp;
-
 
482
        this.title = title;
471
        this.quit = quit;
483
        this.quit = quit;
472
    }
484
    }
473
 
485
 
-
 
486
    public String getTitle() {
-
 
487
        if (this.title != null)
-
 
488
            return this.title;
-
 
489
        return this.quit ? "Erreur fatale" : "Erreur";
-
 
490
    }
-
 
491
 
474
    private void submitError(String error) {
492
    private void submitError(String error) {
475
        final Charset cs = StringUtils.UTF8;
493
        final Charset cs = StringUtils.UTF8;
476
        try {
494
        try {
477
            ProductInfo productInfo = ProductInfo.getInstance();
495
            ProductInfo productInfo = ProductInfo.getInstance();
478
 
496