OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 147 Rev 160
1
package org.openconcerto.modules.customerrelationship.lead;
1
package org.openconcerto.modules.customerrelationship.lead;
2
 
2
 
3
import java.awt.event.ActionEvent;
3
import java.awt.event.ActionEvent;
4
import java.sql.SQLException;
4
import java.sql.SQLException;
5
import java.util.ArrayList;
5
import java.util.ArrayList;
6
import java.util.Calendar;
6
import java.util.Calendar;
7
import java.util.Date;
7
import java.util.Date;
8
import java.util.List;
8
import java.util.List;
9
import java.util.Set;
9
import java.util.Set;
10
 
10
 
11
import javax.swing.AbstractAction;
11
import javax.swing.AbstractAction;
12
import javax.swing.JOptionPane;
12
import javax.swing.JOptionPane;
13
 
13
 
14
import org.openconcerto.erp.modules.AbstractModule;
14
import org.openconcerto.erp.modules.AbstractModule;
15
import org.openconcerto.erp.modules.ModuleElement;
15
import org.openconcerto.erp.modules.ModuleElement;
16
import org.openconcerto.sql.Configuration;
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.element.GlobalMapper;
17
import org.openconcerto.sql.element.GlobalMapper;
18
import org.openconcerto.sql.element.SQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.model.FieldPath;
20
import org.openconcerto.sql.model.FieldPath;
21
import org.openconcerto.sql.model.SQLField;
21
import org.openconcerto.sql.model.SQLField;
22
import org.openconcerto.sql.model.SQLInjector;
22
import org.openconcerto.sql.model.SQLInjector;
23
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRowAccessor;
24
import org.openconcerto.sql.model.SQLRowAccessor;
25
import org.openconcerto.sql.model.SQLRowValues;
25
import org.openconcerto.sql.model.SQLRowValues;
26
import org.openconcerto.sql.model.SQLSelect;
26
import org.openconcerto.sql.model.SQLSelect;
27
import org.openconcerto.sql.model.SQLTable;
27
import org.openconcerto.sql.model.SQLTable;
28
import org.openconcerto.sql.model.Where;
28
import org.openconcerto.sql.model.Where;
29
import org.openconcerto.sql.model.graph.Path;
29
import org.openconcerto.sql.model.graph.Path;
30
import org.openconcerto.sql.users.User;
-
 
31
import org.openconcerto.sql.users.UserManager;
30
import org.openconcerto.sql.users.UserManager;
32
import org.openconcerto.sql.users.rights.UserRights;
-
 
33
import org.openconcerto.sql.users.rights.UserRightsManager;
31
import org.openconcerto.sql.users.rights.UserRightsManager;
34
import org.openconcerto.sql.view.EditFrame;
32
import org.openconcerto.sql.view.EditFrame;
35
import org.openconcerto.sql.view.EditPanel.EditMode;
33
import org.openconcerto.sql.view.EditPanel.EditMode;
36
import org.openconcerto.sql.view.EditPanelListener;
34
import org.openconcerto.sql.view.EditPanelListener;
37
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
35
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
38
import org.openconcerto.sql.view.list.IListe;
36
import org.openconcerto.sql.view.list.IListe;
39
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
37
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
40
import org.openconcerto.sql.view.list.RowAction;
38
import org.openconcerto.sql.view.list.RowAction;
41
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
39
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
42
import org.openconcerto.sql.view.list.SQLTableModelSource;
40
import org.openconcerto.sql.view.list.SQLTableModelSource;
43
import org.openconcerto.ui.EmailComposer;
41
import org.openconcerto.ui.EmailComposer;
44
import org.openconcerto.ui.FrameUtil;
42
import org.openconcerto.ui.FrameUtil;
45
import org.openconcerto.ui.group.Group;
43
import org.openconcerto.ui.group.Group;
46
import org.openconcerto.utils.CollectionUtils;
44
import org.openconcerto.utils.CollectionUtils;
47
import org.openconcerto.utils.ExceptionHandler;
45
import org.openconcerto.utils.ExceptionHandler;
48
import org.openconcerto.utils.ListMap;
46
import org.openconcerto.utils.ListMap;
49
import org.openconcerto.utils.cc.ITransformer;
47
import org.openconcerto.utils.cc.ITransformer;
50
 
