OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 87 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ilm 1
package org.openconcerto.modules.customerrelationship.lead;
2
 
3
import java.util.HashSet;
4
import java.util.Set;
5
 
6
import javax.swing.JComponent;
7
import javax.swing.JLabel;
8
 
9
import org.openconcerto.sql.element.GroupSQLComponent;
10
import org.openconcerto.sql.element.SQLElement;
140 ilm 11
import org.openconcerto.sql.model.SQLBackgroundTableCache;
12
import org.openconcerto.sql.model.SQLRow;
13
import org.openconcerto.sql.model.SQLRowValues;
14
import org.openconcerto.sql.model.SQLTable;
30 ilm 15
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo;
140 ilm 16
import org.openconcerto.sql.users.UserManager;
30 ilm 17
import org.openconcerto.ui.JDate;
140 ilm 18
import org.openconcerto.ui.JLabelBold;
30 ilm 19
import org.openconcerto.ui.component.ComboLockedMode;
140 ilm 20
import org.openconcerto.ui.component.ITextArea;
30 ilm 21
import org.openconcerto.ui.group.Group;
22
 
23
public class LeadSQLComponent extends GroupSQLComponent {
24
    public LeadSQLComponent(SQLElement element, Group group) {
25
        super(element, group);
26
    }
27
 
28
    @Override
29
    protected Set<String> createRequiredNames() {
30
        final Set<String> s = new HashSet<String>(1);
31
        s.add("ID_ADRESSE");
140 ilm 32
        s.add("NOM");
30 ilm 33
        return s;
34
    }
35
 
36
    @Override
140 ilm 37
    public JComponent getLabel(String id) {
38
        if (id.equals("customerrelationship.lead.person")) {
39
            return new JLabelBold("Contact");
40
        } else if (id.equals("customerrelationship.lead.contact")) {
41
            return new JLabel();
42
        } else if (id.equals("customerrelationship.lead.address")) {
43
            return new JLabelBold("Adresse");
44
        } else {
45
            return super.getLabel(id);
46
        }
47
    }
48
 
49
    @Override
87 ilm 50
    public JComponent createEditor(String id) {
140 ilm 51
 
52
        if (id.equals("INFORMATION") || id.equals("INFOS")) {
53
            final ITextArea jTextArea = new ITextArea();
30 ilm 54
            jTextArea.setFont(new JLabel().getFont());
140 ilm 55
            return jTextArea;
56
        } else if (id.equals("INDUSTRY") || id.equals("STATUS") || id.equals("RATING") || id.equals("SOURCE") || id.equals("DISPO")) {
30 ilm 57
            return new SQLSearchableTextCombo(ComboLockedMode.UNLOCKED, 1, 20, false);
58
        } else if (id.equals("DATE")) {
59
            return new JDate(true);
60
        }
87 ilm 61
        return super.createEditor(id);
30 ilm 62
    }
140 ilm 63
 
64
    @Override
65
    protected SQLRowValues createDefaults() {
66
        SQLRowValues rowVals = new SQLRowValues(getTable());
67
        rowVals.put("STATUS", "Nouveau");
68
 
69
        final int idUser = UserManager.getInstance().getCurrentUser().getId();
70
        final SQLTable foreignTableComm = getTable().getForeignTable("ID_COMMERCIAL");
71
        SQLRow rowsComm = SQLBackgroundTableCache.getInstance().getCacheForTable(foreignTableComm).getFirstRowContains(idUser, foreignTableComm.getField("ID_USER_COMMON"));
72
 
73
        if (rowsComm != null) {
74
            rowVals.put("ID_COMMERCIAL", rowsComm.getID());
75
        }
76
        return rowVals;
77
    }
30 ilm 78
}