OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 80 Rev 83
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.action;
14
 package org.openconcerto.erp.action;
15
 
15
 
16
import static org.openconcerto.task.config.ComptaBasePropsConfiguration.getStreamStatic;
16
import static org.openconcerto.task.config.ComptaBasePropsConfiguration.getStreamStatic;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18
import org.openconcerto.erp.config.DefaultMenuConfiguration;
18
import org.openconcerto.erp.config.DefaultMenuConfiguration;
19
import org.openconcerto.erp.config.Gestion;
19
import org.openconcerto.erp.config.Gestion;
20
import org.openconcerto.erp.config.Log;
20
import org.openconcerto.erp.config.Log;
21
import org.openconcerto.erp.config.MainFrame;
21
import org.openconcerto.erp.config.MainFrame;
22
import org.openconcerto.erp.config.MenuManager;
22
import org.openconcerto.erp.config.MenuManager;
23
import org.openconcerto.erp.config.MinimalMenuConfiguration;
23
import org.openconcerto.erp.config.MinimalMenuConfiguration;
24
import org.openconcerto.erp.core.common.ui.PanelFrame;
24
import org.openconcerto.erp.core.common.ui.PanelFrame;
25
import org.openconcerto.erp.core.common.ui.StatusPanel;
25
import org.openconcerto.erp.core.common.ui.StatusPanel;
26
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
26
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
27
import org.openconcerto.erp.core.humanresources.payroll.element.CaisseCotisationSQLElement;
27
import org.openconcerto.erp.core.humanresources.payroll.element.CaisseCotisationSQLElement;
28
import org.openconcerto.erp.element.objet.ClasseCompte;
28
import org.openconcerto.erp.element.objet.ClasseCompte;
29
import org.openconcerto.erp.modules.ModuleFrame;
29
import org.openconcerto.erp.modules.ModuleFrame;
30
import org.openconcerto.erp.modules.ModuleManager;
30
import org.openconcerto.erp.modules.ModuleManager;
31
import org.openconcerto.erp.panel.ComptaTipsFrame;
31
import org.openconcerto.erp.panel.ComptaTipsFrame;
32
import org.openconcerto.erp.utils.NXDatabaseAccessor;
32
import org.openconcerto.erp.utils.NXDatabaseAccessor;
33
import org.openconcerto.map.model.Ville;
33
import org.openconcerto.map.model.Ville;
34
import org.openconcerto.sql.Configuration;
34
import org.openconcerto.sql.Configuration;
35
import org.openconcerto.sql.element.SQLElement;
35
import org.openconcerto.sql.element.SQLElement;
36
import org.openconcerto.sql.model.SQLBackgroundTableCache;
36
import org.openconcerto.sql.model.SQLBackgroundTableCache;
37
import org.openconcerto.sql.model.SQLBase;
37
import org.openconcerto.sql.model.SQLBase;
38
import org.openconcerto.sql.model.SQLRow;
38
import org.openconcerto.sql.model.SQLRow;
39
import org.openconcerto.sql.model.SQLRowListRSH;
39
import org.openconcerto.sql.model.SQLRowListRSH;
40
import org.openconcerto.sql.model.SQLRowValues;
-
 
41
import org.openconcerto.sql.model.SQLSelect;
40
import org.openconcerto.sql.model.SQLSelect;
42
import org.openconcerto.sql.model.SQLTable;
41
import org.openconcerto.sql.model.SQLTable;
43
import org.openconcerto.sql.model.UndefinedRowValuesCache;
42
import org.openconcerto.sql.model.UndefinedRowValuesCache;
44
import org.openconcerto.sql.model.Where;
43
import org.openconcerto.sql.model.Where;
45
import org.openconcerto.sql.preferences.SQLPreferences;
44
import org.openconcerto.sql.preferences.SQLPreferences;
46
import org.openconcerto.sql.preferences.UserProps;
45
import org.openconcerto.sql.preferences.UserProps;
47
import org.openconcerto.sql.sqlobject.IComboSelectionItem;
46
import org.openconcerto.sql.sqlobject.IComboSelectionItem;
48
import org.openconcerto.sql.ui.ConnexionPanel;
47
import org.openconcerto.sql.ui.ConnexionPanel;
49
import org.openconcerto.sql.users.User;
48
import org.openconcerto.sql.users.User;
50
import org.openconcerto.sql.users.UserManager;
49
import org.openconcerto.sql.users.UserManager;
51
import org.openconcerto.sql.users.rights.TableAllRights;
50
import org.openconcerto.sql.users.rights.TableAllRights;
52
import org.openconcerto.sql.users.rights.UserRightsManager;
51
import org.openconcerto.sql.users.rights.UserRightsManager;
53
import org.openconcerto.sql.users.rights.UserRightsManager.RightTuple;
52
import org.openconcerto.sql.users.rights.UserRightsManager.RightTuple;
-
 
