OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 181 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 181 Rev 183
Line 6... Line 6...
6
import java.awt.geom.Rectangle2D;
6
import java.awt.geom.Rectangle2D;
7
import java.io.File;
7
import java.io.File;
8
import java.io.IOException;
8
import java.io.IOException;
9
import java.nio.charset.StandardCharsets;
9
import java.nio.charset.StandardCharsets;
10
import java.util.ArrayList;
10
import java.util.ArrayList;
-
 
11
import java.util.HashMap;
11
import java.util.LinkedHashMap;
12
import java.util.LinkedHashMap;
12
import java.util.List;
13
import java.util.List;
-
 
14
import java.util.Map;
13
import java.util.Map.Entry;
15
import java.util.Map.Entry;
14
import java.util.TreeMap;
16
import java.util.TreeMap;
15
 
17
 
16
import javax.swing.AbstractAction;
18
import javax.swing.AbstractAction;
17
import javax.swing.JFrame;
19
import javax.swing.JFrame;
Line 19... Line 21...
19
 
21
 
20
import org.openconcerto.erp.generationDoc.provider.AdresseFullClientValueProvider;
22
import org.openconcerto.erp.generationDoc.provider.AdresseFullClientValueProvider;
21
import org.openconcerto.erp.modules.AbstractModule;
23
import org.openconcerto.erp.modules.AbstractModule;
22
import org.openconcerto.erp.modules.ComponentsContext;
24
import org.openconcerto.erp.modules.ComponentsContext;
23
import org.openconcerto.erp.modules.ModuleFactory;
25
import org.openconcerto.erp.modules.ModuleFactory;
-
 
26
import org.openconcerto.sql.model.SQLField;
24
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLRowAccessor;
26
import org.openconcerto.sql.model.SQLRowValues;
29
import org.openconcerto.sql.model.SQLRowValues;
27
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
30
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
28
import org.openconcerto.sql.model.SQLTable;
31
import org.openconcerto.sql.model.SQLTable;
Line 35... Line 38...
35
import org.openconcerto.utils.GestionDevise;
38
import org.openconcerto.utils.GestionDevise;
36
import org.openconcerto.utils.StringUtils;
39
import org.openconcerto.utils.StringUtils;
37
 
40
 
