OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 181 Rev 183
1
package org.openconcerto.modules.label;
1
package org.openconcerto.modules.label;
2
 
2
 
3
import java.awt.Color;
3
import java.awt.Color;
4
import java.awt.Graphics;
4
import java.awt.Graphics;
5
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionEvent;
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;
18
import javax.swing.SwingWorker;
20
import javax.swing.SwingWorker;
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;
29
import org.openconcerto.sql.model.Where;
32
import org.openconcerto.sql.model.Where;
30
import org.openconcerto.sql.view.list.IListe;
33
import org.openconcerto.sql.view.list.IListe;
31
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
34
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
32
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
35
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
33
import org.openconcerto.utils.ExceptionHandler;
36
import org.openconcerto.utils.ExceptionHandler;
34
import org.openconcerto.utils.FileUtils;
37
import org.openconcerto.utils.FileUtils;
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
 
45
    @Override
50
    @Override
46
    protected void setupComponents(ComponentsContext ctxt) {
51
    protected void setupComponents(ComponentsContext ctxt) {
47
        readTemplates(new File("Template/Labels"));
52
        readTemplates(new File("Template/Labels"));
48
        readTemplates(new File("Configuration/Template/Labels"));
53
        readTemplates(new File("Configuration/Template/Labels"));
49
 
54
 
50
        final String actionName = "Imprimer les étiquettes";
55
        final String actionName = "Imprimer les étiquettes";
51
        final PredicateRowAction aArticle = new PredicateRowAction(new AbstractAction(actionName) {
56
        final PredicateRowAction aArticle = new PredicateRowAction(new AbstractAction(actionName) {
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);
63
                        graph.putNulls("NOM", "PV_TTC");
68
                        graph.putNulls("NOM", "PV_TTC");
64
                        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
69
                        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
65
                        final List<SQLRowValues> rows = fetcher.fetch(new Where(tArticle.getKey(), selectedIDs));
70
                        final List<SQLRowValues> rows = fetcher.fetch(new Where(tArticle.getKey(), selectedIDs));
66
                        final List<RowValuesLabel> list = new ArrayList<>(rows.size());
71
                        final List<RowValuesLabel> list = new ArrayList<>(rows.size());
67
                        for (SQLRowValues row : rows) {
72
                        for (SQLRowValues row : rows) {
68
                            list.add(new RowValuesLabel(row));
73
                            list.add(new RowValuesLabel(row));
69
                        }
74
                        }
70
                        return list;
75
                        return list;
71
                    }
76
                    }
72
 
77
 
73
                    @Override
78
                    @Override
74
                    protected void done() {
79
                    protected void done() {
75
                        try {
80
                        try {
76
                            final List<RowValuesLabel> values = get();
81
                            final List<RowValuesLabel> values = get();
77
 
82
 
78
                            final LabelFrame f = new LabelFrame(values, new LabelRenderer() {
83
                            final LabelFrame f = new LabelFrame(values, new LabelRenderer() {
79
 
84
 
80
                                @Override
85
                                @Override
81
                                public void paintLabel(Graphics g, Label label, int x, int y, int gridWith, int gridHeight, float fontSize) {
86
                                public void paintLabel(Graphics g, Label label, int x, int y, int gridWith, int gridHeight, float fontSize) {
82
                                    g.setColor(Color.BLACK);
87
                                    g.setColor(Color.BLACK);
83
                                    g.setFont(g.getFont().deriveFont(fontSize));
88
                                    g.setFont(g.getFont().deriveFont(fontSize));
84
                                    // Labels borders
89
                                    // Labels borders
85
                                    final int hBorder = 12;
90
                                    final int hBorder = 12;
86
                                    final int vBorder = 8;
91
                                    final int vBorder = 8;
87
                                    // Product name
92
                                    // Product name
88
                                    SQLRowValues row = ((RowValuesLabel) label).getSQLRowValues();
93
                                    SQLRowValues row = ((RowValuesLabel) label).getSQLRowValues();
89
                                    final String text = row.getString("NOM");
94
                                    final String text = row.getString("NOM");
90
                                    final List<String> l = StringUtils.wrap(text, g.getFontMetrics(), gridWith - 2 * hBorder);
95
                                    final List<String> l = StringUtils.wrap(text, g.getFontMetrics(), gridWith - 2 * hBorder);
91
                                    final int lineHeight = g.getFontMetrics().getHeight();
96
                                    final int lineHeight = g.getFontMetrics().getHeight();
92
                                    int lineY = y;
97
                                    int lineY = y;
93
                                    final int margin = gridHeight - l.size() * lineHeight;
98
                                    final int margin = gridHeight - l.size() * lineHeight;
94
                                    if (margin > 0) {
99
                                    if (margin > 0) {
95
                                        lineY += margin / 2;
100
                                        lineY += margin / 2;
96
                                    }
101
                                    }
97
                                    for (String line : l) {
102
                                    for (String line : l) {
98
                                        g.drawString(line, x + hBorder, lineY);
103
                                        g.drawString(line, x + hBorder, lineY);
99
                                        lineY += lineHeight;
104
                                        lineY += lineHeight;
100
                                    }
105
                                    }
101
                                    // Price
106
                                    // Price
102
                                    g.setFont(g.getFont().deriveFont(fontSize + 2));
107
                                    g.setFont(g.getFont().deriveFont(fontSize + 2));
103
                                    final String price = GestionDevise.currencyToString(row.getBigDecimal("PV_TTC")) + " € TTC";
108
                                    final String price = GestionDevise.currencyToString(row.getBigDecimal("PV_TTC")) + " € TTC";
104
                                    final Rectangle2D r2 = g.getFont().getStringBounds(price, g.getFontMetrics().getFontRenderContext());
109
                                    final Rectangle2D r2 = g.getFont().getStringBounds(price, g.getFontMetrics().getFontRenderContext());
105
                                    g.drawString(price, x + (int) (gridWith - hBorder - r2.getWidth()), y + gridHeight - vBorder);
110
                                    g.drawString(price, x + (int) (gridWith - hBorder - r2.getWidth()), y + gridHeight - vBorder);
106
 
111
 
107
                                }
112
                                }
108
                            });
113
                            });
109
                            f.setTitle(actionName);
114
                            f.setTitle(actionName);
110
                            f.setLocationRelativeTo(null);
115
                            f.setLocationRelativeTo(null);
111
                            f.pack();
116
                            f.pack();
112
                            f.setResizable(false);
117
                            f.setResizable(false);
113
                            f.setVisible(true);
118
                            f.setVisible(true);
114
                        } catch (Exception e) {
119
                        } catch (Exception e) {
115
                            ExceptionHandler.handle("Erreur d'impression", e);
120
                            ExceptionHandler.handle("Erreur d'impression", e);
116
                        }
121
                        }
117
                    }
122
                    }
118
                };
123
                };
119
                wworker.execute();
124
                wworker.execute();
120
 
125
 
121
            }