53
import org.openconcerto.sql.utils.BackupPanel;
54
import org.openconcerto.task.config.ComptaBasePropsConfiguration;
54
import org.openconcerto.task.config.ComptaBasePropsConfiguration;
55
import org.openconcerto.ui.DefaultGridBagConstraints;
55
import org.openconcerto.ui.DefaultGridBagConstraints;
56
import org.openconcerto.ui.FrameUtil;
56
import org.openconcerto.ui.FrameUtil;
-
 
57
import org.openconcerto.ui.component.MutableListComboPopupListener;
57
import org.openconcerto.utils.ExceptionHandler;
58
import org.openconcerto.utils.ExceptionHandler;
58
import org.openconcerto.utils.JImage;
59
import org.openconcerto.utils.JImage;
59
import org.openconcerto.utils.cc.IClosure;
60
import org.openconcerto.utils.cc.IClosure;
60
import org.openconcerto.utils.i18n.TranslationManager;
61
import org.openconcerto.utils.i18n.TranslationManager;
61
 
62
 
62
import java.awt.Color;
63
import java.awt.Color;
63
import java.awt.GridBagConstraints;
64
import java.awt.GridBagConstraints;
64
import java.awt.GridBagLayout;
65
import java.awt.GridBagLayout;
65
import java.awt.Image;
66
import java.awt.Image;
66
import java.awt.Insets;
67
import java.awt.Insets;
67
import java.io.InputStream;
68
import java.io.InputStream;
68
import java.sql.SQLException;
-
 
69
import java.util.ArrayList;
69
import java.util.ArrayList;
70
import java.util.Arrays;
70
import java.util.Arrays;
71
import java.util.List;
71
import java.util.List;
72
import java.util.Locale;
72
import java.util.Locale;
73
import java.util.concurrent.CountDownLatch;
73
import java.util.concurrent.CountDownLatch;
74
import java.util.concurrent.FutureTask;
74
import java.util.concurrent.FutureTask;
75
import java.util.logging.Level;
75
import java.util.logging.Level;
76
 
76
 
77
import javax.swing.Action;
77
import javax.swing.Action;
78
import javax.swing.JFrame;
78
import javax.swing.JFrame;
79
import javax.swing.JOptionPane;
79
import javax.swing.JOptionPane;
80
import javax.swing.JPanel;
80
import javax.swing.JPanel;
81
import javax.swing.JTextArea;
81
import javax.swing.JTextArea;
82
import javax.swing.SwingUtilities;
82
import javax.swing.SwingUtilities;
83
import javax.swing.SwingWorker;
83
import javax.swing.SwingWorker;
84
import javax.swing.UIManager;
84
import javax.swing.UIManager;
85
 
85
 
