OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 27 | 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.preferences;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.model.SQLTable;
20
import org.openconcerto.ui.DefaultGridBagConstraints;
21
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
156 ilm 22
import org.openconcerto.utils.checks.ValidListener;
23
import org.openconcerto.utils.checks.ValidObject;
24
import org.openconcerto.utils.checks.ValidState;
18 ilm 25
 
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
 
156 ilm 29
import javax.swing.JOptionPane;
30
import javax.swing.SwingUtilities;
31
 
18 ilm 32
public class SocietePreferencePanel extends DefaultPreferencePanel {
33
 
34
    private SQLComponent sc;
156 ilm 35
    private boolean valid = true;
36
    private String validText = "";
18 ilm 37
 
38
    public SocietePreferencePanel() {
39
        this.setLayout(new GridBagLayout());
40
        final GridBagConstraints c = new DefaultGridBagConstraints();
41
        c.weightx = 1;
42
        c.weighty = 1;
43
        c.fill = GridBagConstraints.BOTH;
44
        c.anchor = GridBagConstraints.NORTHWEST;
45
 
46
        final SQLTable tableSociete = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON");
27 ilm 47
        this.sc = Configuration.getInstance().getDirectory().getElement(tableSociete).createDefaultComponent();
18 ilm 48
        this.sc.uiInit();
49
        this.sc.select(((ComptaPropsConfiguration) Configuration.getInstance()).getSocieteID());
50
        this.add(this.sc, c);
156 ilm 51
        this.sc.addValidListener(new ValidListener() {
52
 
53
            @Override
54
            public void validChange(ValidObject src, ValidState newValue) {
55
                valid = newValue.isValid();
56
                validText = newValue.getValidationText();
57
            }
58
        });
18 ilm 59
    }
60
 
61
    public String getTitleName() {
62
        return "Société";
63
    }
64
 
65
    public void storeValues() {
156 ilm 66
        if (valid) {
67
            this.sc.update();
68
        } else {
69
            final String t;
70
            if (this.validText == null) {
71
                t = "valeurs non valides";
72
            } else {
73
                t = this.validText;
74
            }
75
            SwingUtilities.invokeLater(new Runnable() {
76
 
77
                @Override
78
                public void run() {
79
                    JOptionPane.showMessageDialog(SocietePreferencePanel.this, t);
80
                }
81
            });
82
 
83
        }
18 ilm 84
    }
85
 
86
    public void restoreToDefaults() {
156 ilm 87
        // nothing
18 ilm 88
    }
89
}