OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Rev 90 | 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.core.reports.history.ui;
15
 
16
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer;
17
import org.openconcerto.erp.core.common.ui.PanelFrame;
18
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
19
import org.openconcerto.erp.core.finance.accounting.ui.ListeGestCommEltPanel;
20
import org.openconcerto.erp.core.finance.accounting.ui.SuppressionEcrituresPanel;
21
import org.openconcerto.erp.core.sales.invoice.report.VenteFactureElementXmlSheet;
22
import org.openconcerto.erp.core.sales.quote.ui.EtatDevisRenderer;
23
import org.openconcerto.erp.generationDoc.AbstractSheetXml;
24
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
25
import org.openconcerto.sql.Configuration;
26
import org.openconcerto.sql.element.SQLElement;
27
import org.openconcerto.sql.element.SQLElementDirectory;
80 ilm 28
import org.openconcerto.sql.model.SQLDataSource;
18 ilm 29
import org.openconcerto.sql.model.SQLField;
30
import org.openconcerto.sql.model.SQLRow;
31
import org.openconcerto.sql.model.SQLRowAccessor;
41 ilm 32
import org.openconcerto.sql.model.SQLRowValues;
18 ilm 33
import org.openconcerto.sql.model.SQLTable;
34
import org.openconcerto.sql.model.Where;
65 ilm 35
import org.openconcerto.sql.request.ComboSQLRequest;
67 ilm 36
import org.openconcerto.sql.request.ListSQLRequest;
18 ilm 37
import org.openconcerto.sql.users.rights.JListSQLTablePanel;
38
import org.openconcerto.sql.view.IListPanel;
39
import org.openconcerto.sql.view.ListeAddPanel;
40
import org.openconcerto.sql.view.list.IListe;
41
import org.openconcerto.sql.view.list.ITableModel;
65 ilm 42
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
18 ilm 43
import org.openconcerto.ui.DefaultGridBagConstraints;
41 ilm 44
import org.openconcerto.ui.FrameUtil;
18 ilm 45
 
28 ilm 46
import java.awt.Color;
47
import java.awt.Font;
18 ilm 48
import java.awt.GridBagConstraints;
49
import java.awt.GridBagLayout;
50
import java.awt.Insets;
51
import java.awt.event.ActionEvent;
52
import java.awt.event.ActionListener;
53
import java.math.BigInteger;
54
import java.util.ArrayList;
55
import java.util.Collections;
56
import java.util.HashMap;
57
import java.util.List;
58
import java.util.Map;
80 ilm 59
import java.util.Random;
41 ilm 60
import java.util.Set;
18 ilm 61
import java.util.Vector;
62
 
63
import javax.swing.BorderFactory;
64
import javax.swing.JButton;
65
import javax.swing.JFrame;
80 ilm 66
import javax.swing.JOptionPane;
18 ilm 67
import javax.swing.JPanel;
68
import javax.swing.JSplitPane;
69
import javax.swing.JTabbedPane;
70
import javax.swing.JTable;
71
import javax.swing.SwingUtilities;
28 ilm 72
import javax.swing.UIManager;
73
import javax.swing.border.Border;
74
import javax.swing.border.TitledBorder;
18 ilm 75
import javax.swing.event.AncestorEvent;
76
import javax.swing.event.AncestorListener;
77
import javax.swing.event.ListSelectionEvent;
78
import javax.swing.event.ListSelectionListener;
79
import javax.swing.event.TableModelListener;
80
import javax.swing.table.TableCellRenderer;
41 ilm 81
import javax.swing.table.TableModel;
18 ilm 82
 