86
public class NouvelleConnexionAction extends CreateFrameAbstractAction {
86
public class NouvelleConnexionAction extends CreateFrameAbstractAction {
87
    private ConnexionPanel connexionPanel;
87
    private ConnexionPanel connexionPanel;
88
 
88
 
89
    public NouvelleConnexionAction() {
89
    public NouvelleConnexionAction() {
90
        super();
90
        super();
91
        this.putValue(Action.NAME, "Changer d'utilisateur");
91
        this.putValue(Action.NAME, "Changer d'utilisateur");
92
    }
92
    }
93
 
93
 
94
    public JFrame createFrame() {
94
    public JFrame createFrame() {
95
        // needed as done() must come after us
95
        // needed as done() must come after us
96
        assert SwingUtilities.isEventDispatchThread();
96
        assert SwingUtilities.isEventDispatchThread();
97
        final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration.getInstance());
97
        final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration.getInstance());
98
 
98
 
99
        // Vérification de la licence
-
 
100
 
-
 
101
        Runnable r = new Runnable() {
99
        Runnable r = new Runnable() {
102
 
100
 
103
            public void run() {
101
            public void run() {
104
                try {
102
                try {
105
                    TranslationManager.getInstance().addTranslationStreamFromClass(MainFrame.class);
103
                    TranslationManager.getInstance().addTranslationStreamFromClass(MainFrame.class);
106
                    TranslationManager.getInstance().setLocale(UserProps.getInstance().getLocale());
104
                    TranslationManager.getInstance().setLocale(UserProps.getInstance().getLocale());
107
 
105
 
108
                    final Boolean booleanValue = UserProps.getInstance().getBooleanValue("HideTips");
106
                    final Boolean booleanValue = UserProps.getInstance().getBooleanValue("HideTips");
109
                    if (!booleanValue) {
107
                    if (!booleanValue) {
110
                        SwingUtilities.invokeLater(new Runnable() {
108
                        SwingUtilities.invokeLater(new Runnable() {
111
                            @Override
109
                            @Override
112
                            public void run() {
110
                            public void run() {
113
                                ComptaTipsFrame.getFrame(true).setVisible(true);
111
                                ComptaTipsFrame.getFrame(true).setVisible(true);
114
                            }
112
                            }
115
                        });
113
                        });
116
                    }
114
                    }
117
                    int selectedSociete;
115
                    int selectedSociete;
118
                    if (NouvelleConnexionAction.this.connexionPanel != null && !Gestion.isMinimalMode()) {
116
                    if (NouvelleConnexionAction.this.connexionPanel != null && !Gestion.isMinimalMode()) {
119
                        selectedSociete = NouvelleConnexionAction.this.connexionPanel.getSelectedSociete();
117
                        selectedSociete = NouvelleConnexionAction.this.connexionPanel.getSelectedSociete();
120
                    } else {
118
                    } else {
121
                        selectedSociete = UserProps.getInstance().getLastSocieteID();
119
                        selectedSociete = UserProps.getInstance().getLastSocieteID();
122
                        if (selectedSociete < SQLRow.MIN_VALID_ID) {
120
                        if (selectedSociete < SQLRow.MIN_VALID_ID) {
123
                            final SQLElement elem = comptaPropsConfiguration.getDirectory().getElement(comptaPropsConfiguration.getRoot().getTable("SOCIETE_COMMON"));
121
                            final SQLElement elem = comptaPropsConfiguration.getDirectory().getElement(comptaPropsConfiguration.getRoot().getTable("SOCIETE_COMMON"));
124
                            final List<IComboSelectionItem> comboItems = elem.getComboRequest().getComboItems();
122
                            final List<IComboSelectionItem> comboItems = elem.getComboRequest().getComboItems();
125
                            if (comboItems.size() > 0)
123
                            if (comboItems.size() > 0)
126
                                selectedSociete = comboItems.get(0).getId();
124
                                selectedSociete = comboItems.get(0).getId();
127
                            else
125
                            else
128
                                throw new IllegalStateException("No " + elem + " found");
126
                                throw new IllegalStateException("No " + elem + " found");
129
                        }
127
                        }
130
                    }
128
                    }
131
                    comptaPropsConfiguration.setUpSocieteDataBaseConnexion(selectedSociete);
129
                    comptaPropsConfiguration.setUpSocieteDataBaseConnexion(selectedSociete);
132
                    try {
130
                    try {
133
                        // create table if necessary
131
                        // create table if necessary
134
                        SQLPreferences.getPrefTable(comptaPropsConfiguration.getRootSociete());
132
                        SQLPreferences.getPrefTable(comptaPropsConfiguration.getRootSociete());
135
                        SQLPreferences.startMemCached(comptaPropsConfiguration.getRootSociete());
133
                        SQLPreferences.startMemCached(comptaPropsConfiguration.getRootSociete());
136
                    } catch (Exception e) {
134
                    } catch (Exception e) {
137
                        // don't die now, we might not need them
135
                        // don't die now, we might not need them
138
                        ExceptionHandler.handle("Impossible d'accéder aux préférences", e);
136
                        ExceptionHandler.handle("Impossible d'accéder aux préférences", e);
139
                    }
137
                    }
140
                    // needed by openEmergencyModuleManager()
138
                    // needed by openEmergencyModuleManager()
141
                    UserRightsManager.getInstance().addRightForAdmins(new RightTuple(ModuleManager.MODULE_DB_RIGHT, true));
139
                    UserRightsManager.getInstance().addRightForAdmins(new RightTuple(ModuleManager.MODULE_DB_RIGHT, true));
-
 
140
                    UserRightsManager.getInstance().addRightForAdmins(new RightTuple(BackupPanel.RIGHT_CODE, true));
142
                    // finish filling the configuration before going any further, otherwise the
141
                    // finish filling the configuration before going any further, otherwise the
143
                    // SQLElementDirectory is not coherent
142
                    // SQLElementDirectory is not coherent
144
                    ModuleManager.getInstance().setup(comptaPropsConfiguration.getRootSociete(), comptaPropsConfiguration);
143
                    ModuleManager.getInstance().setup(comptaPropsConfiguration.getRootSociete(), comptaPropsConfiguration);
145
                    try {
144
                    try {
146
                        ModuleManager.getInstance().init();
145
                        ModuleManager.getInstance().init();
147
                    } catch (Throwable e) {
146
                    } catch (Throwable e) {
148
                        // not OK to continue without required elements
147
                        // not OK to continue without required elements
149
                        openEmergencyModuleManager("Impossible de configurer les modules requis", e);
148
                        openEmergencyModuleManager("Impossible de configurer les modules requis", e);
150
                        return;
149
                        return;
151
                    }
150
                    }
152
                    MenuManager.setInstance((Gestion.isMinimalMode() ? new MinimalMenuConfiguration() : new DefaultMenuConfiguration()).createMenuAndActions());
151
                    MenuManager.setInstance((Gestion.isMinimalMode() ? new MinimalMenuConfiguration() : new DefaultMenuConfiguration()).createMenuAndActions());
153
 
152
 
154
                    User user = UserManager.getInstance().getCurrentUser();
153
                    final User user = UserManager.getInstance().getCurrentUser();
155
                    // Si l'utilisateur n'est pas superUser ou si il n'a pas de droit d'accéder
154
                    // Si l'utilisateur n'est pas superUser ou si il n'a pas de droit d'accéder
156
                    // à toutes les société
155
                    // à toutes les société
157
                    final int userId = user.getId();
156
                    final int userId = user.getId();
158
                    if (!user.getRights().isSuperUser() && !user.getRights().haveRight("ACCES_ALL_SOCIETE")) {
157
                    if (!user.getRights().isSuperUser() && !user.getRights().haveRight("ACCES_ALL_SOCIETE")) {
159
                        final boolean emptyMeansAllow;
158
                        final boolean emptyMeansAllow;
160
                        {
159
                        {
161
                            emptyMeansAllow = true;
160
                            emptyMeansAllow = true;
162
                        }
161
                        }
163
 
162
 
164
                        final SQLTable tableAcces = comptaPropsConfiguration.getRoot().findTable("ACCES_SOCIETE");
163
                        final SQLTable tableAcces = comptaPropsConfiguration.getRoot().findTable("ACCES_SOCIETE");
165
                        SQLSelect sel = new SQLSelect();
164
                        SQLSelect sel = new SQLSelect();
166
                        sel.addSelectStar(tableAcces);
165
                        sel.addSelectStar(tableAcces);
167
                        sel.setWhere(new Where(tableAcces.getField("ID_USER_COMMON"), "=", userId));
166
                        sel.setWhere(new Where(tableAcces.getField("ID_USER_COMMON"), "=", userId));
168
                        if (!emptyMeansAllow) {
167
                        if (!emptyMeansAllow) {
169
                            sel.andWhere(new Where(tableAcces.getField("ID_SOCIETE_COMMON"), "=", selectedSociete));
168
                            sel.andWhere(new Where(tableAcces.getField("ID_SOCIETE_COMMON"), "=", selectedSociete));
170
                        }
169
                        }
171
 
170
 
172
                        final List<SQLRow> accessRows = SQLRowListRSH.execute(sel);
171
                        final List<SQLRow> accessRows = SQLRowListRSH.execute(sel);
173
                        final boolean accessGranted;
172
                        final boolean accessGranted;
174
                        if (!emptyMeansAllow) {
173
                        if (!emptyMeansAllow) {
175
                            accessGranted = accessRows.size() > 0;
174
                            accessGranted = accessRows.size() > 0;
176
                        } else {
175
                        } else {
177
                            if (accessRows.size() == 0) {
176
                            if (accessRows.size() == 0) {
178
                                accessGranted = true;
177
                                accessGranted = true;
179
                            } else {
178
                            } else {
180
                                boolean tmp = false;
179
                                boolean tmp = false;
181
                                for (final SQLRow r : accessRows) {
180
                                for (final SQLRow r : accessRows) {
182
                                    if (r.getInt("ID_SOCIETE_COMMON") == selectedSociete) {
181
                                    if (r.getInt("ID_SOCIETE_COMMON") == selectedSociete) {
183
                                        tmp = true;
182
                                        tmp = true;
184
                                        break;
183
                                        break;
185
                                    }
184
                                    }
186
                                }
185
                                }
187
                                accessGranted = tmp;
186
                                accessGranted = tmp;
188
                            }
187
                            }
189
                        }
188
                        }
190
 
189
 
191
                        if (!accessGranted) {
190
                        if (!accessGranted) {
192
                            JOptionPane.showMessageDialog(null, "Vous n'avez pas les droits suffisants, pour accéder à cette société!");
191
                            JOptionPane.showMessageDialog(null, "Vous n'avez pas les droits suffisants, pour accéder à cette société!");
193
                            return;
192
                            return;
194
                        }
193
                        }
195
                    }
194
                    }
196
 
195
 
197
                    SwingUtilities.invokeLater(new Runnable() {
196
                    SwingUtilities.invokeLater(new Runnable() {
198
                        @Override
197
                        @Override
199
                        public void run() {
198
                        public void run() {
200
                            // even for quick login, check the license before displaying the main
199
                            // even for quick login, check the license before displaying the main
201
                            // frame
200
                            // frame
202
 
201
 
-
 
202
                            MutableListComboPopupListener.setLockOverridable(user.getRights().isSuperUser());
-
 
203
 
203
                            StatusPanel.getInstance().fireStatusChanged();
204
                            StatusPanel.getInstance().fireStatusChanged();
204
                            final MainFrame f = new MainFrame();
205
                            final MainFrame f = new MainFrame();
205
                            String version = comptaPropsConfiguration.getVersion();
206
                            String version = comptaPropsConfiguration.getVersion();
206
                            final String socTitle = comptaPropsConfiguration.getRowSociete() == null ? "" : ", [Société " + comptaPropsConfiguration.getRowSociete().getString("NOM") + "]";
207
                            final String socTitle = comptaPropsConfiguration.getRowSociete() == null ? "" : ", [Société " + comptaPropsConfiguration.getRowSociete().getString("NOM") + "]";
207
                            f.setTitle(comptaPropsConfiguration.getAppName() + " " + version + socTitle);
208
                            f.setTitle(comptaPropsConfiguration.getAppName() + " " + version + socTitle);
208
                            f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
209
                            f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
209
                        }
210
                        }
210
                    });
211
                    });
211
                    final FutureTask<?> showMainFrame = new FutureTask<Object>(new Runnable() {
212
                    final FutureTask<?> showMainFrame = new FutureTask<Object>(new Runnable() {
212
                        @Override
213
                        @Override
213
                        public void run() {
214
                        public void run() {
214
                            // make sure the application is started with all required and mandatory
215
                            // make sure the application is started with all required and mandatory
215
                            // modules
216
                            // modules
216
                            if (ModuleManager.getInstance().isInited()) {
217
                            if (ModuleManager.getInstance().isInited()) {
217
                                final MainFrame mainFrame = MainFrame.getInstance();
218
                                final MainFrame mainFrame = MainFrame.getInstance();
218
                                mainFrame.initMenuBar();
219
                                mainFrame.initMenuBar();
219
                                FrameUtil.show(mainFrame);
220
                                FrameUtil.show(mainFrame);
220
                            }
221
                            }
221
                        }
222
                        }
222
                    }, null);
223
                    }, null);
223
                    ModuleManager.getInstance().invoke(new IClosure<ModuleManager>() {
224
                    ModuleManager.getInstance().invoke(new IClosure<ModuleManager>() {
224
                        @Override
225
                        @Override
225
                        public void executeChecked(ModuleManager input) {
226
                        public void executeChecked(ModuleManager input) {
226
                            // start modules before displaying the frame (e.g. avoid modifying a
227
                            // start modules before displaying the frame (e.g. avoid modifying a
227
                            // visible menu bar)
228
                            // visible menu bar)
228
                            try {
229
                            try {
229
                                input.startRequiredModules();
230
                                input.startRequiredModules();
230
                                try {
231
                                try {
231
                                    input.startPreviouslyRunningModules();
232
                                    input.startPreviouslyRunningModules();
232
                                } catch (Exception exn) {
233
                                } catch (Exception exn) {
233
                                    // OK to start the application without all modules started
234
                                    // OK to start the application without all modules started
234
                                    // but don't continue right away otherwise connexion panel will
235
                                    // but don't continue right away otherwise connexion panel will
235
                                    // be closed and the popup with it
236
                                    // be closed and the popup with it
236
                                    try {
237
                                    try {
237
                                        ExceptionHandler.handle(NouvelleConnexionAction.this.connexionPanel, "Impossible de démarrer les modules", exn).getDialogFuture().get();
238
                                        ExceptionHandler.handle(NouvelleConnexionAction.this.connexionPanel, "Impossible de démarrer les modules", exn).getDialogFuture().get();
238
                                    } catch (Exception e) {
239
                                    } catch (Exception e) {
239
                                        e.printStackTrace();
240
                                        e.printStackTrace();
240
                                    }
241
                                    }
241
                                }
242
                                }
242
                                SwingUtilities.invokeLater(showMainFrame);
243
                                SwingUtilities.invokeLater(showMainFrame);
243
                            } catch (Exception exn) {
244
                            } catch (Exception exn) {
244
                                openEmergencyModuleManager("Impossible de démarrer les modules requis", exn);
245
                                openEmergencyModuleManager("Impossible de démarrer les modules requis", exn);
245
                            }
246
                            }
246
                        }
247
                        }
247
                    });
248
                    });
248
                    initCache(comptaPropsConfiguration);
249
                    initCache(comptaPropsConfiguration);
249
                    // don't close ConnexionPanel until the main frame is shown
250
                    // don't close ConnexionPanel until the main frame is shown
250
                    showMainFrame.get();
251
                    showMainFrame.get();
251
                } catch (Throwable e) {
252
                } catch (Throwable e) {
252
                    ExceptionHandler.handle("Erreur de connexion", e);
253
                    if (e.getMessage() != null && e.getMessage().contains("TR_BON_DE_LIVRAISON not found")) {
-
 
254
                        JOptionPane.showMessageDialog(new JFrame(), "Votre base de données n'est pas à jour.\nUtilisez l'outil de configuration et pensez à l'achat du manuel!!!");
253
                }
255
                        return;
254
            }
256
                    }
255
 
-
 
256
            private void fixEcriture() {
-
 
257
                // FIXME Bug archive ecriture (ecriture non archivé ayant un id_mouvement=1)
-
 
258
                SQLElement elt = Configuration.getInstance().getDirectory().getElement("ECRITURE");
-
 
259
                SQLSelect sel = new SQLSelect();
-
 
260
                sel.addSelect(elt.getTable().getKey());
-
 
261
 
-
 
262
                Where w = new Where(elt.getTable().getField("ID_MOUVEMENT"), "=", 1);
-
 
263
                sel.setWhere(w);
-
 
264
                System.err.println(sel.asString());
-
 
265
                List<SQLRow> lerrors = (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), new SQLRowListRSH(elt.getTable()));
-
 
266
                for (SQLRow row : lerrors) {
-
 
267
                    System.err.println("FIX ERROR ID_MOUVEMENT ON ECRITURE ROW " + row.getID());
-
 
268
                    SQLRowValues rowVals = row.createEmptyUpdateRow();
257
                    ExceptionHandler.handle("Erreur de connexion", e);
269
                    rowVals.put("ARCHIVE", 1);
-
 
270
                    try {
-
 
271
                        rowVals.update();
-
 
272
                    } catch (SQLException e) {
-
 
273
                        // TODO Auto-generated catch block
-
 
274
                        e.printStackTrace();
-
 
275
                    }
258
                }
276
 
-
 
277
                }
259
            }
278
 
260
 
279
                if (lerrors.size() > 0) {
-
 
280
                    System.err.println(lerrors.size() + " erreurs");
-
 
281
                    Thread.dumpStack();
-
 
282
                    // JOptionPane.showMessageDialog(null, lerrors.size() +
-
 
283
                    // " erreurs ont été trouvé et corrigé dans la base.");
-
 
284
                }
-
 
285
            }
-
 
286
        };
261
        };
287
 
262
 
288
        final JImage image = new JImage(ComptaBasePropsConfiguration.class.getResource("logo.png"));
263
        final JImage image = new JImage(ComptaBasePropsConfiguration.class.getResource("logo.png"));
289
        Image customImage = ComptaPropsConfiguration.getInstanceCompta().getCustomLogo();
264
        Image customImage = ComptaPropsConfiguration.getInstanceCompta().getCustomLogo();
290
        if (customImage != null) {
265
        if (customImage != null) {
291
            image.setImage(customImage);
266
            image.setImage(customImage);
292
        }
267
        }
293
        image.setBackground(Color.WHITE);
268
        image.setBackground(Color.WHITE);
294
        JPanel p = new JPanel();
269
        JPanel p = new JPanel();
295
 
270
 
296
        p.setLayout(new GridBagLayout());
271
        p.setLayout(new GridBagLayout());
297
        GridBagConstraints c = new DefaultGridBagConstraints();
272
        GridBagConstraints c = new DefaultGridBagConstraints();
298
        c.weightx = 1;
273
        c.weightx = 1;
299
        c.weighty = 1;
274
        c.weighty = 1;
300
        c.insets = new Insets(0, 0, 0, 0);
275
        c.insets = new Insets(0, 0, 0, 0);
301
        c.fill = GridBagConstraints.BOTH;
276
        c.fill = GridBagConstraints.BOTH;
302
 
277
 
303
        this.connexionPanel = ConnexionPanel.create(r, image, !Gestion.isMinimalMode());
278
        this.connexionPanel = ConnexionPanel.create(r, image, !Gestion.isMinimalMode());
304
        if (this.connexionPanel == null)
279
        if (this.connexionPanel == null)
305
            return null;
280
            return null;
306
        this.connexionPanel.initLocalization(getClass().getName(),
281
        this.connexionPanel.initLocalization(getClass().getName(),
307
                Arrays.asList(Locale.FRANCE, Locale.CANADA_FRENCH, new Locale("fr", "CH"), new Locale("fr", "BE"), Locale.UK, Locale.CANADA, Locale.US, Locale.GERMANY, new Locale("de", "CH")));
282
                Arrays.asList(Locale.FRANCE, Locale.CANADA_FRENCH, new Locale("fr", "CH"), new Locale("fr", "BE"), Locale.UK, Locale.CANADA, Locale.US, Locale.GERMANY, new Locale("de", "CH")));
308
 
283
 
309
        p.add(this.connexionPanel, c);
284
        p.add(this.connexionPanel, c);
310
        final PanelFrame panelFrame = new PanelFrame(p, "Connexion");
285
        final PanelFrame panelFrame = new PanelFrame(p, "Connexion");
311
        panelFrame.setLocationRelativeTo(null);
286
        panelFrame.setLocationRelativeTo(null);
312
        panelFrame.pack();
287
        panelFrame.pack();
313
        panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
288
        panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
314
        return panelFrame;
289
        return panelFrame;
315
    }
