OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 180
Line 57... Line 57...
57
import javax.swing.JList;
57
import javax.swing.JList;
58
import javax.swing.JOptionPane;
58
import javax.swing.JOptionPane;
59
import javax.swing.JPanel;
59
import javax.swing.JPanel;
60
import javax.swing.JScrollPane;
60
import javax.swing.JScrollPane;
61
import javax.swing.SwingUtilities;
61
import javax.swing.SwingUtilities;
-
 
62
import javax.swing.SwingWorker;
62
 
63
 
63
import org.jdom.JDOMException;
64
import org.jdom.JDOMException;
64
 
65
 
-
 
66
import net.jcip.annotations.GuardedBy;
-
 
67
 
65
/**
68
/**
66
 * A panel to choose a ReportType, see the tasks of the generation, and optionnaly open the
69
 * A panel to choose a ReportType, see the tasks of the generation, and optionnaly open the
67
 * document. NOTE: you have to call {@link #enableGeneration(boolean)} before being able to
70
 * document. NOTE: you have to call {@link #enableGeneration(boolean)} before being able to
68
 * generate, because it's set to false in the constructor.
71
 * generate, because it's set to false in the constructor.
69
 *
72
 *
Line 93... Line 96...
93
    private JComboBox<FileAction> fileActionCombo;
96
    private JComboBox<FileAction> fileActionCombo;
94
 
97
 
95
    private JList<GenerationTask> tasksView;
98
    private JList<GenerationTask> tasksView;
96
    private final JLabel status;
99
    private final JLabel status;
97
 
100
 
98
    // le groupe dans lequel doivent être toutes les thread de la génération
101
    @GuardedBy("EDT")
99
    private final ThreadGroup thg;
102
    private SwingWorker<Void, Void> generationWorker;
100
 
103
 
101
    public BaseGenerationRapport() throws JDOMException, IOException {
104
    public BaseGenerationRapport() throws JDOMException, IOException {
102
        this.thg = new ThreadGroup(this + " thread group");
105
        this.generationWorker = null;
103
        this.status = new JLabel();
106
        this.status = new JLabel();
104
        this.setStatus("Inactif");
107
        this.setStatus("Inactif");
105
    }
108
    }
106
 
109
 
107
    protected Map<String, JComponent> getEntries() {
110
    protected Map<String, JComponent> getEntries() {
Line 232... Line 235...
232
    /**
235
    /**
233
     * Interrompt la génération.
236
     * Interrompt la génération.
234
     */
237
     */
235
    public final void interrupt() {
238
    public final void interrupt() {
236
        // pas de threads active, quand pas génération
239
        // pas de threads active, quand pas génération
237
        this.thg.interrupt();
240
        if (this.generationWorker != null)
-
 
241
            this.generationWorker.cancel(true);
238
    }
242
    }
239
 
243
 
240
    class GenerateAction implements ActionListener {
244
    class GenerateAction implements ActionListener {
241
        public GenerateAction() {
245
        public GenerateAction() {
242
        }
246
        }
Line 244... Line 248...
244
        @Override
248
        @Override
245
        public void actionPerformed(final ActionEvent e) {
249
        public void actionPerformed(final ActionEvent e) {
246
            enableGeneration(false);
250
            enableGeneration(false);
247
            final FileAction sel = (FileAction) BaseGenerationRapport.this.fileActionCombo.getSelectedItem();
251
            final FileAction sel = (FileAction) BaseGenerationRapport.this.fileActionCombo.getSelectedItem();
248
            // "génération..."
252
            // "génération..."
249
            new Thread(BaseGenerationRapport.this.thg, new Runnable() {
253
            BaseGenerationRapport.this.generationWorker = new SwingWorker<Void, Void>() {
250
                @Override
254
                @Override
251
                public void run() {
255
                protected Void doInBackground() throws Exception {
252
                    generate(sel);
256
                    generate(sel);
253
                    // toujours le faire, même si interrompu
257
                    return null;
254
                    SwingUtilities.invokeLater(new Runnable() {
258
                }
-
 
259
 
255
                        @Override
260
                @Override
256
                        public void run() {
261
                protected void done() {
-
 
262
                    // toujours le faire, même si interrompu
257
                            enableGeneration(true);
263
                    enableGeneration(true);
258
                        }
264
                }
259
                    });
-
 
260
                }
265
            };
261
            }).start();
266
            BaseGenerationRapport.this.generationWorker.execute();
262
        }
267
        }
263
    }
268
    }
264
 
269
 
265
    protected final void enableGeneration(final boolean b) {
270
    protected final void enableGeneration(final boolean b) {
266
        this.fileActionCombo.setEnabled(b);
271
        this.fileActionCombo.setEnabled(b);
267
        this.genererButton.setEnabled(b);
272
        this.genererButton.setEnabled(b);
268
    }
273
    }
269
 
274
 
270
    // doit s'exécuter dans this.thg
-
 
271
    protected final void generate(final FileAction sel) {
275
    protected final void generate(final FileAction sel) {
272
        final ReportType type = (ReportType) this.typeRapportComboSelection.getSelectedItem();
276
        final ReportType type = (ReportType) this.typeRapportComboSelection.getSelectedItem();
273
        final R rg = this.createGeneration(type);
277
        final R rg = this.createGeneration(type);
274
        rg.addTaskListener(new PropertyChangeListener() {
278
        rg.addTaskListener(new PropertyChangeListener() {
275
            @Override
279
            @Override