OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 74 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 74 Rev 86
1
package org.openconcerto.modules.extensionbuilder;
1
package org.openconcerto.modules.extensionbuilder;
2
 
2
 
3
import java.awt.Color;
3
import java.awt.Color;
4
import java.awt.Dimension;
4
import java.awt.Dimension;
5
import java.awt.FileDialog;
5
import java.awt.FileDialog;
6
import java.awt.FlowLayout;
6
import java.awt.FlowLayout;
7
import java.awt.GridBagConstraints;
7
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
8
import java.awt.GridBagLayout;
9
import java.awt.Insets;
9
import java.awt.Insets;
10
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionEvent;
11
import java.awt.event.ActionListener;
11
import java.awt.event.ActionListener;
12
import java.io.BufferedInputStream;
12
import java.io.BufferedInputStream;
13
import java.io.BufferedOutputStream;
13
import java.io.BufferedOutputStream;
14
import java.io.ByteArrayOutputStream;
14
import java.io.ByteArrayOutputStream;
15
import java.io.File;
15
import java.io.File;
16
import java.io.FileInputStream;
16
import java.io.FileInputStream;
17
import java.io.FileOutputStream;
17
import java.io.FileOutputStream;
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.nio.charset.Charset;
19
import java.nio.charset.Charset;
20
import java.sql.SQLException;
20
import java.sql.SQLException;
21
import java.util.List;
21
import java.util.List;
22
import java.util.zip.GZIPInputStream;
22
import java.util.zip.GZIPInputStream;
23
import java.util.zip.GZIPOutputStream;
23
import java.util.zip.GZIPOutputStream;
24
 
24
 
25
import javax.swing.JButton;
25
import javax.swing.JButton;
26
import javax.swing.JFrame;
26
import javax.swing.JFrame;
27
import javax.swing.JLabel;
27
import javax.swing.JLabel;
28
import javax.swing.JOptionPane;
28
import javax.swing.JOptionPane;
29
import javax.swing.JPanel;
29
import javax.swing.JPanel;
30
import javax.swing.JSeparator;
30
import javax.swing.JSeparator;
31
import javax.swing.SwingUtilities;
31
import javax.swing.SwingUtilities;
32
import javax.swing.event.ChangeEvent;
32
import javax.swing.event.ChangeEvent;
33
import javax.swing.event.ChangeListener;
33
import javax.swing.event.ChangeListener;
34
 
34
 
35
import org.openconcerto.erp.config.ComptaPropsConfiguration;
35
import org.openconcerto.erp.config.ComptaPropsConfiguration;
36
import org.openconcerto.modules.extensionbuilder.component.ComponentCreateMainPanel;
36
import org.openconcerto.modules.extensionbuilder.component.ComponentCreateMainPanel;
37
import org.openconcerto.modules.extensionbuilder.component.ComponentDescritor;
37
import org.openconcerto.modules.extensionbuilder.component.ComponentDescritor;
38
import org.openconcerto.modules.extensionbuilder.list.ListCreateMainPanel;
38
import org.openconcerto.modules.extensionbuilder.list.ListCreateMainPanel;
39
import org.openconcerto.modules.extensionbuilder.list.ListDescriptor;
39
import org.openconcerto.modules.extensionbuilder.list.ListDescriptor;
40
import org.openconcerto.modules.extensionbuilder.menu.MenuMainPanel;
40
import org.openconcerto.modules.extensionbuilder.menu.MenuMainPanel;
41
import org.openconcerto.modules.extensionbuilder.table.TableDescritor;
41
import org.openconcerto.modules.extensionbuilder.table.TableDescritor;
42
import org.openconcerto.modules.extensionbuilder.table.TableMainPanel;
42
import org.openconcerto.modules.extensionbuilder.table.TableMainPanel;
43
import org.openconcerto.modules.extensionbuilder.translation.TranslationMainPanel;
43
import org.openconcerto.modules.extensionbuilder.translation.TranslationMainPanel;
44
import org.openconcerto.sql.model.DBRoot;
44
import org.openconcerto.sql.model.DBRoot;
45
import org.openconcerto.ui.DefaultGridBagConstraints;
45
import org.openconcerto.ui.DefaultGridBagConstraints;
46
import org.openconcerto.ui.FrameUtil;
46
import org.openconcerto.ui.FrameUtil;
47
import org.openconcerto.ui.JLabelBold;
47
import org.openconcerto.ui.JLabelBold;
48
import org.openconcerto.ui.ReloadPanel;
48
import org.openconcerto.ui.ReloadPanel;
49
import org.openconcerto.ui.warning.JLabelWarning;
49
import org.openconcerto.ui.warning.JLabelWarning;
50
import org.openconcerto.utils.ExceptionHandler;
50
import org.openconcerto.utils.ExceptionHandler;
51
import org.openconcerto.utils.StreamUtils;
51
import org.openconcerto.utils.StreamUtils;
52
 
52
 
