OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 27 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
 * 
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 */
 
 package org.openconcerto.erp.preferences;

import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.preferences.DefaultPreferencePanel;
import org.openconcerto.utils.checks.ValidListener;
import org.openconcerto.utils.checks.ValidObject;
import org.openconcerto.utils.checks.ValidState;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

public class SocietePreferencePanel extends DefaultPreferencePanel {

    private SQLComponent sc;
    private boolean valid = true;
    private String validText = "";

    public SocietePreferencePanel() {
        this.setLayout(new GridBagLayout());
        final GridBagConstraints c = new DefaultGridBagConstraints();
        c.weightx = 1;
        c.weighty = 1;
        c.fill = GridBagConstraints.BOTH;
        c.anchor = GridBagConstraints.NORTHWEST;

        final SQLTable tableSociete = Configuration.getInstance().getBase().getTable("SOCIETE_COMMON");
        this.sc = Configuration.getInstance().getDirectory().getElement(tableSociete).createDefaultComponent();
        this.sc.uiInit();
        this.sc.select(((ComptaPropsConfiguration) Configuration.getInstance()).getSocieteID());
        this.add(this.sc, c);
        this.sc.addValidListener(new ValidListener() {

            @Override
            public void validChange(ValidObject src, ValidState newValue) {
                valid = newValue.isValid();
                validText = newValue.getValidationText();
            }
        });
    }

    public String getTitleName() {
        return "Société";
    }

    public void storeValues() {
        if (valid) {
            this.sc.update();
        } else {
            final String t;
            if (this.validText == null) {
                t = "valeurs non valides";
            } else {
                t = this.validText;
            }
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    JOptionPane.showMessageDialog(SocietePreferencePanel.this, t);
                }
            });

        }
    }

    public void restoreToDefaults() {
        // nothing
    }
}