83
public class ListeHistoriquePanel extends JPanel {
84
 
85
    private final Vector<IListPanel> vectListePanel = new Vector<IListPanel>();
86
    private Map<Integer, List<TableModelListener>> mapListener = new HashMap<Integer, List<TableModelListener>>();
87
    private JListSQLTablePanel jListePanel;
88
 
89
    private Map<SQLTable, SQLField> listFieldMap = new HashMap<SQLTable, SQLField>();
90
    private Map<String, Where> whereList = new HashMap<String, Where>();
91
    private static Map<SQLElement, Class<? extends AbstractSheetXml>> elementSheet = new HashMap<SQLElement, Class<? extends AbstractSheetXml>>();
61 ilm 92
    private String undefinedLabel;
18 ilm 93
 
94
    static {
95
        SQLElementDirectory dir = Configuration.getInstance().getDirectory();
96
        elementSheet.put(dir.getElement("SAISIE_VENTE_FACTURE_ELEMENT"), VenteFactureElementXmlSheet.class);
97
    }
98
 
99
    // Filtre à partir de la JList sur les IListe
100
    private final ListSelectionListener listListener = new ListSelectionListener() {
101
 
102
        public void valueChanged(ListSelectionEvent e) {
67 ilm 103
            if (e != null && e.getValueIsAdjusting()) {
104
                return;
105
            }
18 ilm 106
            int selectIndex = ListeHistoriquePanel.this.jListePanel.getSelectedIndex();
107
 
108
            SQLRowAccessor row = ListeHistoriquePanel.this.jListePanel.getModel().getRowAt(selectIndex);
61 ilm 109
 
110
            if ((row == null || row.isUndefined()) && undefinedLabel == null) {
111
                return;
112
            }
113
 
19 ilm 114
            int id = SQLRow.NONEXISTANT_ID;
18 ilm 115
            if (row != null) {
116
                id = row.getID();
117
            }
118
 
119
            for (int i = 0; i < ListeHistoriquePanel.this.vectListePanel.size(); i++) {
120
                IListPanel liste = ListeHistoriquePanel.this.vectListePanel.get(i);
121
 
122
                // remove listener
123
                if (ListeHistoriquePanel.this.mapListener.get(i) != null) {
124
                    List<TableModelListener> l = ListeHistoriquePanel.this.mapListener.get(i);
125
                    for (TableModelListener listener : l) {
126
                        liste.getListe().getTableModel().removeTableModelListener(listener);
127
                    }
128
                }
129
 
130
                Where w = null;
131
                final SQLTable table = liste.getElement().getTable();
80 ilm 132
                for (String key : ListeHistoriquePanel.this.whereList.keySet()) {
133
                    Where wTmp = ListeHistoriquePanel.this.whereList.get(key);
18 ilm 134
 
80 ilm 135
                    if (liste.getListe().getRequest().getAllFields().containsAll(wTmp.getFields())) {
136
                        if (w == null) {
137
                            w = wTmp;
138
                        } else {
139
                            w = w.and(wTmp);
140
                        }
141
                    }
142
                }
143
 
18 ilm 144
                if (id > 1) {
145
                    if (ListeHistoriquePanel.this.listFieldMap != null && ListeHistoriquePanel.this.listFieldMap.get(table) != null) {
146
                        SQLField field = ListeHistoriquePanel.this.listFieldMap.get(table);
147
                        Where w2 = new Where(field, "=", table.getForeignTable(field.getName()).getKey());
148
                        w2 = w2.and(new Where(table.getForeignTable(field.getName()).getField("ID_" + ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName()), "=", id));
19 ilm 149
                        liste.getListe().getRequest().setWhere(w2.and(w));
18 ilm 150
                    } else {
28 ilm 151
                        if (liste.getElement().getTable().equals(jListePanel.getModel().getTable())) {
152
                            liste.getListe().getRequest().setWhere(new Where(table.getKey(), "=", id).and(w));
153
                        } else {
154
                            liste.getListe().getRequest().setWhere(new Where(table.getField("ID_" + ListeHistoriquePanel.this.jListePanel.getModel().getTable().getName()), "=", id).and(w));
155
                        }
18 ilm 156
                    }
157
                } else {
19 ilm 158
                    liste.getListe().getRequest().setWhere(w);
18 ilm 159
                }
160
                liste.getListe().setSQLEditable(false);
161
                // Set renderer
162
                setRenderer(liste);
163
 
164
                // Set listener
165
                if (ListeHistoriquePanel.this.mapListener.get(i) != null) {
166
                    List<TableModelListener> l = ListeHistoriquePanel.this.mapListener.get(i);
167
                    for (TableModelListener listener : l) {
168
                        liste.getListe().getTableModel().addTableModelListener(listener);
169
                        if (elementSheet.get(liste.getElement()) != null) {
25 ilm 170
                            liste.getListe().addIListeActions(new MouseSheetXmlListeListener(elementSheet.get(liste.getElement())).getRowActions());
18 ilm 171
                        }
172
                    }
173
                }
174
 
175
            }
176
        }
177
    };
178
 
67 ilm 179
    public ListeHistoriquePanel(final String title, final ComboSQLRequest req, Map<String, List<String>> listTableOnglet, JPanel panelBottom, Map<SQLTable, SQLField> listFieldMap, Where where) {
180
        this(title, req, listTableOnglet, panelBottom, listFieldMap, "Tous", where);
61 ilm 181
    }
182
 
65 ilm 183
    public ListeHistoriquePanel(final String title, final ComboSQLRequest req, Map<String, List<String>> listTableOnglet, JPanel panelBottom, Map<SQLTable, SQLField> listFieldMap,
67 ilm 184
            String undefinedLabel, Where where) {
83 ilm 185
        this(title, req, listTableOnglet, panelBottom, listFieldMap, undefinedLabel, false, where, null);
65 ilm 186
    }
187
 
18 ilm 188
    // TODO verifier que les tables contiennent bien la clef etrangere
189
    /**
190
     * @param title titre de la JList
65 ilm 191
     * @param req table à afficher la JListSQLTablePanel
18 ilm 192
     * @param listTableOnglet liste des tables à afficher
193
     * @param panelBottom panel à afficher en bas de la frame
194
     * @param listFieldMap jointure d'une table pour utiliser le filtre si la table ne contient pas
195
     *        de foreignKey pointant sur tableList
61 ilm 196
     * @param undefinedLabel label pour l'indéfini permettant de tout sélectionner, null si
197
     *        l'undefined n'est pas à inclure.
67 ilm 198
     * @param where
18 ilm 199
     */
65 ilm 200
    public ListeHistoriquePanel(final String title, final ComboSQLRequest req, Map<String, List<String>> listTableOnglet, JPanel panelBottom, Map<SQLTable, SQLField> listFieldMap,
83 ilm 201
            String undefinedLabel, final boolean sourceWithOutTransformer, Where where, SQLTableModelSourceOnline tableSource) {
18 ilm 202
        super();
203
        this.setLayout(new GridBagLayout());
204
        GridBagConstraints c = new GridBagConstraints();
205
        c.insets = new Insets(2, 2, 1, 2);
206
        c.anchor = GridBagConstraints.WEST;
207
        c.fill = GridBagConstraints.BOTH;
208
        c.gridheight = 1;
209
        c.gridwidth = 1;
210
        c.gridx = 0;
211
        c.gridy = 0;
212
        c.weightx = 1;
213
        c.weighty = 1;
214
 
215
        this.listFieldMap = listFieldMap;
216
 
217
        // Onglet de IListe
218
        JTabbedPane tabbedPane = new JTabbedPane();
219
 
28 ilm 220
        for (String key : listTableOnglet.keySet()) {
18 ilm 221
 
28 ilm 222
            List<String> listPanelTable = listTableOnglet.get(key);
18 ilm 223
 
28 ilm 224
            JPanel tabbedPanel = new JPanel(new GridBagLayout());
41 ilm 225
            tabbedPanel.setOpaque(false);
28 ilm 226
            GridBagConstraints c2 = new DefaultGridBagConstraints();
227
            c2.fill = GridBagConstraints.BOTH;
228
            c2.weightx = 1;
229
            c2.weighty = 1;
230
            c2.gridy = GridBagConstraints.RELATIVE;
18 ilm 231
 
28 ilm 232
            for (int i = 0; i < listPanelTable.size(); i++) {
233
                final SQLElement elt = Configuration.getInstance().getDirectory().getElement(listPanelTable.get(i));
234
 
235
                IListPanel liste;
83 ilm 236
                final SQLTableModelSourceOnline createTableSource;
237
                if (tableSource == null) {
238
                    createTableSource = elt.getTableSource(true);
239
                } else {
240
                    createTableSource = tableSource;
241
                }
67 ilm 242
                final ListSQLRequest request = createTableSource.getReq();
243
                if (sourceWithOutTransformer) {
244
                    request.setSelectTransf(null);
245
                }
246
                if (where != null) {
247
                    if (request.getAllFields().containsAll(where.getFields())) {
248
                        request.setWhere(where);
249
                    }
250
                }
28 ilm 251
 
252
                if (elt.getTable().contains("ID_MOUVEMENT")) {
67 ilm 253
 
254
                    liste = new ListeGestCommEltPanel(elt, new IListe(createTableSource), "historique-" + title) {
255
 
28 ilm 256
                        protected void handleAction(JButton source, ActionEvent evt) {
257
 
258
                            if (elt.getTable().contains("ID_MOUVEMENT")) {
80 ilm 259
                                SQLRow row = getListe().fetchSelectedRow();
28 ilm 260
                                if (source == this.buttonModifier) {
261
                                    MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
18 ilm 262
                                } else {
28 ilm 263
                                    if (source == this.buttonEffacer) {
264
                                        PanelFrame f = new PanelFrame(new SuppressionEcrituresPanel(row.getInt("ID_MOUVEMENT")), "Suppresion d'une pièce");
265
                                        f.setLocationRelativeTo(null);
266
                                        f.setResizable(false);
267
                                        f.setVisible(true);
268
                                    } else {
269
                                        super.handleAction(source, evt);
270
                                    }
18 ilm 271
                                }
28 ilm 272
                            } else {
273
                                super.handleAction(source, evt);
18 ilm 274
                            }
275
                        }
28 ilm 276
                    };
18 ilm 277
 
28 ilm 278
                } else {
67 ilm 279
 
65 ilm 280
                    liste = new ListeAddPanel(elt, new IListe(createTableSource), "historique-" + title) {
41 ilm 281
                        @Override
282
                        protected void handleAction(JButton source, ActionEvent evt) {
283
                            if (source == this.buttonAjouter) {
284
                                // toujours remplir la createFrame avec la ligne sélectionnée
285
                                // car la frame écoute la sélection mais pas les modif, et se reset
286
                                // qd on la ferme
287
                                // donc si on clic ajouter, on ferme, on modif la ligne, on clic
288
                                // ajouter
289
                                // on doit reremplir l'EditFrame
290
                                int selectIndex = ListeHistoriquePanel.this.jListePanel.getSelectedIndex();
291
                                SQLRowAccessor row = ListeHistoriquePanel.this.jListePanel.getModel().getRowAt(selectIndex);
292
                                if (row != null && !row.isUndefined()) {
293
                                    SQLTable table = this.getCreateFrame().getSQLComponent().getElement().getTable();
294
                                    Set<SQLField> fields = table.getForeignKeys(ListeHistoriquePanel.this.jListePanel.getModel().getTable());
295
                                    if (fields != null && fields.size() > 0) {
296
                                        SQLRowValues rowVals = new SQLRowValues(table);
297
                                        rowVals.put(((SQLField) fields.toArray()[0]).getName(), row.getID());
298
                                        this.getCreateFrame().getSQLComponent().resetValue();
299
                                        this.getCreateFrame().getSQLComponent().select(rowVals);
300
                                    }
301
                                }
302
                                FrameUtil.show(this.getCreateFrame());
303
                            } else {
304
                                super.handleAction(source, evt);
305
                            }
306
                        }
307
                    };
28 ilm 308
                }
19 ilm 309
 
28 ilm 310
                this.vectListePanel.add(liste);
18 ilm 311
 
28 ilm 312
                setRenderer(liste);
313
                if (elementSheet.get(liste.getElement()) != null) {
314
                    liste.getListe().addIListeActions(new MouseSheetXmlListeListener(elementSheet.get(liste.getElement())).getRowActions());
315
                }
316
                liste.getListe().setSQLEditable(false);
317
                liste.setOpaque(false);
318
                liste.setBorder(null);
67 ilm 319
                liste.getListe().getModel().setHibernateDelay(-1);
28 ilm 320
 
321
                if (listPanelTable.size() > 1) {
322
                    Font f = UIManager.getFont("TitledBorder.font");
323
                    f = f.deriveFont(Font.BOLD);
324
                    Border b = UIManager.getBorder("TitledBorder.border");
325
                    b = BorderFactory.createLineBorder(Color.BLACK);
326
                    liste.setBorder(BorderFactory.createTitledBorder(b, elt.getPluralName(), TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, f));
327
                }
328
 
329
                tabbedPanel.add(liste, c2);
330
 
18 ilm 331
            }
332
 
28 ilm 333
            tabbedPane.add(key, tabbedPanel);
18 ilm 334
        }
335
 
336
        // Left Panel
65 ilm 337
        this.undefinedLabel = undefinedLabel;
338
        this.jListePanel = new JListSQLTablePanel(req, undefinedLabel);
18 ilm 339
 
340
        // Right panel
341
        JPanel rightPanel = new JPanel();
342
        rightPanel.setLayout(new GridBagLayout());
343
        GridBagConstraints cRight = new DefaultGridBagConstraints();
344
        cRight.fill = GridBagConstraints.BOTH;
345
        cRight.weightx = 1;
346
        cRight.weighty = 1;
347
        rightPanel.add(tabbedPane, cRight);
348
 
349
        if (panelBottom != null) {
350
            cRight.fill = GridBagConstraints.HORIZONTAL;
351
            cRight.weightx = 1;
352
            cRight.weighty = 0;
353
            cRight.gridy++;
354
            panelBottom.setBorder(BorderFactory.createTitledBorder("Récapitulatif"));
355
            rightPanel.add(panelBottom, cRight);
356
        }
357
        JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.jListePanel, rightPanel);
358
        split.setBorder(null);
359
        split.setDividerLocation(275);
360
        this.add(split, c);
361
 
362
        JButton buttonClose = new JButton("Fermer");
363
        c.gridy++;
364
        c.weightx = 0;
365
        c.weighty = 0;
366
        c.fill = GridBagConstraints.NONE;
367
        c.anchor = GridBagConstraints.EAST;
368
        this.add(buttonClose, c);
369
 
370
        buttonClose.addActionListener(new ActionListener() {
371
            public void actionPerformed(ActionEvent event) {
372
                ((JFrame) SwingUtilities.getRoot(ListeHistoriquePanel.this)).dispose();
373
            }
374
        });
375
 
376
        this.addAncestorListener(new AncestorListener() {
377
            @Override
378
            public void ancestorAdded(AncestorEvent event) {
80 ilm 379
                jListePanel.addListSelectionListener(listListener);
18 ilm 380
            }
381
 
382
            @Override
383
            public void ancestorMoved(AncestorEvent event) {
19 ilm 384
 
18 ilm 385
            }
386
 
387
            @Override
388
            public void ancestorRemoved(AncestorEvent event) {
389
                jListePanel.removeListSelectionListener(listListener);
390
            }
391
        });
80 ilm 392
 
18 ilm 393
    }