48
 
51
public class LeadSQLElement extends ModuleElement {
49
public class LeadSQLElement extends ModuleElement {
52
    public static final String ELEMENT_CODE = "customerrelationship.lead";
50
    public static final String ELEMENT_CODE = "customerrelationship.lead";
53
    public static String CODE_NOT_RESTRICT = "VIEW_ALL_LEADS";
51
    public static String CODE_NOT_RESTRICT = "VIEW_ALL_LEADS";
54
 
52
 
55
    public LeadSQLElement(final AbstractModule module) {
53
    public LeadSQLElement(final AbstractModule module) {
56
        super(module, Module.TABLE_LEAD);
54
        super(module, Module.TABLE_LEAD);
57
        this.setL18nLocation(LeadSQLElement.class);
-
 
58
 
55
 
59
        // Call
56
        // Call
60
        final RowAction.PredicateRowAction addCallAction = new RowAction.PredicateRowAction(new AbstractAction("Appeler") {
57
        final RowAction.PredicateRowAction addCallAction = new RowAction.PredicateRowAction(new AbstractAction("Appeler") {
61
 
58
 
62
            @Override
59
            @Override
63
            public void actionPerformed(ActionEvent e) {
60
            public void actionPerformed(ActionEvent e) {
64
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
61
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
65
                final SQLTable table = LeadSQLElement.this.getTable().getTable(Module.TABLE_LEAD_CALL);
62
                final SQLTable table = LeadSQLElement.this.getTable().getTable(Module.TABLE_LEAD_CALL);
66
                final SQLElement eCall = LeadSQLElement.this.getDirectory().getElement(table);
63
                final SQLElement eCall = LeadSQLElement.this.getDirectory().getElement(table);
67
                EditFrame editFrame = new EditFrame(eCall);
64
                EditFrame editFrame = new EditFrame(eCall);
68
                final SQLRowValues sqlRowValues = new SQLRowValues(table);
65
                final SQLRowValues sqlRowValues = new SQLRowValues(table);
69
                sqlRowValues.put("ID_LEAD", sRow.getIDNumber());
66
                sqlRowValues.put("ID_LEAD", sRow.getIDNumber());
70
                editFrame.getSQLComponent().select(sqlRowValues);
67
                editFrame.getSQLComponent().select(sqlRowValues);
71
                FrameUtil.show(editFrame);
68
                FrameUtil.show(editFrame);
72
            }
69
            }
73
        }, true) {
70
        }, true) {
74
        };
71
        };
75
        addCallAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
72
        addCallAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
76
        getRowActions().add(addCallAction);
73
        getRowActions().add(addCallAction);
77
        // Visit
74
        // Visit
78
        final RowAction.PredicateRowAction addVisitAction = new RowAction.PredicateRowAction(new AbstractAction("Enregister une visite") {
75
        final RowAction.PredicateRowAction addVisitAction = new RowAction.PredicateRowAction(new AbstractAction("Enregister une visite") {
79
 
76
 
80
            @Override
77
            @Override
81
            public void actionPerformed(ActionEvent e) {
78
            public void actionPerformed(ActionEvent e) {
82
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
79
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
83
                final SQLTable table = LeadSQLElement.this.getTable().getTable(Module.TABLE_LEAD_VISIT);
80
                final SQLTable table = LeadSQLElement.this.getTable().getTable(Module.TABLE_LEAD_VISIT);
84
                final SQLElement eCall = LeadSQLElement.this.getDirectory().getElement(table);
81
                final SQLElement eCall = LeadSQLElement.this.getDirectory().getElement(table);
85
                EditFrame editFrame = new EditFrame(eCall);
82
                EditFrame editFrame = new EditFrame(eCall);
86
                final SQLRowValues sqlRowValues = new SQLRowValues(table);
83
                final SQLRowValues sqlRowValues = new SQLRowValues(table);
87
                sqlRowValues.put("ID_LEAD", sRow.getIDNumber());
84
                sqlRowValues.put("ID_LEAD", sRow.getIDNumber());
88
                editFrame.getSQLComponent().select(sqlRowValues);
85
                editFrame.getSQLComponent().select(sqlRowValues);
89
                FrameUtil.show(editFrame);
86
                FrameUtil.show(editFrame);
90
            }
87
            }
91
        }, true) {
88
        }, true) {
92
        };
89
        };
93
        addVisitAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
90
        addVisitAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
94
        getRowActions().add(addVisitAction);
91
        getRowActions().add(addVisitAction);
95
 
92
 
96
        setRowActions();
93
        setRowActions();
97
    }
94
    }
98
 
95
 
99
    @Override
96
    @Override
100
    protected void _initTableSource(SQLTableModelSource source) {
97
    protected void _initTableSource(SQLTableModelSource source) {
101
 
98
 
102
        super._initTableSource(source);
99
        super._initTableSource(source);
103
 
100
 
104
        if (!UserRightsManager.getCurrentUserRights().haveRight(LeadSQLElement.CODE_NOT_RESTRICT)) {
101
        if (!UserRightsManager.getCurrentUserRights().haveRight(LeadSQLElement.CODE_NOT_RESTRICT)) {
105
            final SQLRow row = Configuration.getInstance().getRoot().findTable("USER_COMMON").getRow(UserManager.getInstance().getCurrentUser().getId());
102
            final SQLRow row = Configuration.getInstance().getRoot().findTable("USER_COMMON").getRow(UserManager.getInstance().getCurrentUser().getId());
106
            final List<SQLRow> rows = row.getReferentRows(Configuration.getInstance().getRoot().findTable("COMMERCIAL").getField("ID_USER_COMMON"));
103
            final List<SQLRow> rows = row.getReferentRows(Configuration.getInstance().getRoot().findTable("COMMERCIAL").getField("ID_USER_COMMON"));
107
            final List<Integer> listComm = new ArrayList<Integer>();
104
            final List<Integer> listComm = new ArrayList<Integer>();
108
            for (SQLRow sqlRow : rows) {
105
            for (SQLRow sqlRow : rows) {
109
                listComm.add(sqlRow.getID());
106
                listComm.add(sqlRow.getID());
110
            }
107
            }
111
            if (!listComm.isEmpty()) {
108
            if (!listComm.isEmpty()) {
112
                source.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
109
                source.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
113
 
110
 
114
                    @Override
111
                    @Override
115
                    public SQLSelect transformChecked(SQLSelect input) {
112
                    public SQLSelect transformChecked(SQLSelect input) {
116
                        final SQLField field = input.getTable(Module.TABLE_LEAD).getField("ID_COMMERCIAL");
113
                        final SQLField field = input.getTable(Module.TABLE_LEAD).getField("ID_COMMERCIAL");
117
                        Where w = new Where(field, listComm);
114
                        Where w = new Where(field, listComm);
118
                        w = w.or(new Where(field, "IS", (Object) null));
115
                        w = w.or(new Where(field, "IS", (Object) null));
119
                        w = w.or(new Where(field, "=", getTable().getTable("COMMERCIAL").getUndefinedID()));
116
                        w = w.or(new Where(field, "=", getTable().getTable("COMMERCIAL").getUndefinedID()));
120
                        input.setWhere(w);
117
                        input.setWhere(w);
121
                        return input;
118
                        return input;
122
                    }
119
                    }
123
                });
120
                });
124
            }
121
            }
125
        }
122
        }