290
    }
316
 
291
 
317
    private void initCache(final ComptaPropsConfiguration comptaConf) {
292
    private void initCache(final ComptaPropsConfiguration comptaConf) {
318
        final SQLBase baseSociete = comptaConf.getSQLBaseSociete();
293
        final SQLBase baseSociete = comptaConf.getSQLBaseSociete();
319
        Thread t = new Thread() {
294
        Thread t = new Thread() {
320
            @Override
295
            @Override
321
            public void run() {
296
            public void run() {
322
                // laisse le temps au logiciel de demarrer
297
                // laisse le temps au logiciel de demarrer
323
                try {
298
                try {
324
                    Thread.sleep(1000);
299
                    Thread.sleep(1000);
325
                } catch (InterruptedException e) {
300
                } catch (InterruptedException e) {
326
                    e.printStackTrace();
301
                    e.printStackTrace();
327
                }
302
                }
328
                ClasseCompte.loadClasseCompte();
303
                ClasseCompte.loadClasseCompte();
329
                CaisseCotisationSQLElement.getCaisseCotisation();
304
                CaisseCotisationSQLElement.getCaisseCotisation();
330
 
305
 
331
                Ville.init(new NXDatabaseAccessor());
306
                Ville.init(new NXDatabaseAccessor());
332
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("TAXE"), 600);
307
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("TAXE"), 600);
333
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("PREFS_COMPTE"), 600);
308
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("PREFS_COMPTE"), 600);
334
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("COMPTE_PCE"), 600);
309
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("COMPTE_PCE"), 600);
335
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("JOURNAL"), 600);
310
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("JOURNAL"), 600);
336
 
