OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Rev 156 | 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.sales.product.ui;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
21 ilm 17
import org.openconcerto.erp.core.common.ui.AbstractVenteArticleItemTable;
18
import org.openconcerto.erp.core.common.ui.TotalPanel;
18 ilm 19
import org.openconcerto.erp.preferences.DefaultNXProps;
20
import org.openconcerto.sql.Configuration;
21
import org.openconcerto.ui.DefaultGridBagConstraints;
93 ilm 22
import org.openconcerto.ui.VerticalLayout;
18 ilm 23
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
24
import org.openconcerto.ui.preferences.DefaultProps;
25
 
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.event.ItemEvent;
29
import java.awt.event.ItemListener;
30
 
31
import javax.swing.BorderFactory;
32
import javax.swing.JCheckBox;
33
import javax.swing.JPanel;
34
 
35
public class GestionArticlePreferencePanel extends DefaultPreferencePanel {
36
 
93 ilm 37
    private final JCheckBox checkModeVente, checkLongueur, checkLargeur, checkPoids;
18 ilm 38
    private final JCheckBox checkService, checkVenteComptoir, checkShowPoids, checkShowStyle, checkSFE;
21 ilm 39
    private final JCheckBox checkDevise, checkMarge;
73 ilm 40
    private JCheckBox checkSite;
18 ilm 41
 
42
    public GestionArticlePreferencePanel() {
43
        super();
44
        setLayout(new GridBagLayout());
45
        final GridBagConstraints c = new DefaultGridBagConstraints();
46
        c.anchor = GridBagConstraints.NORTHWEST;
47
        c.weightx = 1;
48
 
49
        this.checkSFE = new JCheckBox("Activer la vente de formation");
50
        this.checkService = new JCheckBox("Activer la gestion de vente de service");
51
        this.checkLargeur = new JCheckBox("Largeurs");
52
        this.checkLongueur = new JCheckBox("Longueurs");
53
        this.checkPoids = new JCheckBox("Poids");
54
        this.checkShowStyle = new JCheckBox("Voir la colonne Style");
55
        this.checkModeVente = new JCheckBox("Activer le mode de vente spécifique");
56
        this.checkVenteComptoir = new JCheckBox("Activer le mode vente comptoir");
57
        this.checkShowPoids = new JCheckBox("Voir le Poids");
132 ilm 58
        this.checkDevise = new JCheckBox("Gérer les devises");
21 ilm 59
        this.checkMarge = new JCheckBox("Afficher le taux de marque au lieu du taux de marge");
18 ilm 60
 
19 ilm 61
 
21 ilm 62
        this.add(this.checkDevise, c);
63
        c.gridy++;
64
        this.add(this.checkMarge, c);
65
        c.gridy++;
18 ilm 66
        this.add(this.checkService, c);
67
        c.gridy++;
68
        this.add(this.checkVenteComptoir, c);
69
        c.gridy++;
70
        this.add(this.checkShowPoids, c);
71
        c.gridy++;
72
        this.add(this.checkShowStyle, c);
73
        c.gridy++;
74
        this.add(this.checkModeVente, c);
75
 
76
        final JPanel panelGestionArticle = new JPanel();
77
        panelGestionArticle.setBorder(BorderFactory.createTitledBorder("Gérer les"));
78
        panelGestionArticle.setLayout(new VerticalLayout());
79
        panelGestionArticle.add(this.checkLargeur);
80
        panelGestionArticle.add(this.checkLongueur);
81
        panelGestionArticle.add(this.checkPoids);
82
 
83
        c.gridy++;
84
        c.weighty = 1;
85
        this.add(panelGestionArticle, c);
86
 
87
        setValues();
88
 
89
        this.checkModeVente.addItemListener(new ItemListener() {
90
            public void itemStateChanged(final ItemEvent e) {
91
                enableAdvancedMode(GestionArticlePreferencePanel.this.checkModeVente.isSelected());
92
            }
93
        });
94
    }
95
 
96
    @Override
97
    public void storeValues() {
98
        final DefaultProps props = DefaultNXProps.getInstance();
99
 
100
        props.setProperty("ArticleLongueur", String.valueOf(this.checkLongueur.isSelected()));
101
        props.setProperty("ArticleLargeur", String.valueOf(this.checkLargeur.isSelected()));
102
        props.setProperty("ArticlePoids", String.valueOf(this.checkPoids.isSelected()));
103
        props.setProperty("ArticleShowPoids", String.valueOf(this.checkShowPoids.isSelected()));
104
        props.setProperty("ArticleShowStyle", String.valueOf(this.checkShowStyle.isSelected()));
105
        props.setProperty("ArticleModeVenteAvance", String.valueOf(this.checkModeVente.isSelected()));
106
        props.setProperty("ArticleService", String.valueOf(this.checkService.isSelected()));
107
        props.setProperty("ArticleSFE", String.valueOf(this.checkSFE.isSelected()));
73 ilm 108
        if (this.checkSite != null) {
109
            props.setProperty("ShowSiteFacture", String.valueOf(this.checkSite.isSelected()));
110
        }
18 ilm 111
        props.setProperty("ArticleVenteComptoir", String.valueOf(this.checkVenteComptoir.isSelected()));
21 ilm 112
        props.setProperty(AbstractVenteArticleItemTable.ARTICLE_SHOW_DEVISE, String.valueOf(this.checkDevise.isSelected()));
113
        props.setProperty(TotalPanel.MARGE_MARQUE, String.valueOf(this.checkMarge.isSelected()));
18 ilm 114
        props.store();
115
    }
116
 
117
    @Override
118
    public void restoreToDefaults() {
119
        this.checkModeVente.setSelected(false);
21 ilm 120
        this.checkShowPoids.setSelected(false);
121
        this.checkShowStyle.setSelected(false);
18 ilm 122
        enableAdvancedMode(false);
123
        this.checkService.setSelected(true);
124
        this.checkSFE.setSelected(false);
41 ilm 125
        this.checkVenteComptoir.setSelected(true);
21 ilm 126
        this.checkDevise.setSelected(false);
127
        this.checkMarge.setSelected(false);
73 ilm 128
        if (this.checkSite != null) {
129
            this.checkSite.setSelected(false);
130
        }
18 ilm 131
    }
132
 
133
    @Override
134
    public String getTitleName() {
135
        return "Gestion des articles";
136
    }
137
 
138
    private void setValues() {
139
        final DefaultProps props = DefaultNXProps.getInstance();
140
        // service
141
        final String service = props.getStringProperty("ArticleService");
142
        final Boolean bService = Boolean.valueOf(service);
143
        this.checkService.setSelected(bService == null || bService.booleanValue());
144
 
145
        // SFE
146
        final String sfe = props.getStringProperty("ArticleSFE");
147
        final Boolean bSfe = Boolean.valueOf(sfe);
148
        this.checkSFE.setSelected(bSfe != null && bSfe.booleanValue());
149
 
150
        // vente comptoir
41 ilm 151
        final Boolean bVenteComptoir = DefaultNXProps.getInstance().getBooleanValue("ArticleVenteComptoir", true);
18 ilm 152
        this.checkVenteComptoir.setSelected(bVenteComptoir != null && bVenteComptoir.booleanValue());
153
 
154
        // longueur
155
        final String longueur = props.getStringProperty("ArticleLongueur");
156
        final Boolean bLong = Boolean.valueOf(longueur);
157
        this.checkLongueur.setSelected(bLong == null || bLong.booleanValue());
158
 
159
        // Largeur
160
        final String largeur = props.getStringProperty("ArticleLargeur");
161
        final Boolean bLarg = Boolean.valueOf(largeur);
162
        this.checkLargeur.setSelected(bLarg == null || bLarg.booleanValue());
163
 
164
        // Poids
165
        final String poids = props.getStringProperty("ArticlePoids");
166
        final Boolean bPoids = Boolean.valueOf(poids);
167
        this.checkPoids.setSelected(bPoids == null || bPoids.booleanValue());
168
 
169
        // Show Poids
21 ilm 170
        this.checkShowPoids.setSelected(props.getBooleanValue("ArticleShowPoids", false));
18 ilm 171
 
172
        // Show Style
21 ilm 173
        this.checkShowStyle.setSelected(props.getBooleanValue("ArticleShowStyle", false));
18 ilm 174
 
21 ilm 175
        // Devise
176
        this.checkDevise.setSelected(props.getBooleanValue(AbstractVenteArticleItemTable.ARTICLE_SHOW_DEVISE, false));
177
 
178
        // Devise
179
        this.checkMarge.setSelected(props.getBooleanValue(TotalPanel.MARGE_MARQUE, false));
180
 
18 ilm 181
        // Mode vente
182
        final String modeVente = props.getStringProperty("ArticleModeVenteAvance");
183
        final Boolean bModeVente = Boolean.valueOf(modeVente);
184
        this.checkModeVente.setSelected(bModeVente == null || bModeVente.booleanValue());
185
        enableAdvancedMode(bModeVente == null || bModeVente.booleanValue());
186
 
73 ilm 187
        // Site
188
        if (this.checkSite != null) {
189
            // Show Style
190
            final String s = props.getStringProperty("ShowSiteFacture");
191
            final Boolean b = s.equalsIgnoreCase("true");
192
            this.checkSite.setSelected(b != null && b);
193
        }
18 ilm 194
    }
195
 
196
    /**
197
     * Active le mode de gestion avancé avec les metriques
198
     */
199
    private void enableAdvancedMode(final boolean b) {
200
        this.checkLargeur.setEnabled(b);
201
        this.checkLongueur.setEnabled(b);
202
        this.checkPoids.setEnabled(b);
203
    }
204
 
205
}