126
 
123
 
127
        BaseSQLTableModelColumn adresse = new BaseSQLTableModelColumn("Adresse", String.class) {
124
        BaseSQLTableModelColumn adresse = new BaseSQLTableModelColumn("Adresse", String.class) {
128
 
125
 
129
            @Override
126
            @Override
130
            protected Object show_(SQLRowAccessor r) {
127
            protected Object show_(SQLRowAccessor r) {
131
                final SQLRowAccessor rAdr = r.getForeign("ID_ADRESSE");
128
                final SQLRowAccessor rAdr = r.getForeign("ID_ADRESSE");
132
                if (rAdr != null && !rAdr.isUndefined()) {
129
                if (rAdr != null && !rAdr.isUndefined()) {
133
                    return rAdr.getString("RUE");
130
                    return rAdr.getString("RUE");
134
                }
131
                }
135
                return "";
132
                return "";
136
            }
133
            }
137
 
134
 
138
            @Override
135
            @Override
139
            public Set<FieldPath> getPaths() {
136
            public Set<FieldPath> getPaths() {
140
                Path p = new Path(getTable());
137
                Path p = new Path(getTable());
141
                p = p.add(getTable().getTable("ADRESSE"));
138
                p = p.add(getTable().getTable("ADRESSE"));
142
                return CollectionUtils.createSet(new FieldPath(p, "RUE"));
139
                return CollectionUtils.createSet(new FieldPath(p, "RUE"));
143
            }
140
            }
144
        };
141
        };
