Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Duft2012-01-25 07:58:07 +0000
committerMarkus Duft2012-01-25 07:58:07 +0000
commit9320b32ea7758d3f14203756607f646d870a2e7e (patch)
tree91b0cd419a9dca77ae1b71db8cf33d44aecdfd91
parentee288ea2e99b8b737a44fb657f8896994492e0a6 (diff)
downloadegit-9320b32ea7758d3f14203756607f646d870a2e7e.tar.gz
egit-9320b32ea7758d3f14203756607f646d870a2e7e.tar.xz
egit-9320b32ea7758d3f14203756607f646d870a2e7e.zip
Implement decoration for working sets
This splits the current decorate() method in two separate ones. One for what was done already (decorate resources), and one for decorating "the rest" (i.e. ResourceMapping's). Bug: 344937 Change-Id: I5a3ae0ce5d429a7065dc16888f206fdbf777b1fd
-rw-r--r--org.eclipse.egit.ui/plugin.xml2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceMapping.java112
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java96
3 files changed, 184 insertions, 26 deletions
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index beda5bb877..c5e8f6d5c8 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -495,7 +495,7 @@
location="BOTTOM_RIGHT"
id="org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator">
<enablement>
- <objectClass name="org.eclipse.core.resources.IResource"/>
+ <objectClass name="org.eclipse.core.resources.mapping.ResourceMapping"/>
</enablement>
<description>
%Decorator_description
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceMapping.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceMapping.java
new file mode 100644
index 0000000000..479b4a5c88
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceMapping.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (C) 2011, Markus Duft <markus.duft@salomon.at>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.egit.ui.internal.decorators;
+
+import static org.eclipse.jgit.lib.Repository.stripWorkDir;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.egit.core.internal.indexdiff.IndexDiffData;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.ui.IWorkingSet;
+
+/**
+ * Represents a decoratable resource mapping (i.e. a group of resources).
+ */
+public class DecoratableResourceMapping extends DecoratableResource {
+
+ /**
+ * Denotes the type of decoratable resource, used by the decoration helper.
+ */
+ public static final int RESOURCE_MAPPING = 0x10;
+
+ /**
+ * Stores the actual mapping we are currently decorating.
+ */
+ private ResourceMapping mapping;
+
+ /**
+ * Creates a decoratable resource mapping (used for e.g. working sets)
+ *
+ * @param mapping the resource mapping to decorate
+ */
+ public DecoratableResourceMapping(ResourceMapping mapping) {
+ super(null); // no resource ...
+
+ this.mapping = mapping;
+ IProject[] projects = mapping.getProjects();
+
+ if(projects == null || projects.length == 0)
+ return;
+
+ // we could use DecoratableResourceAdapter for each project, but that would be too much overhead,
+ // as we need only very little information at all...
+ for(IProject prj : projects) {
+ RepositoryMapping repoMapping = RepositoryMapping.getMapping(prj);
+ if(repoMapping == null)
+ continue;
+
+ IndexDiffData diffData = GitLightweightDecorator.getIndexDiffDataOrNull(prj);
+ if(diffData == null)
+ continue;
+
+ // at least one contained resource is tracked for sure here.
+ tracked = true;
+
+ String repoRelative = makeRepoRelative(repoMapping.getRepository(), prj) + "/"; //$NON-NLS-1$
+
+ Set<String> modified = diffData.getModified();
+ Set<String> conflicting = diffData.getConflicting();
+
+ // attention - never reset these to false (so don't use the return value of the methods!)
+ if(containsPrefix(modified, repoRelative))
+ dirty = true;
+
+ if(containsPrefix(conflicting, repoRelative))
+ conflicts = true;
+ }
+ }
+
+ public int getType() {
+ return RESOURCE_MAPPING;
+ }
+
+ public String getName() {
+ // TODO: check whether something other than a WorkingSet can
+ // appear here, and calculate a proper name for it.
+ if(mapping.getModelObject() instanceof IWorkingSet) {
+ IWorkingSet ws = (IWorkingSet)mapping.getModelObject();
+ return ws.getLabel();
+ }
+
+ return "<unknown>"; //$NON-NLS-1$
+ }
+
+ private String makeRepoRelative(Repository repository, IResource res) {
+ return stripWorkDir(repository.getWorkTree(), res.getLocation()
+ .toFile());
+ }
+
+ private boolean containsPrefix(Set<String> collection, String prefix) {
+ // when prefix is empty we are handling repository root, therefore we
+ // should return true whenever collection isn't empty
+ if (prefix.length() == 1 && !collection.isEmpty())
+ return true;
+
+ for (String path : collection)
+ if (path.startsWith(prefix))
+ return true;
+ return false;
+ }
+}
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 26238d55c4..56ddc6be3b 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
@@ -52,6 +52,7 @@ import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.team.core.Team;
+import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.ISharedImages;
import org.eclipse.team.ui.TeamImages;
import org.eclipse.team.ui.TeamUI;
@@ -150,64 +151,108 @@ public class GitLightweightDecorator extends LabelProvider implements
* org.eclipse.jface.viewers.IDecoration)
*/
public void decorate(Object element, IDecoration decoration) {
-
- final IResource resource = getResource(element);
- if (resource == null)
+ // Don't decorate if UI plugin is not running
+ if (Activator.getDefault() == null)
return;
// Don't decorate if the workbench is not running
if (!PlatformUI.isWorkbenchRunning())
return;
- // Don't decorate if UI plugin is not running
- final Activator activator = Activator.getDefault();
- if (activator == null)
+ final IResource resource = getResource(element);
+ if (resource == null)
+ decorateResourceMapping(element, decoration);
+ else {
+ try {
+ decorateResource(resource, decoration);
+ } catch(CoreException e) {
+ handleException(resource, e);
+ }
+ }
+ }
+
+ /**
+ * Decorates a single resource (i.e. a project).
+ *
+ * @param resource the resource to decorate
+ * @param decoration the decoration
+ * @throws CoreException
+ */
+ private void decorateResource(IResource resource, IDecoration decoration) throws CoreException {
+ IndexDiffData indexDiffData = getIndexDiffDataOrNull(resource);
+
+ if(indexDiffData == null)
return;
- // Don't decorate the workspace root
+ IDecoratableResource decoratableResource = null;
+ final DecorationHelper helper = new DecorationHelper(
+ Activator.getDefault().getPreferenceStore());
+ try {
+ decoratableResource = new DecoratableResourceAdapter(indexDiffData, resource);
+ } catch (IOException e) {
+ throw new CoreException(Activator.createErrorStatus(UIText.Decorator_exceptionMessage, e));
+ }
+ helper.decorate(decoration, decoratableResource);
+ }
+
+ static IndexDiffData getIndexDiffDataOrNull(IResource resource) {
if (resource.getType() == IResource.ROOT)
- return;
+ return null;
// Don't decorate non-existing resources
if (!resource.exists() && !resource.isPhantom())
- return;
+ return null;
// Make sure we're dealing with a project under Git revision control
final RepositoryMapping mapping = RepositoryMapping
.getMapping(resource);
if (mapping == null)
- return;
+ return null;
// Don't decorate ignored resources (e.g. bin folder content)
if (resource.getType() != IResource.PROJECT
&& Team.isIgnoredHint(resource))
- return;
+ return null;
// Cannot decorate linked resources
if (mapping.getRepoRelativePath(resource) == null)
- return;
+ return null;
IndexDiffData indexDiffData = org.eclipse.egit.core.Activator
.getDefault().getIndexDiffCache()
.getIndexDiffCacheEntry(mapping.getRepository()).getIndexDiff();
- if (indexDiffData == null)
+
+ return indexDiffData;
+ }
+
+ /**
+ * Decorates a resource mapping (i.e. a Working Set).
+ *
+ * @param element the element for which the decoration was initially called
+ * @param decoration the decoration
+ */
+ private void decorateResourceMapping(Object element, IDecoration decoration) {
+ @SuppressWarnings("restriction")
+ ResourceMapping mapping = Utils.getResourceMapping(element);
+
+ IDecoratableResource decoRes = new DecoratableResourceMapping(mapping);
+
+ /*
+ * don't render question marks on working sets. !isTracked() can have two reasons:
+ * 1) nothing is tracked.
+ * 2) no indexDiff for the contained projects ready yet.
+ * in both cases, don't do anything to not pollute the display of the sets.
+ */
+ if(!decoRes.isTracked())
return;
- IDecoratableResource decoratableResource = null;
final DecorationHelper helper = new DecorationHelper(
- activator.getPreferenceStore());
- try {
- decoratableResource = new DecoratableResourceAdapter(indexDiffData, resource);
- } catch (IOException e) {
- handleException(
- resource,
- new CoreException(Activator.createErrorStatus(
- UIText.Decorator_exceptionMessage, e)));
- return;
- }
- helper.decorate(decoration, decoratableResource);
+ Activator.getDefault().getPreferenceStore());
+
+ helper.decorate(decoration, decoRes);
}
+
/**
* Helper class for doing resource decoration, based on the given
* preferences
@@ -355,6 +400,7 @@ public class GitLightweightDecorator extends LabelProvider implements
.getString(UIPreferences.DECORATOR_FILETEXT_DECORATION);
break;
case IResource.FOLDER:
+ case DecoratableResourceMapping.RESOURCE_MAPPING:
format = store
.getString(UIPreferences.DECORATOR_FOLDERTEXT_DECORATION);
break;

Back to the top