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