@Override protected boolean onWindowClosing() { final boolean closing = super.onWindowClosing(); if (closing) { if (_worker != null) { _worker.cancelIfRunning(); } } return closing; }
public void startAnalysis() { _worker.execute(); }
public AnalysisResult getResult() { if (_result == null && _worker != null) { try { _result = _worker.get(); } catch (final Exception e) { WidgetUtils.showErrorMessage("Unable to fetch result", e); } } return _result; }
public void cancelIfRunning() { final javax.swing.SwingWorker.StateValue state = getState(); switch (state) { case STARTED: case DONE: try { final AnalysisResultFuture resultFuture = get(2, TimeUnit.SECONDS); if (!resultFuture.isDone()) { resultFuture.cancel(); } } catch (final Exception e) { logger.warn("Failed to cancel job", e); } break; case PENDING: logger.info("SwingWorker hasn't started yet - cancelIfRunning() invocation disregarded"); break; default: throw new IllegalArgumentException(); } } }
_worker = new AnalysisRunnerSwingWorker(_configuration, _job, this); _cancelButton.addActionListener(e -> _worker.cancelIfRunning()); } else {