394
 
395
    public void selectIDinJList(int id) {
41 ilm 396
        this.jListePanel.selectID(id);
18 ilm 397
    }
398
 
399
    private void setRenderer(IListPanel liste) {
400
 
19 ilm 401
        SQLElement propositionItemElement = Configuration.getInstance().getDirectory().getElement("PROPOSITION_ELEMENT");
18 ilm 402
        SQLElement devisElement = Configuration.getInstance().getDirectory().getElement("DEVIS");
403
        JTable table = liste.getListe().getJTable();
404
        TableCellRenderer rend = null;
19 ilm 405
        if (liste.getElement().getClass() == devisElement.getClass()) {
18 ilm 406
            rend = new EtatDevisRenderer();
407
        } else {
19 ilm 408
                rend = new DeviseNiceTableCellRenderer();
18 ilm 409
        }
410
        for (int j = 0; j < table.getColumnCount(); j++) {
411
            if (rend instanceof EtatDevisRenderer) {
412
                table.getColumnModel().getColumn(j).setCellRenderer(rend);
413
            } else {
414
                if (table.getColumnClass(j) == Long.class || table.getColumnClass(j) == BigInteger.class) {
415
                    table.getColumnModel().getColumn(j).setCellRenderer(rend);
416
                }
417
            }
418
        }
419
    }
