OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 43 | Rev 98 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
43 ilm 1
package org.openconcerto.modules.badge;
2
 
3
import java.awt.Component;
4
import java.io.File;
5
import java.io.IOException;
6
import java.text.DateFormat;
7
import java.text.SimpleDateFormat;
8
import java.util.ArrayList;
79 ilm 9
import java.util.Arrays;
43 ilm 10
import java.util.Calendar;
11
import java.util.Date;
12
import java.util.HashSet;
13
import java.util.List;
14
import java.util.Set;
15
 
16
import javax.swing.Action;
17
import javax.swing.JFrame;
18
import javax.swing.JTable;
19
import javax.swing.table.DefaultTableCellRenderer;
20
 
21
import org.openconcerto.erp.action.CreateFrameAbstractAction;
79 ilm 22
import org.openconcerto.erp.action.PreferencesAction;
43 ilm 23
import org.openconcerto.erp.config.Gestion;
24
import org.openconcerto.erp.config.MainFrame;
25
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
26
import org.openconcerto.erp.core.common.ui.ListeViewPanel;
27
import org.openconcerto.erp.modules.AbstractModule;
28
import org.openconcerto.erp.modules.ComponentsContext;
29
import org.openconcerto.erp.modules.DBContext;
79 ilm 30
import org.openconcerto.erp.modules.MenuContext;
43 ilm 31
import org.openconcerto.erp.modules.ModuleFactory;
32
import org.openconcerto.erp.modules.ModuleManager;
33
import org.openconcerto.erp.modules.ModulePackager;
79 ilm 34
import org.openconcerto.erp.modules.ModulePreferencePanel;
35
import org.openconcerto.erp.modules.ModulePreferencePanelDesc;
43 ilm 36
import org.openconcerto.erp.modules.RuntimeModuleFactory;
79 ilm 37
import org.openconcerto.erp.modules.ModulePreferencePanel.SQLPrefView;
43 ilm 38
import org.openconcerto.sql.Configuration;
39
import org.openconcerto.sql.element.SQLComponent;
40
import org.openconcerto.sql.element.SQLElement;
41
import org.openconcerto.sql.element.SQLElementDirectory;
42
import org.openconcerto.sql.element.UISQLComponent;
43
import org.openconcerto.sql.model.SQLName;
44
import org.openconcerto.sql.model.SQLRowAccessor;
45
import org.openconcerto.sql.model.SQLSyntax;
46
import org.openconcerto.sql.model.Where;
47
import org.openconcerto.sql.utils.SQLCreateTable;
48
import org.openconcerto.sql.view.FileDropHandler;
49
import org.openconcerto.sql.view.IListFrame;
50
import org.openconcerto.sql.view.IListPanel;
51
import org.openconcerto.sql.view.ListeAddPanel;
52
import org.openconcerto.sql.view.list.IListe;
53
import org.openconcerto.sql.view.list.RowAction;
54
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
55
import org.openconcerto.ui.PanelFrame;
56
import org.openconcerto.utils.CollectionMap;
57
import org.openconcerto.utils.FileUtils;
79 ilm 58
import org.openconcerto.utils.PrefType;
43 ilm 59
import org.openconcerto.utils.cc.IClosure;
60
 
