Lancement d'un SwingWorker plusieurs fois
Bonjour à tous,
Voilà j'ai un léger souci sur mon SwingWorker et je ne comprend pas pourquoi.
J'ai créé une classe qui fusionne SwingWorker et ActionListener, cela donne ceci:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| public abstract class AbstractMMIActionSwingWorker extends SwingWorker<Boolean, Boolean> implements ActionListener {
private static final Logger LOGGER = Logger.getLogger(AbstractMMIActionSwingWorker.class);
private ActionEvent event;
public AbstractMMIActionSwingWorker() {
super();
}
public abstract void doInBackground(ActionEvent actionEvent) throws MMIException;
public abstract void preAction(ActionEvent actionEvent) throws MMIException;
public abstract void postAction(ActionEvent actionEvent) throws MMIException;
/**
* {@inheritDoc}
*/
@Override
protected final Boolean doInBackground() throws Exception {
try {
LOGGER.info("AbstractMMIActionSwingWorker.doInBackground()");
doInBackground(event);
} catch (MMIException e) {
handleException(e);
}
return Boolean.TRUE;
}
/**
* {@inheritDoc}
*/
@Override
public void actionPerformed(ActionEvent e) {
this.event = e;
try {
preAction(e);
this.execute();
} catch (MMIException ex) {
handleException(ex);
}
}
/**
* {@inheritDoc}
*/
@Override
protected void done() {
try {
get();
postAction(event);
} catch (MMIException | InterruptedException | ExecutionException e) {
handleException(e);
}
}
protected void handleException(Exception e) {
LOGGER.error("Error", e);
}
} |
Mon problème est que j'ajoute cela à un bouton pour lancer des traitements en tant qu'ActionListener, cela fonctionne très bien... la première fois ! Si je clique sur le bouton une deuxième fois (après que tout le SwingWorker ait été correctement exécuté) la preAction est bien démarrée mais je ne passe jamais dans ma méthode doInBackGround()... Une idée de pourquoi ?
Merci d'avance !