420
 
421
    public void addListSelectionListener(ListSelectionListener l) {
422
        this.jListePanel.addListSelectionListener(l);
67 ilm 423
        System.out.println("ListeHistoriquePanel.addListSelectionListener()" + jListePanel);
18 ilm 424
    }
425
 
426
    public void removeListSelectionListener(ListSelectionListener l) {
427
        this.jListePanel.removeListSelectionListener(l);
428
    }
429
 
430
    public SQLRowAccessor getSelectedRow() {
431
        return this.jListePanel.getModel().getRowAt(this.jListePanel.getSelectedIndex());
432
    }
433
 
434
    public void addWhere(String key, Where w) {
435
        this.whereList.put(key, w);
436
        this.listListener.valueChanged(null);
437
    }
438
 
439
    public void removeWhere(String key) {
440
        this.whereList.remove(key);
441
        this.listListener.valueChanged(null);
442
    }
443
 
444
    public void removeAllWhere() {
445
        for (String key : this.whereList.keySet()) {
446
            this.whereList.remove(key);
447
        }
448
        this.listListener.valueChanged(null);
449
    }
450
 
451
    public Map<String, Where> getWhere() {
452
        return this.whereList;
453
    }
454
 
455
    public List<Integer> getListId(String tableName) {
456
        IListe liste = getIListeFromTableName(tableName);
457
        List<Integer> listeIds = null;
458
        if (liste != null) {
459
            int size = liste.getRowCount();
460
            listeIds = new ArrayList<Integer>(size);
461
            for (int i = 0; i < size; i++) {
462
                listeIds.add(liste.idFromIndex(i));
463
            }
464
        } else {
67 ilm 465
            listeIds = Collections.emptyList();
18 ilm 466
        }
467
        return listeIds;
468
    }