61
public final class Module extends AbstractModule {
62
 
63
    public Module(ModuleFactory f) throws IOException {
64
        super(f);
65
 
66
    }
67
 
68
    @Override
69
    protected void install(DBContext ctxt) {
70
        super.install(ctxt);
71
 
72
        if (!ctxt.getTablesPreviouslyCreated().contains("ENTREE")) {
73
            // ENTREE
74
            final SQLCreateTable createTableEntree = ctxt.getCreateTable("ENTREE");
75
            createTableEntree.addDateAndTimeColumn("DATE");
76
            createTableEntree.addVarCharColumn("NUMERO_CARTE", 256);
77
            createTableEntree.addVarCharColumn("ADHERENT", 512);
78
            createTableEntree.addVarCharColumn("MOTIF", 2048);
79
            createTableEntree.addColumn("ACCEPTE", "boolean");
80
        }
81
        if (!ctxt.getTablesPreviouslyCreated().contains("PLAGE_HORAIRE")) {
82
            // PLAGE
83
            final SQLCreateTable createTablePlage = ctxt.getCreateTable("PLAGE_HORAIRE");
84
            createTablePlage.addVarCharColumn("NOM", 256);
85
            createTablePlage.addColumn("DEBUT_1_LUNDI", "time");
86
            createTablePlage.addColumn("DEBUT_1_MARDI", "time");
87
            createTablePlage.addColumn("DEBUT_1_MERCREDI", "time");
88
            createTablePlage.addColumn("DEBUT_1_JEUDI", "time");
89
            createTablePlage.addColumn("DEBUT_1_VENDREDI", "time");
90
            createTablePlage.addColumn("DEBUT_1_SAMEDI", "time");
91
            createTablePlage.addColumn("DEBUT_1_DIMANCHE", "time");
92
 
93
            createTablePlage.addColumn("DEBUT_2_LUNDI", "time");
94
            createTablePlage.addColumn("DEBUT_2_MARDI", "time");
95
            createTablePlage.addColumn("DEBUT_2_MERCREDI", "time");
96
            createTablePlage.addColumn("DEBUT_2_JEUDI", "time");
97
            createTablePlage.addColumn("DEBUT_2_VENDREDI", "time");
98
            createTablePlage.addColumn("DEBUT_2_SAMEDI", "time");
99
            createTablePlage.addColumn("DEBUT_2_DIMANCHE", "time");
100
 
101
            createTablePlage.addColumn("DEBUT_3_LUNDI", "time");
102
            createTablePlage.addColumn("DEBUT_3_MARDI", "time");
103
            createTablePlage.addColumn("DEBUT_3_MERCREDI", "time");
104
            createTablePlage.addColumn("DEBUT_3_JEUDI", "time");
105
            createTablePlage.addColumn("DEBUT_3_VENDREDI", "time");
106
            createTablePlage.addColumn("DEBUT_3_SAMEDI", "time");
107
            createTablePlage.addColumn("DEBUT_3_DIMANCHE", "time");
108
 
109
            createTablePlage.addColumn("FIN_1_LUNDI", "time");
110
            createTablePlage.addColumn("FIN_1_MARDI", "time");
111
            createTablePlage.addColumn("FIN_1_MERCREDI", "time");
112
            createTablePlage.addColumn("FIN_1_JEUDI", "time");
113
            createTablePlage.addColumn("FIN_1_VENDREDI", "time");
114
            createTablePlage.addColumn("FIN_1_SAMEDI", "time");
115
            createTablePlage.addColumn("FIN_1_DIMANCHE", "time");
116
 
117
            createTablePlage.addColumn("FIN_2_LUNDI", "time");
118
            createTablePlage.addColumn("FIN_2_MARDI", "time");
119
            createTablePlage.addColumn("FIN_2_MERCREDI", "time");
120
            createTablePlage.addColumn("FIN_2_JEUDI", "time");
121
            createTablePlage.addColumn("FIN_2_VENDREDI", "time");
122
            createTablePlage.addColumn("FIN_2_SAMEDI", "time");
123
            createTablePlage.addColumn("FIN_2_DIMANCHE", "time");
124
 
125
            createTablePlage.addColumn("FIN_3_LUNDI", "time");
126
            createTablePlage.addColumn("FIN_3_MARDI", "time");
127
            createTablePlage.addColumn("FIN_3_MERCREDI", "time");
128
            createTablePlage.addColumn("FIN_3_JEUDI", "time");
129
            createTablePlage.addColumn("FIN_3_VENDREDI", "time");
130
            createTablePlage.addColumn("FIN_3_SAMEDI", "time");
131
            createTablePlage.addColumn("FIN_3_DIMANCHE", "time");
132
        }
133
 
134
        if (!ctxt.getTablesPreviouslyCreated().contains("ADHERENT")) {
135
            // ADHERENT
136
            final SQLCreateTable createTable = ctxt.getCreateTable("ADHERENT");
137
 
138
            createTable.addVarCharColumn("NUMERO_CARTE", 256);
139
            createTable.addVarCharColumn("NOM", 256);
140
 
141
            createTable.addVarCharColumn("TEL", 256);
142
            createTable.addColumn("ACTIF", "boolean default false");
143
            createTable.addColumn("ADMIN", "boolean default false");
144
            createTable.addVarCharColumn("MAIL", 256);
145
            createTable.addVarCharColumn("PRENOM", 256);
146
            createTable.addVarCharColumn("INFOS", 2048);
147
            createTable.addColumn("DATE_VALIDITE_INSCRIPTION", "date");
148
            createTable.addColumn("DATE_NAISSANCE", "date");
149
 
150
            createTable.addForeignColumn("ID_ADRESSE", Configuration.getInstance().getRoot().findTable("ADRESSE"));
151
            createTable.addForeignColumn("ID_PLAGE_HORAIRE", new SQLName("PLAGE_HORAIRE"), SQLSyntax.ID_NAME, null);
152
        }
153
    }
154
 
155
    @Override
156
    protected void setupElements(SQLElementDirectory dir) {
157
        super.setupElements(dir);
158
 
159
        final ComptaSQLConfElement entreeElement = new ComptaSQLConfElement("ENTREE", "une entrée", "entrées") {
160
 
161
            @Override
162
            protected List<String> getListFields() {
163
                final List<String> l = new ArrayList<String>();
164
                l.add("DATE");
165
                l.add("NUMERO_CARTE");
166
                l.add("ADHERENT");
167
                l.add("MOTIF");
168
                l.add("ACCEPTE");
169
                return l;
170
            }
171
 
172
            @Override
173
            public Set<String> getReadOnlyFields() {
174
                Set<String> s = new HashSet<String>(super.getReadOnlyFields());
175
                s.add("NUMERO_CARTE");
176
                return s;
177
            }
178
 
179
            @Override
180
            protected List<String> getComboFields() {
181
                final List<String> l = new ArrayList<String>();
182
                l.add("NUMERO_CARTE");
183
                l.add("DATE");
184
                return l;
185
            }
186
 
187
            @Override
188
            public CollectionMap<String, String> getShowAs() {
189
                return CollectionMap.singleton(null, getComboFields());
190
            }
191
 
192
            @Override
193
            public SQLComponent createComponent() {
194
                return new UISQLComponent(this) {
195
                    @Override
196
                    protected void addViews() {
197
                        this.addView("NUMERO_CARTE");
198
                        this.addView("DATE");
199
                    }
200
                };
201
            }
202
        };
203
        dir.addSQLElement(entreeElement);
204
        dir.addSQLElement(new PlageHoraireSQLElement());
205
        dir.addSQLElement(new AdherentSQLElement());
206
    }
207
 
208
    private IListPanel getPanelEntree(boolean filtered) {
209
        final SQLElement element = Configuration.getInstance().getDirectory().getElement("ENTREE");
210
 
211
        final SQLTableModelSourceOnline tableModelEntree = element.getTableSource(true);
212
 
213
        if (filtered) {
214
            Calendar cal = Calendar.getInstance();
215
            cal.add(Calendar.DAY_OF_MONTH, -15);
216
            Where wAttente = new Where(element.getTable().getField("DATE"), ">=", cal.getTime());
217
            tableModelEntree.getReq().setWhere(wAttente);
218
        }
219
        tableModelEntree.getColumn(element.getTable().getField("DATE")).setRenderer(new DefaultTableCellRenderer() {
220
 
221
            DateFormat format = new SimpleDateFormat("EEEE dd MMMM yyyy HH:mm:ss");
222
 
223
            @Override
224
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
225
                final String format2 = format.format((Date) value);
226
                return super.getTableCellRendererComponent(table, format2, isSelected, hasFocus, row, column);
227
 
228
            }
229
        });
230
 
231
        final IListPanel panel = new ListeViewPanel(element, new IListe(tableModelEntree));
232
 
233
        final Action createAction = RowAction.createAction("Assigner à", null, new IClosure<List<SQLRowAccessor>>() {
234
 
235
            @Override
236
            public void executeChecked(List<SQLRowAccessor> input) {
237
                SQLRowAccessor row = input.get(0);
238
                PanelFrame frame = new PanelFrame(new AssignationPanel(row.getString("NUMERO_CARTE")), "Assignation d'une carte");
239
                frame.setLocationRelativeTo(null);
240
                frame.setVisible(true);
241
 
242
            }
243
        });
244
 
245
        panel.getListe().addRowAction(createAction);
246
 
247
        return panel;
248
    }