311
 
337
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("COMMERCIAL"), 600);
312
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("COMMERCIAL"), 600);
338
 
313
 
339
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("TYPE_REGLEMENT"), 1000);
314
                SQLBackgroundTableCache.getInstance().add(baseSociete.getTable("TYPE_REGLEMENT"), 1000);
340
                SQLBackgroundTableCache.getInstance().startCacheWatcher();
315
                SQLBackgroundTableCache.getInstance().startCacheWatcher();
341
 
316
 
342
                TaxeCache.getCache();
317
                TaxeCache.getCache();
343
 
318
 
344
                final UndefinedRowValuesCache undefCache = UndefinedRowValuesCache.getInstance();
319
                final UndefinedRowValuesCache undefCache = UndefinedRowValuesCache.getInstance();
345
                final List<SQLTable> tablesToCache = new ArrayList<SQLTable>();
320
                final List<SQLTable> tablesToCache = new ArrayList<SQLTable>();
346
                tablesToCache.add(baseSociete.getTable("DEVIS"));
321
                tablesToCache.add(baseSociete.getTable("DEVIS"));
347
                tablesToCache.add(baseSociete.getTable("ETAT_DEVIS"));
322
                tablesToCache.add(baseSociete.getTable("ETAT_DEVIS"));
348
                tablesToCache.add(baseSociete.getTable("FAMILLE_ARTICLE"));