38
public final class ModuleLabel extends AbstractModule {
41
public final class ModuleLabel extends AbstractModule {
39
    final LinkedHashMap<String, String> zplTemplates = new LinkedHashMap<String, String>();
42
    final LinkedHashMap<String, String> zplTemplates = new LinkedHashMap<String, String>();
-
 
43
    final LinkedHashMap<String, String> gplTemplates = new LinkedHashMap<String, String>();
-
 
44
    private Map<String, File> dirMap = new HashMap<>();
40
 
45
 
41
    public ModuleLabel(ModuleFactory f) throws IOException {
46
    public ModuleLabel(ModuleFactory f) throws IOException {
42
        super(f);
47
        super(f);
43
    }
48
    }
44
 
49
 
Line 52... Line 57...
52
 
57
 
53
            @Override
58
            @Override
54
            public void actionPerformed(ActionEvent arg0) {
59
            public void actionPerformed(ActionEvent arg0) {
55
                final IListe list = IListe.get(arg0);
60
                final IListe list = IListe.get(arg0);
56
                final List<Integer> selectedIDs = list.getSelection().getSelectedIDs();
61
                final List<Integer> selectedIDs = list.getSelection().getSelectedIDs();
57
                final SQLTable tArticle = list.getSelectedRows().get(0).getTable();
62
                final SQLTable tArticle = list.getSelectedRowAccessors().get(0).getTable();
58
                final SwingWorker<List<RowValuesLabel>, String> wworker = new SwingWorker<List<RowValuesLabel>, String>() {
63
                final SwingWorker<List<RowValuesLabel>, String> wworker = new SwingWorker<List<RowValuesLabel>, String>() {
59
 
64
 
60
                    @Override
65
                    @Override
61
                    protected List<RowValuesLabel> doInBackground() throws Exception {
66
                    protected List<RowValuesLabel> doInBackground() throws Exception {
62
                        final SQLRowValues graph = new SQLRowValues(tArticle);
67
                        final SQLRowValues graph = new SQLRowValues(tArticle);
Line 212... Line 217...
212
                    public void actionPerformed(ActionEvent arg0) {
217
                    public void actionPerformed(ActionEvent arg0) {
213
                        final ZPLPrinterPanel p = new ZPLPrinterPanel(zpl);
218
                        final ZPLPrinterPanel p = new ZPLPrinterPanel(zpl);
214
                        final JFrame f = new JFrame();
219
                        final JFrame f = new JFrame();
215
                        final IListe list = IListe.get(arg0);
220
                        final IListe list = IListe.get(arg0);
216
                        final int idProduct = list.getSelection().getSelectedID();
221
                        final int idProduct = list.getSelection().getSelectedID();
-
 
222
                        final SQLTable tArticle = list.getSelectedRowAccessors().get(0).getTable();
-
 
223
 
-
 
224
                        final SwingWorker<SQLRowValues, String> wworker = new SwingWorker<SQLRowValues, String>() {
-
 
225
 
-
 
226
                            @Override
-
 
227
                            protected SQLRowValues doInBackground() throws Exception {
-
 
228
                                SQLRowValues rArticle = new SQLRowValues(tArticle);
-
 
229
                                rArticle.putNulls(tArticle.getFieldsName());
-
 
230
                                for (SQLField f : tArticle.getFields()) {
-
 
231
                                    if (f.getName().startsWith("ID_ARTICLE_DECLINAISON_")) {
-
 
232
                                        SQLRowValues rowValsDecl = rArticle.putRowValues(f.getName());
-
 
233
                                        rowValsDecl.putNulls(f.getForeignTable().getFieldsName());
-
 
234
                                    }
-
 
235
                                }
-
 
236
 
-
 
237
                                final List<SQLRowValues> fetchRow = SQLRowValuesListFetcher.create(rArticle).fetch(new Where(tArticle.getKey(), "=", idProduct));
-
 
238
                                return fetchRow.get(0);
-
 
239
                            }
-
 
240
 
-
 
241
                            @Override
-
 
242
                            protected void done() {
-
 
243
                                try {
-
 
244
                                    final SQLRowValues values = get();
-
 
245
                                    p.initUI(values);
-
 
246
                                    f.setTitle(entry.getKey());
-
 
247
                                    f.setContentPane(p);
-
 
248
                                    f.pack();
-
 
249
                                    f.setLocationRelativeTo(null);
-
 
250
                                    f.setVisible(true);
-
 
251
 
-
 
252
                                } catch (Exception e) {
-
 
253
                                    ExceptionHandler.handle("Erreur d'impression", e);
-
 
254
                                }
-
 
255
                            }
-
 
256
                        };
-
 
257
                        wworker.execute();
-
 
258
 
-
 
259
                    }
-
 
260
                }, true, false);
-
 
261
 
-
 
262
                action.setPredicate(IListeEvent.createSelectionCountPredicate(1, 1));
-
 
263
                ctxt.getElement("ARTICLE").getRowActions().add(action);
-
 
264
            }
-
 
265
        }
-
 
266
 
-
 
267
        if (!gplTemplates.isEmpty()) {
-
 
268
            for (final Entry<String, String> entry : gplTemplates.entrySet()) {
-
 
269
                final String gpl = entry.getValue();
-
 
270
                final PredicateRowAction action = new PredicateRowAction(new AbstractAction("Imprimer l'étiquette " + entry.getKey()) {
-
 
271
 
-
 
272
                    @Override
-
 
273
                    public void actionPerformed(ActionEvent arg0) {
-
 
274
                        final GPLPrinterPanel p = new GPLPrinterPanel(gpl, getDir(entry.getKey()));
-
 
275
                        final JFrame f = new JFrame();
-
 
276
                        final IListe list = IListe.get(arg0);
-
 
277
                        final int idProduct = list.getSelection().getSelectedID();
217
                        final SQLTable tArticle = list.getSelectedRows().get(0).getTable();
278
                        final SQLTable tArticle = list.getSelectedRowAccessors().get(0).getTable();
218
 
279
 
219
                        final SwingWorker<SQLRowValues, String> wworker = new SwingWorker<SQLRowValues, String>() {
280
                        final SwingWorker<SQLRowValues, String> wworker = new SwingWorker<SQLRowValues, String>() {
220
 
281
 
221
                            @Override
282
                            @Override
222
                            protected SQLRowValues doInBackground() throws Exception {
283
                            protected SQLRowValues doInBackground() throws Exception {
Line 251... Line 312...
251
            }
312
            }
252
        }
313
        }
253
 
314
 
254
    }
315
    }
255
 
316
 
-
 
317
    protected File getDir(String value) {
-
 
318
        return dirMap.get(value);
-
 
319
    }
-
 
320
 
256
    @Override
321
    @Override
257
    protected void start() {
322
    protected void start() {
258
 
323
 
259
    }
324
    }
260
 
325
 
Line 262... Line 327...
262
        System.out.println("ModuleLabel.readTemplates() " + templatesDir.getAbsolutePath());
327
        System.out.println("ModuleLabel.readTemplates() " + templatesDir.getAbsolutePath());
263
        if (templatesDir.exists() && templatesDir.isDirectory()) {
328
        if (templatesDir.exists() && templatesDir.isDirectory()) {
264
            System.err.println("ModuleLabel.readTemplates() " + templatesDir.getAbsolutePath());
329
            System.err.println("ModuleLabel.readTemplates() " + templatesDir.getAbsolutePath());
265
            File[] files = templatesDir.listFiles();
330
            File[] files = templatesDir.listFiles();
266
            if (files != null) {
331
            if (files != null) {
-
 
332
                LinkedHashMap<String, String> zmap = new LinkedHashMap<>();
267
                LinkedHashMap<String, String> map = new LinkedHashMap<>();
333
                LinkedHashMap<String, String> gmap = new LinkedHashMap<>();
268
                for (File f : files) {
334
                for (File f : files) {
269
                    if (f.getName().endsWith(".zpl")) {
335
                    if (f.getName().endsWith(".zpl")) {
270
                        try {
336
                        try {
271
                            String zpl = FileUtils.read(f, StandardCharsets.UTF_8);
337
                            String zpl = FileUtils.read(f, StandardCharsets.UTF_8);
272
                            String name = f.getName().substring(0, f.getName().length() - 4).trim();
338
                            String name = f.getName().substring(0, f.getName().length() - 4).trim();
-
 
339
 
273
                            map.put(name, zpl);
340
                            zmap.put(name, zpl);
-
 
341
                            dirMap.put(name, templatesDir);
-
 
342
 
274
                            System.err.println("ModuleLabel.readTemplates() add " + name);
343
                            System.err.println("ModuleLabel.readTemplates() add " + name);
-
 
344
 
275
                        } catch (Exception e) {
345
                        } catch (Exception e) {
276
                            System.err.println(this.getClass().getCanonicalName() + "start() cannot read zpl template : " + f.getAbsolutePath() + " : " + e.getMessage());
346
                            System.err.println(this.getClass().getCanonicalName() + "start() cannot read zpl template : " + f.getAbsolutePath() + " : " + e.getMessage());
277
                        }
347
                        }
-
 
348
                    } else if (f.getName().endsWith(".graphicspl")) {
-
 
349
                        try {
-
 
350
                            String zpl = FileUtils.read(f, StandardCharsets.UTF_8);
-
 
351
                            String name = f.getName().substring(0, f.getName().length() - ".graphicspl".length()).trim();
-
 
352
                            gmap.put(name, zpl);
-
 
353
                            dirMap.put(name, templatesDir);
-
 
354
 
-
 
355
                        } catch (Exception e) {
-
 
356
                            System.err.println(this.getClass().getCanonicalName() + "start() cannot read graphicspl template : " + f.getAbsolutePath() + " : " + e.getMessage());
-
 
357
                        }
278
                    }
358
                    }
279
                }
359
                }
280
                // Tri de la map par clef
360
                // Tri de la map par clef
281
                final TreeMap<String, String> copy = new TreeMap<>(map);
361
                final TreeMap<String, String> copy1 = new TreeMap<>(zmap);
-
 
362
 
282
                this.zplTemplates.clear();
363
                zplTemplates.clear();
283
                this.zplTemplates.putAll(copy);
364
                zplTemplates.putAll(copy1);
-
 
365
 
-
 
366
                final TreeMap<String, String> copy2 = new TreeMap<>(gmap);
-
 
367
                gplTemplates.clear();
-
 
368
                gplTemplates.putAll(copy2);
-
 
369
 
284
            }
370
            }
285
 
371
 
286
        } else {
372
        } else {
287
            System.err.println("ModuleLabel.readTemplates() " + templatesDir.getAbsolutePath() + " missing");
373
            System.err.println("ModuleLabel.readTemplates() " + templatesDir.getAbsolutePath() + " missing");
288
        }
374
        }