OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 21 | Rev 28 | Go to most recent revision | 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.config;
15
 
16
import org.openconcerto.erp.action.AboutAction;
17
import org.openconcerto.erp.action.AstuceAction;
18
import org.openconcerto.erp.action.GestionDroitsAction;
19
import org.openconcerto.erp.action.NouvelleSocieteAction;
20
import org.openconcerto.erp.action.PreferencesAction;
21
import org.openconcerto.erp.action.SauvegardeBaseAction;
22
import org.openconcerto.erp.action.TaskAdminAction;
23
import org.openconcerto.erp.action.list.ListeDesSocietesCommonsAction;
24
import org.openconcerto.erp.action.list.ListeDesUsersCommonAction;
25
import org.openconcerto.erp.core.common.ui.StatusPanel;
26
import org.openconcerto.erp.core.customerrelationship.customer.action.ListeDesClientsAction;
27
import org.openconcerto.erp.core.customerrelationship.customer.action.ListeDesContactsAction;
28
import org.openconcerto.erp.core.customerrelationship.customer.action.NouvelHistoriqueListeClientAction;
29
import org.openconcerto.erp.core.customerrelationship.mail.action.ListeDesCourriersClientsAction;
30
import org.openconcerto.erp.core.customerrelationship.mail.action.NouveauCourrierClientAction;
31
import org.openconcerto.erp.core.finance.accounting.action.CompteResultatBilanAction;
32
import org.openconcerto.erp.core.finance.accounting.action.EtatBalanceAction;
33
import org.openconcerto.erp.core.finance.accounting.action.EtatChargeAction;
34
import org.openconcerto.erp.core.finance.accounting.action.EtatGrandLivreAction;
35
import org.openconcerto.erp.core.finance.accounting.action.EtatJournauxAction;
21 ilm 36
import org.openconcerto.erp.core.finance.accounting.action.ExportRelationExpertAction;
18 ilm 37
import org.openconcerto.erp.core.finance.accounting.action.GenerePointageAction;
38
import org.openconcerto.erp.core.finance.accounting.action.GestionPlanComptableEAction;
39
import org.openconcerto.erp.core.finance.accounting.action.ImpressionLivrePayeAction;
40
import org.openconcerto.erp.core.finance.accounting.action.ListeDesEcrituresAction;
41
import org.openconcerto.erp.core.finance.accounting.action.ListeEcritureParClasseAction;
42
import org.openconcerto.erp.core.finance.accounting.action.NouveauClotureAction;
43
import org.openconcerto.erp.core.finance.accounting.action.NouveauJournalAction;
44
import org.openconcerto.erp.core.finance.accounting.action.NouveauLettrageAction;
45
import org.openconcerto.erp.core.finance.accounting.action.NouveauPointageAction;
46
import org.openconcerto.erp.core.finance.accounting.action.NouvelleValidationAction;
19 ilm 47
import org.openconcerto.erp.core.finance.accounting.action.ResultatAnalytiqueAction;
18 ilm 48
import org.openconcerto.erp.core.finance.payment.action.ListeDesChequesAEncaisserAction;
49
import org.openconcerto.erp.core.finance.payment.action.ListeDesChequesAvoirAction;
50
import org.openconcerto.erp.core.finance.payment.action.ListeDesChequesFournisseursAction;
51
import org.openconcerto.erp.core.finance.payment.action.ListeDesEncaissementsAction;
52
import org.openconcerto.erp.core.finance.payment.action.ListeDesReferencesAction;
53
import org.openconcerto.erp.core.finance.payment.action.ListeDesRelancesAction;
54
import org.openconcerto.erp.core.finance.payment.action.ListeDesTraitesFournisseursAction;
55
import org.openconcerto.erp.core.finance.payment.action.NouveauDecaissementChequeAvoirAction;
56
import org.openconcerto.erp.core.finance.payment.action.NouveauListeDesChequesADecaisserAction;
57
import org.openconcerto.erp.core.finance.payment.action.NouveauListeDesChequesAEncaisserAction;
58
import org.openconcerto.erp.core.finance.tax.action.DeclarationTVAAction;
59
import org.openconcerto.erp.core.humanresources.employe.action.ListeDesCommerciauxAction;
60
import org.openconcerto.erp.core.humanresources.employe.action.ListeDesSalariesAction;
61
import org.openconcerto.erp.core.humanresources.employe.action.ListeDesSecretairesAction;
25 ilm 62
import org.openconcerto.erp.core.humanresources.employe.action.N4DSAction;
63
import org.openconcerto.erp.core.humanresources.employe.report.N4DS;
18 ilm 64
import org.openconcerto.erp.core.humanresources.payroll.action.ClotureMensuellePayeAction;
65
import org.openconcerto.erp.core.humanresources.payroll.action.EditionFichePayeAction;
66
import org.openconcerto.erp.core.humanresources.payroll.action.ListeDesProfilsPayeAction;
67
import org.openconcerto.erp.core.humanresources.payroll.action.ListeDesRubriquesDePayeAction;
68
import org.openconcerto.erp.core.humanresources.payroll.action.ListeDesVariablesPayes;
69
import org.openconcerto.erp.core.humanresources.payroll.action.NouvelAcompteAction;
70
import org.openconcerto.erp.core.humanresources.payroll.action.NouvelHistoriqueFichePayeAction;
71
import org.openconcerto.erp.core.humanresources.payroll.action.NouvelleSaisieKmAction;
72
import org.openconcerto.erp.core.reports.stat.action.EvolutionCAAction;
73
import org.openconcerto.erp.core.reports.stat.action.EvolutionMargeAction;
74
import org.openconcerto.erp.core.reports.stat.action.VenteArticleGraphAction;
75
import org.openconcerto.erp.core.reports.stat.action.VenteArticleMargeGraphAction;
76
import org.openconcerto.erp.core.sales.credit.action.ListeDesAvoirsClientsAction;
77
import org.openconcerto.erp.core.sales.credit.action.NouveauAvoirClientAction;
78
import org.openconcerto.erp.core.sales.invoice.action.EtatVenteAction;
79
import org.openconcerto.erp.core.sales.invoice.action.GenListeVenteAction;
21 ilm 80
import org.openconcerto.erp.core.sales.invoice.action.ListeDebiteursAction;
18 ilm 81
import org.openconcerto.erp.core.sales.invoice.action.ListeDesElementsFactureAction;
82
import org.openconcerto.erp.core.sales.invoice.action.ListeDesVentesAction;
83
import org.openconcerto.erp.core.sales.invoice.action.ListeSaisieVenteFactureAction;
84
import org.openconcerto.erp.core.sales.invoice.action.ListesFacturesClientsImpayeesAction;
85
import org.openconcerto.erp.core.sales.invoice.action.NouveauSaisieVenteComptoirAction;
86
import org.openconcerto.erp.core.sales.invoice.action.NouveauSaisieVenteFactureAction;
87
import org.openconcerto.erp.core.sales.order.action.NouvelleCommandeClientAction;
88
import org.openconcerto.erp.core.sales.pos.action.ListeDesCaissesTicketAction;
89
import org.openconcerto.erp.core.sales.pos.action.ListeDesTicketsAction;
90
import org.openconcerto.erp.core.sales.product.action.FamilleArticleAction;
91
import org.openconcerto.erp.core.sales.product.action.ListeDesArticlesAction;
92
import org.openconcerto.erp.core.sales.quote.action.ListeDesDevisAction;
93
import org.openconcerto.erp.core.sales.quote.action.ListeDesElementsPropositionsAction;
94
import org.openconcerto.erp.core.sales.quote.action.NouveauDevisAction;
95
import org.openconcerto.erp.core.sales.quote.action.NouvellePropositionAction;
96
import org.openconcerto.erp.core.sales.shipment.action.ListeDesBonsDeLivraisonAction;
97
import org.openconcerto.erp.core.sales.shipment.action.NouveauBonLivraisonAction;
98
import org.openconcerto.erp.core.supplychain.credit.action.ListeDesAvoirsFournisseurAction;
99
import org.openconcerto.erp.core.supplychain.credit.action.NouvelAvoirFournisseurAction;
100
import org.openconcerto.erp.core.supplychain.order.action.ListeDesCommandesAction;
101
import org.openconcerto.erp.core.supplychain.order.action.ListeDesCommandesClientAction;
102
import org.openconcerto.erp.core.supplychain.order.action.ListeSaisieAchatAction;
103
import org.openconcerto.erp.core.supplychain.order.action.NouveauSaisieAchatAction;
104
import org.openconcerto.erp.core.supplychain.order.action.NouvelleCommandeAction;
105
import org.openconcerto.erp.core.supplychain.receipt.action.ListeDesBonsReceptionsAction;
106
import org.openconcerto.erp.core.supplychain.receipt.action.NouveauBonReceptionAction;
107
import org.openconcerto.erp.core.supplychain.stock.action.ListeDesMouvementsStockAction;
108
import org.openconcerto.erp.core.supplychain.stock.action.NouvelleSaisieMouvementStockAction;
21 ilm 109
import org.openconcerto.erp.core.supplychain.supplier.action.ListeDesContactsFournisseursAction;
18 ilm 110
import org.openconcerto.erp.core.supplychain.supplier.action.ListeDesFournisseursAction;
111
import org.openconcerto.erp.core.supplychain.supplier.action.ListesFacturesFournImpayeesAction;
112
import org.openconcerto.erp.core.supplychain.supplier.action.NouvelHistoriqueListeFournAction;
19 ilm 113
import org.openconcerto.erp.modules.ModuleFrame;
18 ilm 114
import org.openconcerto.erp.preferences.DefaultNXProps;
115
import org.openconcerto.erp.rights.ComptaUserRight;
116
import org.openconcerto.erp.rights.NXRights;
117
import org.openconcerto.sql.Configuration;
118
import org.openconcerto.sql.users.UserManager;
119
import org.openconcerto.sql.users.rights.LockAdminUserRight;
120
import org.openconcerto.sql.users.rights.UserRights;
121
import org.openconcerto.task.TodoListPanel;
122
import org.openconcerto.task.config.ComptaBasePropsConfiguration;
20 ilm 123
import org.openconcerto.ui.AutoHideTabbedPane;
19 ilm 124
import org.openconcerto.ui.MenuUtils;
18 ilm 125
import org.openconcerto.ui.SwingThreadUtils;
20 ilm 126
import org.openconcerto.ui.state.WindowStateManager;
18 ilm 127
import org.openconcerto.utils.JImage;
128
import org.openconcerto.utils.OSXAdapter;
129
 