323
                tablesToCache.add(baseSociete.getTable("FAMILLE_ARTICLE"));
349
                tablesToCache.add(baseSociete.getTable("ADRESSE"));
324
                tablesToCache.add(baseSociete.getTable("ADRESSE"));
350
                tablesToCache.add(baseSociete.getTable("DEVIS_ELEMENT"));
325
                tablesToCache.add(baseSociete.getTable("DEVIS_ELEMENT"));
351
                tablesToCache.add(baseSociete.getTable("CONTACT"));
326
                tablesToCache.add(baseSociete.getTable("CONTACT"));
352
                tablesToCache.add(baseSociete.getTable("SAISIE_VENTE_FACTURE_ELEMENT"));
327
                tablesToCache.add(baseSociete.getTable("SAISIE_VENTE_FACTURE_ELEMENT"));
353
                tablesToCache.add(baseSociete.getTable("SAISIE_KM_ELEMENT"));
328
                tablesToCache.add(baseSociete.getTable("SAISIE_KM_ELEMENT"));
354
                tablesToCache.add(baseSociete.getTable("BON_DE_LIVRAISON_ELEMENT"));
329
                tablesToCache.add(baseSociete.getTable("BON_DE_LIVRAISON_ELEMENT"));
355
                tablesToCache.add(baseSociete.getTable("COMMANDE_CLIENT_ELEMENT"));
