private void initialize(final IRefreshSubscriberListener listener) { final GotoActionWrapper actionWrapper = new GotoActionWrapper(); IProgressMonitor group = Job.getJobManager().createProgressGroup(); group.beginTask(taskName, 100); setProgressGroup(group, 80); handleProgressGroupSet(group, 20); setProperty(IProgressConstants.ICON_PROPERTY, participant.getImageDescriptor()); setProperty(IProgressConstants.ACTION_PROPERTY, actionWrapper); setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean.valueOf(!isJobModal())); // Listener delegate IRefreshSubscriberListener autoListener = new IRefreshSubscriberListener() { @Override public void refreshStarted(IRefreshEvent event) { if (listener != null) { listener.refreshStarted(event); } } @Override public ActionFactory.IWorkbenchAction refreshDone(IRefreshEvent event) { if (listener != null) { boolean isModal = isJobModal(); event.setIsLink(!isModal); final ActionFactory.IWorkbenchAction runnable = listener.refreshDone(event); if (runnable != null) { // If the job is being run modally then simply prompt the user immediately if (isModal) { if (runnable != null) { Job update = new UIJob("") { // $NON-NLS-1$ @Override public IStatus runInUIThread(IProgressMonitor monitor) { runnable.run(); return Status.OK_STATUS; } }; update.setSystem(true); update.schedule(); } } else { // If the job is being run in the background, don't interrupt the user and simply // update the goto action // to perform the results. actionWrapper.setGotoAction(runnable); } } RefreshParticipantJob.removeRefreshListener(this); } return null; } }; if (listener != null) { RefreshParticipantJob.addRefreshListener(autoListener); } }
@Override public boolean isCanceled() { if (super.isCanceled()) { return true; } if (job.shouldReschedule() && job.isBlocking()) { if (blockTime == 0) { blockTime = System.currentTimeMillis(); } else if (System.currentTimeMillis() - blockTime > THRESHOLD) { // We've been blocking for too long wasBlocking = true; return true; } } else { blockTime = 0; } wasBlocking = false; return false; }