249
 
250
    @Override
251
    protected void setupComponents(ComponentsContext ctxt) {
252
        ctxt.addFileDropHandler("ADHERENT", new FileDropHandler() {
253
 
254
            @Override
255
            public boolean handle(File f, Component source) {
256
                AdherentImporter importer;
257
                try {
258
                    importer = new AdherentImporter(f);
259
                    importer.importAdherent();
260
                } catch (Exception e) {
261
                    e.printStackTrace();
262
                }
263
                return true;
264
            }
265
 
266
            @Override
267
            public boolean canHandle(File f) {
268
                String n = f.getName().toLowerCase();
269
                return n.endsWith(".xls") || n.endsWith(".ods");
270
            }
271
        });
79 ilm 272
 
273
    }
274
 
275
    @Override
276
    protected void setupMenu(MenuContext ctxt) {
43 ilm 277
        ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des adhérents") {
278
 
279
            @Override
280
            public JFrame createFrame() {
281
                IListFrame frameAdh = new IListFrame(new ListeAddPanel(Configuration.getInstance().getDirectory().getElement("ADHERENT")));
282
                return frameAdh;
283
            }
284
        }, MainFrame.LIST_MENU);
285
 
286
        ctxt.addMenuItem(new CreateFrameAbstractAction("Liste des entrées") {
287
 
288
            @Override
289
            public JFrame createFrame() {
290
 
291
                return new IListFrame(getPanelEntree(false));
292
            }
293
        }, MainFrame.LIST_MENU);
