aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Thun2011-02-28 05:01:47 (EST)
committerPhilipp Thun2011-02-28 05:01:47 (EST)
commitc65d7e7586e37520db43f3acc88d1c329e7f8e06 (patch)
tree228baf6983b0f194c7f8e65cb2caa48bd7bffbf2
parent84c6cf13bd3bbecb8b8fcf0d7d3ab5f5cf801ee9 (diff)
downloadegit-c65d7e7586e37520db43f3acc88d1c329e7f8e06.zip
egit-c65d7e7586e37520db43f3acc88d1c329e7f8e06.tar.gz
egit-c65d7e7586e37520db43f3acc88d1c329e7f8e06.tar.bz2
Improve GitLightweightDecoratorrefs/changes/99/2599/4
This change contains two improvements to the decorator: 1. Outdated decorations are shown until newly calculated decorations are available - this reduces 'flickering' 2. ResourceChangeEvents are better filtered - 'false' events are ignored (i.e. when a project is opened) and team private resource are also not included in the list of changed resources Change-Id: I62af897cda118b3fc7cf42d2b444a685053dc79c Signed-off-by: Philipp Thun <philipp.thun@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java125
1 files changed, 83 insertions, 42 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
index af63b8f..38df16a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java
@@ -225,29 +225,31 @@ public class GitLightweightDecorator extends LabelProvider implements
try {
final Boolean notDecoratable = (Boolean) resource
.getSessionProperty(NOT_DECORATABLE_KEY);
- if (notDecoratable != null && notDecoratable.equals(Boolean.TRUE)) {
+ if (notDecoratable != null && notDecoratable.equals(Boolean.TRUE))
// Resource is not decoratable, do not try again
return;
- } else {
- final Long refreshed = (Long) resource
- .getSessionProperty(REFRESHED_KEY);
- if (refreshed != null) {
- // Stored decoratable resource is available
- final Long refresh = (Long) resource.getWorkspace()
- .getRoot().getSessionProperty(REFRESH_KEY);
- if (refresh == null
- || refresh.longValue() <= refreshed.longValue()) {
- // Stored decoratable resource is up-to-date
- final IDecoratableResource decoratableResource = (IDecoratableResource) resource
- .getSessionProperty(DECORATABLE_RESOURCE_KEY);
- if (decoratableResource != null) {
- // Use stored decoratable resource
- final DecorationHelper helper = new DecorationHelper(
- activator.getPreferenceStore());
- helper.decorate(decoration, decoratableResource);
- return;
- }
- }
+
+ final IDecoratableResource decoratableResource = (IDecoratableResource) resource
+ .getSessionProperty(DECORATABLE_RESOURCE_KEY);
+ boolean decorated = false;
+ if (decoratableResource != null) {
+ // Use stored decoratable resource (even when it is outdated)
+ final DecorationHelper helper = new DecorationHelper(
+ activator.getPreferenceStore());
+ helper.decorate(decoration, decoratableResource);
+ decorated = true;
+ }
+
+ final Long refreshed = (Long) resource
+ .getSessionProperty(REFRESHED_KEY);
+ if (refreshed != null) {
+ final Long refresh = (Long) resource.getWorkspace().getRoot()
+ .getSessionProperty(REFRESH_KEY);
+ if (refresh == null
+ || refresh.longValue() <= refreshed.longValue()) {
+ // Stored decoratable resource is up-to-date
+ if (decorated)
+ return;
}
}
} catch (CoreException e) {
@@ -662,12 +664,12 @@ public class GitLightweightDecorator extends LabelProvider implements
if (prop.equals(TeamUI.GLOBAL_IGNORES_CHANGED)
|| prop.equals(TeamUI.GLOBAL_FILE_TYPES_CHANGED)
|| prop.equals(Activator.DECORATORS_CHANGED)) {
- postLabelEvent(null);
+ postLabelEvent();
} else if (prop.equals(UIPreferences.THEME_UncommittedChangeBackgroundColor)
|| prop.equals(UIPreferences.THEME_UncommittedChangeFont)
|| prop.equals(UIPreferences.THEME_UncommittedChangeForegroundColor)) {
ensureFontAndColorsCreated(fonts, colors);
- postLabelEvent(null); // TODO do I really need this?
+ postLabelEvent(); // TODO do I really need this?
}
}
@@ -682,6 +684,7 @@ public class GitLightweightDecorator extends LabelProvider implements
* @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
*/
public void resourceChanged(IResourceChangeEvent event) {
+ final long currentTime = System.currentTimeMillis();
final Set<IResource> resourcesToUpdate = new HashSet<IResource>();
try { // Compute the changed resources by looking at the delta
@@ -717,6 +720,15 @@ public class GitLightweightDecorator extends LabelProvider implements
return false;
}
+ // Ignore resources that haven't been changed within the
+ // last 10 seconds
+ if (currentTime - resource.getLocalTimeStamp() > 10000)
+ return false;
+
+ // Don't include ignored resources
+ if (Team.isIgnoredHint(resource))
+ return false;
+
// All seems good, schedule the resource for update
if (Constants.GITIGNORE_FILENAME.equals(resource.getName())) {
// re-decorate all container members when .gitignore changes
@@ -764,11 +776,11 @@ public class GitLightweightDecorator extends LabelProvider implements
}
public void onIndexChanged(IndexChangedEvent e) {
- postLabelEvent(null);
+ postLabelEvent();
}
public void onRefsChanged(RefsChangedEvent e) {
- postLabelEvent(null);
+ postLabelEvent();
}
/**
@@ -780,7 +792,7 @@ public class GitLightweightDecorator extends LabelProvider implements
public void repositoryChanged(RepositoryMapping mapping) {
// Until we find a way to refresh visible labels within a project
// we have to use this blanket refresh that includes all projects.
- postLabelEvent(null);
+ postLabelEvent();
}
// -------- Helper methods --------
@@ -811,14 +823,54 @@ public class GitLightweightDecorator extends LabelProvider implements
/**
* Post a label event to the LabelEventJob
*
+ * Posts a generic label event. No specific elements are provided; all
+ * decorations shall be invalidated. Same as
+ * <code>postLabelEvent(null, true)</code>.
+ */
+ private void postLabelEvent() {
+ postLabelEvent(null, true);
+ }
+
+ /**
+ * Post a label event to the LabelEventJob
+ *
+ * Posts a label event for specific elements. Does not invalidate other
+ * decorations. Same as <code>postLabelEvent(elements, false)</code>.
+ *
* @param elements
* The elements to update
*/
private void postLabelEvent(final Object[] elements) {
- if (elements == null) {
- // Update all elements
- final IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
- .getRoot();
+ postLabelEvent(elements, false);
+ }
+
+ private void postLabelEvent(final Object[] elements,
+ final boolean invalidateAllDecorations) {
+ final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ boolean updateRoot = false;
+
+ if (elements != null) {
+ // Update specific elements
+ for (Object element : elements) {
+ final IResource resource = getResource(element);
+ if (resource != null) {
+ if (resource.equals(root)) {
+ updateRoot = true;
+ break;
+ } else {
+ try {
+ // Remove 'refreshed' property
+ resource.setSessionProperty(REFRESHED_KEY, null);
+ } catch (CoreException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
+ if (invalidateAllDecorations || updateRoot) {
+ // Invalidate all decorations
try {
// Set (new) 'refresh' timestamp
root.setSessionProperty(REFRESH_KEY,
@@ -826,20 +878,9 @@ public class GitLightweightDecorator extends LabelProvider implements
} catch (CoreException e) {
handleException(root, e);
}
- } else {
- // Update specific elements
- for (Object element : elements) {
- final IResource resource = getResource(element);
- if (resource != null)
- try {
- // Remove 'refreshed' property
- resource.setSessionProperty(REFRESHED_KEY, null);
- } catch (CoreException e) {
- // Ignore
- }
- }
}
+ // Post label event to LabelEventJob
LabelEventJob.getInstance().postLabelEvent(this);
}