469
 
470
    public void removeAllTableListener() {
41 ilm 471
        this.jListePanel.removeAllTableListener();
18 ilm 472
        for (Integer i : this.mapListener.keySet()) {
473
            IListPanel panel = vectListePanel.get(i);
474
            List<TableModelListener> l = this.mapListener.get(i);
475
            for (TableModelListener tableModelListener : l) {
476
                final IListe liste = panel.getListe();
41 ilm 477
                if (liste != null) {
478
                    final TableModel tableModel = liste.getTableModel();
479
                    if (tableModel != null) {
480
                        tableModel.removeTableModelListener(tableModelListener);
481
                    }
482
                }
18 ilm 483
            }
484
 
485
        }
486
    }
487
 
488
    public void addListenerTable(TableModelListener listener, String tableName) {
489
        IListe liste = getIListeFromTableName(tableName);
490
        int index = getIndexFromTableName(tableName);
491
        if (liste != null) {
492
            liste.getTableModel().addTableModelListener(listener);
493
            List<TableModelListener> l = this.mapListener.get(liste);
494
            if (l == null) {
495
                l = new ArrayList<TableModelListener>();
496
                this.mapListener.put(index, l);
497
            }
498
            l.add(listener);
499
        }
500
    }
501
 
502
    /**
503
     * Permet d'obtenir la IListe correspondant au nom d'une table
504
     *
505
     * @param tableName nom de la table
506
     * @return la Iliste associée, dans le cas échéant null
507
     */
