OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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");
90 ilm 43
    private final JCheckBox checkAbo = new JCheckBox("Créer l'abonnement associé");
21 ilm 44
 
45
    public PanelOOSQLComponent(final BaseSQLComponent comp) {
46
        super(new GridBagLayout());
47
        GridBagConstraints c = new DefaultGridBagConstraints();
48
        c.gridx = GridBagConstraints.RELATIVE;
49
        this.setOpaque(false);
90 ilm 50
 
51
        final SQLTable tableComp = comp.getElement().getTable();
52
        if (tableComp.getName().equals("SAISIE_VENTE_FACTURE") && tableComp.getDBRoot().contains("ABONNEMENT")) {
132 ilm 53
            this.checkAbo.setOpaque(false);
90 ilm 54
            this.add(this.checkAbo, c);
55
        }
56
 
67 ilm 57
        SQLPreferences prefs = SQLPreferences.getMemCached(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete());
61 ilm 58
        if (prefs.getBoolean(GenerationDocGlobalPreferencePanel.MULTIMOD, false)) {
21 ilm 59
 
90 ilm 60
            if (tableComp.getFieldsName().contains("ID_MODELE")) {
61 ilm 61
                String labelFor = comp.getLabelFor("ID_MODELE");
62
                if (labelFor == null || labelFor.trim().length() == 0) {
63
                    labelFor = "Modéles";
64
                }
65
                JLabel labelModele = new JLabel(labelFor);
66
                ElementComboBox boxModele = new ElementComboBox(true, 25);
67
                SQLElement modeleElement = Configuration.getInstance().getDirectory().getElement("MODELE");
68
                boxModele.init(modeleElement, modeleElement.getComboRequest(true));
21 ilm 69
                comp.addView(boxModele, "ID_MODELE");
70
                boxModele.getRequest().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
71
 
72
                    @Override
73
                    public SQLSelect transformChecked(SQLSelect input) {
74
                        SQLTable table = Configuration.getInstance().getDirectory().getElement("TYPE_MODELE").getTable();
90 ilm 75
                        Where w = new Where(input.getAlias(table.getField("TABLE")), "=", tableComp.getName());
21 ilm 76
                        input.setWhere(w);
77
                        return input;
78
                    }
79
                });
80
                this.add(labelModele, c);
61 ilm 81
                DefaultGridBagConstraints.lockMinimumSize(boxModele);
21 ilm 82
                this.add(boxModele, c);
83
            } else {
90 ilm 84
                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 " + tableComp.getName());
21 ilm 85
                Thread.dumpStack();
86
            }
87
        }
132 ilm 88
        this.checkImpression.setOpaque(false);
89
        this.checkVisu.setOpaque(false);
21 ilm 90
        this.add(this.checkImpression, c);
91
        this.add(this.checkVisu, c);
92
    }
93
 
90 ilm 94
    public JCheckBox getCheckAbo() {
95
        return checkAbo;
96
    }
97
 
21 ilm 98
    public boolean isVisualisationSelected() {
99
        return this.checkVisu.isSelected();
100
    }
101
 
102
    public boolean isImpressionSelected() {
103
        return this.checkImpression.isSelected();
104
    }
105
 
90 ilm 106
    public boolean isCheckAboSelected() {
107
        return this.checkAbo.isSelected();
108
    }
109
 
21 ilm 110
}