126
            }
122
        }, true, false);
127
        }, true, false);
123
        final PredicateRowAction aClient = new PredicateRowAction(new AbstractAction(actionName) {
128
        final PredicateRowAction aClient = new PredicateRowAction(new AbstractAction(actionName) {
124
 
129
 
125
            @Override
130
            @Override
126
            public void actionPerformed(ActionEvent arg0) {
131
            public void actionPerformed(ActionEvent arg0) {
127
                final IListe list = IListe.get(arg0);
132
                final IListe list = IListe.get(arg0);
128
                final List<Integer> selectedIDs = list.getSelection().getSelectedIDs();
133
                final List<Integer> selectedIDs = list.getSelection().getSelectedIDs();
129
                final SQLTable tClient = list.getSelectedRows().get(0).getTable();
134
                final SQLTable tClient = list.getSelectedRows().get(0).getTable();
130
                final SwingWorker<List<RowValuesLabel>, String> wworker = new SwingWorker<List<RowValuesLabel>, String>() {
135
                final SwingWorker<List<RowValuesLabel>, String> wworker = new SwingWorker<List<RowValuesLabel>, String>() {
131
 
136
 
132
                    @Override
137
                    @Override
133
                    protected List<RowValuesLabel> doInBackground() throws Exception {
138
                    protected List<RowValuesLabel> doInBackground() throws Exception {
134
                        final SQLRowValues graph = new SQLRowValues(tClient);
139
                        final SQLRowValues graph = new SQLRowValues(tClient);
135
                        graph.putNulls("NOM");
140
                        graph.putNulls("NOM");
136
                        final SQLRowValues a1 = graph.putRowValues("ID_ADRESSE");
141
                        final SQLRowValues a1 = graph.putRowValues("ID_ADRESSE");
137
                        a1.putNulls(a1.getTable().getFieldsName());
142
                        a1.putNulls(a1.getTable().getFieldsName());
138
                        final SQLRowValues a2 = graph.putRowValues("ID_ADRESSE_L");
143
                        final SQLRowValues a2 = graph.putRowValues("ID_ADRESSE_L");
139
                        a2.putNulls(a2.getTable().getFieldsName());
144
                        a2.putNulls(a2.getTable().getFieldsName());
140
                        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
145
                        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(graph);
141
                        final List<SQLRowValues> rows = fetcher.fetch(new Where(tClient.getKey(), selectedIDs));
146
                        final List<SQLRowValues> rows = fetcher.fetch(new Where(tClient.getKey(), selectedIDs));
142
 
147
 
143
                        final List<RowValuesLabel> list = new ArrayList<>(rows.size());
148
                        final List<RowValuesLabel> list = new ArrayList<>(rows.size());
144
                        for (SQLRowValues row : rows) {
149
                        for (SQLRowValues row : rows) {
145
                            list.add(new RowValuesLabel(row));
150
                            list.add(new RowValuesLabel(row));
146
                        }
151
                        }
147
                        return list;
152
                        return list;
148
                    }
153
                    }
149
 
154
 
150
                    @Override
155
                    @Override
151
                    protected void done() {
156
                    protected void done() {
152
                        try {
157
                        try {
153
                            final List<RowValuesLabel> values = get();
158
                            final List<RowValuesLabel> values = get();
154
                            final LabelFrame f = new LabelFrame(values, new LabelRenderer() {
159
                            final LabelFrame f = new LabelFrame(values, new LabelRenderer() {
155
 
160
 
156
                                @Override
161
                                @Override
157
                                public void paintLabel(Graphics g, Label label, int x, int y, int gridWith, int gridHeight, float fontSize) {
162
                                public void paintLabel(Graphics g, Label label, int x, int y, int gridWith, int gridHeight, float fontSize) {
158
                                    SQLRowValues row = ((RowValuesLabel) label).getSQLRowValues();
163
                                    SQLRowValues row = ((RowValuesLabel) label).getSQLRowValues();
159
                                    SQLRowAccessor rAddr = row.getForeign("ID_ADRESSE_L");
164
                                    SQLRowAccessor rAddr = row.getForeign("ID_ADRESSE_L");
160
                                    if (rAddr == null || rAddr.isUndefined()) {
165
                                    if (rAddr == null || rAddr.isUndefined()) {
161
                                        rAddr = row.getForeign("ID_ADRESSE");
166
                                        rAddr = row.getForeign("ID_ADRESSE");
162
                                    }
167
                                    }
163
                                    if (rAddr == null || rAddr.isUndefined()) {
168
                                    if (rAddr == null || rAddr.isUndefined()) {
164
                                        return;
169
                                        return;
165
                                    }
170
                                    }
166
 
171
 
167
                                    String text = AdresseFullClientValueProvider.getFormattedAddress(rAddr, row.getString("NOM") + "\n");
172
                                    String text = AdresseFullClientValueProvider.getFormattedAddress(rAddr, row.getString("NOM") + "\n");
168
 
173
 
169
                                    // Default font at 10pt black
174
                                    // Default font at 10pt black
170
                                    g.setColor(Color.BLACK);
175
                                    g.setColor(Color.BLACK);
171
                                    g.setFont(g.getFont().deriveFont(fontSize));
176
                                    g.setFont(g.getFont().deriveFont(fontSize));
172
                                    // Labels borders
177
                                    // Labels borders
173
                                    final int hBorder = 12;
178
                                    final int hBorder = 12;
174
                                    // Product name
179
                                    // Product name
175
                                    final List<String> l = StringUtils.wrap(text, g.getFontMetrics(), gridWith - 2 * hBorder);
180
                                    final List<String> l = StringUtils.wrap(text, g.getFontMetrics(), gridWith - 2 * hBorder);
176
                                    final int lineHeight = g.getFontMetrics().getHeight();
181
                                    final int lineHeight = g.getFontMetrics().getHeight();
177
                                    int lineY = y + lineHeight + 4;
182
                                    int lineY = y + lineHeight + 4;
178
                                    for (String line : l) {
183
                                    for (String line : l) {
179
                                        g.drawString(line, x + hBorder, lineY);
184
                                        g.drawString(line, x + hBorder, lineY);
180
                                        lineY += lineHeight;
185
                                        lineY += lineHeight;
181
                                    }
186
                                    }
182
 
187
 
183
                                }
188
                                }
184
                            });
189
                            });
185
                            f.setTitle(actionName);
190
                            f.setTitle(actionName);
186
                            f.setLocationRelativeTo(null);
191
                            f.setLocationRelativeTo(null);
187
                            f.pack();
192
                            f.pack();
188
                            f.setResizable(false);
193
                            f.setResizable(false);
189
                            f.setVisible(true);
194
                            f.setVisible(true);
190
 
195
 
191
                        } catch (Exception e) {
196
                        } catch (Exception e) {
192
                            ExceptionHandler.handle("Erreur d'impression", e);
197
                            ExceptionHandler.handle("Erreur d'impression", e);
193
                        }
198
                        }
194
                    }
199
                    }
195
                };
200
                };
196
                wworker.execute();
201
                wworker.execute();
197
 
202
 
198
            }
203
            }
199
        }, true, false);
204
        }, true, false);