53
public class ExtensionInfoPanel extends JPanel implements ChangeListener {
53
public class ExtensionInfoPanel extends JPanel implements ChangeListener {
54
    private Extension extension;
54
    private Extension extension;
55
 
55
 
56
    private JFrame frameTableEditor;
56
    private JFrame frameTableEditor;
57
 
57
 
58
    private JFrame frameListEditor;
58
    private JFrame frameListEditor;
59
    private JFrame frameMenuEditor;
59
    private JFrame frameMenuEditor;
60
    private JFrame frameTranslationEditor;
60
    private JFrame frameTranslationEditor;
61
 
61
 
62
    ExtensionInfoPanel(Extension extension, ExtensionListPanel moduleListPanel) {
62
    ExtensionInfoPanel(Extension extension, ExtensionListPanel moduleListPanel) {
63
        this.extension = extension;
63
        this.extension = extension;
64
        this.extension.addChangeListener(this);
64
        this.extension.addChangeListener(this);
65
        reloadUI();
65
        reloadUI();
66
    }
66
    }
67
 
67
 
68
    @Override
68
    @Override
69
    public void stateChanged(ChangeEvent e) {
69
    public void stateChanged(ChangeEvent e) {
70
        SwingUtilities.invokeLater(new Runnable() {
70
        SwingUtilities.invokeLater(new Runnable() {
71
 
71
 
72
            @Override
72
            @Override
73
            public void run() {
73
            public void run() {
74
                reloadUI();
74
                reloadUI();
75
 
75
 
76
            }
76
            }
77
        });
77
        });
78
 
78
 
79
    }
79
    }
80
 
80
 
81
    private void reloadUI() {
81
    private void reloadUI() {
82
        if (!SwingUtilities.isEventDispatchThread()) {
82
        if (!SwingUtilities.isEventDispatchThread()) {
83
            throw new IllegalStateException("Not in AWT");
83
            throw new IllegalStateException("Not in AWT");
84
        }
84
        }
85
        System.out.println("ExtensionInfoPanel.reloadUI()");
85
        System.out.println("ExtensionInfoPanel.reloadUI()");
86
        this.setBackground(Color.WHITE);
86
        this.setBackground(Color.WHITE);
87
        this.invalidate();
87
        this.invalidate();
88
        this.removeAll();
88
        this.removeAll();
89
 
89
 
90
        this.setLayout(new GridBagLayout());
90
        this.setLayout(new GridBagLayout());
91
        GridBagConstraints c = new DefaultGridBagConstraints();
91
        GridBagConstraints c = new DefaultGridBagConstraints();
92
        c.insets = new Insets(0, 0, 0, 0);
92
        c.insets = new Insets(0, 0, 0, 0);
93
 
93
 
94
        this.add(createToolbar(), c);
94
        this.add(createToolbar(), c);
95
        c.gridy++;
95
        c.gridy++;
96
 
96
 
97
        this.add(new JSeparator(JSeparator.HORIZONTAL), c);
97
        this.add(new JSeparator(JSeparator.HORIZONTAL), c);
98
        c.gridy++;
98
        c.gridy++;
99
        c.weightx = 1;
99
        c.weightx = 1;
100
        c.weighty = 1;
100
        c.weighty = 1;
101
        c.fill = GridBagConstraints.BOTH;
101
        c.fill = GridBagConstraints.BOTH;
102
 
102
 
103
        this.add(createInfoPanel(), c);
103
        this.add(createInfoPanel(), c);
104
        this.revalidate();
104
        this.revalidate();
105
    }
105
    }
106
 
106
 
107
    private JPanel createToolbar() {
107
    private JPanel createToolbar() {
108
        JPanel panel = new JPanel();
108
        JPanel panel = new JPanel();
109
        panel.setLayout(new FlowLayout(FlowLayout.LEADING));
109
        panel.setLayout(new FlowLayout(FlowLayout.LEADING));
110
        panel.add(new JLabelBold(this.extension.getName()));
110
        panel.add(new JLabelBold(this.extension.getName()));
111
        final ReloadPanel reload = new ReloadPanel();
111
        final ReloadPanel reload = new ReloadPanel();
112
        panel.add(reload);
112
        panel.add(reload);
113
        final JButton startButton = new JButton("Démarrer");
113
        final JButton startButton = new JButton("Démarrer");
114
 
114
 
115
        panel.add(startButton);
115
        panel.add(startButton);
116
        startButton.setEnabled(!extension.isStarted());
116
        startButton.setEnabled(!extension.isStarted());
117
        final JButton stopButton = new JButton("Arrêter");
117
        final JButton stopButton = new JButton("Arrêter");
118
        panel.add(stopButton);
118
        panel.add(stopButton);
119
        stopButton.setEnabled(extension.isStarted());
119
        stopButton.setEnabled(extension.isStarted());
120
        final JButton saveButton = new JButton("Enregister");
120
        final JButton saveButton = new JButton("Enregister");
121
        saveButton.addActionListener(new ActionListener() {
121
        saveButton.addActionListener(new ActionListener() {
122
 
122
 
123
            @Override
123
            @Override
124
            public void actionPerformed(ActionEvent e) {
124
            public void actionPerformed(ActionEvent e) {
125
                extension.save();
125
                extension.save();
126
 
126
 
127
            }
127
            }
128
        });
128
        });
129
        saveButton.setEnabled(extension.isNotSaved());
-
 
130
        panel.add(saveButton);
129
        panel.add(saveButton);
131
        // TODO: a mettre en clic droit sur la liste gauche
130
        // TODO: a mettre en clic droit sur la liste gauche
132
        final JButton exportButton = new JButton("Exporter");
131
        final JButton exportButton = new JButton("Exporter");
133
        panel.add(exportButton);
132
        panel.add(exportButton);
134
        final JButton importButton = new JButton("Importer");
133
        final JButton importButton = new JButton("Importer");
135
        panel.add(importButton);
134
        panel.add(importButton);
136
 
135
 
137
        exportButton.addActionListener(new ActionListener() {
136
        exportButton.addActionListener(new ActionListener() {
138
 
137
 
139
            @Override
138
            @Override
140
            public void actionPerformed(ActionEvent e) {
139
            public void actionPerformed(ActionEvent e) {
141
                String xml = extension.toXML();
140
                String xml = extension.toXML();
142
                System.out.println(xml);
141
                System.out.println(xml);
143
                FileDialog fDialog = new FileDialog(new JFrame(), "Export", FileDialog.SAVE);
142
                FileDialog fDialog = new FileDialog(new JFrame(), "Export", FileDialog.SAVE);
144
                fDialog.setFile(extension.getName() + ".ocext");
143
                fDialog.setFile(extension.getName() + ".ocext");
145
                fDialog.setVisible(true);
144
                fDialog.setVisible(true);
146
                String fileName = fDialog.getFile();
145
                String fileName = fDialog.getFile();
147
                if (fileName != null) {
146
                if (fileName != null) {
148
                    File file = new File(fDialog.getDirectory(), fDialog.getFile());
147
                    File file = new File(fDialog.getDirectory(), fDialog.getFile());
149
                    byte[] bytes = xml.getBytes(Charset.forName("UTF-8"));
148
                    byte[] bytes = xml.getBytes(Charset.forName("UTF-8"));
150
                    byte[] open = "openconcerto".getBytes();
149
                    byte[] open = "openconcerto".getBytes();
151
                    final int length = bytes.length;
150
                    final int length = bytes.length;
152
                    for (int i = 0; i < length; i++) {
151
                    for (int i = 0; i < length; i++) {
153
                        bytes[i] = (byte) (bytes[i] ^ open[i % 12]);
152
                        bytes[i] = (byte) (bytes[i] ^ open[i % 12]);
154
                    }
153
                    }
155
                    BufferedOutputStream out = null;
154
                    BufferedOutputStream out = null;
156
                    try {
155
                    try {
157
                        out = new BufferedOutputStream(new FileOutputStream(file));
156
                        out = new BufferedOutputStream(new FileOutputStream(file));
158
                        GZIPOutputStream gZ = new GZIPOutputStream(out);
157
                        GZIPOutputStream gZ = new GZIPOutputStream(out);
159
                        gZ.write(bytes);
158
                        gZ.write(bytes);
160
                        gZ.close();
159
                        gZ.close();
161
                    } catch (Exception e1) {
160
                    } catch (Exception e1) {
162
                        ExceptionHandler.handle("Unable to save extension " + file.getAbsolutePath(), e1);
161
                        ExceptionHandler.handle("Unable to save extension " + file.getAbsolutePath(), e1);
163
                    } finally {
162
                    } finally {
164
                        if (out != null) {
163
                        if (out != null) {
165
                            try {
164
                            try {
166
                                out.close();
165
                                out.close();
167
                            } catch (IOException e1) {
166
                            } catch (IOException e1) {
168
                                // Nothing
167
                                // Nothing
169
                            }
168
                            }
170
                        }
169
                        }
171
                    }
170
                    }
172
 
171
 
173
                }
172
                }
174
 
173
 
175
            }
174
            }
176
        });
175
        });
177
        importButton.addActionListener(new ActionListener() {
176
        importButton.addActionListener(new ActionListener() {
178
 
177
 
179
            @Override
178
            @Override
180
            public void actionPerformed(ActionEvent e) {
179
            public void actionPerformed(ActionEvent e) {
181
                final FileDialog fDialog = new FileDialog(new JFrame(), "Import", FileDialog.LOAD);
180
                final FileDialog fDialog = new FileDialog(new JFrame(), "Import", FileDialog.LOAD);
182
                fDialog.setVisible(true);
181
                fDialog.setVisible(true);
183
                final String fileName = fDialog.getFile();
182
                final String fileName = fDialog.getFile();
184
                String xml = "";
183
                String xml = "";
185
                if (fileName != null && fileName.endsWith(".ocext")) {
184
                if (fileName != null && fileName.endsWith(".ocext")) {
186
                    File file = new File(fDialog.getDirectory(), fDialog.getFile());
185
                    File file = new File(fDialog.getDirectory(), fDialog.getFile());
187
                    if (file.exists()) {
186
                    if (file.exists()) {
188
                        FileInputStream fIn = null;
187
                        FileInputStream fIn = null;
189
                        GZIPInputStream gIn = null;
188
                        GZIPInputStream gIn = null;
190
                        try {
189
                        try {
191
                            fIn = new FileInputStream(file);
190
                            fIn = new FileInputStream(file);
192
                            BufferedInputStream bIn = new BufferedInputStream(fIn);
191
                            BufferedInputStream bIn = new BufferedInputStream(fIn);
193
                            gIn = new GZIPInputStream(bIn);
192
                            gIn = new GZIPInputStream(bIn);
194
                            final ByteArrayOutputStream out = new ByteArrayOutputStream();
193
                            final ByteArrayOutputStream out = new ByteArrayOutputStream();
195
                            StreamUtils.copy(gIn, out);
194
                            StreamUtils.copy(gIn, out);
196
                            out.close();
195
                            out.close();
197
                            // decode
196
                            // decode
198
                            byte[] bytes = out.toByteArray();
197
                            byte[] bytes = out.toByteArray();
199
                            byte[] open = "openconcerto".getBytes();
198
                            byte[] open = "openconcerto".getBytes();
200
                            final int length = bytes.length;
199
                            final int length = bytes.length;
201
                            for (int i = 0; i < length; i++) {
200
                            for (int i = 0; i < length; i++) {
202
                                bytes[i] = (byte) (bytes[i] ^ open[i % 12]);
201
                                bytes[i] = (byte) (bytes[i] ^ open[i % 12]);
203
                            }
202
                            }
204
                            xml = new String(bytes, Charset.forName("UTF-8"));
203
                            xml = new String(bytes, Charset.forName("UTF-8"));
205
                        } catch (Exception ex) {
204
                        } catch (Exception ex) {
206
                            ex.printStackTrace();
205
                            ex.printStackTrace();
207
                            JOptionPane.showMessageDialog(new JFrame(), "Invalid extension");
206
                            JOptionPane.showMessageDialog(new JFrame(), "Invalid extension");
208
                        } finally {
207
                        } finally {
209
                            if (gIn != null) {
208
                            if (gIn != null) {
210
                                try {
209
                                try {
211
                                    gIn.close();
210
                                    gIn.close();
212
                                } catch (IOException e1) {
211
                                } catch (IOException e1) {
213
                                    e1.printStackTrace();
212
                                    e1.printStackTrace();
214
                                }
213
                                }
215
                            }
214
                            }
216
                            if (fIn != null) {
215
                            if (fIn != null) {
217
                                try {
216
                                try {
218
                                    fIn.close();
217
                                    fIn.close();
219
                                } catch (IOException e1) {
218
                                } catch (IOException e1) {
220
                                    e1.printStackTrace();
219
                                    e1.printStackTrace();
221
                                }
220
                                }
222
                            }
221
                            }
223
                        }
222
                        }
224
 
223
 
225
                    }
224
                    }
226
 
225
 
227
                }
226
                }
228
                // Create extension from XML
227
                // Create extension from XML
229
                extension.stop();
228
                extension.stop();
230
                if (!xml.isEmpty()) {
229
                if (!xml.isEmpty()) {
231
                    if (!extension.isEmpty()) {
230
                    if (!extension.isEmpty()) {
232
                        int result = JOptionPane.showConfirmDialog(ExtensionInfoPanel.this, "Attention l'extension actuelle sera écrasée.\nContinuer l'importation?");
231
                        int result = JOptionPane.showConfirmDialog(ExtensionInfoPanel.this, "Attention l'extension actuelle sera écrasée.\nContinuer l'importation?");
233
                        if (result != JOptionPane.YES_OPTION) {
232
                        if (result != JOptionPane.YES_OPTION) {
234
                            return;
233
                            return;
235
                        }
234
                        }
236
                    }
235
                    }
237
                    extension.clearAll();
236
                    extension.clearAll();
238
                    extension.importFromXML(xml);
237
                    extension.importFromXML(xml);
239
                    extension.setChanged();
238
                    extension.setChanged();
240
                }
239
                }
241
 
240
 
242
            }
241
            }
243
        });
242
        });
244
        startButton.addActionListener(new ActionListener() {
243
        startButton.addActionListener(new ActionListener() {
245
 
244
 
246
            @Override
245
            @Override
247
            public void actionPerformed(ActionEvent e) {
246
            public void actionPerformed(ActionEvent e) {
248
                reload.setMode(ReloadPanel.MODE_ROTATE);
247
                reload.setMode(ReloadPanel.MODE_ROTATE);
249
                new Thread(new Runnable() {
248
                new Thread(new Runnable() {
250
 
249
 
251
                    @Override
250
                    @Override
252
                    public void run() {
251
                    public void run() {
253
                        final DBRoot root = ComptaPropsConfiguration.getInstanceCompta().getRootSociete();
252
                        final DBRoot root = ComptaPropsConfiguration.getInstanceCompta().getRootSociete();
254
                        try {
253
                        try {
255
                            extension.start(root);
254
                            extension.start(root, false);
256
                        } catch (SQLException e1) {
255
                        } catch (SQLException e1) {
257
                            e1.printStackTrace();
256
                            e1.printStackTrace();
258
                        }
257
                        }
259
                    }
258
                    }
260
                }).start();
259
                }).start();
261
            }
260
            }
262
        });
261
        });
263
        stopButton.addActionListener(new ActionListener() {
262
        stopButton.addActionListener(new ActionListener() {
264
 
263
 
265
            @Override
264
            @Override
266
            public void actionPerformed(ActionEvent e) {
265
            public void actionPerformed(ActionEvent e) {
267
                reload.setMode(ReloadPanel.MODE_ROTATE);
266
                reload.setMode(ReloadPanel.MODE_ROTATE);
268
                new Thread(new Runnable() {
267
                new Thread(new Runnable() {
269
                    @Override
268
                    @Override
270
                    public void run() {
269
                    public void run() {
271
                        extension.stop();
270
                        extension.stop();
272
                    }
271
                    }
273
                }).start();
272
                }).start();
274
            }
273
            }
275
        });
274
        });
276
        return panel;
275
        return panel;
277
    }
276
    }
278
 
277
 
279
    private JPanel createInfoPanel() {
278
    private JPanel createInfoPanel() {
280
        final JPanel panel = new JPanel();
279
        final JPanel panel = new JPanel();
281
        panel.setOpaque(false);
280
        panel.setOpaque(false);
282
        final GridBagConstraints c = new DefaultGridBagConstraints();
281
        final GridBagConstraints c = new DefaultGridBagConstraints();
283
        panel.setLayout(new GridBagLayout());
282
        panel.setLayout(new GridBagLayout());
284
        c.fill = GridBagConstraints.NONE;
283
        c.fill = GridBagConstraints.NONE;
285
        c.gridy++;
284
        c.gridy++;
286
        // --------- TABLES
285
        // --------- TABLES
287
        panel.add(new JLabelBold("Tables et champs de la base de données"), c);
286
        panel.add(new JLabelBold("Tables et champs de la base de données"), c);
288
        c.gridy++;
287
        c.gridy++;
289
        final List<TableDescritor> createTableList = this.extension.getCreateTableList();
288
        final List<TableDescritor> createTableList = this.extension.getCreateTableList();
290
        if (createTableList.size() > 0) {
289
        if (createTableList.size() > 0) {
291
 
290
 
292
            panel.add(new JLabel("Cette extension crée " + createTableList.size() + " tables :"), c);
291
            panel.add(new JLabel("Cette extension crée " + createTableList.size() + " tables :"), c);
293
            c.gridy++;
292
            c.gridy++;
294
            c.gridwidth = 1;
293
            c.gridwidth = 1;
295
            for (final TableDescritor sqlCreateTable : createTableList) {
294
            for (final TableDescritor sqlCreateTable : createTableList) {
296
                c.gridx = 0;
295
                c.gridx = 0;
297
                c.weightx = 0;
296
                c.weightx = 0;
298
                JPanel line = new JPanel();
297
                JPanel line = new JPanel();
299
                line.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
298
                line.setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
300
                line.setOpaque(false);
299
                line.setOpaque(false);
301
                line.add(new JLabel("- " + sqlCreateTable.getName()));
300
                line.add(new JLabel("- " + sqlCreateTable.getName()));
302
                if (sqlCreateTable.getFields().size() > 0) {
301
                if (sqlCreateTable.getFields().size() > 0) {
303
                    line.add(new JLabel(" " + sqlCreateTable.getFields().size() + " champs"));
302
                    line.add(new JLabel(" " + sqlCreateTable.getFields().size() + " champs"));
304
                } else {
303
                } else {
305
                    line.add(new JLabelWarning(" " + "aucun champ"));
304
                    line.add(new JLabelWarning(" " + "aucun champ"));
306
                }
305
                }
307
                panel.add(line, c);
306
                panel.add(line, c);
308
                c.gridy++;
307
                c.gridy++;
309
            }
308
            }
310
 
309
 
311
        }
310
        }
312
        final List<TableDescritor> modifyTableList = this.extension.getModifyTableList();
311
        final List<TableDescritor> modifyTableList = this.extension.getModifyTableList();
313
        if (modifyTableList.size() > 0) {
312
        if (modifyTableList.size() > 0) {
314
            String tables = "";
313
            String tables = "";
315
            for (int i = 0; i < modifyTableList.size(); i++) {
314
            for (int i = 0; i < modifyTableList.size(); i++) {
316
                String tableName = modifyTableList.get(i).getName();
315
                String tableName = modifyTableList.get(i).getName();
317
                if (i < modifyTableList.size() - 1) {
316
                if (i < modifyTableList.size() - 1) {
318
                    tables += tableName + ", ";
317
                    tables += tableName + ", ";
319
                } else {
318
                } else {
320
                    tables += tableName;
319
                    tables += tableName;
321
                }
320
                }
322
            }
321
            }
323
            if (modifyTableList.size() > 1) {
322
            if (modifyTableList.size() > 1) {
324
                panel.add(new JLabel("Tables modifiées : " + tables), c);
323
                panel.add(new JLabel("Tables modifiées : " + tables), c);
325
            } else {
324
            } else {
326
                panel.add(new JLabel("Table modifiée : " + tables), c);
325
                panel.add(new JLabel("Table modifiée : " + tables), c);
327
            }
326
            }
328
            c.gridy++;
327
            c.gridy++;
329
        }
328
        }
330
        final JButton buttonCreateTable = new JButton("Afficher les tables");
329
        final JButton buttonCreateTable = new JButton("Afficher les tables");
331
        panel.add(buttonCreateTable, c);
330
        panel.add(buttonCreateTable, c);
332
        c.gridy++;
331
        c.gridy++;
333
        panel.add(new JLabel(" "), c);
332
        panel.add(new JLabel(" "), c);
334
        c.gridy++;
333
        c.gridy++;
335
        // --------- UI
334
        // --------- UI
336
        panel.add(new JLabelBold("Interfaces de saisie"), c);
335
        panel.add(new JLabelBold("Interfaces de saisie"), c);
337
        c.gridy++;
336
        c.gridy++;
338
        List<ComponentDescritor> createComponentList = extension.getCreateComponentList();
337
        List<ComponentDescritor> createComponentList = extension.getCreateComponentList();
339
        if (createComponentList.size() > 0) {
338
        if (createComponentList.size() > 0) {
340
            String components = "";
339
            String components = "";
341
            for (int i = 0; i < createComponentList.size(); i++) {
340
            for (int i = 0; i < createComponentList.size(); i++) {
342
                String tableName = createComponentList.get(i).getId();
341
                String tableName = createComponentList.get(i).getId();
343
                if (i < createComponentList.size() - 1) {
342
                if (i < createComponentList.size() - 1) {
344
                    components += tableName + ", ";
343
                    components += tableName + ", ";
345
                } else {
344
                } else {
346
                    components += tableName;
345
                    components += tableName;
347
                }
346
                }
348
            }
347
            }
349
 
348
 
350
            if (createComponentList.size() > 1) {
349
            if (createComponentList.size() > 1) {
351
                panel.add(new JLabel("Interfaces créées : " + components), c);
350
                panel.add(new JLabel("Interfaces créées : " + components), c);
352
            } else {
351
            } else {
353
                panel.add(new JLabel("Interface créée : " + components), c);
352
                panel.add(new JLabel("Interface créée : " + components), c);
354
            }
353
            }
355
            c.gridy++;
354
            c.gridy++;
356
        }
355
        }
357
 
356
 
358
        final JButton buttonCreateComponent = new JButton("Afficher les interfaces");
357
        final JButton buttonCreateComponent = new JButton("Afficher les interfaces");
359
        panel.add(buttonCreateComponent, c);
358
        panel.add(buttonCreateComponent, c);
360
        c.gridy++;
359
        c.gridy++;
361
        panel.add(new JLabel(" "), c);
360
        panel.add(new JLabel(" "), c);
362
        c.gridy++;
361
        c.gridy++;
363
 
362
 
364
        // --------- LIST
363
        // --------- LIST
365
        panel.add(new JLabelBold("Listes"), c);
364
        panel.add(new JLabelBold("Listes"), c);
366
        c.gridy++;
365
        c.gridy++;
367
        List<ListDescriptor> createListList = extension.getCreateListList();
366
        List<ListDescriptor> createListList = extension.getCreateListList();
368
        if (createListList.size() > 0) {
367
        if (createListList.size() > 0) {
369
            String components = "";
368
            String components = "";
370
            for (int i = 0; i < createListList.size(); i++) {
369
            for (int i = 0; i < createListList.size(); i++) {
371
                String tableName = createListList.get(i).getId();
370
                String tableName = createListList.get(i).getId();
372
                if (i < createListList.size() - 1) {
371
                if (i < createListList.size() - 1) {
373
                    components += tableName + ", ";
372
                    components += tableName + ", ";
374
                } else {
373
                } else {
375
                    components += tableName;
374
                    components += tableName;
376
                }
375
                }
377
            }
376
            }
378
 
377
 
379
            if (createListList.size() > 1) {
378
            if (createListList.size() > 1) {
380
                panel.add(new JLabel("Listes créées : " + components), c);
379
                panel.add(new JLabel("Listes créées : " + components), c);
381
            } else {
380
            } else {
382
                panel.add(new JLabel("Liste créée : " + components), c);
381
                panel.add(new JLabel("Liste créée : " + components), c);
383
            }
382
            }
384
            c.gridy++;
383
            c.gridy++;
385
        }
384
        }
386
 
385
 
387
        final JButton buttonCreateList = new JButton("Afficher les listes");
386
        final JButton buttonCreateList = new JButton("Afficher les listes");
388
        panel.add(buttonCreateList, c);
387
        panel.add(buttonCreateList, c);
389
        c.gridy++;
388
        c.gridy++;
390
        panel.add(new JLabel(" "), c);
389
        panel.add(new JLabel(" "), c);
391
        c.gridy++;
390
        c.gridy++;
392
        // --------- MENUS
391
        // --------- MENUS
393
        panel.add(new JLabelBold("Menus et actions"), c);
392
        panel.add(new JLabelBold("Menus et actions"), c);
394
        c.gridy++;
393
        c.gridy++;
395
        final int actionCount = extension.getActionDescriptors().size();
394
        final int actionCount = extension.getActionDescriptors().size();
396
        final int menuCount = extension.getCreateMenuList().size();
395
        final int menuCount = extension.getCreateMenuList().size();
397
        final int menuCount2 = extension.getRemoveMenuList().size();
396
        final int menuCount2 = extension.getRemoveMenuList().size();
398
        if (actionCount > 0) {
397
        if (actionCount > 0) {
399
            if (actionCount > 1)
398
            if (actionCount > 1)
400
                panel.add(new JLabel(actionCount + " actions"), c);
399
                panel.add(new JLabel(actionCount + " actions"), c);
401
            else
400
            else
402
                panel.add(new JLabel(actionCount + " action"), c);
401
                panel.add(new JLabel(actionCount + " action"), c);
403
 
402
 
404
            c.gridy++;
403
            c.gridy++;
405
        }
404
        }
406
        if (menuCount > 0) {
405
        if (menuCount > 0) {
407
            if (menuCount > 1)
406
            if (menuCount > 1)
408
                panel.add(new JLabel(menuCount + " ajouts de menu"), c);
407
                panel.add(new JLabel(menuCount + " ajouts de menu"), c);
409
            else
408
            else
410
                panel.add(new JLabel(menuCount + " ajout de menu"), c);
409
                panel.add(new JLabel(menuCount + " ajout de menu"), c);
411
            c.gridy++;
410
            c.gridy++;
412
        }
411
        }
413
        if (menuCount2 > 0) {
412
        if (menuCount2 > 0) {
414
            if (menuCount2 > 1)
413
            if (menuCount2 > 1)
415
                panel.add(new JLabel(menuCount2 + " suppressions de menu"), c);
414
                panel.add(new JLabel(menuCount2 + " suppressions de menu"), c);
416
            else
415
            else
417
                panel.add(new JLabel(menuCount2 + " suppression de menu"), c);
416
                panel.add(new JLabel(menuCount2 + " suppression de menu"), c);
418
            c.gridy++;
417
            c.gridy++;
419
        }
418
        }
420
        final JButton buttonCreateMenu = new JButton("Afficher les menus");
419
        final JButton buttonCreateMenu = new JButton("Afficher les menus");
421
        panel.add(buttonCreateMenu, c);
420
        panel.add(buttonCreateMenu, c);
422
        c.gridy++;
421
        c.gridy++;
423
        panel.add(new JLabel(" "), c);
422
        panel.add(new JLabel(" "), c);
424
 
423
 
425
        c.gridy++;
424
        c.gridy++;
426
 
425
 
427
        // --------- TRANSLATIONS
426
        // --------- TRANSLATIONS
428
        panel.add(new JLabelBold("Traductions et renommage de labels"), c);
427
        panel.add(new JLabelBold("Traductions et renommage de labels"), c);
429
        c.gridy++;
428
        c.gridy++;
430
 
429
 
431
        int actionTranslationCount = extension.getActionTranslations().size();
430
        int actionTranslationCount = extension.getActionTranslations().size();
432
        int menuTranslationCount = extension.getMenuTranslations().size();
431
        int menuTranslationCount = extension.getMenuTranslations().size();
433
        int fieldTranslationCount = extension.getFieldTranslations().size();
432
        int fieldTranslationCount = extension.getFieldTranslations().size();
434
        if (fieldTranslationCount > 0) {
433
        if (fieldTranslationCount > 0) {
435
            if (fieldTranslationCount > 1)
434
            if (fieldTranslationCount > 1)
436
                panel.add(new JLabel(fieldTranslationCount + " traductions de champs"), c);
435
                panel.add(new JLabel(fieldTranslationCount + " traductions de champs"), c);
437
            else
436
            else
438
                panel.add(new JLabel(fieldTranslationCount + " traduction de champs"), c);
437
                panel.add(new JLabel(fieldTranslationCount + " traduction de champs"), c);
439
 
438
 
440
            c.gridy++;
439
            c.gridy++;
441
        }
440
        }
442
        if (menuTranslationCount > 0) {
441
        if (menuTranslationCount > 0) {
443
            if (menuTranslationCount > 1)
442
            if (menuTranslationCount > 1)
444
                panel.add(new JLabel(menuTranslationCount + " traductions de menu"), c);
443
                panel.add(new JLabel(menuTranslationCount + " traductions de menu"), c);
445
            else
444
            else
446
                panel.add(new JLabel(menuTranslationCount + " traduction de menu"), c);
445
                panel.add(new JLabel(menuTranslationCount + " traduction de menu"), c);
447
            c.gridy++;
446
            c.gridy++;
448
        }
447
        }
449
 
448
 
450
        if (actionTranslationCount > 0) {
449
        if (actionTranslationCount > 0) {
451
            if (actionTranslationCount > 1)
450
            if (actionTranslationCount > 1)
452
                panel.add(new JLabel(actionTranslationCount + " traductions d'action"), c);
451
                panel.add(new JLabel(actionTranslationCount + " traductions d'action"), c);
453
            else
452
            else
454
                panel.add(new JLabel(actionTranslationCount + " traduction d'action"), c);
453
                panel.add(new JLabel(actionTranslationCount + " traduction d'action"), c);
455
            c.gridy++;
454
            c.gridy++;
456
        }
455
        }
457
 
456
 
458
        final JButton buttonCreateTranslation = new JButton("Afficher les traductions");
457
        final JButton buttonCreateTranslation = new JButton("Afficher les traductions");
459
        panel.add(buttonCreateTranslation, c);
458
        panel.add(buttonCreateTranslation, c);
460
        c.gridy++;
459
        c.gridy++;
461
        panel.add(new JLabel(" "), c);
460
        panel.add(new JLabel(" "), c);
462
        c.gridy++;
461
        c.gridy++;
463
        c.weighty = 1;
462
        c.weighty = 1;
464
        c.gridwidth = 2;
463
        c.gridwidth = 2;
465
        c.weightx = 1;
464
        c.weightx = 1;
466
        panel.add(new JLabel(" "), c);
465
        panel.add(new JLabel(" "), c);
467
        c.gridy++;
466
        c.gridy++;
468
        //
467
        //
469
        buttonCreateTable.addActionListener(new ActionListener() {
468
        buttonCreateTable.addActionListener(new ActionListener() {
470
 
469
 
471
            @Override
470
            @Override
472
            public void actionPerformed(ActionEvent e) {
471
            public void actionPerformed(ActionEvent e) {
473
                openTableEditor();
472
                openTableEditor();
474
            }
473
            }
475
        });
474
        });
476
        buttonCreateList.addActionListener(new ActionListener() {
475
        buttonCreateList.addActionListener(new ActionListener() {
477
 
476
 
478
            @Override
477
            @Override
479
            public void actionPerformed(ActionEvent e) {
478
            public void actionPerformed(ActionEvent e) {
480
                openListEditor();
479
                openListEditor();
481
            }
480
            }
482
        });
481
        });
483
        buttonCreateComponent.addActionListener(new ActionListener() {
482
        buttonCreateComponent.addActionListener(new ActionListener() {
484
 
483
 
485
            @Override
484
            @Override
486
            public void actionPerformed(ActionEvent e) {
485
            public void actionPerformed(ActionEvent e) {
487
                openComponentEditor();
486
                openComponentEditor();
488
            }
487
            }
489
        });
488
        });
490
        buttonCreateMenu.addActionListener(new ActionListener() {
489
        buttonCreateMenu.addActionListener(new ActionListener() {
491
 
490
 
492
            @Override
491
            @Override
493
            public void actionPerformed(ActionEvent e) {
492
            public void actionPerformed(ActionEvent e) {
494
                openMenuEditor();
493
                openMenuEditor();
495
            }
494
            }
496
        });
495
        });
497
        buttonCreateTranslation.addActionListener(new ActionListener() {
496
        buttonCreateTranslation.addActionListener(new ActionListener() {
498
 
497
 
499
            @Override
498
            @Override
500
            public void actionPerformed(ActionEvent e) {
499
            public void actionPerformed(ActionEvent e) {
501
                openTranslationEditor();
500
                openTranslationEditor();
502
            }
501
            }
503
        });
502
        });
504
        return panel;
503
        return panel;
505
    }
504
    }
506
 
505
 
507
    private void openTableEditor() {
506
    private void openTableEditor() {
508
        final TableMainPanel contentPane = new TableMainPanel(extension);
507
        final TableMainPanel contentPane = new TableMainPanel(extension);
509
        openEditor(frameTableEditor, contentPane, "Tables dans la base de données");
508
        openEditor(frameTableEditor, contentPane, "Tables dans la base de données");
510
 
509
 
511
    }
510
    }
512
 
511
 
513
    private void openListEditor() {
512
    private void openListEditor() {
514
        final ListCreateMainPanel contentPane = new ListCreateMainPanel(extension);
513
        final ListCreateMainPanel contentPane = new ListCreateMainPanel(extension);
515
        openEditor(frameListEditor, contentPane, "Listes personnalisées");
514
        openEditor(frameListEditor, contentPane, "Listes personnalisées");
516
 
515
 
517
    }
516
    }
518
 
517
 
519
    protected void openComponentEditor() {
518
    protected void openComponentEditor() {
520
        final ComponentCreateMainPanel contentPane = new ComponentCreateMainPanel(extension);
519
        final ComponentCreateMainPanel contentPane = new ComponentCreateMainPanel(extension);
521
        openEditor(frameListEditor, contentPane, "Interfaces personnalisées");
520
        openEditor(frameListEditor, contentPane, "Interfaces personnalisées");
522
 
521
 
523
    }
522
    }
524
 
523
 
525
    protected void openMenuEditor() {
524
    protected void openMenuEditor() {
526
        final MenuMainPanel contentPane = new MenuMainPanel(extension);
525
        final MenuMainPanel contentPane = new MenuMainPanel(extension);
527
        openEditor(frameMenuEditor, contentPane, "Menus et actions");
526
        openEditor(frameMenuEditor, contentPane, "Menus et actions");
528
 
527
 
529
    }
528
    }
530
 
529
 
531
    protected void openTranslationEditor() {
530
    protected void openTranslationEditor() {
532
        final TranslationMainPanel contentPane = new TranslationMainPanel(extension);
531
        final TranslationMainPanel contentPane = new TranslationMainPanel(extension);
533
        openEditor(frameTranslationEditor, contentPane, "Traductions");
532
        openEditor(frameTranslationEditor, contentPane, "Traductions");
534
 
533
 
535
    }
534
    }
536
 
535
 
537
    private void openEditor(JFrame frame, JPanel mainPanel, String title) {
536
    private void openEditor(JFrame frame, JPanel mainPanel, String title) {
538
        if (frame == null) {
537
        if (frame == null) {
539
            frame = new JFrame();
538
            frame = new JFrame();
540
            frame.setTitle(extension.getName() + " - " + title);
539
            frame.setTitle(extension.getName() + " - " + title);
541
            frame.setContentPane(mainPanel);
540
            frame.setContentPane(mainPanel);
542
            frame.setMinimumSize(new Dimension(796, 560));
541
            frame.setMinimumSize(new Dimension(796, 560));
543
            frame.pack();
542
            frame.pack();
544
            frame.setLocationRelativeTo(ExtensionInfoPanel.this);
543
            frame.setLocationRelativeTo(ExtensionInfoPanel.this);
545
        }
544
        }
546
        FrameUtil.show(frame);
545
        FrameUtil.show(frame);
547
    }
546
    }
548
}
547
}