From 3025329e824ac5ddceadd7c24b83f2fed118b136 Mon Sep 17 00:00:00 2001 From: Jean Michel-Lemieux Date: Thu, 14 Mar 2002 16:14:07 +0000 Subject: Batching of decorations in runnable. --- .../internal/ccvs/ui/CVSDecorationRunnable.java | 62 ++++++++++++++-------- .../team/internal/ccvs/ui/CVSDecorator.java | 46 ++++++++-------- .../eclipse/team/internal/ccvs/ui/CVSUIPlugin.java | 1 - .../team/internal/ccvs/ui/IDecorationNotifier.java | 7 ++- 4 files changed, 71 insertions(+), 45 deletions(-) diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecorationRunnable.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecorationRunnable.java index 07d842ee0..7ba31ad73 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecorationRunnable.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecorationRunnable.java @@ -52,6 +52,11 @@ public class CVSDecorationRunnable implements Runnable { // Provides resources to be decorated and is notified when decoration has been calculated private IDecorationNotifier notifier; + // Remember the non posted decorated resources + List resources = new ArrayList(); + List decorations = new ArrayList(); + private final static int NUM_TO_BATCH = 50; + /* * Define a cached image descriptor which only creates the image data once */ @@ -90,33 +95,48 @@ public class CVSDecorationRunnable implements Runnable { if (resource == null) { return; } - // it is possible that the resource to be decorated is no longer associated - // with a CVS provider. This could happen if the team nature was removed - // between the time the decoration event was posted to the thread and the time - // the thread processes the decoration. - ITeamProvider provider = TeamPlugin.getManager().getProvider(resource); - if(!resource.exists() || provider==null || !(provider instanceof CVSTeamProvider)) { - continue; - } - // determine a if resource has outgoing changes (e.g. is dirty). - IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); - boolean isDirty = false; - boolean computeDeepDirtyCheck = store.getBoolean(ICVSUIConstants.PREF_CALCULATE_DIRTY); - int type = resource.getType(); - if(type == IResource.FILE || computeDeepDirtyCheck) { - isDirty = isDirty(resource); - } - - // compute decorations - CVSDecoration decoration = computeTextLabelFor(resource, isDirty, provider); - decoration.setOverlays(computeLabelOverlaysFor(resource, isDirty, provider)); + CVSDecoration decoration = decorate(resource); // notify that decoration is ready - notifier.decorated(resource, decoration); + if(decoration!=null) { + resources.add(resource); + decorations.add(decoration); + if(!resources.isEmpty() && (notifier.remaining()==0 || resources.size() >= NUM_TO_BATCH)) { + notifier.decorated((IResource[])resources.toArray(new IResource[resources.size()]), + (CVSDecoration[])decorations.toArray(new CVSDecoration[decorations.size()])); + resources.clear(); + decorations.clear(); + } + } } } + public CVSDecoration decorate(IResource resource) { + // it is possible that the resource to be decorated is no longer associated + // with a CVS provider. This could happen if the team nature was removed + // between the time the decoration event was posted to the thread and the time + // the thread processes the decoration. + ITeamProvider provider = TeamPlugin.getManager().getProvider(resource); + if(!resource.exists() || provider==null || !(provider instanceof CVSTeamProvider)) { + return null; + } + + // determine a if resource has outgoing changes (e.g. is dirty). + IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); + boolean isDirty = false; + boolean computeDeepDirtyCheck = store.getBoolean(ICVSUIConstants.PREF_CALCULATE_DIRTY); + int type = resource.getType(); + if(type == IResource.FILE || computeDeepDirtyCheck) { + isDirty = isDirty(resource); + } + + // compute decorations + CVSDecoration decoration = computeTextLabelFor(resource, isDirty, provider); + decoration.setOverlays(computeLabelOverlaysFor(resource, isDirty, provider)); + return decoration; + } + private CVSDecoration computeTextLabelFor(IResource resource, boolean isDirty, ITeamProvider provider) { Map bindings = new HashMap(3); String format = ""; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecorator.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecorator.java index 33d9a66d7..f6e949eec 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecorator.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSDecorator.java @@ -82,6 +82,7 @@ public class CVSDecorator extends LabelProvider implements ILabelDecorator, IRes } protected void finished() { resourceStateChanged((IResource[])changedResources.toArray(new IResource[changedResources.size()])); + changedResources.clear(); } protected int getEventMask() { return IResourceChangeEvent.PRE_AUTO_BUILD; @@ -89,15 +90,14 @@ public class CVSDecorator extends LabelProvider implements ILabelDecorator, IRes } public CVSDecorator() { - // The decorator is a singleton, there should never be more than one instance. - // temporary until the UI component properly calls dispose when the workbench shutsdown - // UI Bug 9633 - Assert.isTrue(theDecorator==null); - theDecorator = this; - + // thread that calculates the decoration for a resource decoratorUpdateThread = new Thread(new CVSDecorationRunnable(this), "CVS"); //$NON-NLS-1$ decoratorUpdateThread.start(); + + // listener for cvs state change (e.g. any sync info changes) TeamPlugin.getManager().addResourceStateChangeListener(this); + + // listener for workspace resource changes changeListener = new ChangeListener(); changeListener.register(); } @@ -190,20 +190,28 @@ public class CVSDecorator extends LabelProvider implements ILabelDecorator, IRes } /* - * @see IDecorationNotifier#notify(IResource, CVSDecoration) + * @see IDecorationNotifier#decorated(IResource[], CVSDecoration[]) */ - public synchronized void decorated(IResource resource, CVSDecoration decoration) { - // ignore resources that aren't in the workbench anymore. - if(resource.exists() && !shutdown) { - cache.put(resource, decoration); - postLabelEvents(new LabelProviderChangedEvent[] { new LabelProviderChangedEvent(this, resource)}); + public synchronized void decorated(IResource[] resources, CVSDecoration[] decorations) { + List events = new ArrayList(); + if(!shutdown) { + for (int i = 0; i < resources.length; i++) { + IResource resource= resources[i]; + if(resource.exists()) { + cache.put(resource, decorations[i]); + events.add(new LabelProviderChangedEvent(this, resource)); + } + } + postLabelEvents((LabelProviderChangedEvent[]) events.toArray(new LabelProviderChangedEvent[events.size()])); } } /* - * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) + * @see IDecorationNotifier#remaining() */ - + public int remaining() { + return decoratorNeedsUpdating.size(); + } /* * @see IResourceStateChangeListener#resourceStateChanged(IResource[]) */ @@ -345,13 +353,7 @@ public class CVSDecorator extends LabelProvider implements ILabelDecorator, IRes } catch (InterruptedException e) { } } - - public static void shutdownAll() { - if(theDecorator!=null) { - theDecorator.dispose(); - } - } - + /* * @see IBaseLabelProvider#dispose() */ @@ -362,7 +364,7 @@ public class CVSDecorator extends LabelProvider implements ILabelDecorator, IRes shutdown(); // unregister change listeners - changeListener.register(); + changeListener.deregister(); TeamPlugin.getManager().removeResourceStateChangeListener(this); // dispose of images created as overlays diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java index 6ecfad7ec..a6dd3d465 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java @@ -246,7 +246,6 @@ public class CVSUIPlugin extends AbstractUIPlugin { * @see Plugin#shutdown() */ public void shutdown() throws CoreException { - CVSDecorator.shutdownAll(); changeListener.deregister(); super.shutdown(); try { diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/IDecorationNotifier.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/IDecorationNotifier.java index 541086bfa..d465f5893 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/IDecorationNotifier.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/IDecorationNotifier.java @@ -17,5 +17,10 @@ public interface IDecorationNotifier { /** * Called to associate a decoration to a resource. */ - public void decorated(IResource resource, CVSDecoration decoration); + public void decorated(IResource[] resource, CVSDecoration[] decoration); + + /** + * Number of resources remaining to be decorated + */ + public int remaining(); } -- cgit v1.2.3