OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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