200
 
205
 
201
        aArticle.setPredicate(IListeEvent.createSelectionCountPredicate(1, Integer.MAX_VALUE));
206
        aArticle.setPredicate(IListeEvent.createSelectionCountPredicate(1, Integer.MAX_VALUE));
202
        aClient.setPredicate(IListeEvent.createSelectionCountPredicate(1, Integer.MAX_VALUE));
207
        aClient.setPredicate(IListeEvent.createSelectionCountPredicate(1, Integer.MAX_VALUE));
203
        ctxt.getElement("ARTICLE").getRowActions().add(aArticle);
208
        ctxt.getElement("ARTICLE").getRowActions().add(aArticle);
204
        ctxt.getElement("CLIENT").getRowActions().add(aClient);
209
        ctxt.getElement("CLIENT").getRowActions().add(aClient);
205
 
210
 
206
        if (!this.zplTemplates.isEmpty()) {
211
        if (!this.zplTemplates.isEmpty()) {
207
            for (final Entry<String, String> entry : this.zplTemplates.entrySet()) {
212
            for (final Entry<String, String> entry : this.zplTemplates.entrySet()) {
208
                final String zpl = entry.getValue();
213
                final String zpl = entry.getValue();
209
                final PredicateRowAction action = new PredicateRowAction(new AbstractAction("Imprimer l'étiquette " + entry.getKey()) {
214
                final PredicateRowAction action = new PredicateRowAction(new AbstractAction("Imprimer l'étiquette " + entry.getKey()) {
210
 
215
 
211
                    @Override
216
                    @Override
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 {
223
                                final SQLRow row = tArticle.getRow(idProduct);
284
                                final SQLRow row = tArticle.getRow(idProduct);
224
                                row.fetchValues();
285
                                row.fetchValues();
225
                                return row.asRowValues();
286
                                return row.asRowValues();
226
                            }
287
                            }
227
 
288
 
228
                            @Override
289
                            @Override
229
                            protected void done() {
290
                            protected void done() {
230
                                try {
291
                                try {
231
                                    final SQLRowValues values = get();
292
                                    final SQLRowValues values = get();
232
                                    p.initUI(values);
293
                                    p.initUI(values);
233
                                    f.setTitle(entry.getKey());
294
                                    f.setTitle(entry.getKey());
234
                                    f.setContentPane(p);
295
                                    f.setContentPane(p);
235
                                    f.pack();
296
                                    f.pack();
236
                                    f.setLocationRelativeTo(null);
297
                                    f.setLocationRelativeTo(null);
237
                                    f.setVisible(true);
298
                                    f.setVisible(true);
238
 
299
 
239
                                } catch (Exception e) {
300
                                } catch (Exception e) {
240
                                    ExceptionHandler.handle("Erreur d'impression", e);
301
                                    ExceptionHandler.handle("Erreur d'impression", e);
241
                                }
302
                                }
242
                            }
303
                            }
243
                        };
304
                        };
244
                        wworker.execute();
305
                        wworker.execute();
245
 
306
 
246
                    }
307
                    }
247
                }, true, false);
308
                }, true, false);
248
 
309
 
249
                action.setPredicate(IListeEvent.createSelectionCountPredicate(1, 1));
310
                action.setPredicate(IListeEvent.createSelectionCountPredicate(1, 1));
250
                ctxt.getElement("ARTICLE").getRowActions().add(action);
311
                ctxt.getElement("ARTICLE").getRowActions().add(action);
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
 
261
    private void readTemplates(File templatesDir) {
326
    private void readTemplates(File templatesDir) {
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
        }
289
    }
375
    }
290
 
376
 
291
    @Override
377
    @Override
292
    protected void stop() {
378
    protected void stop() {
293
        // nothing
379
        // nothing
294
    }
380
    }
295
}
381
}