OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Rev 61 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19 Rev 25
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.modules;
14
 package org.openconcerto.erp.modules;
15
 
15
 
-
 
16
import org.openconcerto.sql.view.AbstractFileTransfertHandler;
16
import org.openconcerto.ui.DefaultGridBagConstraints;
17
import org.openconcerto.ui.DefaultGridBagConstraints;
17
import org.openconcerto.utils.ExceptionHandler;
18
import org.openconcerto.utils.ExceptionHandler;
-
 
19
import org.openconcerto.utils.FileUtils;
18
 
20
 
19
import java.awt.GridBagConstraints;
21
import java.awt.GridBagConstraints;
20
import java.awt.GridBagLayout;
22
import java.awt.GridBagLayout;
21
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionEvent;
-
 
24
import java.io.File;
-
 
25
import java.io.IOException;
22
import java.util.Collection;
26
import java.util.Collection;
23
 
27
 
24
import javax.swing.AbstractAction;
28
import javax.swing.AbstractAction;
25
import javax.swing.JButton;
29
import javax.swing.JButton;
-
 
30
import javax.swing.JOptionPane;
26
import javax.swing.JPanel;
31
import javax.swing.JPanel;
27
import javax.swing.JScrollPane;
32
import javax.swing.JScrollPane;
28
import javax.swing.JTable;
33
import javax.swing.JTable;
-
 
34
import javax.swing.SwingUtilities;
29
 
35
 
30
public class AvailableModulesPanel extends JPanel {
36
public class AvailableModulesPanel extends JPanel {
31
    private final AvailableModuleTableModel tm;
37
    private final AvailableModuleTableModel tm;
32
 
38
 
33
    AvailableModulesPanel(final ModuleFrame moduleFrame) {
39
    AvailableModulesPanel(final ModuleFrame moduleFrame) {
Line 89... Line 95...
89
        JPanel space = new JPanel();
95
        JPanel space = new JPanel();
90
        space.setOpaque(false);
96
        space.setOpaque(false);
91
        c.weighty = 1;
97
        c.weighty = 1;
92
        c.gridy++;
98
        c.gridy++;
93
        this.add(space, c);
99
        this.add(space, c);
-
 
100
        this.setTransferHandler(new AbstractFileTransfertHandler() {
-
 
101
 
-
 
102
            @Override
-
 
103
            public void handleFile(File f) {
-
 
104
                if (!f.getName().endsWith(".jar")) {
-
 
105
                    JOptionPane.showMessageDialog(AvailableModulesPanel.this, "Impossible d'installer le module. Le fichier n'est pas un module.");
-
 
106
                    return;
-
 
107
                }
-
 
108
                File dir = new File("Modules");
-
 
109
                dir.mkdir();
-
 
110
                File out = null;
-
 
111
                if (dir.canWrite()) {
-
 
112
                    try {
-
 
113
                        out = new File(dir, f.getName());
-
 
114
                        FileUtils.copyFile(f, out);
-
 
115
                    } catch (IOException e) {
-
 
116
                        JOptionPane.showMessageDialog(AvailableModulesPanel.this, "Impossible d'installer le module.\n" + f.getAbsolutePath() + " vers " + dir.getAbsolutePath());
-
 
117
                        return;
-
 
118
                    }
-
 
119
                } else {
-
 
120
                    JOptionPane.showMessageDialog(AvailableModulesPanel.this, "Impossible d'installer le module.\nVous devez disposer des droits en écriture sur le dossier:\n" + dir.getAbsolutePath());
-
 
121
                    return;
-
 
122
                }
-
 
123
                try {
-
 
124
                    ModuleManager.getInstance().addFactory(new JarModuleFactory(out));
-
 
125
                } catch (IOException e) {
-
 
126
                    JOptionPane.showMessageDialog(AvailableModulesPanel.this, "Impossible d'intégrer le module.\n" + e.getMessage());
-
 
127
                    return;
-
 
128
                }
-
 
129
                SwingUtilities.invokeLater(new Runnable() {
-
 
130
 
-
 
131
                    @Override
-
 
132
                    public void run() {
-
 
133
                        reload();
-
 
134
                    }
-
 
135
                });
-
 
136
 
-
 
137
            }
-
 
138
        });
94
    }
139
    }
95
 
140
 
96
    public void reload() {
141
    public void reload() {
97
        this.tm.reload();
142
        this.tm.reload();
98
    }
143
    }