145
        source.getColumns().add(adresse);
142
        source.getColumns().add(adresse);
146
 
143
 
147
        BaseSQLTableModelColumn cp = new BaseSQLTableModelColumn("Code Postal", String.class) {
144
        BaseSQLTableModelColumn cp = new BaseSQLTableModelColumn("Code Postal", String.class) {
148
 
145
 
149
            @Override
146
            @Override
150
            protected Object show_(SQLRowAccessor r) {
147
            protected Object show_(SQLRowAccessor r) {
151
                SQLRowAccessor rAdr = r.getForeign("ID_ADRESSE");
148
                SQLRowAccessor rAdr = r.getForeign("ID_ADRESSE");
152
                if (rAdr != null && !rAdr.isUndefined()) {
149
                if (rAdr != null && !rAdr.isUndefined()) {
153
 
150
 
154
                    return rAdr.getString("CODE_POSTAL");
151
                    return rAdr.getString("CODE_POSTAL");
155
                }
152
                }
156
 
153
 
157
                return "";
154
                return "";
158
 
155
 
159
            }
156
            }
160
 
157
 
161
            @Override
158
            @Override
162
            public Set<FieldPath> getPaths() {
159
            public Set<FieldPath> getPaths() {
163
                Path p = new Path(getTable());
160
                Path p = new Path(getTable());
164
                p = p.add(getTable().getTable("ADRESSE"));
161
                p = p.add(getTable().getTable("ADRESSE"));
165
 
162
 
166
                return CollectionUtils.createSet(new FieldPath(p, "CODE_POSTAL"));
163
                return CollectionUtils.createSet(new FieldPath(p, "CODE_POSTAL"));
167
            }
164
            }
168
        };
165
        };
169
        source.getColumns().add(cp);
166
        source.getColumns().add(cp);
170
 
167
 
171
        BaseSQLTableModelColumn ville = new BaseSQLTableModelColumn("Ville", String.class) {
168
        BaseSQLTableModelColumn ville = new BaseSQLTableModelColumn("Ville", String.class) {
172
 
169
 
173
            @Override
170
            @Override
174
            protected Object show_(SQLRowAccessor r) {
171
            protected Object show_(SQLRowAccessor r) {
175
 
172
 
176
                SQLRowAccessor rAdr = r.getForeign("ID_ADRESSE");
173
                SQLRowAccessor rAdr = r.getForeign("ID_ADRESSE");
177
                if (rAdr != null && !rAdr.isUndefined()) {
174
                if (rAdr != null && !rAdr.isUndefined()) {
178
 
175
 
179
                    return rAdr.getString("VILLE");
176
                    return rAdr.getString("VILLE");
180
                }
177
                }
181
                return "";
178
                return "";
182
 
179
 
183
            }
180
            }
184
 
181
 
185
            @Override
182
            @Override
186
            public Set<FieldPath> getPaths() {
183
            public Set<FieldPath> getPaths() {
187
                Path p = new Path(getTable());
184
                Path p = new Path(getTable());
188
                p = p.add(getTable().getTable("ADRESSE"));
185
                p = p.add(getTable().getTable("ADRESSE"));
189
 
186
 
190
                return CollectionUtils.createSet(new FieldPath(p, "VILLE"));
187
                return CollectionUtils.createSet(new FieldPath(p, "VILLE"));
191
            }
188
            }
192
        };
189
        };
193
        source.getColumns().add(ville);
190
        source.getColumns().add(ville);
194
 
191
 