330
                tablesToCache.add(baseSociete.getTable("COMMANDE_CLIENT_ELEMENT"));
356
                tablesToCache.add(baseSociete.getTable("AVOIR_CLIENT_ELEMENT"));
331
                tablesToCache.add(baseSociete.getTable("AVOIR_CLIENT_ELEMENT"));
357
                tablesToCache.add(baseSociete.getTable("BON_RECEPTION_ELEMENT"));
332
                tablesToCache.add(baseSociete.getTable("BON_RECEPTION_ELEMENT"));
358
                undefCache.preload(tablesToCache);
333
                undefCache.preload(tablesToCache);
359
            }
334
            }
360
 
335
 
361
        };
336
        };
362
        t.setName("Cache preload");
337
        t.setName("Cache preload");
363
        t.setDaemon(true);
338
        t.setDaemon(true);
364
        t.setPriority(Thread.MIN_PRIORITY);
339
        t.setPriority(Thread.MIN_PRIORITY);
365
        t.start();
340
        t.start();
366
    }
341
    }
367
 
342
 
368
    private String checkLicense(final SwingWorker<String, Object> w) {
343
    private String checkLicense(final SwingWorker<String, Object> w) {
369
        try {
344
        try {
370
            return w.get();
345
            return w.get();
371
        } catch (Exception e) {
346
        } catch (Exception e) {
372
            throw ExceptionHandler.die("Impossible de charger la licence.", e);
347
            throw ExceptionHandler.die("Impossible de charger la licence.", e);
373
        }
348
        }
374
    }
349
    }