508
 
28 ilm 509
    public IListe getIListeFromTableName(String tableName) {
67 ilm 510
        IListPanel liste = getIListePanelFromTableName(tableName);
511
        if (liste == null) {
512
            return null;
513
        } else {
514
            return liste.getListe();
515
        }
516
    }
517
 
518
    /**
519
     * Permet d'obtenir la IListe correspondant au nom d'une table
520
     *
521
     * @param tableName nom de la table
522
     * @return la Iliste associée, dans le cas échéant null
523
     */
524
 
525
    public IListPanel getIListePanelFromTableName(String tableName) {
526
        IListPanel liste = null;
80 ilm 527
        final int size = this.vectListePanel.size();
528
        for (int i = 0; i < size; i++) {
18 ilm 529
            IListPanel listeTmp = this.vectListePanel.get(i);
530
            // FIXME Null pointer Exception when client deleted
531
            if (listeTmp != null) {
532
                IListe list = listeTmp.getListe();
533
                if (list != null) {
534
                    final ITableModel model = list.getModel();
535
                    if (model != null) {
536
                        if (model.getTable().getName().equalsIgnoreCase(tableName)) {
67 ilm 537
                            liste = listeTmp;
18 ilm 538
                        }
539
                    }
540
                }
541
            }
542
        }
543
        return liste;
544
    }
545
 
546
    /**
547
     * Permet d'obtenir la position dans le vecteur correspondant au nom d'une table
548
     *
549
     * @param tableName nom de la table
550
     * @return -1 si la table n'est pas dans le vecteur
551
     */
552
    private int getIndexFromTableName(String tableName) {
80 ilm 553
        final int size = this.vectListePanel.size();
554
        for (int i = 0; i < size; i++) {
555
            final IListPanel listeTmp = this.vectListePanel.get(i);
556
            final String name = listeTmp.getListe().getModel().getTable().getName();
557
            if (name.equalsIgnoreCase(tableName)) {
18 ilm 558
                return i;
559
            }
560
        }
561
        return -1;
562
    }
563
 
19 ilm 564
    public IListe getListe(int index) {
565
        return this.vectListePanel.get(index).getListe();
566
    }
567
 
18 ilm 568
    public void fireListesChanged() {
67 ilm 569
        final int size = this.vectListePanel.size();
570
        for (int i = 0; i < size; i++) {
571
            final IListPanel listeTmp = this.vectListePanel.get(i);
572
            final ITableModel model = listeTmp.getListe().getModel();
573
            model.fireTableDataChanged();
574
            model.fireTableStructureChanged();
18 ilm 575
        }
576
 
577
    }
67 ilm 578
 
18 ilm 579
}