79 ilm 294
        ctxt.addMenuItem(new PreferencesAction(), MainFrame.FILE_MENU);
43 ilm 295
    }
296
 
297
    @Override
298
    protected void start() {
299
        MainFrame.getInstance().getTabbedPane().addTab("Liste des entrées", getPanelEntree(true));
300
    }
301
 
302
    @Override
303
    protected void stop() {
304
    }
305
 
306
    public static void main(String[] args) throws IOException {
307
        final File propsFile = new File("gestionModule.properties");
308
 
309
        final ModuleFactory factory = new RuntimeModuleFactory(propsFile);
310
 
311
        final File distDir = new File("dist");
312
        FileUtils.mkdir_p(distDir);
313
        new ModulePackager(propsFile, new File("bin/")).writeToDir(distDir);
314
        new ModulePackager(propsFile, new File("bin/")).writeToDir(new File("../OpenConcerto/Modules"));
315
 
316
        ModuleManager.getInstance().addFactoryAndStart(factory, false);
317
 
318
        Gestion.main(args);
319
 
320
    }
79 ilm 321
 
322
    public final static String ENTREE_PREF = "entreeAdmin";
323
 
324
    @Override
325
    public List<ModulePreferencePanelDesc> getPrefDescriptors() {
326
        return Arrays.<ModulePreferencePanelDesc> asList(new ModulePreferencePanelDesc("Gestion des entrées") {
327
            @Override
328
            protected ModulePreferencePanel createPanel() {
329
                return new ModulePreferencePanel("Gestion des entrées") {
330
                    @Override
331
                    protected void addViews() {
332
 
333
                        this.addView(new SQLPrefView<Boolean>(PrefType.BOOLEAN_TYPE, "N'autoriser que les administrateurs à entrer ", ENTREE_PREF));
334
                    }
335
                };
336
            }
337
        }.setLocal(false).setKeywords("entrée"));
338
    }
339
 
43 ilm 340
}