195
        if (getTable().contains("REMIND_DATE")) {
192
        if (getTable().contains("REMIND_DATE")) {
196
            BaseSQLTableModelColumn dateRemind = new BaseSQLTableModelColumn("Date de rappel", Date.class) {
193
            BaseSQLTableModelColumn dateRemind = new BaseSQLTableModelColumn("Date de rappel", Date.class) {
197
 
194
 
198
                @Override
195
                @Override
199
                protected Object show_(SQLRowAccessor r) {
196
                protected Object show_(SQLRowAccessor r) {
200
 
197
 
201
                    Calendar c = r.getDate("REMIND_DATE");
198
                    Calendar c = r.getDate("REMIND_DATE");
202
                    if (c == null) {
199
                    if (c == null) {
203
                        return null;
200
                        return null;
204
                    } else {
201
                    } else {
205
                        return c.getTime();
202
                        return c.getTime();
206
                    }
203
                    }
207
 
204
 
208
                }
205
                }
209
 
206
 
210
                @Override
207
                @Override
211
                public Set<FieldPath> getPaths() {
208
                public Set<FieldPath> getPaths() {
212
                    Path p = new Path(getTable());
209
                    Path p = new Path(getTable());
213
                    return CollectionUtils.createSet(new FieldPath(p, "REMIND_DATE"));
210
                    return CollectionUtils.createSet(new FieldPath(p, "REMIND_DATE"));
214
                }
211
                }
215
            };
212
            };
216
 
213
 
217
            dateRemind.setRenderer(new RemindDateRenderer());
214
            dateRemind.setRenderer(new RemindDateRenderer());
218
            source.getColumns().add(dateRemind);
215
            source.getColumns().add(dateRemind);
219
 
216
 
220
        }
217
        }
221
    }
218
    }
222
 
219
 
223
    private void setRowActions() {
220
    private void setRowActions() {
224
 
221
 
225
        AbstractAction action = new AbstractAction("Transférer en client") {
222
        AbstractAction action = new AbstractAction("Transférer en client") {
226
 
223
 
227
            @Override
224
            @Override
228
            public void actionPerformed(ActionEvent e) {
225
            public void actionPerformed(ActionEvent e) {
229
 
226
 
230
                final SQLRow row = IListe.get(e).getSelectedRow().asRow();
227
                final SQLRow row = IListe.get(e).getSelectedRow().asRow();
231
 
228
 
232
                SQLRowAccessor foreign = row.getForeign("ID_CLIENT");
229
                SQLRowAccessor foreign = row.getForeign("ID_CLIENT");
233
                if (foreign == null || foreign.isUndefined()) {
230
                if (foreign == null || foreign.isUndefined()) {
234
 
231
 
235
                    // Client
232
                    // Client
236
                    SQLRowValues rowVals = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("CLIENT")).createRowValuesFrom(row);
233
                    SQLRowValues rowVals = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("CLIENT")).createRowValuesFrom(row);
237
 
234
 
238
                    SQLRowAccessor adresse = row.getForeign("ID_ADRESSE");
235
                    SQLRowAccessor adresse = row.getForeign("ID_ADRESSE");
239
                    if (adresse != null && !adresse.isUndefined()) {
236
                    if (adresse != null && !adresse.isUndefined()) {
240
                        SQLRowValues rowValsAdr = new SQLRowValues(adresse.asRowValues());
237
                        SQLRowValues rowValsAdr = new SQLRowValues(adresse.asRowValues());
241
                        // rowValsAdr.clearPrimaryKeys();
238
                        // rowValsAdr.clearPrimaryKeys();
242
                        rowVals.put("ID_ADRESSE", rowValsAdr);
239
                        rowVals.put("ID_ADRESSE", rowValsAdr);
243
                    }
240
                    }
244
 
241
 
245
                    // Contact
242
                    // Contact
246
                    SQLRowValues rowValsContact = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("CONTACT")).createRowValuesFrom(row);
243
                    SQLRowValues rowValsContact = SQLInjector.getInjector(row.getTable(), row.getTable().getTable("CONTACT")).createRowValuesFrom(row);
247
                    rowValsContact.put("ID_CLIENT", rowVals);
244
                    rowValsContact.put("ID_CLIENT", rowVals);
248
 
245
 
249
                    EditFrame frame = new EditFrame(Configuration.getInstance().getDirectory().getElement("CLIENT"), EditMode.CREATION);
246
                    EditFrame frame = new EditFrame(Configuration.getInstance().getDirectory().getElement("CLIENT"), EditMode.CREATION);
250
                    frame.getSQLComponent().select(rowVals);
247
                    frame.getSQLComponent().select(rowVals);
251
                    frame.setVisible(true);
248
                    frame.setVisible(true);
252
 
249
 
253
                    frame.addEditPanelListener(new EditPanelListener() {
250
                    frame.addEditPanelListener(new EditPanelListener() {
254
 
251
 
255
                        @Override
252
                        @Override
256
                        public void modified() {
253
                        public void modified() {
257
                        }
254
                        }
258
 
255
 
259
                        @Override
256
                        @Override
260
                        public void inserted(int id) {
257
                        public void inserted(int id) {
261
                            SQLRowValues rowVals = row.asRowValues();
258
                            SQLRowValues rowVals = row.asRowValues();
262
                            rowVals.put("ID_CLIENT", id);
259
                            rowVals.put("ID_CLIENT", id);
263
                            rowVals.put("STATUS", "Acquis");
260
                            rowVals.put("STATUS", "Acquis");
264
                            try {
261
                            try {
265
                                rowVals.commit();
262
                                rowVals.commit();
266
                            } catch (SQLException exn) {
263
                            } catch (SQLException exn) {
267
                                exn.printStackTrace();
264
                                exn.printStackTrace();
268
                            }
265
                            }
269
                        }
266
                        }
270
 
267
 
271
                        @Override
268
                        @Override
272
                        public void deleted() {
269
                        public void deleted() {
273
                        }
270
                        }
274
 
271
 
275
                        @Override
272
                        @Override
276
                        public void cancelled() {
273
                        public void cancelled() {
277
                        }
274
                        }
278
                    });
275
                    });
279
                } else {
276
                } else {
280
                    JOptionPane.showMessageDialog(null, "Ce prospect a déjà été transféré en client!");
277
                    JOptionPane.showMessageDialog(null, "Ce prospect a déjà été transféré en client!");
281
                }
278
                }
282
            }
279
            }
283
        };