130
import java.awt.Color;
131
import java.awt.Container;
19 ilm 132
import java.awt.Dimension;
18 ilm 133
import java.awt.GridBagConstraints;
134
import java.awt.GridBagLayout;
135
import java.awt.event.ActionEvent;
136
import java.awt.event.WindowAdapter;
137
import java.awt.event.WindowEvent;
20 ilm 138
import java.io.File;
18 ilm 139
import java.util.ArrayList;
19 ilm 140
import java.util.Arrays;
18 ilm 141
import java.util.List;
142
 
143
import javax.swing.AbstractAction;
19 ilm 144
import javax.swing.Action;
18 ilm 145
import javax.swing.ImageIcon;
146
import javax.swing.JFrame;
147
import javax.swing.JMenu;
148
import javax.swing.JMenuBar;
149
import javax.swing.JMenuItem;
150
import javax.swing.JSeparator;
151
 
152
public class MainFrame extends JFrame {
153
 
19 ilm 154
    // menus
155
    public static final String STRUCTURE_MENU = "Structure";
156
    public static final String PAYROLL_MENU = "Paye";
157
    public static final String PAYMENT_MENU = "Paiement";
158
    public static final String STATS_MENU = "Statistiques";
159
    public static final String DECLARATION_MENU = "Déclaration";
160
    public static final String STATE_MENU = "Etats";
161
    public static final String LIST_MENU = "Gestion";
162
    public static final String CREATE_MENU = "Saisie";
163
    public static final String FILE_MENU = "Fichier";
20 ilm 164
    private static final String HELP_MENU = "Aide";
19 ilm 165
 
18 ilm 166
    static private final List<Runnable> runnables = new ArrayList<Runnable>();
167
    static private MainFrame instance = null;
168
 
169
    public static MainFrame getInstance() {
170
        return instance;
171
    }
172
 
173
    private static void setInstance(MainFrame f) {
174
        if (f != null && instance != null)
175
            throw new IllegalStateException("More than one main frame");
176
        instance = f;
177
        if (f != null) {
178
            for (final Runnable r : runnables)
179
                r.run();
180
            runnables.clear();
181
        }
182
    }
183
 
184
    /**
185
     * Execute the runnable in the EDT after the main frame has been created. Thus if the main frame
186
     * has already been created and we're in the EDT, execute <code>r</code> immediately.
187
     *
188
     * @param r the runnable to run.
189
     * @see #getInstance()
190
     */
191
    public static void invoke(final Runnable r) {
192
        SwingThreadUtils.invoke(new Runnable() {
193
            @Override
194
            public void run() {
195
                if (instance == null) {
196
                    runnables.add(r);
197
                } else {
198
                    r.run();
199
                }
200
            }
201
        });
202
    }
203
 
20 ilm 204
    private final AutoHideTabbedPane tabContainer;
205
    private TodoListPanel todoPanel;
18 ilm 206
    private JImage image;
207
 
208
    public TodoListPanel getTodoPanel() {
209
        return this.todoPanel;
210
    }
211
 
212
    public MainFrame() {
213
        super();
214
 
215
        this.setIconImage(new ImageIcon(this.getClass().getResource("frameicon.png")).getImage());
20 ilm 216
        this.setJMenuBar(Gestion.isMinimalMode() ? createMinimalMenu() : createMenu());
18 ilm 217
        Container co = this.getContentPane();
218
        co.setLayout(new GridBagLayout());
219
        GridBagConstraints c = new GridBagConstraints();
220
        c.fill = GridBagConstraints.HORIZONTAL;
221
        c.gridx = 0;
222
        c.gridy = 0;
223
        // // co.add(new RangeSlider(2005), c);
224
        c.weightx = 1;
225
        c.weighty = 0;
20 ilm 226
        this.image = new JImage(ComptaBasePropsConfiguration.class.getResource("logo.png"));
227
        this.image.setBackground(Color.WHITE);
228
        this.image.check();
229
        co.add(this.image, c);
18 ilm 230
        c.weighty = 0;
231
        c.gridy++;
232
        c.fill = GridBagConstraints.BOTH;
233
        co.add(new JSeparator(JSeparator.HORIZONTAL), c);
234
        c.gridy++;
235
        c.weighty = 1;
20 ilm 236
        this.tabContainer = new AutoHideTabbedPane();
237
        co.add(this.tabContainer, c);
238
        Dimension minSize;
239
        final String confSuffix;
240
        if (!Gestion.isMinimalMode()) {
241
            this.todoPanel = new TodoListPanel();
242
            this.getTabbedPane().addTab("Tâches", this.todoPanel);
243
            minSize = new Dimension(800, 600);
244
            confSuffix = "";
245
        } else {
246
            minSize = null;
247
            confSuffix = "-minimal";
248
        }
18 ilm 249
        c.weighty = 0;
250
        c.gridy++;
251
        c.fill = GridBagConstraints.HORIZONTAL;
252
        co.add(StatusPanel.getInstance(), c);
253
 
20 ilm 254
        if (minSize == null) {
255
            this.pack();
256
            minSize = new Dimension(this.getSize());
257
        }
258
        this.setMinimumSize(minSize);
259
 
260
        final File confFile = new File(Configuration.getInstance().getConfDir(), "Configuration" + File.separator + "Frame" + File.separator + "mainFrame" + confSuffix + ".xml");
261
        new WindowStateManager(this, confFile).loadState();
262
 
18 ilm 263
        registerForMacOSXEvents();
264
 
265
        this.addWindowListener(new WindowAdapter() {
20 ilm 266
            @Override
18 ilm 267
            public void windowClosing(WindowEvent arg0) {
268
                quit();
269
            }
270
        });
271
 
272
        setInstance(this);
20 ilm 273
        new NewsUpdater(this.image);
18 ilm 274
    }
275
 
20 ilm 276
    private final JMenuBar createMinimalMenu() {
277
        final JMenuBar res = new JMenuBar();
278
        final JMenu fileMenu = new JMenu(FILE_MENU);
279
        fileMenu.add(new SauvegardeBaseAction());
280
        if (!Gestion.MAC_OS_X) {
281
            fileMenu.add(new JMenuItem(new AbstractAction("Quitter") {
282
                @Override
283
                public void actionPerformed(ActionEvent e) {
284
                    quit();
285
                }
286
            }));
287
        }
288
        res.add(fileMenu);
289
 
290
        final UserRights rights = UserManager.getInstance().getCurrentUser().getRights();
291
        if (rights.haveRight(LockAdminUserRight.LOCK_MENU_ADMIN)) {
292
            final JMenu structMenu = new JMenu(STRUCTURE_MENU);
293
            structMenu.add(new JMenuItem(new ListeDesUsersCommonAction()));
294
            res.add(structMenu);
295
        }
296
 
297
        final JMenu helpMenu = new JMenu(HELP_MENU);
298
        helpMenu.add(new JMenuItem(AboutAction.getInstance()));
299
        res.add(helpMenu);
300
 
301
        return res;
302
    }
303
 
304
    private final JMenuBar createMenu() {
18 ilm 305
        JMenuBar result = new JMenuBar();
306
 
307
        JMenu menu;
308
 
309
        String valModeVenteComptoir = DefaultNXProps.getInstance().getStringProperty("ArticleVenteComptoir");
310
        Boolean bModeVenteComptoir = Boolean.valueOf(valModeVenteComptoir);
311
 
312
        // Fichier
19 ilm 313
        menu = new JMenu(FILE_MENU);
18 ilm 314
 
315
        // FIXME Probleme AliasedTable --> flush showAs, ...
316
        // item = new JMenuItem(new NouvelleConnexionAction());
317
        // menu.add(item);
318
 
319
        // Boolean bSauvegarde =
320
        // UserManager.getInstance().getCurrentUser().getRights().haveRight("BACKUP");
321
        // if (bSauvegarde) {
322
 
323
        // item = new JMenuItem("Sauvegarde"); // eSauvegarde
324
        final UserRights rights = UserManager.getInstance().getCurrentUser().getRights();
325
        final ComptaPropsConfiguration configuration = (ComptaPropsConfiguration) Configuration.getInstance();
326
 
19 ilm 327
            menu.add(new SauvegardeBaseAction());
21 ilm 328
            menu.add(new ExportRelationExpertAction());
18 ilm 329
 
19 ilm 330
        // if (rights.haveRight(NXRights.LOCK_MENU_TEST.getCode())) {
331
        // menu.add(new GenerateEcrFactAction());
332
        // menu.add(new ImportCielDataAction());
333
        // }
18 ilm 334
 
19 ilm 335
        menu.add(new JMenuItem(new AbstractAction("Modules") {
336
            @Override
337
            public void actionPerformed(ActionEvent e) {
338
                final ModuleFrame frame = new ModuleFrame();
339
                frame.setMinimumSize(new Dimension(480, 640));
340
                frame.setLocationRelativeTo(null);
341
                frame.setVisible(true);
342
            }
343
        }));
18 ilm 344
 
345
        if (!Gestion.MAC_OS_X) {
346
            menu.add(new JMenuItem(new PreferencesAction()));
347
            menu.add(new JMenuItem(new AbstractAction("Quitter") {
20 ilm 348
                @Override
18 ilm 349
                public void actionPerformed(ActionEvent e) {
350
                    quit();
351
                }
352
            }));
353
        }
354
        result.add(menu);
355
 
356
        // Saisie
19 ilm 357
        menu = new JMenu(CREATE_MENU);
18 ilm 358
 
359
        if (rights.haveRight(ComptaUserRight.MENU)) {
19 ilm 360
            menu.add(new NouvelleSaisieKmAction());
18 ilm 361
            menu.add(new JSeparator());
362
        }
363
 
19 ilm 364
            menu.add(new NouveauDevisAction());
18 ilm 365
 
366
 
367
        menu.add(new JSeparator());
368
 
19 ilm 369
            menu.add(new NouveauBonLivraisonAction());
370
            menu.add(new NouvelleCommandeClientAction());
18 ilm 371
        if (bModeVenteComptoir && rights.haveRight("VENTE_COMPTOIR")) {
19 ilm 372
            menu.add(new NouveauSaisieVenteComptoirAction());
18 ilm 373
        }
19 ilm 374
        menu.add(new NouveauSaisieVenteFactureAction());
18 ilm 375
 
19 ilm 376
        menu.add(new NouveauAvoirClientAction());
18 ilm 377
 
378
            if (rights.haveRight(NXRights.LOCK_MENU_ACHAT.getCode())) {
379
 
380
                menu.add(new JSeparator());
19 ilm 381
                    menu.add(new NouvelleCommandeAction());
382
                menu.add(new NouveauBonReceptionAction());
383
                menu.add(new NouveauSaisieAchatAction());
384
                    menu.add(new NouvelAvoirFournisseurAction());
385
                menu.add(new NouvelleSaisieMouvementStockAction());
18 ilm 386
            }
387
        result.add(menu);
388
 
389
        // Gestion
19 ilm 390
        menu = new JMenu(LIST_MENU);
18 ilm 391
 
19 ilm 392
        menu.add(new ListeDesClientsAction());
393
        menu.add(new ListeDesContactsAction());
18 ilm 394
 
395
        if (rights.haveRight(NXRights.ACCES_HISTORIQUE.getCode())) {
19 ilm 396
            menu.add(new NouvelHistoriqueListeClientAction());
18 ilm 397
        }
398
 
399
 
400
        menu.add(new JSeparator());
401
 
19 ilm 402
            menu.add(new ListeDesDevisAction());
18 ilm 403
 
404
 
19 ilm 405
            menu.add(new ListeDesCommandesClientAction());
406
            menu.add(new ListeDesBonsDeLivraisonAction());
18 ilm 407
 
408
        boolean useListDesVentesAction = bModeVenteComptoir;
409
        if (useListDesVentesAction) {
19 ilm 410
            menu.add(new ListeDesVentesAction());
18 ilm 411
 
412
        } else {
413
 
19 ilm 414
            menu.add(new ListeSaisieVenteFactureAction());
18 ilm 415
        }
416
 
19 ilm 417
        menu.add(new ListeDesAvoirsClientsAction());
18 ilm 418
 
419
            menu.add(new JSeparator());
19 ilm 420
            menu.add(new ListeDesFournisseursAction());
21 ilm 421
            menu.add(new ListeDesContactsFournisseursAction());
19 ilm 422
                menu.add(new NouvelHistoriqueListeFournAction());
18 ilm 423
            if (rights.haveRight(NXRights.LOCK_MENU_ACHAT.getCode())) {
19 ilm 424
                    menu.add(new ListeDesCommandesAction());
425
                menu.add(new ListeDesBonsReceptionsAction());
426
                menu.add(new ListeSaisieAchatAction());
427
                    menu.add(new ListeDesAvoirsFournisseurAction());
18 ilm 428
            }
429
 
430
            menu.add(new JSeparator());
19 ilm 431
            menu.add(new ListeDesArticlesAction());
432
            menu.add(new ListeDesMouvementsStockAction());
18 ilm 433
 
19 ilm 434
            menu.add(new JSeparator());
435
            menu.add(new ListeDesTicketsAction());
18 ilm 436
 
437
        result.add(menu);
438
        // Etats
19 ilm 439
        menu = new JMenu(STATE_MENU);
18 ilm 440
 
19 ilm 441
        menu.add(new EtatBalanceAction());
442
        menu.add(new org.openconcerto.erp.core.finance.accounting.action.BalanceAgeeAction());
443
        menu.add(new EtatJournauxAction());
444
        menu.add(new EtatGrandLivreAction());
445
        menu.add(new ListeDesEcrituresAction());
446
        menu.add(new ListeEcritureParClasseAction());
18 ilm 447
        menu.add(new JSeparator());
19 ilm 448
        menu.add(new NouvelleValidationAction());
18 ilm 449
        menu.add(new JMenuItem(new NouveauClotureAction()));
450
 
451
        if (rights.haveRight(ComptaUserRight.MENU)) {
452
            result.add(menu);
453
        }
454
 
19 ilm 455
        menu = new JMenu(DECLARATION_MENU);
18 ilm 456
 
19 ilm 457
        menu.add(new DeclarationTVAAction());
18 ilm 458
        menu.add(new JSeparator());
19 ilm 459
        menu.add(new EtatChargeAction());
460
        menu.add(new CompteResultatBilanAction());
25 ilm 461
        menu.add(new N4DSAction());
18 ilm 462
        if (rights.haveRight(ComptaUserRight.MENU)) {
463
            result.add(menu);
464
        }
465
 
19 ilm 466
        menu = new JMenu(STATS_MENU);
18 ilm 467
 
468
 
19 ilm 469
        menu.add(new EvolutionCAAction());
18 ilm 470
 
19 ilm 471
            menu.add(new EvolutionMargeAction());
18 ilm 472
        menu.addSeparator();
19 ilm 473
        menu.add(new GenListeVenteAction());
474
            menu.add(new VenteArticleGraphAction());
475
            menu.add(new VenteArticleMargeGraphAction());
476
        menu.add(new EtatVenteAction());
18 ilm 477
 
478
        if (rights.haveRight(NXRights.ACCES_MENU_STAT.getCode())) {
479
            result.add(menu);
480
        }
19 ilm 481
        menu = new JMenu(PAYMENT_MENU);
18 ilm 482
 
483
        if (rights.haveRight(ComptaUserRight.MENU) || rights.haveRight(ComptaUserRight.POINTAGE_LETTRAGE)) {
19 ilm 484
            menu.add(new NouveauPointageAction());
485
            menu.add(new NouveauLettrageAction());
18 ilm 486
            menu.add(new JSeparator());
487
        }
488
 
19 ilm 489
        menu.add(new ListesFacturesClientsImpayeesAction());
21 ilm 490
        menu.add(new ListeDebiteursAction());
18 ilm 491
        if (rights.haveRight(NXRights.GESTION_ENCAISSEMENT.getCode())) {
19 ilm 492
            menu.add(new ListeDesEncaissementsAction());
493
            menu.add(new ListeDesRelancesAction());
18 ilm 494
            menu.add(new JSeparator());
19 ilm 495
            menu.add(new ListeDesChequesAEncaisserAction());
496
            menu.add(new NouveauListeDesChequesAEncaisserAction());
18 ilm 497
            menu.add(new JSeparator());
19 ilm 498
            menu.add(new ListeDesChequesAvoirAction());
499
            menu.add(new NouveauDecaissementChequeAvoirAction());
18 ilm 500
            menu.add(new JSeparator());
501
        }
502
        if (rights.haveRight(NXRights.LOCK_MENU_ACHAT.getCode())) {
19 ilm 503
            menu.add(new ListesFacturesFournImpayeesAction());
504
            menu.add(new ListeDesTraitesFournisseursAction());
505
            menu.add(new ListeDesChequesFournisseursAction());
506
            menu.add(new NouveauListeDesChequesADecaisserAction());
18 ilm 507
        }
508
            result.add(menu);
509
 
510
        // Paye
19 ilm 511
        menu = new JMenu(PAYROLL_MENU);
18 ilm 512
 
19 ilm 513
        menu.add(new ImpressionLivrePayeAction());
514
        menu.add(new ListeDesProfilsPayeAction());
515
        menu.add(new NouvelHistoriqueFichePayeAction());
516
        menu.add(new EditionFichePayeAction());
517
        menu.add(new NouvelAcompteAction());
518
        menu.add(new ListeDesSalariesAction());
18 ilm 519
        menu.add(new JSeparator());
19 ilm 520
        menu.add(new ListeDesRubriquesDePayeAction());
521
        menu.add(new ListeDesVariablesPayes());
18 ilm 522
        menu.add(new JSeparator());
19 ilm 523
        menu.add(new ClotureMensuellePayeAction());
18 ilm 524
 
525
        if (rights.haveRight(NXRights.LOCK_MENU_PAYE.getCode())) {
526
            result.add(menu);
527
        }
528
 
529
        // Structure
19 ilm 530
        menu = new JMenu(STRUCTURE_MENU);
18 ilm 531
 
532
        if (rights.haveRight(ComptaUserRight.MENU)) {
533
 
19 ilm 534
            menu.add(new GestionPlanComptableEAction());
535
            menu.add(new NouveauJournalAction());
18 ilm 536
            menu.add(new JSeparator());
537
 
538
        }
539
 
540
        if (rights.haveRight(LockAdminUserRight.LOCK_MENU_ADMIN)) {
541
            menu.add(new JMenuItem(new ListeDesUsersCommonAction()));
542
            menu.add(new JMenuItem(new GestionDroitsAction()));
543
            menu.add(new JMenuItem(new TaskAdminAction()));
544
            menu.add(new JSeparator());
545
        }
546
 
19 ilm 547
        menu.add(new ListeDesCommerciauxAction());
18 ilm 548
        menu.add(new JSeparator());
19 ilm 549
        menu.add(new ListeDesCaissesTicketAction());
18 ilm 550
 
551
        menu.add(new JSeparator());
552
 
19 ilm 553
            menu.add(new ListeDesSocietesCommonsAction());
18 ilm 554
 
19 ilm 555
            menu.add(new NouvelleSocieteAction());
18 ilm 556
 
557
 
558
        if (rights.haveRight(NXRights.ACCES_MENU_STRUCTURE.getCode())) {
559
            result.add(menu);
560
        }
561
        // Aide
20 ilm 562
        menu = new JMenu(HELP_MENU);
18 ilm 563
        menu.add(new JMenuItem(AboutAction.getInstance()));
564
        menu.add(new JMenuItem(new AstuceAction()));
565
 
566
        result.add(menu);
567
        return result;
568
    }
569
 
19 ilm 570
    public JMenuItem addMenuItem(final Action action, final String... path) {
571
        return this.addMenuItem(action, Arrays.asList(path));
572
    }
573
 
574
    /**
575
     * Adds a menu item to this menu. The path should be an alternation of menu and group within
576
     * that menu. All items within the same group will be grouped together inside separators. Menus
577
     * will be created as needed.
578
     *
579
     * @param action the action to perform.
580
     * @param path where to add the menu item.
581
     * @return the newly created item.
582
     * @throws IllegalArgumentException if path is not even.
583
     */
584
    public JMenuItem addMenuItem(final Action action, final List<String> path) throws IllegalArgumentException {
585
        if (path.size() == 0 || path.size() % 2 != 0)
586
            throw new IllegalArgumentException("Path should be of the form menu/group/menu/group/... : " + path);
587
        final JMenu topLevelMenu = getMenu(path.get(0));
588
        return MenuUtils.addMenuItem(action, topLevelMenu, path.subList(1, path.size()));
589
    }
590
 
591
    // get or create (at the end) a top level menu
592
    private JMenu getMenu(final String name) {
593
        final JMenu existing = MenuUtils.findChild(this.getJMenuBar(), name, JMenu.class);
594
        final JMenu res;
595
        if (existing == null) {
596
            res = new JMenu(name);
20 ilm 597
            // insert before the help menu
598
            this.getJMenuBar().add(res, this.getJMenuBar().getComponentCount() - 1);
19 ilm 599
        } else {
600
            res = existing;
601
        }
602
        return res;
603
    }
604
 
605
    /**
606
     * Remove the passed item from this menu. This method handles the cleanup of separators and
607
     * empty menus.
608
     *
609
     * @param item the item to remove.
610
     * @throws IllegalArgumentException if <code>item</code> is not in this menu.
611
     */
612
    public void removeMenuItem(final JMenuItem item) throws IllegalArgumentException {
613
        if (SwingThreadUtils.getAncestorOrSelf(JMenuBar.class, item) != this.getJMenuBar())
614
            throw new IllegalArgumentException("Item not in this menu " + item);
615
        MenuUtils.removeMenuItem(item);
616
    }
617
 
18 ilm 618
    // Generic registration with the Mac OS X application menu
619
    // Checks the platform, then attempts to register with the Apple EAWT
620
    // See OSXAdapter.java to see how this is done without directly referencing any Apple APIs
621
    public void registerForMacOSXEvents() {
622
        if (Gestion.MAC_OS_X) {
623
            try {
624
                // Generate and register the OSXAdapter, passing it a hash of all the methods we
625
                // wish to use as delegates for various com.apple.eawt.ApplicationListener methods
626
                OSXAdapter.setQuitHandler(this, getClass().getDeclaredMethod("quit", new Class[0]));
627
                OSXAdapter.setAboutHandler(this, getClass().getDeclaredMethod("about", new Class[0]));
628
                OSXAdapter.setPreferencesHandler(this, getClass().getDeclaredMethod("preferences", new Class[0]));
629
                // no OSXAdapter.setFileHandler() for now
630
            } catch (Exception e) {
631
                System.err.println("Error while loading the OSXAdapter:");
632
                e.printStackTrace();
633
            }
634
        }
635
    }
636
 
637
    // used by OSXAdapter
638
    public final void preferences() {
639
        new PreferencesAction().actionPerformed(null);
640
    }
641
 
642
    public final void about() {
643
        AboutAction.getInstance().actionPerformed(null);
644
    }
645
 
646
    public boolean quit() {
20 ilm 647
        if (this.getTodoPanel() != null)
648
            this.getTodoPanel().stopUpdate();
18 ilm 649
        Gestion.askForExit();
650
        return false;
651
    }
20 ilm 652
 
653
    public final AutoHideTabbedPane getTabbedPane() {
654
        return this.tabContainer;
655
    }
18 ilm 656
}