OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 153 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 153 Rev 171
1
package org.openconcerto.modules.card;
1
package org.openconcerto.modules.card;
2
 
2
 
3
import java.io.IOException;
3
import java.io.IOException;
4
import java.sql.SQLException;
4
import java.sql.SQLException;
5
import java.util.ArrayList;
5
import java.util.ArrayList;
6
import java.util.Arrays;
6
import java.util.Arrays;
7
import java.util.List;
7
import java.util.List;
8
 
8
 
9
import org.openconcerto.erp.config.MainFrame;
9
import org.openconcerto.erp.config.MainFrame;
10
import org.openconcerto.erp.modules.AbstractModule;
10
import org.openconcerto.erp.modules.AbstractModule;
11
import org.openconcerto.erp.modules.AlterTableRestricted;
11
import org.openconcerto.erp.modules.AlterTableRestricted;
12
import org.openconcerto.erp.modules.ComponentsContext;
12
import org.openconcerto.erp.modules.ComponentsContext;
13
import org.openconcerto.erp.modules.DBContext;
13
import org.openconcerto.erp.modules.DBContext;
14
import org.openconcerto.erp.modules.MenuContext;
14
import org.openconcerto.erp.modules.MenuContext;
15
import org.openconcerto.erp.modules.ModuleElement;
15
import org.openconcerto.erp.modules.ModuleElement;
16
import org.openconcerto.erp.modules.ModuleFactory;
16
import org.openconcerto.erp.modules.ModuleFactory;
17
import org.openconcerto.erp.modules.ModulePreferencePanel;
17
import org.openconcerto.erp.modules.ModulePreferencePanel;
18
import org.openconcerto.erp.modules.ModulePreferencePanelDesc;
18
import org.openconcerto.erp.modules.ModulePreferencePanelDesc;
19
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.element.SQLElement.ReferenceAction;
20
import org.openconcerto.sql.element.SQLElement.ReferenceAction;
21
import org.openconcerto.sql.element.SQLElementDirectory;
21
import org.openconcerto.sql.element.SQLElementDirectory;
22
import org.openconcerto.sql.element.UISQLComponent;
22
import org.openconcerto.sql.element.UISQLComponent;
-
 
23
import org.openconcerto.sql.model.DBRoot;
23
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.model.SQLTable;
24
import org.openconcerto.sql.utils.SQLCreateTable;
25
import org.openconcerto.sql.utils.SQLCreateTable;
25
import org.openconcerto.utils.ListMap;
26
import org.openconcerto.utils.ListMap;
26
import org.openconcerto.utils.PrefType;
27
import org.openconcerto.utils.PrefType;
27
 
28
 
