OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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;
156 ilm 21
import org.openconcerto.erp.utils.TM;
21 ilm 22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.element.BaseSQLComponent;
61 ilm 24
import org.openconcerto.sql.element.SQLElement;
21 ilm 25
import org.openconcerto.sql.model.SQLSelect;
26
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.model.Where;
61 ilm 28
import org.openconcerto.sql.preferences.SQLPreferences;
21 ilm 29
import org.openconcerto.sql.sqlobject.ElementComboBox;
30
import org.openconcerto.ui.DefaultGridBagConstraints;
31
import org.openconcerto.utils.cc.ITransformer;
32
 
33
import java.awt.GridBagConstraints;
34
import java.awt.GridBagLayout;
35
 
36
import javax.swing.JCheckBox;
37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
39
 
40
public class PanelOOSQLComponent extends JPanel {
41
 
156 ilm 42
    private final JCheckBox checkImpression = new JCheckBox(TM.tr("PanelOOSQLComponent.print")); //$NON-NLS-1$
43
    private final JCheckBox checkVisu = new JCheckBox(TM.tr("PanelOOSQLComponent.view")); //$NON-NLS-1$
44
    private final JCheckBox checkAbo = new JCheckBox(TM.tr("PanelOOSQLComponent.createSubscription")); //$NON-NLS-1$
21 ilm 45
 
46
    public PanelOOSQLComponent(final BaseSQLComponent comp) {
47
        super(new GridBagLayout());
48
        GridBagConstraints c = new DefaultGridBagConstraints();
49
        c.gridx = GridBagConstraints.RELATIVE;
50
        this.setOpaque(false);
90 ilm 51
 
52
        final SQLTable tableComp = comp.getElement().getTable();
156 ilm 53
        if (tableComp.getName().equals("SAISIE_VENTE_FACTURE") && tableComp.getDBRoot().contains("ABONNEMENT")) { //$NON-NLS-1$ //$NON-NLS-2$
132 ilm 54
            this.checkAbo.setOpaque(false);
90 ilm 55
            this.add(this.checkAbo, c);
56
        }
57
 
67 ilm 58
        SQLPreferences prefs = SQLPreferences.getMemCached(((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete());
61 ilm 59
        if (prefs.getBoolean(GenerationDocGlobalPreferencePanel.MULTIMOD, false)) {
21 ilm 60
 
156 ilm 61
            if (tableComp.getFieldsName().contains("ID_MODELE")) { //$NON-NLS-1$
62
                String labelFor = comp.getLabelFor("ID_MODELE"); //$NON-NLS-1$
61 ilm 63
                if (labelFor == null || labelFor.trim().length() == 0) {
156 ilm 64
                    labelFor = "Modéles"; //$NON-NLS-1$
61 ilm 65
                }
66
                JLabel labelModele = new JLabel(labelFor);
67
                ElementComboBox boxModele = new ElementComboBox(true, 25);
156 ilm 68
                SQLElement modeleElement = Configuration.getInstance().getDirectory().getElement("MODELE"); //$NON-NLS-1$
61 ilm 69
                boxModele.init(modeleElement, modeleElement.getComboRequest(true));
156 ilm 70
                comp.addView(boxModele, "ID_MODELE"); //$NON-NLS-1$
21 ilm 71
                boxModele.getRequest().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
72
 
73
                    @Override
74
                    public SQLSelect transformChecked(SQLSelect input) {
156 ilm 75
                        SQLTable table = Configuration.getInstance().getDirectory().getElement("TYPE_MODELE").getTable(); //$NON-NLS-1$
76
                        Where w = new Where(input.getAlias(table.getField("TABLE")), "=", tableComp.getName()); //$NON-NLS-1$ //$NON-NLS-2$
21 ilm 77
                        input.setWhere(w);
78
                        return input;
79
                    }
80
                });
81
                this.add(labelModele, c);
61 ilm 82
                DefaultGridBagConstraints.lockMinimumSize(boxModele);
21 ilm 83
                this.add(boxModele, c);
84
            } else {
156 ilm 85
                System.err.println(TM.tr("PanelOOSQLComponent.missingField", tableComp.getName())); //$NON-NLS-1$
21 ilm 86
                Thread.dumpStack();
87
            }
88
        }
132 ilm 89
        this.checkImpression.setOpaque(false);
90
        this.checkVisu.setOpaque(false);
21 ilm 91
        this.add(this.checkImpression, c);
92
        this.add(this.checkVisu, c);
93
    }
94
 
90 ilm 95
    public JCheckBox getCheckAbo() {
96
        return checkAbo;
97
    }
98
 
21 ilm 99
    public boolean isVisualisationSelected() {
100
        return this.checkVisu.isSelected();
101
    }
102
 
103
    public boolean isImpressionSelected() {
104
        return this.checkImpression.isSelected();
105
    }
106
 
90 ilm 107
    public boolean isCheckAboSelected() {
108
        return this.checkAbo.isSelected();
109
    }
110
 
21 ilm 111
}