OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 63 | Rev 90 | 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);
67 ilm 49
        SQLPreferences prefs = SQLPreferences.getMemCached(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete());
61 ilm 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();
63 ilm 67
                        Where w = new Where(input.getAlias(table.getField("TABLE")), "=", comp.getElement().getTable().getName());
21 ilm 68
                        input.setWhere(w);
69
                        return input;
70
                    }
71
                });
72
                this.add(labelModele, c);
61 ilm 73
                DefaultGridBagConstraints.lockMinimumSize(boxModele);
21 ilm 74
                this.add(boxModele, c);
75
            } else {
76
                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());
77
                Thread.dumpStack();
78
            }
79
        }
80
        this.add(this.checkImpression, c);
81
        this.add(this.checkVisu, c);
82
    }
83
 
84
    public boolean isVisualisationSelected() {
85
        return this.checkVisu.isSelected();
86
    }
87
 
88
    public boolean isImpressionSelected() {
89
        return this.checkImpression.isSelected();
90
    }
91
 
92
}