280
        };
284
        PredicateRowAction transfertClient = new PredicateRowAction(action, true);
281
        PredicateRowAction transfertClient = new PredicateRowAction(action, true);
285
        transfertClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
282
        transfertClient.setPredicate(IListeEvent.getSingleSelectionPredicate());
286
        this.getRowActions().add(transfertClient);
283
        this.getRowActions().add(transfertClient);
287
 
284
 
288
        AbstractAction actionMail = new AbstractAction("Envoyer un e-mail") {
285
        AbstractAction actionMail = new AbstractAction("Envoyer un e-mail") {
289
 
286
 
290
            @Override
287
            @Override
291
            public void actionPerformed(ActionEvent e) {
288
            public void actionPerformed(ActionEvent e) {
292
 
289
 
293
                sendMail(IListe.get(e).getSelectedRows());
290
                sendMail(IListe.get(e).getSelectedRows());
294
 
291
 
295
            }
292
            }
296
        };
293
        };
297
        PredicateRowAction mail = new PredicateRowAction(actionMail, true);
294
        PredicateRowAction mail = new PredicateRowAction(actionMail, true);
298
        mail.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
295
        mail.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
299
        this.getRowActions().add(mail);
296
        this.getRowActions().add(mail);
300
    }
297
    }
301
 
298
 
302
    protected void sendMail(List<SQLRowValues> l) {
299
    protected void sendMail(List<SQLRowValues> l) {
303
 
300
 
304
        String mail = "";
301
        String mail = "";
305
 
302
 
306
        // #endif
303
        // #endif
307
        for (SQLRowAccessor rowCli : l) {
304
        for (SQLRowAccessor rowCli : l) {
308
            String string = rowCli.getString("EMAIL");
305
            String string = rowCli.getString("EMAIL");
309
            if (string != null && string.trim().length() > 0) {
306
            if (string != null && string.trim().length() > 0) {
310
                mail += string + ";";
307
                mail += string + ";";
311
            }
308
            }
312
        }
309
        }
313
 
310
 
314
        try {
311
        try {
315
            EmailComposer.getInstance().compose(mail, "", "");
312
            EmailComposer.getInstance().compose(mail, "", "");
316
        } catch (Exception exn) {
313
        } catch (Exception exn) {
317
            ExceptionHandler.handle(null, "Impossible de créer le courriel", exn);
314
            ExceptionHandler.handle(null, "Impossible de créer le courriel", exn);
318
        }
315
        }
319
 
316
 
320
    }
317
    }
