diff options
author | Michael Valenta | 2003-09-15 19:11:27 +0000 |
---|---|---|
committer | Michael Valenta | 2003-09-15 19:11:27 +0000 |
commit | c5f3200fa0d14063afc84d77ac50555990f02682 (patch) | |
tree | 1fe2ecdbf4367633bfbf9d19ce8e39dd7e271da2 | |
parent | efd7a043767b7462801157396a3d88e0dbf0b846 (diff) | |
download | eclipse.platform.team-branch_20030915_JobFeedbackInView.tar.gz eclipse.platform.team-branch_20030915_JobFeedbackInView.tar.xz eclipse.platform.team-branch_20030915_JobFeedbackInView.zip |
*** empty log message ***branch_20030915_JobFeedbackInView
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java | 3 | ||||
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/JobStatusHandler.java (renamed from bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/ViewFeedbackManager.java) | 79 | ||||
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java | 3 | ||||
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java | 3 | ||||
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java | 10 | ||||
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberAction.java | 14 |
6 files changed, 54 insertions, 58 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java index 6d49acf4b..c1ff81da9 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java @@ -32,7 +32,6 @@ import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.graphics.Image; import org.eclipse.team.internal.ui.jobs.RefreshSubscriberInputJob; import org.eclipse.team.internal.ui.jobs.RefreshSubscriberJob; -import org.eclipse.team.internal.ui.jobs.ViewFeedbackManager; import org.eclipse.team.internal.ui.sync.actions.SyncViewerDirectionFilters; import org.eclipse.team.internal.ui.sync.views.SyncViewerTableSorter; import org.eclipse.team.ui.ISharedImages; @@ -198,7 +197,7 @@ public class TeamUIPlugin extends AbstractUIPlugin implements IPropertyChangeLis refreshJob.setRestartOnCancel(true); refreshJob.setReschedule(true); // start once the platform has started and stabilized - ViewFeedbackManager.getInstance().schedule(refreshJob, 20000 /* 20 seconds */, SubscriberAction.SUBSCRIBER_JOB_TYPE); + SubscriberAction.getJobStatusHandler().schedule(refreshJob, 20000 /* 20 seconds */); } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/ViewFeedbackManager.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/JobStatusHandler.java index 40f9e1bca..7d05049ff 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/ViewFeedbackManager.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/JobStatusHandler.java @@ -11,10 +11,8 @@ package org.eclipse.team.internal.ui.jobs; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import org.eclipse.core.runtime.QualifiedName; @@ -23,42 +21,41 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; /** - * This class is reponisble for notifying views when jobs that effect - * the contents of the view start and stop + * This class is reponsible for notifying listeners when jobs registered + * with the handler start and stop. Start is invoked when the first registered job starts + * anf finish is invoked when the last registered job finishes. */ -public class ViewFeedbackManager { +public class JobStatusHandler { + private QualifiedName jobType; + private Set jobs = new HashSet(); private List listeners = new ArrayList(); - private Map jobTypes = new HashMap(); - private static ViewFeedbackManager instance; - - public synchronized static ViewFeedbackManager getInstance() { - if (instance == null) { - instance = new ViewFeedbackManager(); - } - return instance; + public JobStatusHandler(QualifiedName jobType) { + super(); + this.jobType = jobType; } - public void schedule(Job job, final QualifiedName jobType) { - job.addJobChangeListener(getJobChangeListener(jobType)); + + public void schedule(Job job) { + job.addJobChangeListener(getJobChangeListener()); // indicate that the job has started since it will be schdulued immediatley - jobStarted(job, jobType); + jobStarted(job); job.schedule(); } - public void schedule(Job job, long delay, final QualifiedName jobType) { - job.addJobChangeListener(getJobChangeListener(jobType)); + public void schedule(Job job, long delay) { + job.addJobChangeListener(getJobChangeListener()); job.schedule(delay); } - private JobChangeAdapter getJobChangeListener(final QualifiedName jobType) { + private JobChangeAdapter getJobChangeListener() { return new JobChangeAdapter() { public void done(IJobChangeEvent event) { - jobDone(event.getJob(), jobType); + jobDone(event.getJob()); } public void running(IJobChangeEvent event) { - jobStarted(event.getJob(), jobType); + jobStarted(event.getJob()); } }; } @@ -80,23 +77,18 @@ public class ViewFeedbackManager { } } - /* internal use only */ void jobStarted(Job job, QualifiedName jobType) { - if (recordJob(job, jobType)) { - fireStartNotification(jobType); + /* internal use only */ void jobStarted(Job job) { + if (recordJob(job)) { + fireStartNotification(); } } /* * Record the job and return true if it's the first job of that type */ - private boolean recordJob(Job job, QualifiedName jobType) { - Set jobs = (Set)jobTypes.get(jobType); - if (jobs == null) { - jobs = new HashSet(); - jobTypes.put(jobType, jobs); - } + private boolean recordJob(Job job) { if (!jobs.add(job)) { - // The job was already in the set. Invalid? + // The job was already in the set. return false; } return jobs.size() == 1; @@ -105,20 +97,15 @@ public class ViewFeedbackManager { /* * Remove the job and return true if it is the last job for the type */ - private boolean removeJob(Job job, QualifiedName jobType) { - Set jobs = (Set)jobTypes.get(jobType); - if (jobs == null) { - // TODO: Is this invalid? - return false; - } + private boolean removeJob(Job job) { if (!jobs.remove(job)) { - // The job wasn't in the list. Probably invalid + // The job wasn't in the list. return false; } return jobs.isEmpty(); } - private void fireStartNotification(QualifiedName jobType) { + private void fireStartNotification() { IJobListener[] listenerArray = getJobListeners(); for (int i = 0; i < listenerArray.length; i++) { IJobListener listener = listenerArray[i]; @@ -126,13 +113,13 @@ public class ViewFeedbackManager { } } - /* internal use only */ void jobDone(Job job, QualifiedName jobType) { - if (removeJob(job, jobType)) { - fireEndNotification(jobType); + /* internal use only */ void jobDone(Job job) { + if (removeJob(job)) { + fireEndNotification(); } } - private void fireEndNotification(QualifiedName jobType) { + private void fireEndNotification() { IJobListener[] listenerArray = getJobListeners(); for (int i = 0; i < listenerArray.length; i++) { IJobListener listener = listenerArray[i]; @@ -140,8 +127,8 @@ public class ViewFeedbackManager { } } - public boolean hasRunningJobs(QualifiedName jobType) { - Set jobs = (Set)jobTypes.get(jobType); - return jobs != null && !jobs.isEmpty(); + public boolean hasRunningJobs() { + return !jobs.isEmpty(); } + } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java index b7151b6e2..0bcf17985 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java @@ -26,7 +26,6 @@ import org.eclipse.team.internal.ui.TeamUIPlugin; import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.internal.ui.actions.TeamAction; import org.eclipse.team.internal.ui.jobs.RefreshSubscriberJob; -import org.eclipse.team.internal.ui.jobs.ViewFeedbackManager; import org.eclipse.team.internal.ui.sync.sets.SubscriberInput; import org.eclipse.team.internal.ui.sync.views.SynchronizeView; import org.eclipse.team.ui.sync.SubscriberAction; @@ -70,7 +69,7 @@ public class RefreshAction extends Action { Platform.getJobManager().cancel(RefreshSubscriberJob.getFamily()); if(TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_BACKGROUND_SYNC)) { RefreshSubscriberJob job = new RefreshSubscriberJob(Policy.bind("SyncViewRefresh.taskName", new Integer(resources.length).toString(), subscriber.getName()), resources, subscriber); //$NON-NLS-1$ - ViewFeedbackManager.getInstance().schedule(job, SubscriberAction.SUBSCRIBER_JOB_TYPE); + SubscriberAction.getJobStatusHandler().schedule(job); } else { runBlocking(viewer, subscriber, resources); } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java index 5390c923a..98e172234 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java @@ -25,7 +25,6 @@ import org.eclipse.team.core.subscribers.SyncInfo; import org.eclipse.team.internal.core.ExceptionCollector; import org.eclipse.team.internal.ui.Policy; import org.eclipse.team.internal.ui.TeamUIPlugin; -import org.eclipse.team.internal.ui.jobs.ViewFeedbackManager; import org.eclipse.team.ui.sync.SubscriberAction; /** @@ -119,7 +118,7 @@ public class SubscriberEventHandler { * Schedule the job or process the events now. */ public void schedule() { - ViewFeedbackManager.getInstance().schedule(eventHandlerJob, SubscriberAction.SUBSCRIBER_JOB_TYPE); + SubscriberAction.getJobStatusHandler().schedule(eventHandlerJob); } /** * Initialize all resources for the subscriber associated with the set. This will basically recalculate diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java index cb7d968f4..b38d05fb7 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SynchronizeView.java @@ -66,7 +66,6 @@ import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.internal.ui.actions.TeamAction; import org.eclipse.team.internal.ui.jobs.IJobListener; import org.eclipse.team.internal.ui.jobs.RefreshSubscriberInputJob; -import org.eclipse.team.internal.ui.jobs.ViewFeedbackManager; import org.eclipse.team.internal.ui.sync.actions.OpenInCompareAction; import org.eclipse.team.internal.ui.sync.actions.RefreshAction; import org.eclipse.team.internal.ui.sync.actions.SyncViewerActions; @@ -139,7 +138,6 @@ public class SynchronizeView extends ViewPart implements ITeamResourceChangeList */ private IJobListener jobListener = new IJobListener() { public synchronized void started(QualifiedName jobType) { - if (!jobType.equals(SubscriberAction.SUBSCRIBER_JOB_TYPE)) return; Display.getDefault().asyncExec(new Runnable() { public void run() { showBusyCursor(); @@ -148,7 +146,6 @@ public class SynchronizeView extends ViewPart implements ITeamResourceChangeList } public synchronized void finished(QualifiedName jobType) { - if (!jobType.equals(SubscriberAction.SUBSCRIBER_JOB_TYPE)) return; Display.getDefault().asyncExec(new Runnable() { public void run() { showNormalCursor(); @@ -310,12 +307,13 @@ public class SynchronizeView extends ViewPart implements ITeamResourceChangeList // Register for feedback from subscriber jobs. // Synchronize so the state doesn't change while setting the cursor synchronized (jobListener) { - ViewFeedbackManager.getInstance().addJobListener(jobListener); - if (ViewFeedbackManager.getInstance().hasRunningJobs(SubscriberAction.SUBSCRIBER_JOB_TYPE)) { + SubscriberAction.getJobStatusHandler().addJobListener(jobListener); + if (SubscriberAction.getJobStatusHandler().hasRunningJobs()) { showBusyCursor(); } } } + protected void initializeActions() { actions = new SyncViewerActions(this); actions.restore(memento); @@ -541,7 +539,7 @@ public class SynchronizeView extends ViewPart implements ITeamResourceChangeList input.dispose(); } - ViewFeedbackManager.getInstance().removeJobListener(jobListener); + SubscriberAction.getJobStatusHandler().removeJobListener(jobListener); waitCursor.dispose(); } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberAction.java index 24d24655b..daf4df22a 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberAction.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberAction.java @@ -22,6 +22,7 @@ import org.eclipse.team.core.TeamException; import org.eclipse.team.core.subscribers.SyncInfo; import org.eclipse.team.internal.ui.TeamUIPlugin; import org.eclipse.team.internal.ui.actions.TeamAction; +import org.eclipse.team.internal.ui.jobs.JobStatusHandler; /** * This is the abstract superclass for actions associated with a subscriber. @@ -31,6 +32,19 @@ public abstract class SubscriberAction extends TeamAction { public static final QualifiedName SUBSCRIBER_JOB_TYPE = new QualifiedName(TeamUIPlugin.ID, "subcriber_job"); //$NON-NLS-1$ + private static final JobStatusHandler feedbackManager = new JobStatusHandler(SUBSCRIBER_JOB_TYPE); + + /** + * Return the <code>JobStatusHandler</code> that is used to show busy indication + * in the Synchronize view. Subscribers should use the handler to schedule jobs + * that affect the Synchronize view so that the view shows proper busy indication + * to the user. + * @return the JobStatusHandler linked to the Sychcronize view + */ + public static JobStatusHandler getJobStatusHandler() { + return feedbackManager; + } + /** * This method returns all instances of SynchronizeViewNode that are in the current * selection. For a table view, this is any resource that is directly selected. |