28
public final class ModuleCard extends AbstractModule {
29
public final class ModuleCard extends AbstractModule {
29
 
30
 
30
    private static final String TABLE_NAME = "FIDELITY_CARD";
31
    private static final String TABLE_NAME = "FIDELITY_CARD";
31
 
32
 
32
    public ModuleCard(ModuleFactory f) throws IOException {
33
    public ModuleCard(ModuleFactory f) throws IOException {
33
        super(f);
34
        super(f);
34
 
35
 
35
    }
36
    }
36
 
37
 
37
    @Override
38
    @Override
38
    protected void install(DBContext ctxt) throws SQLException, IOException {
39
    protected void install(DBContext ctxt) throws SQLException, IOException {
39
        super.install(ctxt);
40
        super.install(ctxt);
40
        // TODO use version to upgrade
41
        // TODO use version to upgrade
41
        if (!ctxt.getTablesPreviouslyCreated().contains(TABLE_NAME)) {
42
        if (!ctxt.getTablesPreviouslyCreated().contains(TABLE_NAME)) {
42
            final SQLCreateTable createTable = ctxt.getCreateTable(TABLE_NAME);
43
            final SQLCreateTable createTable = ctxt.getCreateTable(TABLE_NAME);
43
            createTable.addVarCharColumn("SERIAL", 64);
44
            createTable.addVarCharColumn("SERIAL", 64);
44
            createTable.addColumn("POINTS", "int NOT NULL DEFAULT 0");
45
            createTable.addColumn("POINTS", "int NOT NULL DEFAULT 0");
45
            createTable.addDateAndTimeColumn("EXPIRATION_DATE");
46
            createTable.addDateAndTimeColumn("EXPIRATION_DATE");
46
 
47
 
47
            final AlterTableRestricted alterTable = ctxt.getAlterTable("CLIENT");
48
            final AlterTableRestricted alterTable = ctxt.getAlterTable("CLIENT");
48
            alterTable.addForeignColumn("ID_FIDELITY_CARD", createTable);
49
            alterTable.addForeignColumn("ID_FIDELITY_CARD", createTable);
49
        }
50
        }
50
    }
51
    }
51
 
52
 
52
    @Override
53
    @Override
53
    protected void setupElements(SQLElementDirectory dir) {
54
    protected void setupElements(SQLElementDirectory dir) {
54
        super.setupElements(dir);
55
        super.setupElements(dir);
55
        final ModuleElement fidCardElement = new ModuleElement(this, TABLE_NAME) {
56
        final ModuleElement fidCardElement = new ModuleElement(this, TABLE_NAME) {
56
 
57
 
57
            @Override
58
            @Override
58
            protected List<String> getListFields() {
59
            protected List<String> getListFields() {
59
                final List<String> l = new ArrayList<String>();
60
                final List<String> l = new ArrayList<String>();
60
                l.add("SERIAL");
61
                l.add("SERIAL");
61
                l.add("POINTS");
62
                l.add("POINTS");
62
                l.add("EXPIRATION_DATE");
63
                l.add("EXPIRATION_DATE");
63
                return l;
64
                return l;
64
            }
65
            }
65
 
66
 
66
            @Override
67
            @Override
67
            protected List<String> getComboFields() {
68
            protected List<String> getComboFields() {
68
                final List<String> l = new ArrayList<String>();
69
                final List<String> l = new ArrayList<String>();
69
                l.add("SERIAL");
70
                l.add("SERIAL");
70
                l.add("POINTS");
71
                l.add("POINTS");
71
                return l;
72
                return l;
72
            }
73
            }
73
 
74
 
74
            @Override
75
            @Override
75
            public ListMap<String, String> getShowAs() {
76
            public ListMap<String, String> getShowAs() {
76
                return ListMap.singleton(null, getComboFields());
77
                return ListMap.singleton(null, getComboFields());
77
            }
78
            }
78
 
79
 
79
            @Override
80
            @Override
80
            protected SQLComponent createComponent() {
81
            protected SQLComponent createComponent() {
81
                return new UISQLComponent(this) {
82
                return new UISQLComponent(this) {
82
                    @Override
83
                    @Override
83
                    protected void addViews() {
84
                    protected void addViews() {
84
                        this.addView("SERIAL");
85
                        this.addView("SERIAL");
85
                        this.addView("POINTS");
86
                        this.addView("POINTS");
86
                        this.addView("EXPIRATION_DATE");
87
                        this.addView("EXPIRATION_DATE");
87
                    }
88
                    }
88
                };
89
                };
89
            }
90
            }
90
        };
91
        };
91
 
92
 
92
        dir.addSQLElement(fidCardElement);
93
        dir.addSQLElement(fidCardElement);
93
        final SQLTable clientT = fidCardElement.getTable().findReferentTable("CLIENT");
94
        final SQLTable clientT = fidCardElement.getTable().findReferentTable("CLIENT");
94
        // do not delete a client
95
        // do not delete a client
95
        dir.getElement(clientT).setAction("ID_FIDELITY_CARD", ReferenceAction.SET_EMPTY);
96
        dir.getElement(clientT).setAction("ID_FIDELITY_CARD", ReferenceAction.SET_EMPTY);
96
    }
97
    }
97
 
98
 
98
    @Override
99
    @Override
99
    protected void setupComponents(ComponentsContext ctxt) {
100
    protected void setupComponents(ComponentsContext ctxt) {
100
        ctxt.putAdditionalField("CLIENT", "ID_FIDELITY_CARD");
101
        ctxt.putAdditionalField("CLIENT", "ID_FIDELITY_CARD");
101
    }
102
    }
102
 
103
 
103
    @Override
104
    @Override
104
    protected void setupMenu(MenuContext ctxt) {
105
    protected void setupMenu(MenuContext ctxt) {
105
        ctxt.addMenuItem(ctxt.createListAction(TABLE_NAME), MainFrame.LIST_MENU);
106
        ctxt.addMenuItem(ctxt.createListAction(TABLE_NAME), MainFrame.LIST_MENU);
106
    }
107
    }
107
 
108
 
108
    @Override
109
    @Override
109
    protected void start() {
110
    protected void start() {
110
    }
111
    }
111
 
112
 
112
    @Override
113
    @Override
113
    public List<ModulePreferencePanelDesc> getPrefDescriptors() {
114
    public List<ModulePreferencePanelDesc> getPrefDescriptors(final DBRoot root) {
114
        return Arrays.<ModulePreferencePanelDesc> asList(new ModulePreferencePanelDesc("Préf") {
115
        return Arrays.<ModulePreferencePanelDesc> asList(new ModulePreferencePanelDesc("Préf") {
115
            @Override
116
            @Override
116
            protected ModulePreferencePanel createPanel() {
117
            protected ModulePreferencePanel createPanel() {
117
                return new ModulePreferencePanel("Mon super titre") {
118
                return new ModulePreferencePanel(root, "Mon super titre") {
118
                    @Override
119
                    @Override
119
                    protected void addViews() {
120
                    protected void addViews() {
120
                        this.addView(new SQLPrefView<Boolean>(PrefType.BOOLEAN_TYPE, "Un booléen", "boolPref").setDefaultValue(Boolean.TRUE));
121
                        this.addView(new SQLPrefView<Boolean>(PrefType.BOOLEAN_TYPE, "Un booléen", "boolPref").setDefaultValue(Boolean.TRUE));
121
                        this.addView(new SQLPrefView<String>(PrefType.STRING_TYPE, 12, "Du texte", "textPref").setDefaultValue("court"));
122
                        this.addView(new SQLPrefView<String>(PrefType.STRING_TYPE, 12, "Du texte", "textPref").setDefaultValue("court"));
122
                        this.addView(new SQLPrefView<Double>(PrefType.DOUBLE_TYPE, "Un double", "doublePref"));
123
                        this.addView(new SQLPrefView<Double>(PrefType.DOUBLE_TYPE, "Un double", "doublePref"));
123
                    }
124
                    }
124
                };
125
                };
125
            }
126
            }
126
        }, new ModulePreferencePanelDesc("Préf2") {
127
        }, new ModulePreferencePanelDesc("Préf2") {
127
            @Override
128
            @Override
128
            protected ModulePreferencePanel createPanel() {
129
            protected ModulePreferencePanel createPanel() {
129
                return new ModulePreferencePanel("Mon super titre") {
130
                return new ModulePreferencePanel(root, "Mon super titre") {
130
                    @Override
131
                    @Override
131
                    protected void addViews() {
132
                    protected void addViews() {
132
                        this.addView(new SQLPrefView<String>(PrefType.STRING_TYPE, 512, "Du texte", "textPref").setDefaultValue("long texte"));
133
                        this.addView(new SQLPrefView<String>(PrefType.STRING_TYPE, 512, "Du texte", "textPref").setDefaultValue("long texte"));
133
                        this.addView(new SQLPrefView<Long>(PrefType.LONG_TYPE, "Un long", "longPref"));
134
                        this.addView(new SQLPrefView<Long>(PrefType.LONG_TYPE, "Un long", "longPref"));
134
                    }
135
                    }
135
                };
136
                };
136
            }
137
            }
137
        }.setLocal(false).setKeywords("toto", "vélo"));
138
        }.setLocal(false).setKeywords("toto", "vélo"));
138
    }
139
    }
139
 
140
 
140
    @Override
141
    @Override
141
    protected void stop() {
142
    protected void stop() {
142
    }
143
    }
143
}
144
}