OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 25 Rev 61
Line 13... Line 13...
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.sql.view.AbstractFileTransfertHandler;
17
import org.openconcerto.ui.DefaultGridBagConstraints;
17
import org.openconcerto.ui.DefaultGridBagConstraints;
-
 
18
import org.openconcerto.ui.component.WaitIndeterminatePanel;
18
import org.openconcerto.utils.ExceptionHandler;
19
import org.openconcerto.utils.ExceptionHandler;
19
import org.openconcerto.utils.FileUtils;
20
import org.openconcerto.utils.FileUtils;
20
 
21
 
-
 
22
import java.awt.Dialog.ModalityType;
21
import java.awt.GridBagConstraints;
23
import java.awt.GridBagConstraints;
22
import java.awt.GridBagLayout;
24
import java.awt.GridBagLayout;
23
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionEvent;
24
import java.io.File;
26
import java.io.File;
25
import java.io.IOException;
27
import java.io.IOException;
-
 
28
import java.text.ChoiceFormat;
-
 
29
import java.text.MessageFormat;
26
import java.util.Collection;
30
import java.util.Collection;
27
 
31
 
28
import javax.swing.AbstractAction;
32
import javax.swing.AbstractAction;
29
import javax.swing.JButton;
33
import javax.swing.JButton;
-
 
34
import javax.swing.JComponent;
-
 
35
import javax.swing.JDialog;
30
import javax.swing.JOptionPane;
36
import javax.swing.JOptionPane;
31
import javax.swing.JPanel;
37
import javax.swing.JPanel;
32
import javax.swing.JScrollPane;
38
import javax.swing.JScrollPane;
33
import javax.swing.JTable;
39
import javax.swing.JTable;
34
import javax.swing.SwingUtilities;
40
import javax.swing.SwingUtilities;
-
 
41
import javax.swing.SwingWorker;
35
 
42
 
36
public class AvailableModulesPanel extends JPanel {
43
public class AvailableModulesPanel extends JPanel {
-
 
44
 
-
 
45
    static final MessageFormat MODULE_FMT;
-
 
46
 
-
 
47
    static {
-
 
48
        final ChoiceFormat choiceForm = new ChoiceFormat(new double[] { 1, 2 }, new String[] { "d'un module", "de {0} modules" });
-
 
49
        MODULE_FMT = new MessageFormat("{0}");
-
 
50
        MODULE_FMT.setFormatByArgumentIndex(0, choiceForm);
-
 
51
    }
-
 
52
 
-
 
53
    // prevent the user from interacting when un/installing modules
-
 
54
    static JDialog displayDialog(JComponent parent, final String text) {
-
 
55
        final WaitIndeterminatePanel panel = new WaitIndeterminatePanel(text);
-
 
56
        final JDialog dialog = new JDialog(SwingUtilities.getWindowAncestor(parent), ModalityType.APPLICATION_MODAL);
-
 
57
        dialog.add(panel);
-
 
58
        dialog.pack();
-
 
59
        dialog.setLocationRelativeTo(parent);
-
 
60
        SwingUtilities.invokeLater(new Runnable() {
-
 
61
            @Override
-
 
62
            public void run() {
-
 
63
                dialog.setVisible(true);
-
 
64
            }
-
 
65
        });
-
 
66
        return dialog;
-
 
67
    }
-
 
68
 
37
    private final AvailableModuleTableModel tm;
69
    private final AvailableModuleTableModel tm;
38
 
70
 
39
    AvailableModulesPanel(final ModuleFrame moduleFrame) {
71
    AvailableModulesPanel(final ModuleFrame moduleFrame) {
40
        this.setOpaque(false);
72
        this.setOpaque(false);
41
        this.setLayout(new GridBagLayout());
73
        this.setLayout(new GridBagLayout());
Line 74... Line 106...
74
        c.gridheight = 1;
106
        c.gridheight = 1;
75
        final JButton activateButton = new JButton(new AbstractAction("Installer") {
107
        final JButton activateButton = new JButton(new AbstractAction("Installer") {
76
            @Override
108
            @Override
77
            public void actionPerformed(ActionEvent evt) {
109
            public void actionPerformed(ActionEvent evt) {
78
                final Collection<ModuleFactory> checkedRows = AvailableModulesPanel.this.tm.getCheckedRows();
110
                final Collection<ModuleFactory> checkedRows = AvailableModulesPanel.this.tm.getCheckedRows();
-
 
111
                if (checkedRows.isEmpty()) {
-
 
112
                    JOptionPane.showMessageDialog(AvailableModulesPanel.this, "Aucune ligne cochée");
-
 
113
                    return;
-
 
114
                }
-
 
115
 
-
 
116
                final JDialog dialog = displayDialog(AvailableModulesPanel.this, "Installation " + MODULE_FMT.format(new Object[] { checkedRows.size() }));
79
                final ModuleManager mngr = ModuleManager.getInstance();
117
                final ModuleManager mngr = ModuleManager.getInstance();
-
 
118
                new SwingWorker<Object, Object>() {
80
                try {
119
                    @Override
81
                    // TODO install out of EDT
120
                    protected Object doInBackground() throws Exception {
82
                    for (final ModuleFactory f : checkedRows) {
121
                        for (final ModuleFactory f : checkedRows) {
83
                        mngr.startModule(f.getID(), true);
122
                            mngr.startModule(f.getID(), true);
84
                    }
123
                        }
-
 
124
                        return null;
-
 
125
                    }
-
 
126
 
-
 
127
                    @Override
-
 
128
                    protected void done() {
-
 
129
                        try {
-
 
130
                            this.get();
85
                } catch (Exception e) {
131
                        } catch (Exception e) {
86
                    ExceptionHandler.handle(AvailableModulesPanel.this, "Impossible de démarrer les modules", e);
132
                            ExceptionHandler.handle(AvailableModulesPanel.this, "Impossible de démarrer les modules", e);
87
                }
133
                        }
88
                // some might have started
134
                        // some might have started
89
                moduleFrame.reload();
135
                        moduleFrame.reload();
-
 
136
                        dialog.dispose();
-
 
137
                    }
-
 
138
                }.execute();
90
            }
139
            }
91
        });
140
        });
92
        activateButton.setOpaque(false);
141
        activateButton.setOpaque(false);
93
        this.add(activateButton, c);
142
        this.add(activateButton, c);
94
 
143