/** {@inheritDoc} */ @Override public void clear() { if (recentGroup == null) { return; } openRecentFilesPresenter.clearRecentFiles(); recentStorage.clear(); // de-register all previously registered actions for (Pair<File, RecentFileAction> pair : fileToAction) { actionManager.unregisterAction(pair.getSecond().getId()); recentGroup.remove(pair.getSecond()); } fileToAction.clear(); }
/** {@inheritDoc} */ @Override public boolean remove(File item) { if (recentGroup == null) { return false; } recentStorage.remove(item); openRecentFilesPresenter.setRecentFiles(getAll()); // with one cycle de-register action and remove it from recent group Iterator<Pair<File, RecentFileAction>> iterator = fileToAction.iterator(); while (iterator.hasNext()) { Pair<File, RecentFileAction> pair = iterator.next(); if (pair.getFirst().equals(item)) { recentGroup.remove(pair.getSecond()); actionManager.unregisterAction(pair.getSecond().getId()); iterator.remove(); return true; } } return false; }
private void startProcessesCleaner() { Scheduler.get() .scheduleFixedDelay( () -> { for (Iterator<Map.Entry<String, Pair<ProgressReport, Long>>> it = progresses.entrySet().iterator(); it.hasNext(); ) { Map.Entry<String, Pair<ProgressReport, Long>> entry = it.next(); long lastUpdate = entry.getValue().getSecond(); ProgressReport progress = entry.getValue().getFirst(); if ((currentTimeMillis() - lastUpdate) > DELAY_MS) { it.remove(); backgroundLoader.removeProgress(progress); String currentTaskId = currentProgress.getId(); String taskId = progress.getId(); if (currentTaskId.equals(taskId)) { updateCurrentProgress(); } } } return !progresses.isEmpty(); }, DELAY_MS); }
/** * Updates progress for one task. * * @param progress updated progress */ public void updateProgress(ProgressReport progress) { String taskId = progress.getId(); if (!progresses.containsKey(taskId)) { return; } Pair<ProgressView, Long> updatedView = progresses.get(taskId); ProgressView progressView = updatedView.getFirst(); if (progress.isComplete()) { view.remove(progressView); progresses.remove(taskId); return; } Long updated = updatedView.getSecond(); if (currentTimeMillis() - updated < UPDATE_PERIOD) { return; } progressView.updateProgressBar(progress); }