OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | 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.core.customerrelationship.customer.element;

import org.openconcerto.sql.element.ElementSQLObject;
import org.openconcerto.sql.element.GroupSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.ui.JLabelBold;
import org.openconcerto.ui.group.Group;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.JComponent;
import javax.swing.JLabel;

public class AgenceSQLElement extends SQLElement {

    public AgenceSQLElement(DBRoot root) {
        super(root.findTable("AGENCE"));
        // TODO Auto-generated constructor stub
    }

    @Override
    protected List<String> getListFields() {
        List<String> list = new ArrayList<>(2);

        list.add("DESIGNATION");
        list.add("ID_CLIENT");
        list.add("ID_ADRESSE");
        return list;
    }

    @Override
    public Group getGroupForCreation() {
        // TODO Auto-generated method stub
        return super.getGroupForCreation();
    }

    @Override
    protected SQLComponent createComponent() {
        return new GroupSQLComponent(this, new AgenceGroup(this.getCode())) {

            @Override
            public JComponent createEditor(String id) {
                if (id.equals("customerrelationship.customer.agency.address")) {
                    org.openconcerto.sql.element.ElementSQLObject c = (ElementSQLObject) super.createEditor(id);
                    c.setRequired(true);
                    return c;
                }
                if (id.equals("customerrelationship.customer.agency.customer")) {
                    ElementComboBox compClient = new ElementComboBox();
                    compClient.setVisible(false);

                    return compClient;
                }
                return super.createEditor(id);
            }

            @Override
            protected Set<String> createRequiredNames() {
                final Set<String> required = new HashSet<>();
                required.add("customerrelationship.customer.agency.designation");
                return required;
            }

            @Override
            public JComponent createLabel(String id) {
                if (id.equals("customerrelationship.customer.agency.customer")) {
                    JLabel label = new JLabel();
                    label.setVisible(false);
                    return label;
                }
                if (id.equals("customerrelationship.customer.agency.grp1")) {
                    JLabel label = new JLabel();
                    label.setVisible(false);
                    return label;
                } else if (id.equals("customerrelationship.customer.agency.address")) {
                    return new JLabelBold("Adresse de l'agence");
                } else {
                    return super.createLabel(id);
                }
            }
        };
    }

    @Override
    protected String createCode() {
        return "customerrelationship.customer.agency";
    }

}