/** * Cancel running task if there is any. */ public void cancel() { if (taskHandler != null) taskHandler.cancel(); } }
/** * If there is running task, block until its completion and return result. * * @return last task's result or null if no tasks were run yet */ @Nullable public V getResult() { if (taskHandler != null) return taskHandler.getResult(); else return null; }
/** * Cancel running task if there is at the moment. * Launch it again. */ public void restart() { cancel(); Objects.requireNonNull(task, "Task must be specified either in constructor or by passing it to restart() method"); taskHandler = backgroundWorker.handle(task); taskHandler.execute(); }
protected void searchSuggestions(final String query) { BackgroundTask<Long, List<V>> task = getSearchSuggestionsTask(query); if (task != null) { handler = backgroundWorker.handle(task); handler.execute(); } }
/** * Cancel running task if there is at the moment. * Launch new task specified as parameter. * * @param task task to start, also will be saved for future restarts */ public void restart(BackgroundTask<T, V> task) { cancel(); this.task = task; taskHandler = backgroundWorker.handle(task); taskHandler.execute(); }
protected void cancelSearch() { if (handler != null) { log.debug("Cancel previous search"); handler.cancel(); handler = null; } }
protected void searchSuggestions(final String query) { BackgroundTask<Long, List<V>> task = getSearchSuggestionsTask(query); if (task != null) { handler = backgroundWorker.handle(task); handler.execute(); } }
protected void cancelSearch() { if (handler != null) { log.debug("Cancel previous search"); handler.cancel(); handler = null; } }
@Override public void init(Map<String, Object> params) { @SuppressWarnings("unchecked") BackgroundTask<T, V> task = (BackgroundTask<T, V>) params.get("task"); String title = (String) params.get("title"); if (title != null) { setCaption(title); } String message = (String) params.get("message"); if (message != null) { text.setValue(message); } Boolean cancelAllowedNullable = (Boolean) params.get("cancelAllowed"); cancelAllowed = BooleanUtils.isTrue(cancelAllowedNullable); cancelButton.setVisible(cancelAllowed); getDialogOptions().setCloseable(cancelAllowed); BackgroundTask<T, V> wrapperTask = new LocalizedTaskWrapper<>(task, this); taskHandler = backgroundWorker.handle(wrapperTask); taskHandler.execute(); }
@Override protected boolean preClose(String actionId) { if (!taskHandler.cancel()) { return false; } return super.preClose(actionId); }
taskHandler.execute();
@Override protected boolean preClose(String actionId) { if (!taskHandler.cancel()) { return false; } return super.preClose(actionId); } }