375
 
350
 
376
    private void openEmergencyModuleManager(final String str, final Throwable e) {
351
    private void openEmergencyModuleManager(final String str, final Throwable e) {
377
        Log.get().log(Level.SEVERE, "Normal startup impossible, opening the module manager in order to resolve the issue.", e);
352
        Log.get().log(Level.SEVERE, "Normal startup impossible, opening the module manager in order to resolve the issue.", e);
378
        SwingUtilities.invokeLater(new Runnable() {
353
        SwingUtilities.invokeLater(new Runnable() {
379
            @Override
354
            @Override
380
            public void run() {
355
            public void run() {
381
                ExceptionHandler.handle(str, e);
356
                ExceptionHandler.handle(str, e);
382
                // can't start since there's no main frame (and obviously no modules can be stopped
357
                // can't start since there's no main frame (and obviously no modules can be stopped
383
                // since none are running)
358
                // since none are running)
384
                final ModuleFrame fMod = ModuleFrame.createInstallOnlyInstance();
359
                final ModuleFrame fMod = ModuleFrame.createInstallOnlyInstance();
385
                fMod.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
360
                fMod.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
386
                fMod.setTitle(str);
361
                fMod.setTitle(str);
387
                FrameUtil.show(fMod);
362
                FrameUtil.show(fMod);
388
            }
363
            }
389
        });
364
        });
390
    }
365
    }
391
}
366
}