321
 
318
 
322
    @Override
319
    @Override
323
    protected String createCode() {
320
    protected String createCode() {
324
        return ELEMENT_CODE;
321
        return ELEMENT_CODE;
325
    }
322
    }
326
 
323
 
327
    @Override
324
    @Override
328
    protected List<String> getListFields() {
325
    protected List<String> getListFields() {
329
        final List<String> l = new ArrayList<String>();
326
        final List<String> l = new ArrayList<String>();
330
        l.add("ID_COMMERCIAL");
327
        l.add("ID_COMMERCIAL");
331
        l.add("DATE");
328
        l.add("DATE");
332
        l.add("COMPANY");
329
        l.add("COMPANY");
333
        l.add("LOCALISATION");
330
        l.add("LOCALISATION");
334
        l.add("ID_TITRE_PERSONNEL");
331
        l.add("ID_TITRE_PERSONNEL");
335
        l.add("NAME");
332
        l.add("NAME");
336
        l.add("FIRSTNAME");
333
        l.add("FIRSTNAME");
337
        l.add("PHONE");
334
        l.add("PHONE");
338
        l.add("MOBILE");
335
        l.add("MOBILE");
339
        l.add("EMAIL");
336
        l.add("EMAIL");
340
        l.add("SOURCE");
337
        l.add("SOURCE");
341
        l.add("INFORMATION");
338
        l.add("INFORMATION");
342
        l.add("INFOS");
339
        l.add("INFOS");
343
        // l.add("REMIND_DATE");
340
        // l.add("REMIND_DATE");
344
        return l;
341
        return l;
345
    }
342
    }
346
 
343
 
347
    @Override
344
    @Override
348
    protected List<String> getComboFields() {
345
    protected List<String> getComboFields() {
349
        final List<String> l = new ArrayList<String>();
346
        final List<String> l = new ArrayList<String>();
350
        l.add("COMPANY");
347
        l.add("COMPANY");
351
        l.add("FIRSTNAME");
348
        l.add("FIRSTNAME");
352
        l.add("NAME");
349
        l.add("NAME");
353
        return l;
350
        return l;
354
    }
351
    }
355
 
352
 
356
    @Override
353
    @Override
357
    protected List<String> getPrivateFields() {
354
    protected List<String> getPrivateFields() {
358
        final List<String> l = new ArrayList<String>();
355
        final List<String> l = new ArrayList<String>();
359
        l.add("ID_ADRESSE");
356
        l.add("ID_ADRESSE");
360
        return l;
357
        return l;
361
    }
358
    }
362
 
359
 
363
    @Override
360
    @Override
364
    public ListMap<String, String> getShowAs() {
361
    public ListMap<String, String> getShowAs() {
365
        return ListMap.singleton(null, getComboFields());
362
        return ListMap.singleton(null, getComboFields());
366
    }
363
    }
367
 
364
 
368
    @Override
365
    @Override
369
    public SQLComponent createComponent() {
366
    public SQLComponent createComponent() {
370
        final String groupId = this.getCode() + ".default";
367
        final String groupId = this.getCode() + ".default";
371
        final Group group = GlobalMapper.getInstance().getGroup(groupId);
368
        final Group group = GlobalMapper.getInstance().getGroup(groupId);
372
        if (group == null) {
369
        if (group == null) {
373
            throw new IllegalStateException("No group found for id " + groupId);
370
            throw new IllegalStateException("No group found for id " + groupId);
374
        }
371
        }
375
        return createComponent(group);
372
        return createComponent(group);
376
    }
373
    }
377
 
374
 
378
    protected SQLComponent createComponent(final Group group) {
375
    protected SQLComponent createComponent(final Group group) {
379
        return new LeadSQLComponent(this, group);
376
        return new LeadSQLComponent(this, group);
380
    }
377
    }
381
}
378
}