OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 21 | Rev 63 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21 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
 /*
15
 * Créé le 11 oct. 2011
16
 */
17
package org.openconcerto.erp.panel;
18
 
61 ilm 19
import org.openconcerto.erp.config.ComptaPropsConfiguration;
20
import org.openconcerto.erp.preferences.GenerationDocGlobalPreferencePanel;
21 ilm 21
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.element.BaseSQLComponent;
61 ilm 23
import org.openconcerto.sql.element.SQLElement;
21 ilm 24
import org.openconcerto.sql.model.SQLSelect;
25
import org.openconcerto.sql.model.SQLTable;
26
import org.openconcerto.sql.model.Where;
61 ilm 27
import org.openconcerto.sql.preferences.SQLPreferences;
21 ilm 28
import org.openconcerto.sql.sqlobject.ElementComboBox;
29
import org.openconcerto.ui.DefaultGridBagConstraints;
30
import org.openconcerto.utils.cc.ITransformer;
31
 
32
import java.awt.GridBagConstraints;
33
import java.awt.GridBagLayout;
34
 
35
import javax.swing.JCheckBox;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38
 
39
public class PanelOOSQLComponent extends JPanel {
40
 
41
    private final JCheckBox checkImpression = new JCheckBox("Imprimer");
42
    private final JCheckBox checkVisu = new JCheckBox("Visualiser");
43
 
44
    public PanelOOSQLComponent(final BaseSQLComponent comp) {
45
        super(new GridBagLayout());
46
        GridBagConstraints c = new DefaultGridBagConstraints();
47
        c.gridx = GridBagConstraints.RELATIVE;
48
        this.setOpaque(false);
61 ilm 49
        SQLPreferences prefs = new SQLPreferences(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete());
50
        if (prefs.getBoolean(GenerationDocGlobalPreferencePanel.MULTIMOD, false)) {
21 ilm 51
 
52
            if (comp.getElement().getTable().getFieldsName().contains("ID_MODELE")) {
61 ilm 53
                String labelFor = comp.getLabelFor("ID_MODELE");
54
                if (labelFor == null || labelFor.trim().length() == 0) {
55
                    labelFor = "Modéles";
56
                }
57
                JLabel labelModele = new JLabel(labelFor);
58
                ElementComboBox boxModele = new ElementComboBox(true, 25);
59
                SQLElement modeleElement = Configuration.getInstance().getDirectory().getElement("MODELE");
60
                boxModele.init(modeleElement, modeleElement.getComboRequest(true));
21 ilm 61
                comp.addView(boxModele, "ID_MODELE");
62
                boxModele.getRequest().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
63
 
64
                    @Override
65
                    public SQLSelect transformChecked(SQLSelect input) {
66
                        SQLTable table = Configuration.getInstance().getDirectory().getElement("TYPE_MODELE").getTable();
67
                        Where w = new Where(table.getField("TABLE"), "=", comp.getElement().getTable().getName());
68
                        input.setWhere(w);
69
                        System.err.println(input.asString());
70
                        return input;
71
                    }
72
                });
73
                this.add(labelModele, c);
61 ilm 74
                DefaultGridBagConstraints.lockMinimumSize(boxModele);
21 ilm 75
                this.add(boxModele, c);
76
            } else {
77
                System.err.println("Impossible d'ajouter la combo pour le choix des modèles car le champ ID_MODELE n'est pas présent dans la table " + comp.getElement().getTable().getName());
78
                Thread.dumpStack();
79
            }
80
        }
81
        this.add(this.checkImpression, c);
82
        this.add(this.checkVisu, c);
83
    }
84
 
85
    public boolean isVisualisationSelected() {
86
        return this.checkVisu.isSelected();
87
    }
88
 
89
    public boolean isImpressionSelected() {
90
        return this.checkImpression.isSelected();
91
    }
92
 
93
}