Skip to contentSkip to conversation

Support customizable label decorations

PATCH In review Tor Arne Vestbø 3 participants 21 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover Support customizable label decorations

This series adds support for customizable label decorations, which is usefull for hiding selected decorations, or tweaking the format of the decoration text.

Changes in v2:

- Fixed layout issues in preference dialog
- Icons replaced to match established conventions
- 'Assume unchanged' icon is back
- Added tooltips in the preference dialog
- 'Added and dirty' is now decorated appropriately
- Refactored container decorations. Now shares code path with files for more accurate results, and to allow inheritance

Decorations are edited using the new Team->Git->Label Decorations preference page, which is based off similar functionality from the existing CVS and SVN team providers.

Icons can be enabled and disabled individually, and text can be customized by reordering and editing the set of mapped variables. Boolean variables like 'dirty' and 'staged' can be customized by postfixing the variable name with a colon and a selected string that should be insert if the variable evaluates to true.

The two general options control traversal of child and parent elements during decoration. The first, 'Also re-decorate...', controls whether or not ancestor elements of the current decorated elment will also be scheduled for re-recoration. The second, 'Maximum number of levels...', controls how deep the container decoration algorithm will recurse when trying to determine the state (dirty, staged, etc.) of a container.

Tweaking these options will improve performance for large trees.

The code should work fairly well for most usecases, but I may have missed cases where the decorations will fail misserably. If so, please let me know.

Known issues are:

- If a project has a repository more than one level above the project directory decorations will fail.

- When a Java resource is dirty, each package in the package hierarcy will appear dirty, also when the layout is set to 'flat', which can be confusing.

These are on my list for features to add on top of these series, but I consider them non-blocking. This also goes for online help, which will be added when things stabilize some more.

I've also sprinkled the code with TODOs where I found possible future improvments. One such improvment is performance, where for example refactoring to use one shared status cache should help.

Tor Arne

Tor Arne Vestbø (12):
Add support code to handle plugin property changes Use Set instead of array to keep track of change listeners Add a specialized team exception for Git
Add new class ExceptionCollector for grouping exceptions Add new class SWTUtils with helper-methods for creating controls Implement basic customizable label decorations with preferences Add binding for name of the current branch
Add icon decoration for tracked and untracked resources Implement icon and text decorations of various resource states Don't decorate every single resource on repository change Expose the underlying resource entries in ContainerTreeIterator Implement label decorations for folders and projects

 org.spearce.egit.core/META-INF/MANIFEST.MF         |    5 +-
 .../spearce/egit/core/ContainerTreeIterator.java   |   23 +-
 .../src/org/spearce/egit/core/GitException.java    |  168 ++++
 .../core/internal/util/ExceptionCollector.java     |  128 +++
 .../spearce/egit/core/project/GitProjectData.java  |   40 +-
 org.spearce.egit.ui/icons/ovr/assume_valid.gif     |  Bin 0 -> 85 bytes
 org.spearce.egit.ui/icons/ovr/assumevalid.gif      |  Bin 64 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/conflict.gif         |  Bin 64 -> 194 bytes
 org.spearce.egit.ui/icons/ovr/pending_add.gif      |  Bin 64 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/pending_remove.gif   |  Bin 111 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/shared.gif           |  Bin 106 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/staged.gif           |  Bin 0 -> 114 bytes
 org.spearce.egit.ui/icons/ovr/staged_added.gif     |  Bin 0 -> 169 bytes
 org.spearce.egit.ui/icons/ovr/staged_removed.gif   |  Bin 0 -> 176 bytes
 org.spearce.egit.ui/icons/ovr/untracked.gif        |  Bin 0 -> 79 bytes
 org.spearce.egit.ui/plugin.properties              |    1 +
 org.spearce.egit.ui/plugin.xml                     |   12 +-
 .../src/org/spearce/egit/ui/Activator.java         |   68 ++
 .../egit/ui/PluginPreferenceInitializer.java       |   15 +
 .../src/org/spearce/egit/ui/UIIcons.java           |   21 +-
 .../src/org/spearce/egit/ui/UIPreferences.java     |   21 +
 .../src/org/spearce/egit/ui/UIText.java            |   99 ++-
 .../src/org/spearce/egit/ui/internal/SWTUtils.java |  595 ++++++++++++
 .../egit/ui/internal/actions/BranchAction.java     |    4 +-
 .../egit/ui/internal/actions/Disconnect.java       |    4 +-
 .../egit/ui/internal/actions/ResetAction.java      |    4 +-
 .../decorators/DecoratableResourceAdapter.java     |  391 ++++++++
 .../decorators/GitLightweightDecorator.java        |  653 ++++++++++++++
 .../internal/decorators/GitResourceDecorator.java  |  454 ----------
 .../internal/decorators/IDecoratableResource.java  |  100 ++
 .../preferences/GitDecoratorPreferencePage.java    |  949 ++++++++++++++++++++
 .../src/org/spearce/egit/ui/uitext.properties      |   38 +-
 .../src/org/spearce/jgit/treewalk/TreeWalk.java    |    9 +
 33 files changed, 3310 insertions(+), 492 deletions(-)
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/GitException.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/internal/util/ExceptionCollector.java
 create mode 100644 org.spearce.egit.ui/icons/ovr/assume_valid.gif
 delete mode 100644 org.spearce.egit.ui/icons/ovr/assumevalid.gif
 delete mode 100644 org.spearce.egit.ui/icons/ovr/pending_add.gif
 delete mode 100644 org.spearce.egit.ui/icons/ovr/pending_remove.gif
 delete mode 100644 org.spearce.egit.ui/icons/ovr/shared.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/staged.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/staged_added.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/staged_removed.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/untracked.gif
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/SWTUtils.java
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/DecoratableResourceAdapter.java
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java
 delete mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
#1 lore raw

PATCH v2 1/12 Add support code to handle plugin property changes

---
 .../src/org/spearce/egit/ui/Activator.java         |   52 ++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +52 -0
index fced643..534c408 100644
@@ -10,9 +10,11 @@
 
 import java.net.Authenticator;
 import java.net.ProxySelector;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.eclipse.core.net.proxy.IProxyService;
@@ -27,6 +29,8 @@
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.ISchedulingRule;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.jsch.core.IJSchService;
 import org.eclipse.swt.graphics.Font;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
@@ -44,9 +48,24 @@
  * This is a plugin singleton mostly controlling logging.
  */
 public class Activator extends AbstractUIPlugin {
+
+	/**
+	 *  The one and only instance
+	 */
 	private static Activator plugin;
 
 	/**
+	 * Property listeners for plugin specific events
+	 */
+	private static List<IPropertyChangeListener> propertyChangeListeners =
+		new ArrayList<IPropertyChangeListener>(5);
+
+	/**
+	 * Property constant indicating the decorator configuration has changed.
+	 */
+	public static final String DECORATORS_CHANGED = "org.spearce.egit.ui.DECORATORS_CHANGED"; //$NON-NLS-1$
+
+	/**
 	 * @return the {@link Activator} singleton.
 	 */
 	public static Activator getDefault() {
@@ -167,6 +186,39 @@ private void setupRepoIndexRefresh() {
 		Repository.addAnyRepositoryChangedListener(refreshJob);
 	}
 
+	/**
+	 * Register for changes made to Team properties.
+	 * 
+	 * @param listener
+	 *            The listener to register
+	 */
+	public static synchronized void addPropertyChangeListener(
+			IPropertyChangeListener listener) {
+		propertyChangeListeners.add(listener);
+	}
+
+	/**
+	 * Remove a Team property changes.
+	 * 
+	 * @param listener
+	 *            The listener to remove
+	 */
+	public static synchronized void removePropertyChangeListener(
+			IPropertyChangeListener listener) {
+		propertyChangeListeners.remove(listener);
+	}
+
+	/**
+	 * Broadcast a Team property change.
+	 * 
+	 * @param event
+	 *            The event to broadcast
+	 */
+	public static synchronized void broadcastPropertyChange(PropertyChangeEvent event) {
+		for (IPropertyChangeListener listener : propertyChangeListeners)
+			listener.propertyChange(event);
+	}
+
 	static class RIRefresh extends Job implements RepositoryListener {
 
 		RIRefresh() {
Signature · 1 line
1.6.1.2.309.g2ea3
#2 lore raw

PATCH v2 2/12 Use Set instead of array to keep track of change listeners

Also, add method for removing listeners.

---
 .../spearce/egit/core/project/GitProjectData.java  |   40 ++++++++++++-------
 1 files changed, 25 insertions(+), 15 deletions(-)
org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +25 -15
index db5f20b..b12a85f 100644
@@ -52,7 +52,7 @@
 
 	private static final Map<File, WeakReference> repositoryCache = new HashMap<File, WeakReference>();
 
-	private static RepositoryChangeListener[] repositoryChangeListeners = {};
+	private static Set<RepositoryChangeListener> repositoryChangeListeners = new HashSet<RepositoryChangeListener>();
 
 	@SuppressWarnings("synthetic-access")
 	private static final IResourceChangeListener rcl = new RCL();
@@ -112,16 +112,18 @@ public static synchronized void addRepositoryChangeListener(
 			final RepositoryChangeListener objectThatCares) {
 		if (objectThatCares == null)
 			throw new NullPointerException();
-		for (int k = repositoryChangeListeners.length - 1; k >= 0; k--) {
-			if (repositoryChangeListeners[k] == objectThatCares)
-				return;
-		}
-		final int p = repositoryChangeListeners.length;
-		final RepositoryChangeListener[] n;
-		n = new RepositoryChangeListener[p + 1];
-		System.arraycopy(repositoryChangeListeners, 0, n, 0, p);
-		n[p] = objectThatCares;
-		repositoryChangeListeners = n;
+		repositoryChangeListeners.add(objectThatCares);
+	}
+
+	/**
+	 * Remove a registered {@link RepositoryChangeListener}
+	 * 
+	 * @param objectThatCares
+	 *            The listener to remove
+	 */
+	public static synchronized void removeRepositoryChangeListener(
+			final RepositoryChangeListener objectThatCares) {
+		repositoryChangeListeners.remove(objectThatCares);
 	}
 
 	/**
@@ -131,13 +133,21 @@ public static synchronized void addRepositoryChangeListener(
 	 *            the repository which has had changes occur within it.
 	 */
 	static void fireRepositoryChanged(final RepositoryMapping which) {
-		final RepositoryChangeListener[] e = getRepositoryChangeListeners();
-		for (int k = e.length - 1; k >= 0; k--)
-			e[k].repositoryChanged(which);
+		for (RepositoryChangeListener listener : getRepositoryChangeListeners())
+			listener.repositoryChanged(which);
 	}
 
+	/**
+	 * Get a copy of the current set of repository change listeners
+	 * <p>
+	 * The array has no references, so is safe for iteration and modification
+	 * 
+	 * @return a copy of the current repository change listeners
+	 */
 	private static synchronized RepositoryChangeListener[] getRepositoryChangeListeners() {
-		return repositoryChangeListeners;
+		return repositoryChangeListeners
+				.toArray(new RepositoryChangeListener[repositoryChangeListeners
+						.size()]);
 	}
 
 	/**
Signature · 1 line
1.6.1.2.309.g2ea3
#3 lore raw

PATCH v2 3/12 Add a specialized team exception for Git

Copied largly from org.eclipse.team.internal.ccvs.core (CVS) and org.tigris.subversion.subclipse.core (SVN), and then cleaned up.

---
 .../src/org/spearce/egit/core/GitException.java    |  168 ++++++++++++++++++++
 1 files changed, 168 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/GitException.java
org.spearce.egit.core/src/org/spearce/egit/core/GitException.java new file +168 -0
new file mode 100644
index 0000000..7217fb7
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2003, 2006 Subclipse project and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * See LICENSE for the full license text, also available.
+ *******************************************************************************/
+
+package org.spearce.egit.core;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.*;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.TeamStatus;
+
+/**
+ * A checked exception representing a failure in the Git plugin.
+ * <p>
+ * Git exceptions contain a status object describing the cause of the exception.
+ * </p>
+ * 
+ * @see IStatus
+ */
+public class GitException extends TeamException {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Constructs a new Git exception
+	 * 
+	 * @param severity
+	 * @param code
+	 * @param message
+	 * @param e
+	 */
+	public GitException(int severity, int code, String message, Throwable e) {
+		super(new TeamStatus(severity, Activator.getPluginId(), code, message,
+				e, null));
+	}
+
+	/**
+	 * Constructs a new Git exception
+	 * 
+	 * @param severity
+	 * @param code
+	 * @param message
+	 */
+	public GitException(int severity, int code, String message) {
+		this(severity, code, message, null);
+	}
+
+	/**
+	 * Constructs a new Git exception
+	 * 
+	 * @param message
+	 * @param e
+	 */
+	public GitException(String message, Throwable e) {
+		this(IStatus.ERROR, UNABLE, message, e);
+	}
+
+	/**
+	 * Constructs a new Git exception
+	 * 
+	 * @param message
+	 */
+	public GitException(String message) {
+		this(message, null);
+	}
+
+	/**
+	 * Constructs a new Git exception
+	 * 
+	 * @param status
+	 */
+	public GitException(IStatus status) {
+		super(status);
+	}
+
+	/**
+	 * Transform this exception into a CoreException
+	 * 
+	 * @return the new CoreException
+	 */
+	public CoreException toCoreException() {
+		IStatus status = getStatus();
+		return new CoreException(new Status(status.getSeverity(), status
+				.getPlugin(), 0, status.getMessage(), this));
+	}
+
+	/**
+	 * Static helper method for creating a Git exception
+	 * 
+	 * @param resource
+	 * @param message
+	 * @param e
+	 * @return the created exception
+	 */
+	public static GitException wrapException(IResource resource,
+			String message, CoreException e) {
+		return new GitException(IStatus.ERROR, e.getStatus().getCode(),
+				message, e);
+	}
+
+	/**
+	 * Static helper method for creating a Git exception
+	 * 
+	 * @param e
+	 * @return the created exception
+	 */
+	public static GitException wrapException(Exception e) {
+		Throwable t = e;
+		if (e instanceof InvocationTargetException) {
+			Throwable target = ((InvocationTargetException) e)
+					.getTargetException();
+			if (target instanceof GitException) {
+				return (GitException) target;
+			}
+			t = target;
+		}
+
+		return new GitException(IStatus.ERROR, UNABLE,
+				t.getMessage() != null ? t.getMessage() : "", t); //$NON-NLS-1$
+	}
+
+	/**
+	 * Static helper method for creating a Git exception
+	 * 
+	 * @param e
+	 * @return the created exception
+	 */
+	public static GitException wrapException(CoreException e) {
+		IStatus status = e.getStatus();
+		if (!status.isMultiStatus()) {
+			status = new TeamStatus(status.getSeverity(), Activator
+					.getPluginId(), status.getCode(), status.getMessage(), e,
+					null);
+		}
+		return new GitException(status);
+	}
+
+	/**
+	 * Static helper method for creating a Git exception
+	 * 
+	 * @param e
+	 * @return the created exception
+	 */
+	public static GitException wrapException(IOException e) {
+		return new GitException(IStatus.ERROR, IO_FAILED, e.getMessage(), e);
+	}
+
+	/**
+	 * Static helper method for creating a Git exception
+	 * 
+	 * @param e
+	 * @return the created exception
+	 */
+	public static GitException wrapException(TeamException e) {
+		if (e instanceof GitException)
+			return (GitException) e;
+		else
+			return new GitException(e.getStatus());
+	}
+}
Signature · 1 line
1.6.1.2.309.g2ea3
#4 lore raw

PATCH v2 4/12 Add new class ExceptionCollector for grouping exceptions

Copied from org.eclipse.team.internal.core

---
 org.spearce.egit.core/META-INF/MANIFEST.MF         |    5 +-
 .../core/internal/util/ExceptionCollector.java     |  128 ++++++++++++++++++++
 2 files changed, 131 insertions(+), 2 deletions(-)
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/internal/util/ExceptionCollector.java
org.spearce.egit.core/META-INF/MANIFEST.MF +3 -2
index e13732b..20df15f 100644
@@ -12,8 +12,9 @@ Require-Bundle: org.eclipse.core.runtime,
  org.spearce.jgit,
  org.eclipse.core.filesystem,
  org.eclipse.ui
-Export-Package: org.spearce.egit.core.internal.storage;x-friends:="org.spearce.egit.ui",
- org.spearce.egit.core,
+Export-Package: org.spearce.egit.core,
+ org.spearce.egit.core.internal.storage;x-friends:="org.spearce.egit.ui",
+ org.spearce.egit.core.internal.util;x-friends:="org.spearce.egit.ui",
  org.spearce.egit.core.op,
  org.spearce.egit.core.project
 Bundle-ActivationPolicy: lazy
org.spearce.egit.core/src/org/spearce/egit/core/internal/util/ExceptionCollector.java new file +128 -0

128 lines not on this page · raw message

Signature · 1 line
1.6.1.2.309.g2ea3
#5 lore raw

PATCH v2 5/12 Add new class SWTUtils with helper-methods for creating controls

Copied verbatim from org.eclipse.team.internal.ui and documented

---
 .../src/org/spearce/egit/ui/internal/SWTUtils.java |  595 ++++++++++++++++++++
 1 files changed, 595 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/SWTUtils.java
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/SWTUtils.java new file +595 -0
new file mode 100644
index 0000000..fe65bbb
@@ -0,0 +1,595 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * 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
+ *
+ * Contributors:
+ *	 IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.spearce.egit.ui.internal;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.dialogs.PreferenceLinkArea;
+import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
+
+/**
+ * A collection of factory methods for creating common SWT controls
+ */
+public class SWTUtils {
+
+	/** */
+	public static final int MARGINS_DEFAULT = -1;
+
+	/** */
+	public static final int MARGINS_NONE = 0;
+
+	/** */
+	public static final int MARGINS_DIALOG = 1;
+
+	/**
+	 * Creates a preference link which will open in the specified container
+	 * 
+	 * @param container
+	 * @param parent
+	 * @param pageId
+	 * @param text
+	 * 
+	 * @return the created link
+	 */
+	public static PreferenceLinkArea createPreferenceLink(
+			IWorkbenchPreferenceContainer container, Composite parent,
+			String pageId, String text) {
+		final PreferenceLinkArea area = new PreferenceLinkArea(parent,
+				SWT.NONE, pageId, text, container, null);
+		return area;
+	}
+
+	/**
+	 * Creates a grid data with the specified metrics
+	 * 
+	 * @param width
+	 * @param height
+	 * @param hFill
+	 * @param vFill
+	 * 
+	 * @return the created grid data
+	 */
+	public static GridData createGridData(int width, int height, boolean hFill,
+			boolean vFill) {
+		return createGridData(width, height, hFill ? SWT.FILL : SWT.BEGINNING,
+				vFill ? SWT.FILL : SWT.CENTER, hFill, vFill);
+	}
+
+	/**
+	 * Creates a grid data with the specified metrics
+	 * 
+	 * @param width
+	 * @param height
+	 * @param hAlign
+	 * @param vAlign
+	 * @param hGrab
+	 * @param vGrab
+	 * 
+	 * @return the created grid data
+	 */
+	public static GridData createGridData(int width, int height, int hAlign,
+			int vAlign, boolean hGrab, boolean vGrab) {
+		final GridData gd = new GridData(hAlign, vAlign, hGrab, vGrab);
+		gd.widthHint = width;
+		gd.heightHint = height;
+		return gd;
+	}
+
+	/**
+	 * Creates a horizontal grid data with the default metrics
+	 * 
+	 * @return the created grid data
+	 */
+	public static GridData createHFillGridData() {
+		return createHFillGridData(1);
+	}
+
+	/**
+	 * Creates a horizontal grid data with the specified span
+	 * 
+	 * @param span
+	 * 
+	 * @return the created grid data
+	 */
+	public static GridData createHFillGridData(int span) {
+		final GridData gd = createGridData(0, SWT.DEFAULT, SWT.FILL,
+				SWT.CENTER, true, false);
+		gd.horizontalSpan = span;
+		return gd;
+	}
+
+	/**
+	 * Creates a horizontal fill composite with the specified margins
+	 * 
+	 * @param parent
+	 * @param margins
+	 * 
+	 * @return the created composite
+	 */
+	public static Composite createHFillComposite(Composite parent, int margins) {
+		return createHFillComposite(parent, margins, 1);
+	}
+
+	/**
+	 * Creates a horizontal fill composite with the specified margins and
+	 * columns
+	 * 
+	 * @param parent
+	 * @param margins
+	 * @param columns
+	 * 
+	 * @return the created composite
+	 */
+	public static Composite createHFillComposite(Composite parent, int margins,
+			int columns) {
+		final Composite composite = new Composite(parent, SWT.NONE);
+		composite.setFont(parent.getFont());
+		composite.setLayoutData(createHFillGridData());
+		composite.setLayout(createGridLayout(columns,
+				new PixelConverter(parent), margins));
+		return composite;
+	}
+
+	/**
+	 * Creates a horizontal/vertical fill composite with the specified margins
+	 * 
+	 * @param parent
+	 * @param margins
+	 * 
+	 * @return the created composite
+	 */
+	public static Composite createHVFillComposite(Composite parent, int margins) {
+		return createHVFillComposite(parent, margins, 1);
+	}
+
+	/**
+	 * Creates a horizontal/vertical fill composite with the specified margins
+	 * and columns
+	 * 
+	 * @param parent
+	 * @param margins
+	 * @param columns
+	 * 
+	 * @return the created composite
+	 */
+	public static Composite createHVFillComposite(Composite parent,
+			int margins, int columns) {
+		final Composite composite = new Composite(parent, SWT.NONE);
+		composite.setFont(parent.getFont());
+		composite.setLayoutData(createHVFillGridData());
+		composite.setLayout(createGridLayout(columns,
+				new PixelConverter(parent), margins));
+		return composite;
+	}
+
+	/**
+	 * Creates a horizontal fill group with the specified text and margins
+	 * 
+	 * @param parent
+	 * @param text
+	 * @param margins
+	 * @return the created group
+	 */
+	public static Group createHFillGroup(Composite parent, String text,
+			int margins) {
+		return createHFillGroup(parent, text, margins, 1);
+	}
+
+	/**
+	 * Creates a horizontal fill group with the specified text, margins and rows
+	 * 
+	 * @param parent
+	 * @param text
+	 * @param margins
+	 * @param rows
+	 * 
+	 * @return the created group
+	 */
+	public static Group createHFillGroup(Composite parent, String text,
+			int margins, int rows) {
+		final Group group = new Group(parent, SWT.NONE);
+		group.setFont(parent.getFont());
+		group.setLayoutData(createHFillGridData());
+		if (text != null)
+			group.setText(text);
+		group.setLayout(createGridLayout(rows, new PixelConverter(parent),
+				margins));
+		return group;
+	}
+
+	/**
+	 * Creates a horizontal/vertical fill group with the specified text and
+	 * margins
+	 * 
+	 * @param parent
+	 * @param text
+	 * @param margins
+	 * 
+	 * @return the created group
+	 */
+	public static Group createHVFillGroup(Composite parent, String text,
+			int margins) {
+		return createHVFillGroup(parent, text, margins, 1);
+	}
+
+	/**
+	 * Creates a horizontal/vertical fill group with the specified text, margins
+	 * and rows
+	 * 
+	 * @param parent
+	 * @param text
+	 * @param margins
+	 * @param rows
+	 * 
+	 * @return the created group
+	 */
+	public static Group createHVFillGroup(Composite parent, String text,
+			int margins, int rows) {
+		final Group group = new Group(parent, SWT.NONE);
+		group.setFont(parent.getFont());
+		group.setLayoutData(createHVFillGridData());
+		if (text != null)
+			group.setText(text);
+		group.setLayout(createGridLayout(rows, new PixelConverter(parent),
+				margins));
+		return group;
+	}
+
+	/**
+	 * Creates a horizontal/vertical fill grid data with the default metrics
+	 * 
+	 * @return the created grid data
+	 */
+	public static GridData createHVFillGridData() {
+		return createHVFillGridData(1);
+	}
+
+	/**
+	 * Creates a horizontal/vertical fill grid data with the specified span
+	 * 
+	 * @param span
+	 * 
+	 * @return the created grid data
+	 */
+	public static GridData createHVFillGridData(int span) {
+		final GridData gd = createGridData(0, 0, true, true);
+		gd.horizontalSpan = span;
+		return gd;
+	}
+
+	/**
+	 * Creates a grid layout with the specified number of columns and the
+	 * standard spacings.
+	 * 
+	 * @param numColumns
+	 *            the number of columns
+	 * @param converter
+	 *            the pixel converter
+	 * @param margins
+	 *            one of <code>MARGINS_DEFAULT</code>, <code>MARGINS_NONE</code>
+	 *            or <code>MARGINS_DIALOG</code>.
+	 * 
+	 * @return the created grid layout
+	 */
+	public static GridLayout createGridLayout(int numColumns,
+			PixelConverter converter, int margins) {
+		Assert.isTrue(margins == MARGINS_DEFAULT || margins == MARGINS_NONE
+				|| margins == MARGINS_DIALOG);
+
+		final GridLayout layout = new GridLayout(numColumns, false);
+		layout.horizontalSpacing = converter
+				.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+		layout.verticalSpacing = converter
+				.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+
+		switch (margins) {
+		case MARGINS_NONE:
+			layout.marginLeft = layout.marginRight = 0;
+			layout.marginTop = layout.marginBottom = 0;
+			break;
+		case MARGINS_DIALOG:
+			layout.marginLeft = layout.marginRight = converter
+					.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+			layout.marginTop = layout.marginBottom = converter
+					.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+			break;
+		case MARGINS_DEFAULT:
+			layout.marginLeft = layout.marginRight = layout.marginWidth;
+			layout.marginTop = layout.marginBottom = layout.marginHeight;
+		}
+		layout.marginWidth = layout.marginHeight = 0;
+		return layout;
+	}
+
+	/**
+	 * Creates a label with the specified message
+	 * 
+	 * @param parent
+	 * @param message
+	 * 
+	 * @return the created label
+	 */
+	public static Label createLabel(Composite parent, String message) {
+		return createLabel(parent, message, 1);
+	}
+
+	/**
+	 * Creates a label with the specified message and span
+	 * 
+	 * @param parent
+	 * @param message
+	 * @param span
+	 * 
+	 * @return the created label
+	 */
+	public static Label createLabel(Composite parent, String message, int span) {
+		final Label label = new Label(parent, SWT.WRAP);
+		if (message != null)
+			label.setText(message);
+		label.setLayoutData(createHFillGridData(span));
+		return label;
+	}
+
+	/**
+	 * Creates a check box with the specified message
+	 * 
+	 * @param parent
+	 * @param message
+	 * 
+	 * @return the created check box
+	 */
+	public static Button createCheckBox(Composite parent, String message) {
+		return createCheckBox(parent, message, 1);
+	}
+
+	/**
+	 * Creates a check box with the specified message and span
+	 * 
+	 * @param parent
+	 * @param message
+	 * @param span
+	 * 
+	 * @return the created check box
+	 */
+	public static Button createCheckBox(Composite parent, String message,
+			int span) {
+		final Button button = new Button(parent, SWT.CHECK);
+		button.setText(message);
+		button.setLayoutData(createHFillGridData(span));
+		return button;
+	}
+
+	/**
+	 * Creates a radio button with the specified message
+	 * 
+	 * @param parent
+	 * @param message
+	 * 
+	 * @return the created radio button
+	 */
+	public static Button createRadioButton(Composite parent, String message) {
+		return createRadioButton(parent, message, 1);
+	}
+
+	/**
+	 * Creates a radio button with the specified message and span
+	 * 
+	 * @param parent
+	 * @param message
+	 * @param span
+	 * 
+	 * @return the created radio button
+	 */
+	public static Button createRadioButton(Composite parent, String message,
+			int span) {
+		final Button button = new Button(parent, SWT.RADIO);
+		button.setText(message);
+		button.setLayoutData(createHFillGridData(span));
+		return button;
+	}
+
+	/**
+	 * Creates a text control
+	 * 
+	 * @param parent
+	 * 
+	 * @return the created text control
+	 */
+	public static Text createText(Composite parent) {
+		return createText(parent, 1);
+	}
+
+	/**
+	 * Creates a text control with the specified span
+	 * 
+	 * @param parent
+	 * @param span
+	 * 
+	 * @return the created text control
+	 */
+	public static Text createText(Composite parent, int span) {
+		final Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
+		text.setLayoutData(createHFillGridData(span));
+		return text;
+	}
+
+	/**
+	 * Creates a place holder with the specified height and span
+	 * 
+	 * @param parent
+	 * @param heightInChars
+	 * @param span
+	 * 
+	 * @return the created place holder
+	 */
+	public static Control createPlaceholder(Composite parent,
+			int heightInChars, int span) {
+		Assert.isTrue(heightInChars > 0);
+		final Control placeHolder = new Composite(parent, SWT.NONE);
+		final GridData gd = new GridData(SWT.BEGINNING, SWT.TOP, false, false);
+		gd.heightHint = new PixelConverter(parent)
+				.convertHeightInCharsToPixels(heightInChars);
+		gd.horizontalSpan = span;
+		placeHolder.setLayoutData(gd);
+		return placeHolder;
+	}
+
+	/**
+	 * Creates a place holder with the specified height
+	 * 
+	 * @param parent
+	 * @param heightInChars
+	 * @return the created place holder
+	 */
+	public static Control createPlaceholder(Composite parent, int heightInChars) {
+		return createPlaceholder(parent, heightInChars, 1);
+	}
+
+	/**
+	 * Creates a pixel converter
+	 * 
+	 * @param control
+	 * 
+	 * @return the created pixel converter
+	 */
+	public static PixelConverter createDialogPixelConverter(Control control) {
+		Dialog.applyDialogFont(control);
+		return new PixelConverter(control);
+	}
+
+	/**
+	 * Calculates the size of the specified controls, using the specified
+	 * converter
+	 * 
+	 * @param converter
+	 * @param controls
+	 * 
+	 * @return the size of the control(s)
+	 */
+	public static int calculateControlSize(PixelConverter converter,
+			Control[] controls) {
+		return calculateControlSize(converter, controls, 0, controls.length - 1);
+	}
+
+	/**
+	 * Calculates the size of the specified subset of controls, using the
+	 * specified converter
+	 * 
+	 * @param converter
+	 * @param controls
+	 * @param start
+	 * @param end
+	 * 
+	 * @return the created control
+	 */
+	public static int calculateControlSize(PixelConverter converter,
+			Control[] controls, int start, int end) {
+		int minimum = converter
+				.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
+		for (int i = start; i <= end; i++) {
+			final int length = controls[i]
+					.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+			if (minimum < length)
+				minimum = length;
+		}
+		return minimum;
+	}
+
+	/**
+	 * Equalizes the specified controls using the specified converter
+	 * 
+	 * @param converter
+	 * @param controls
+	 */
+	public static void equalizeControls(PixelConverter converter,
+			Control[] controls) {
+		equalizeControls(converter, controls, 0, controls.length - 1);
+	}
+
+	/**
+	 * Equalizes the specified subset of controls using the specified converter
+	 * 
+	 * @param converter
+	 * @param controls
+	 * @param start
+	 * @param end
+	 */
+	public static void equalizeControls(PixelConverter converter,
+			Control[] controls, int start, int end) {
+		final int size = calculateControlSize(converter, controls, start, end);
+		for (int i = start; i <= end; i++) {
+			final Control button = controls[i];
+			if (button.getLayoutData() instanceof GridData) {
+				((GridData) button.getLayoutData()).widthHint = size;
+			}
+		}
+	}
+
+	/**
+	 * Gets the width of the longest string in <code>strings</code>, using the
+	 * specified pixel converter
+	 * 
+	 * @param converter
+	 * @param strings
+	 * 
+	 * @return the width of the longest string
+	 */
+	public static int getWidthInCharsForLongest(PixelConverter converter,
+			String[] strings) {
+		int minimum = 0;
+		for (int i = 0; i < strings.length; i++) {
+			final int length = converter.convertWidthInCharsToPixels(strings[i]
+					.length());
+			if (minimum < length)
+				minimum = length;
+		}
+		return minimum;
+	}
+
+	private static class PixelConverter {
+
+		private final FontMetrics fFontMetrics;
+
+		public PixelConverter(Control control) {
+			GC gc = new GC(control);
+			try {
+				gc.setFont(control.getFont());
+				fFontMetrics = gc.getFontMetrics();
+			} finally {
+				gc.dispose();
+			}
+		}
+
+		public int convertHeightInCharsToPixels(int chars) {
+			return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
+		}
+
+		public int convertHorizontalDLUsToPixels(int dlus) {
+			return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
+		}
+
+		public int convertVerticalDLUsToPixels(int dlus) {
+			return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
+		}
+
+		public int convertWidthInCharsToPixels(int chars) {
+			return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
+		}
+	}
+}
Signature · 1 line
1.6.1.2.309.g2ea3
#6 lore raw

PATCH v2 6/12 Implement basic customizable label decorations with preferences

Currently the only binding available is the resource name, but this commit enables a framework for adding more bindings.

---
 org.spearce.egit.ui/plugin.properties              |    1 +
 org.spearce.egit.ui/plugin.xml                     |   12 +-
 .../src/org/spearce/egit/ui/Activator.java         |   16 +
 .../egit/ui/PluginPreferenceInitializer.java       |    8 +
 .../src/org/spearce/egit/ui/UIPreferences.java     |    9 +
 .../src/org/spearce/egit/ui/UIText.java            |   63 ++-
 .../egit/ui/internal/actions/BranchAction.java     |    4 +-
 .../egit/ui/internal/actions/Disconnect.java       |    4 +-
 .../egit/ui/internal/actions/ResetAction.java      |    4 +-
 .../decorators/GitLightweightDecorator.java        |  538 +++++++++++++++
 .../internal/decorators/GitResourceDecorator.java  |  454 -------------
 .../internal/decorators/IDecoratableResource.java  |   31 +
 .../preferences/GitDecoratorPreferencePage.java    |  702 ++++++++++++++++++++
 .../src/org/spearce/egit/ui/uitext.properties      |   25 +-
 14 files changed, 1405 insertions(+), 466 deletions(-)
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java
 delete mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java
org.spearce.egit.ui/plugin.properties +1 -0
index fa043f1..58b879f 100644
@@ -64,3 +64,4 @@ Theme_CommitMessageFont_description=This font is used to show a commit message.
 GitPreferences_name=Git
 GitPreferences_HistoryPreferencePage_name=History
 GitPreferences_WindowCachePreferencePage_name=Window Cache
+GitPreferences_DecoratorPreferencePage_name=Label Decorations
org.spearce.egit.ui/plugin.xml +10 -2
index 869108c..2f23559 100644
@@ -200,6 +200,14 @@
 		  id="org.spearce.egit.ui.keyword.git">
 	    </keywordReference>
       </page>
+	  <page name="%GitPreferences_DecoratorPreferencePage_name"
+	    category="org.spearce.egit.ui.GitPreferences"
+            class="org.spearce.egit.ui.internal.preferences.GitDecoratorPreferencePage"
+	    id="org.spearce.egit.ui.internal.preferences.GitDecoratorPreferencePage" >
+	    <keywordReference
+		  id="org.spearce.egit.ui.keyword.git">
+	    </keywordReference>
+      </page>
    </extension>
 
    <extension point="org.eclipse.ui.propertyPages">
@@ -233,10 +241,10 @@
             lightweight="true"
             adaptable="true"
             label="%Decorator_name"
-            class="org.spearce.egit.ui.internal.decorators.GitResourceDecorator"
+            class="org.spearce.egit.ui.internal.decorators.GitLightweightDecorator"
             state="true"
             location="BOTTOM_RIGHT"
-            id="org.spearce.egit.ui.internal.decorators.GitResourceDecorator">
+            id="org.spearce.egit.ui.internal.decorators.GitLightweightDecorator">
             <enablement>
               <objectClass name="org.eclipse.core.resources.IResource"/>
             </enablement>
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +16 -0
index 534c408..87f45d2 100644
@@ -33,6 +33,7 @@
 import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.jsch.core.IJSchService;
 import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.eclipse.ui.themes.ITheme;
 import org.osgi.framework.BundleContext;
@@ -80,6 +81,21 @@ public static String getPluginId() {
 	}
 
 	/**
+	 * Returns the standard display to be used. The method first checks, if the
+	 * thread calling this method has an associated display. If so, this display
+	 * is returned. Otherwise the method returns the default display.
+	 * 
+	 * @return the display to use
+	 */
+	public static Display getStandardDisplay() {
+		Display display = Display.getCurrent();
+		if (display == null) {
+			display = Display.getDefault();
+		}
+		return display;
+	}
+
+	/**
 	 * Instantiate an error exception.
 	 * 
 	 * @param message
org.spearce.egit.ui/src/org/spearce/egit/ui/PluginPreferenceInitializer.java +8 -0
index bb7381f..79c2665 100644
@@ -35,6 +35,14 @@ public void initializeDefaultPreferences() {
 		prefs.setDefault(UIPreferences.RESOURCEHISTORY_SHOW_REV_COMMENT, true);
 		prefs.setDefault(UIPreferences.RESOURCEHISTORY_SHOW_TOOLTIPS, false);
 
+		prefs.setDefault(UIPreferences.DECORATOR_FILETEXT_DECORATION,
+				UIText.DecoratorPreferencesPage_fileFormatDefault);
+		prefs.setDefault(UIPreferences.DECORATOR_FOLDERTEXT_DECORATION,
+				UIText.DecoratorPreferencesPage_folderFormatDefault);
+		prefs.setDefault(UIPreferences.DECORATOR_PROJECTTEXT_DECORATION,
+				UIText.DecoratorPreferencesPage_projectFormatDefault);
+		prefs.setDefault(UIPreferences.DECORATOR_CALCULATE_DIRTY, true);
+
 		w = new int[] { 500, 500 };
 		UIPreferences.setDefault(prefs,
 				UIPreferences.RESOURCEHISTORY_GRAPH_SPLIT, w);
org.spearce.egit.ui/src/org/spearce/egit/ui/UIPreferences.java +9 -0
index 5ab6b25..a6168a0 100644
@@ -52,6 +52,15 @@
 	/** */
 	public final static String THEME_CommitMessageFont = "org.spearce.egit.ui.CommitMessageFont";
 
+	/** */
+	public final static String DECORATOR_CALCULATE_DIRTY = "decorator_calculate_dirty";
+	/** */
+	public final static String DECORATOR_FILETEXT_DECORATION = "decorator_filetext_decoration";
+	/** */
+	public final static String DECORATOR_FOLDERTEXT_DECORATION = "decorator_foldertext_decoration";
+	/** */
+	public final static String DECORATOR_PROJECTTEXT_DECORATION = "decorator_projecttext_decoration";
+
 	/**
 	 * Get the preference values associated with a fixed integer array.
 	 * 
org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +60 -3

75 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/BranchAction.java +2 -2
index 7ca4d10..38ee3d8 100644
@@ -19,7 +19,7 @@
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.swt.widgets.Display;
 import org.spearce.egit.core.op.BranchOperation;
-import org.spearce.egit.ui.internal.decorators.GitResourceDecorator;
+import org.spearce.egit.ui.internal.decorators.GitLightweightDecorator;
 import org.spearce.egit.ui.internal.dialogs.BranchSelectionDialog;
 import org.spearce.jgit.lib.Repository;
 
@@ -56,7 +56,7 @@ public void run(final IProgressMonitor monitor)
 				throws InvocationTargetException {
 					try {
 						new BranchOperation(repository, refName).run(monitor);
-						GitResourceDecorator.refresh();
+						GitLightweightDecorator.refresh();
 					} catch (final CoreException ce) {
 						ce.printStackTrace();
 						Display.getDefault().asyncExec(new Runnable() {
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/Disconnect.java +2 -2
index 18d6b4b..4201822 100644
@@ -13,7 +13,7 @@
 import org.eclipse.core.resources.IWorkspaceRunnable;
 import org.eclipse.jface.action.IAction;
 import org.spearce.egit.core.op.DisconnectProviderOperation;
-import org.spearce.egit.ui.internal.decorators.GitResourceDecorator;
+import org.spearce.egit.ui.internal.decorators.GitLightweightDecorator;
 
 /**
  *	Action to disassociate a project from its Git repository.
@@ -27,6 +27,6 @@ protected IWorkspaceRunnable createOperation(final IAction act,
 	}
 
 	protected void postOperation() {
-		GitResourceDecorator.refresh();
+		GitLightweightDecorator.refresh();
 	}
 }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/actions/ResetAction.java +2 -2
index b05cdd3..a329925 100644
@@ -19,7 +19,7 @@
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.spearce.egit.core.op.ResetOperation;
 import org.spearce.egit.core.op.ResetOperation.ResetType;
-import org.spearce.egit.ui.internal.decorators.GitResourceDecorator;
+import org.spearce.egit.ui.internal.decorators.GitLightweightDecorator;
 import org.spearce.egit.ui.internal.dialogs.BranchSelectionDialog;
 import org.spearce.jgit.lib.Repository;
 
@@ -55,7 +55,7 @@ public void run(final IProgressMonitor monitor)
 					throws InvocationTargetException {
 						try {
 							new ResetOperation(repository, refName, type).run(monitor);
-							GitResourceDecorator.refresh();
+							GitLightweightDecorator.refresh();
 						} catch (CoreException ce) {
 							ce.printStackTrace();
 							throw new InvocationTargetException(ce);
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java new file +538 -0

538 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitResourceDecorator.java deleted +0 -454

454 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java new file +31 -0
new file mode 100644
index 0000000..8d6c741
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (C) 2008, Tor Arne Vestbø <[email protected]>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * See LICENSE for the full license text, also available.
+ *******************************************************************************/
+
+package org.spearce.egit.ui.internal.decorators;
+
+import org.eclipse.core.resources.IResource;
+
+/**
+ * Represents the state of a resource that can be used as a basis for decoration
+ */
+public interface IDecoratableResource {
+
+	/**
+	 * Gets the type of the resource as defined by {@link IResource}
+	 * 
+	 * @return the type of the resource
+	 */
+	int getType();
+
+	/**
+	 * Gets the name of the resource
+	 * 
+	 * @return the name of the resource
+	 */
+	String getName();
+}
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java new file +702 -0

702 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +24 -1
index c1d9db6..4660983 100644
@@ -169,7 +169,6 @@ RefSpecPage_annotatedTagsAutoFollow=Automatically follow tags if we fetch the th
 RefSpecPage_annotatedTagsFetchTags=Always fetch tags, even if we do not have the thing it points at
 RefSpecPage_annotatedTagsNoTags=Never fetch tags, even if we have the thing it points at
 
-Decorator_failedLazyLoading=Resource decorator failed to load tree contents on demand.
 QuickDiff_failedLoading=Quick diff failed to obtain file data.
 
 ResourceHistory_toggleCommentWrap=Wrap Comments
@@ -346,3 +345,27 @@ BranchSelectionDialog_ResetTypeMixed=&Mixed (working directory unmodified)
 BranchSelectionDialog_ResetTypeSoft=&Soft (Index and working directory unmodified)
 BranchSelectionDialog_Tags=Tags
 BranchSelectionDialog_Refs=&Refs
+
+Decorator_exceptionMessage=Errors occurred while applying Git decorations to resources.
+
+DecoratorPreferencesPage_addVariablesTitle=Add Variables
+DecoratorPreferencesPage_addVariablesAction=Add &Variables...
+DecoratorPreferencesPage_computeDeep=Include &ancestors when re-decorating changed resources
+DecoratorPreferencesPage_description=Shows Git specific information on resources in projects under version control.
+
+DecoratorPreferencesPage_decorationSettings=Decoration &settings:
+DecoratorPreferencesPage_preview=Preview:
+DecoratorPreferencesPage_fileFormatLabel=&Files:
+DecoratorPreferencesPage_folderFormatLabel=F&olders:
+DecoratorPreferencesPage_projectFormatLabel=&Projects:
+DecoratorPreferencesPage_fileFormatDefault={name}
+DecoratorPreferencesPage_folderFormatDefault={name}
+DecoratorPreferencesPage_projectFormatDefault={name}
+DecoratorPreferencesPage_labelDecorationsLink=See <a>''{0}''</a> to enable or disable Git decorations.
+DecoratorPreferencesPage_generalTabFolder=&General
+DecoratorPreferencesPage_nameResourceVariable=name of the resource being decorated
+DecoratorPreferencesPage_selectFormats=Select the format for file, folders, and project text labels:
+DecoratorPreferencesPage_selectVariablesToAdd=Select the &variables to add to the decoration format:
+DecoratorPreferencesPage_textLabel=T&ext Decorations
+DecoratorPreferencesPage_iconLabel=&Icon Decorations
+
Signature · 1 line
1.6.1.2.309.g2ea3
#7 lore raw

PATCH v2 7/12 Add binding for name of the current branch

This is an example of how to add more bindings to the decoration preferences, and how they are implemented in the decorator.

---
 .../src/org/spearce/egit/ui/UIText.java            |    3 ++
 .../decorators/GitLightweightDecorator.java        |   26 ++++++++++++++++---
 .../internal/decorators/IDecoratableResource.java  |    8 ++++++
 .../preferences/GitDecoratorPreferencePage.java    |   21 +++++++++++----
 .../src/org/spearce/egit/ui/uitext.properties      |    3 +-
 5 files changed, 50 insertions(+), 11 deletions(-)
org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +3 -0
index a7ef408..345c66b 100644
@@ -971,6 +971,9 @@
 	public static String DecoratorPreferencesPage_nameResourceVariable;
 
 	/** */
+	public static String DecoratorPreferencesPage_bindingBranchName;
+
+	/** */
 	public static String DecoratorPreferencesPage_selectFormats;
 
 	/** */
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java +22 -4
index 85b9173..265d5a3 100644
@@ -13,6 +13,7 @@
 
 package org.spearce.egit.ui.internal.decorators;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -44,6 +45,7 @@
 import org.eclipse.team.ui.TeamUI;
 import org.eclipse.ui.IContributorResourceAdapter;
 import org.eclipse.ui.PlatformUI;
+import org.spearce.egit.core.GitException;
 import org.spearce.egit.core.internal.util.ExceptionCollector;
 import org.spearce.egit.core.project.GitProjectData;
 import org.spearce.egit.core.project.RepositoryChangeListener;
@@ -157,17 +159,26 @@ public void decorate(Object element, IDecoration decoration) {
 		if (activator == null)
 			return;
 
-		DecorationHelper helper = new DecorationHelper(activator
-				.getPreferenceStore());
-		helper.decorate(decoration, new DecoratableResourceAdapter(resource));
+		try {
+			DecorationHelper helper = new DecorationHelper(activator
+					.getPreferenceStore());
+			helper.decorate(decoration,
+					new DecoratableResourceAdapter(resource));
+		} catch (IOException e) {
+			handleException(resource, GitException.wrapException(e));
+		}
 	}
 
 	private class DecoratableResourceAdapter implements IDecoratableResource {
 
 		private IResource resource;
+		private String branch;
 
-		public DecoratableResourceAdapter(IResource resourceToWrap) {
+		public DecoratableResourceAdapter(IResource resourceToWrap) throws IOException {
 			resource = resourceToWrap;
+			RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
+			Repository repository = mapping.getRepository();
+			branch = repository.getBranch();
 		}
 
 		public String getName() {
@@ -177,6 +188,10 @@ public String getName() {
 		public int getType() {
 			return resource.getType();
 		}
+
+		public String getBranch() {
+			return branch;
+		}
 	}
 
 	/**
@@ -192,6 +207,8 @@ public int getType() {
 
 		/** */
 		public static final String BINDING_RESOURCE_NAME = "name"; //$NON-NLS-1$
+		/** */
+		public static final String BINDING_BRANCH_NAME = "branch"; //$NON-NLS-1$
 
 		/**
 		 * Constructs a decorator using the rules from the given
@@ -234,6 +251,7 @@ public void decorate(IDecoration decoration,
 
 			Map<String, String> bindings = new HashMap<String, String>();
 			bindings.put(BINDING_RESOURCE_NAME, resource.getName());
+			bindings.put(BINDING_BRANCH_NAME, resource.getBranch());
 
 			decorate(decoration, format, bindings);
 		}
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java +8 -0
index 8d6c741..6b36e0e 100644
@@ -28,4 +28,12 @@
 	 * @return the name of the resource
 	 */
 	String getName();
+
+	/**
+	 * Gets the current branch of the resource if applicable
+	 * 
+	 * @return the name of the current branch, or <code>null</code> if not
+	 *         applicable
+	 */
+	String getBranch();
 }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java +15 -6
index 84203b7..b7d737c 100644
@@ -93,10 +93,10 @@
 
 	static {
 		final PreviewResource project = new PreviewResource(
-				"Project", IResource.PROJECT); //$NON-NLS-1$1
+				"Project", IResource.PROJECT, "master"); //$NON-NLS-1$1
 		final ArrayList<PreviewResource> children = new ArrayList<PreviewResource>();
-		children.add(new PreviewResource("folder", IResource.FOLDER)); //$NON-NLS-1$
-		children.add(new PreviewResource("file.txt", IResource.FILE)); //$NON-NLS-1$
+		children.add(new PreviewResource("folder", IResource.FOLDER, null)); //$NON-NLS-1$
+		children.add(new PreviewResource("file.txt", IResource.FILE, null)); //$NON-NLS-1$
 		project.children = children;
 		PREVIEW_FILESYSTEM_ROOT = Collections.singleton(project);
 	}
@@ -456,6 +456,8 @@ private Map getProjectBindingDescriptions() {
 		Map<String, String> bindings = new HashMap<String, String>();
 		bindings.put(DecorationHelper.BINDING_RESOURCE_NAME,
 				UIText.DecoratorPreferencesPage_nameResourceVariable);
+		bindings.put(DecorationHelper.BINDING_BRANCH_NAME,
+				UIText.DecoratorPreferencesPage_bindingBranchName);
 		return bindings;
 	}
 
@@ -478,8 +480,8 @@ private void updatePreview() {
 		private DecorationHelper fHelper;
 
 		public Preview(Composite composite) {
-			reloadDecorationHelper(); // Has to happen before the tree control
-										// is constructed
+			// Has to happen before the tree control is constructed
+			reloadDecorationHelper();
 			SWTUtils.createLabel(composite,
 					UIText.DecoratorPreferencesPage_preview);
 			fImageCache = new LocalResourceManager(JFaceResources
@@ -602,12 +604,15 @@ private PreviewDecoration getDecoration(Object element) {
 	private static class PreviewResource implements IDecoratableResource {
 		public final String name;
 
+		public final String branch;
+
 		public final int type;
 
 		public Collection children;
 
-		public PreviewResource(String name, int type) {
+		public PreviewResource(String name, int type, String branch) {
 			this.name = name;
+			this.branch = branch;
 			this.type = type;
 			this.children = Collections.EMPTY_LIST;
 		}
@@ -619,6 +624,10 @@ public String getName() {
 		public int getType() {
 			return type;
 		}
+
+		public String getBranch() {
+			return branch;
+		}
 	}
 
 	private class PreviewDecoration implements IDecoration {
org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +2 -1
index 4660983..d050be9 100644
@@ -360,10 +360,11 @@ DecoratorPreferencesPage_folderFormatLabel=F&olders:
 DecoratorPreferencesPage_projectFormatLabel=&Projects:
 DecoratorPreferencesPage_fileFormatDefault={name}
 DecoratorPreferencesPage_folderFormatDefault={name}
-DecoratorPreferencesPage_projectFormatDefault={name}
+DecoratorPreferencesPage_projectFormatDefault={name} [{branch}]
 DecoratorPreferencesPage_labelDecorationsLink=See <a>''{0}''</a> to enable or disable Git decorations.
 DecoratorPreferencesPage_generalTabFolder=&General
 DecoratorPreferencesPage_nameResourceVariable=name of the resource being decorated
+DecoratorPreferencesPage_bindingBranchName=current branch of the project
 DecoratorPreferencesPage_selectFormats=Select the format for file, folders, and project text labels:
 DecoratorPreferencesPage_selectVariablesToAdd=Select the &variables to add to the decoration format:
 DecoratorPreferencesPage_textLabel=T&ext Decorations
Signature · 1 line
1.6.1.2.309.g2ea3
#8 lore raw

PATCH v2 8/12 Add icon decoration for tracked and untracked resources

Can be enabled/disabled in the preferences

---
 org.spearce.egit.ui/icons/ovr/shared.gif           |  Bin 106 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/untracked.gif        |  Bin 0 -> 79 bytes
 .../egit/ui/PluginPreferenceInitializer.java       |    4 +-
 .../src/org/spearce/egit/ui/UIIcons.java           |    6 +-
 .../src/org/spearce/egit/ui/UIPreferences.java     |    4 +
 .../src/org/spearce/egit/ui/UIText.java            |    6 +
 .../decorators/GitLightweightDecorator.java        |  162 ++++++++++++++++++--
 .../internal/decorators/IDecoratableResource.java  |   15 ++
 .../preferences/GitDecoratorPreferencePage.java    |   89 +++++++++--
 .../src/org/spearce/egit/ui/uitext.properties      |    2 +
 10 files changed, 259 insertions(+), 29 deletions(-)
 delete mode 100644 org.spearce.egit.ui/icons/ovr/shared.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/untracked.gif
org.spearce.egit.ui/icons/ovr/shared.gif deleted binary +0 -0
deleted file mode 100644
index eb71a3c742e133c2ed61c958e237c71e0f7cb6aa..0000000000000000000000000000000000000000
GIT binary patch
org.spearce.egit.ui/icons/ovr/untracked.gif new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..45ca32060700d71abcb88bbcdb1000d503fe11cf
GIT binary patch
org.spearce.egit.ui/src/org/spearce/egit/ui/PluginPreferenceInitializer.java +3 -1
index 79c2665..7465444 100644
@@ -35,13 +35,15 @@ public void initializeDefaultPreferences() {
 		prefs.setDefault(UIPreferences.RESOURCEHISTORY_SHOW_REV_COMMENT, true);
 		prefs.setDefault(UIPreferences.RESOURCEHISTORY_SHOW_TOOLTIPS, false);
 
+		prefs.setDefault(UIPreferences.DECORATOR_CALCULATE_DIRTY, true);
 		prefs.setDefault(UIPreferences.DECORATOR_FILETEXT_DECORATION,
 				UIText.DecoratorPreferencesPage_fileFormatDefault);
 		prefs.setDefault(UIPreferences.DECORATOR_FOLDERTEXT_DECORATION,
 				UIText.DecoratorPreferencesPage_folderFormatDefault);
 		prefs.setDefault(UIPreferences.DECORATOR_PROJECTTEXT_DECORATION,
 				UIText.DecoratorPreferencesPage_projectFormatDefault);
-		prefs.setDefault(UIPreferences.DECORATOR_CALCULATE_DIRTY, true);
+		prefs.setDefault(UIPreferences.DECORATOR_SHOW_TRACKED_ICON, true);
+		prefs.setDefault(UIPreferences.DECORATOR_SHOW_UNTRACKED_ICON, true);
 
 		w = new int[] { 500, 500 };
 		UIPreferences.setDefault(prefs,
org.spearce.egit.ui/src/org/spearce/egit/ui/UIIcons.java +3 -3
index ced186e..4c0d189 100644
@@ -24,8 +24,8 @@
 	/** Decoration for resource removed from the index but not commit. */
 	public static final ImageDescriptor OVR_PENDING_REMOVE;
 
-	/** Decoration for resource tracked and committed in git. */
-	public static final ImageDescriptor OVR_SHARED;
+	/** Decoration for resource not being tracked by Git */
+	public static final ImageDescriptor OVR_UNTRACKED;
 
 	/** Decoration for tracked resource with a merge conflict.  */
 	public static final ImageDescriptor OVR_CONFLICT;
@@ -86,7 +86,7 @@
 		base = init();
 		OVR_PENDING_ADD = map("ovr/pending_add.gif");
 		OVR_PENDING_REMOVE = map("ovr/pending_remove.gif");
-		OVR_SHARED = map("ovr/shared.gif");
+		OVR_UNTRACKED = map("ovr/untracked.gif");
 		OVR_CONFLICT = map("ovr/conflict.gif");
 		OVR_ASSUMEVALID = map("ovr/assumevalid.gif");
 		ELCL16_FIND = map("elcl16/find.gif");
org.spearce.egit.ui/src/org/spearce/egit/ui/UIPreferences.java +4 -0
index a6168a0..7916cea 100644
@@ -60,6 +60,10 @@
 	public final static String DECORATOR_FOLDERTEXT_DECORATION = "decorator_foldertext_decoration";
 	/** */
 	public final static String DECORATOR_PROJECTTEXT_DECORATION = "decorator_projecttext_decoration";
+	/** */
+	public final static String DECORATOR_SHOW_TRACKED_ICON = "decorator_show_tracked_icon";
+	/** */
+	public final static String DECORATOR_SHOW_UNTRACKED_ICON = "decorator_show_untracked_icon";
 
 	/**
 	 * Get the preference values associated with a fixed integer array.
org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +6 -0
index 345c66b..60e4eaa 100644
@@ -988,6 +988,12 @@
 	/** */
 	public static String DecoratorPreferencesPage_labelDecorationsLink;
 
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowTracked;
+
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowUntracked;
+
 	static {
 		initializeMessages(UIText.class.getPackage().getName() + ".uitext",
 				UIText.class);
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java +152 -10

239 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java +15 -0
index 6b36e0e..f144214 100644
@@ -36,4 +36,19 @@
 	 *         applicable
 	 */
 	String getBranch();
+
+	/**
+	 * Returns whether or not the resource is tracked by Git
+	 * 
+	 * @return whether or not the resource is tracked by Git
+	 */
+	boolean isTracked();
+
+	/**
+	 * Returns whether or not the resource is ignored, either by a global team
+	 * ignore in Eclipse, or by .git/info/exclude et al.
+	 * 
+	 * @return whether or not the resource is ignored
+	 */
+	boolean isIgnored();
 }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java +74 -15

177 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +2 -0
index d050be9..9940177 100644
@@ -369,4 +369,6 @@ DecoratorPreferencesPage_selectFormats=Select the format for file, folders, and
 DecoratorPreferencesPage_selectVariablesToAdd=Select the &variables to add to the decoration format:
 DecoratorPreferencesPage_textLabel=T&ext Decorations
 DecoratorPreferencesPage_iconLabel=&Icon Decorations
+DecoratorPreferencesPage_iconsShowTracked=Tracked resources
+DecoratorPreferencesPage_iconsShowUntracked=Untracked resources
 
Signature · 1 line
1.6.1.2.309.g2ea3
#9 lore raw

PATCH v2 9/12 Implement icon and text decorations of various resource states

- Dirty
- Staged
- Conflict
- Assume valid

---
 org.spearce.egit.ui/icons/ovr/assume_valid.gif     |  Bin 0 -> 85 bytes
 org.spearce.egit.ui/icons/ovr/assumevalid.gif      |  Bin 64 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/conflict.gif         |  Bin 64 -> 194 bytes
 org.spearce.egit.ui/icons/ovr/pending_add.gif      |  Bin 64 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/pending_remove.gif   |  Bin 111 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/staged.gif           |  Bin 0 -> 114 bytes
 org.spearce.egit.ui/icons/ovr/staged_added.gif     |  Bin 0 -> 169 bytes
 org.spearce.egit.ui/icons/ovr/staged_removed.gif   |  Bin 0 -> 176 bytes
 .../egit/ui/PluginPreferenceInitializer.java       |    3 +
 .../src/org/spearce/egit/ui/UIIcons.java           |   15 +-
 .../src/org/spearce/egit/ui/UIPreferences.java     |    6 +
 .../src/org/spearce/egit/ui/UIText.java            |   17 +-
 .../decorators/GitLightweightDecorator.java        |  299 +++++++++++++++++---
 .../internal/decorators/IDecoratableResource.java  |   46 +++
 .../preferences/GitDecoratorPreferencePage.java    |  152 +++++++++--
 .../src/org/spearce/egit/ui/uitext.properties      |   15 +-
 16 files changed, 477 insertions(+), 76 deletions(-)
 create mode 100644 org.spearce.egit.ui/icons/ovr/assume_valid.gif
 delete mode 100644 org.spearce.egit.ui/icons/ovr/assumevalid.gif
 delete mode 100644 org.spearce.egit.ui/icons/ovr/pending_add.gif
 delete mode 100644 org.spearce.egit.ui/icons/ovr/pending_remove.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/staged.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/staged_added.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/staged_removed.gif
org.spearce.egit.ui/icons/ovr/assume_valid.gif new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..b6d7167cb38b147aa0fcc115121f3166276f6688
GIT binary patch
org.spearce.egit.ui/icons/ovr/assumevalid.gif deleted binary +0 -0
deleted file mode 100644
index c7262ed4e3f9437a51806f70fbc851e3a6f951d3..0000000000000000000000000000000000000000
GIT binary patch
org.spearce.egit.ui/icons/ovr/conflict.gif binary +0 -0
index b444be94a2d09561b212138b1514d5c07610cc07..fce456a49a0d6b19feaef4e1fb8615d8083c674c 100644
GIT binary patch
org.spearce.egit.ui/icons/ovr/pending_add.gif deleted binary +0 -0
deleted file mode 100644
index f2306024b2872e50db4143a790bca93189ef8d5f..0000000000000000000000000000000000000000
GIT binary patch
org.spearce.egit.ui/icons/ovr/pending_remove.gif deleted binary +0 -0
deleted file mode 100644
index 4ecce038e66f904af8345f88c2c007706a4bc3d0..0000000000000000000000000000000000000000
GIT binary patch
org.spearce.egit.ui/icons/ovr/staged.gif new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..dc0b8c01673b32fde0f9b11c8302ad1ca0a1e902
GIT binary patch
org.spearce.egit.ui/icons/ovr/staged_added.gif new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..c65d16a191f259e0feb55c9244e7545c9063f2ee
GIT binary patch
org.spearce.egit.ui/icons/ovr/staged_removed.gif new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..8aaadfb9b9300594a3448986650b82841398287c
GIT binary patch
org.spearce.egit.ui/src/org/spearce/egit/ui/PluginPreferenceInitializer.java +3 -0
index 7465444..a3196f4 100644
@@ -44,6 +44,9 @@ public void initializeDefaultPreferences() {
 				UIText.DecoratorPreferencesPage_projectFormatDefault);
 		prefs.setDefault(UIPreferences.DECORATOR_SHOW_TRACKED_ICON, true);
 		prefs.setDefault(UIPreferences.DECORATOR_SHOW_UNTRACKED_ICON, true);
+		prefs.setDefault(UIPreferences.DECORATOR_SHOW_STAGED_ICON, true);
+		prefs.setDefault(UIPreferences.DECORATOR_SHOW_CONFLICTS_ICON, true);
+		prefs.setDefault(UIPreferences.DECORATOR_SHOW_ASSUME_VALID_ICON, true);
 
 		w = new int[] { 500, 500 };
 		UIPreferences.setDefault(prefs,
org.spearce.egit.ui/src/org/spearce/egit/ui/UIIcons.java +10 -5
index 4c0d189..952816c 100644
@@ -18,11 +18,15 @@
  * Icons for the the Eclipse plugin. Mostly decorations.
  */
 public class UIIcons {
+
+	/** Decoration for resource in the index but not yet committed. */
+	public static final ImageDescriptor OVR_STAGED;
+
 	/** Decoration for resource added to index but not yet committed. */
-	public static final ImageDescriptor OVR_PENDING_ADD;
+	public static final ImageDescriptor OVR_STAGED_ADD;
 
 	/** Decoration for resource removed from the index but not commit. */
-	public static final ImageDescriptor OVR_PENDING_REMOVE;
+	public static final ImageDescriptor OVR_STAGED_REMOVE;
 
 	/** Decoration for resource not being tracked by Git */
 	public static final ImageDescriptor OVR_UNTRACKED;
@@ -84,11 +88,12 @@
 
 	static {
 		base = init();
-		OVR_PENDING_ADD = map("ovr/pending_add.gif");
-		OVR_PENDING_REMOVE = map("ovr/pending_remove.gif");
+		OVR_STAGED = map("ovr/staged.gif");
+		OVR_STAGED_ADD = map("ovr/staged_added.gif");
+		OVR_STAGED_REMOVE = map("ovr/staged_removed.gif");
 		OVR_UNTRACKED = map("ovr/untracked.gif");
 		OVR_CONFLICT = map("ovr/conflict.gif");
-		OVR_ASSUMEVALID = map("ovr/assumevalid.gif");
+		OVR_ASSUMEVALID = map("ovr/assume_valid.gif");
 		ELCL16_FIND = map("elcl16/find.gif");
 		ELCL16_NEXT = map("elcl16/next.gif");
 		ELCL16_PREVIOUS = map("elcl16/previous.gif");
org.spearce.egit.ui/src/org/spearce/egit/ui/UIPreferences.java +6 -0
index 7916cea..e812716 100644
@@ -64,6 +64,12 @@
 	public final static String DECORATOR_SHOW_TRACKED_ICON = "decorator_show_tracked_icon";
 	/** */
 	public final static String DECORATOR_SHOW_UNTRACKED_ICON = "decorator_show_untracked_icon";
+	/** */
+	public final static String DECORATOR_SHOW_STAGED_ICON = "decorator_show_staged_icon";
+	/** */
+	public final static String DECORATOR_SHOW_CONFLICTS_ICON = "decorator_show_conflicts_icon";
+	/** */
+	public final static String DECORATOR_SHOW_ASSUME_VALID_ICON = "decorator_show_assume_valid_icon";
 
 	/**
 	 * Get the preference values associated with a fixed integer array.
org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +16 -1
index 60e4eaa..7e26337 100644
@@ -968,12 +968,18 @@
 	public static String DecoratorPreferencesPage_generalTabFolder;
 
 	/** */
-	public static String DecoratorPreferencesPage_nameResourceVariable;
+	public static String DecoratorPreferencesPage_bindingResourceName;
 
 	/** */
 	public static String DecoratorPreferencesPage_bindingBranchName;
 
 	/** */
+	public static String DecoratorPreferencesPage_bindingDirtyFlag;
+
+	/** */
+	public static String DecoratorPreferencesPage_bindingStagedFlag;
+
+	/** */
 	public static String DecoratorPreferencesPage_selectFormats;
 
 	/** */
@@ -994,6 +1000,15 @@
 	/** */
 	public static String DecoratorPreferencesPage_iconsShowUntracked;
 
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowStaged;
+
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowConflicts;
+
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowAssumeValid;
+
 	static {
 		initializeMessages(UIText.class.getPackage().getName() + ".uitext",
 				UIText.class);
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java +252 -47

402 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java +46 -0

56 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java +133 -19

289 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +11 -4
index 9940177..e9a2321 100644
@@ -358,17 +358,24 @@ DecoratorPreferencesPage_preview=Preview:
 DecoratorPreferencesPage_fileFormatLabel=&Files:
 DecoratorPreferencesPage_folderFormatLabel=F&olders:
 DecoratorPreferencesPage_projectFormatLabel=&Projects:
-DecoratorPreferencesPage_fileFormatDefault={name}
-DecoratorPreferencesPage_folderFormatDefault={name}
-DecoratorPreferencesPage_projectFormatDefault={name} [{branch}]
+DecoratorPreferencesPage_fileFormatDefault={dirty:>} {name}
+DecoratorPreferencesPage_folderFormatDefault={dirty:>} {name}
+DecoratorPreferencesPage_projectFormatDefault={dirty:>} {name} [{branch}]
 DecoratorPreferencesPage_labelDecorationsLink=See <a>''{0}''</a> to enable or disable Git decorations.
 DecoratorPreferencesPage_generalTabFolder=&General
-DecoratorPreferencesPage_nameResourceVariable=name of the resource being decorated
+DecoratorPreferencesPage_bindingResourceName=name of the resource being decorated
 DecoratorPreferencesPage_bindingBranchName=current branch of the project
+DecoratorPreferencesPage_bindingDirtyFlag=flag indicating whether or not the resource is dirty
+DecoratorPreferencesPage_bindingStagedFlag=flag indicating whether or not the resource is staged
 DecoratorPreferencesPage_selectFormats=Select the format for file, folders, and project text labels:
 DecoratorPreferencesPage_selectVariablesToAdd=Select the &variables to add to the decoration format:
 DecoratorPreferencesPage_textLabel=T&ext Decorations
 DecoratorPreferencesPage_iconLabel=&Icon Decorations
 DecoratorPreferencesPage_iconsShowTracked=Tracked resources
 DecoratorPreferencesPage_iconsShowUntracked=Untracked resources
+DecoratorPreferencesPage_iconsShowStaged=Staged resources
+DecoratorPreferencesPage_iconsShowConflicts=Conflicting resources
+DecoratorPreferencesPage_iconsShowAssumeValid=Assumed unchanged resources
+
+Decorator_exceptionMessage=Errors occurred while applying Git decorations to resources.
 
Signature · 1 line
1.6.1.2.309.g2ea3
#10 lore raw

PATCH v2 10/12 Don't decorate every single resource on repository change

Not all resources have corresponding labels that are visible, so by using LabelProviderChangedEvent() we ensure that only the visible labels are refreshed.

The downside is that we lose project precition, so all projects are included, but only visible labels in those projects are re-decorated, so it is OK for now.

---
 .../decorators/GitLightweightDecorator.java        |   28 +++-----------------
 1 files changed, 4 insertions(+), 24 deletions(-)
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java +4 -24
index c23ce24..1e95369 100644
@@ -14,11 +14,9 @@
 package org.spearce.egit.ui.internal.decorators;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -28,7 +26,6 @@
 import org.eclipse.core.resources.IResourceChangeListener;
 import org.eclipse.core.resources.IResourceDelta;
 import org.eclipse.core.resources.IResourceDeltaVisitor;
-import org.eclipse.core.resources.IResourceVisitor;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.resources.mapping.ResourceMapping;
 import org.eclipse.core.runtime.CoreException;
@@ -697,7 +694,7 @@ public void propertyChange(PropertyChangeEvent event) {
 		if (prop.equals(TeamUI.GLOBAL_IGNORES_CHANGED)
 				|| prop.equals(TeamUI.GLOBAL_FILE_TYPES_CHANGED)
 				|| prop.equals(Activator.DECORATORS_CHANGED)) {
-			postLabelEvent(new LabelProviderChangedEvent(this, null /* all */));
+			postLabelEvent(new LabelProviderChangedEvent(this));
 		}
 	}
 
@@ -824,29 +821,12 @@ public void refsChanged(RefsChangedEvent e) {
 	 * Callback for RepositoryChangeListener events, as well as
 	 * RepositoryListener events via repositoryChanged()
 	 * 
-	 * We resolve the project and schedule a refresh of each resource in the
-	 * project.
-	 * 
 	 * @see org.spearce.egit.core.project.RepositoryChangeListener#repositoryChanged(org.spearce.egit.core.project.RepositoryMapping)
 	 */
 	public void repositoryChanged(RepositoryMapping mapping) {
-		final IProject project = mapping.getContainer().getProject();
-		if (project == null)
-			return;
-
-		final List<IResource> resources = new ArrayList<IResource>();
-		try {
-			project.accept(new IResourceVisitor() {
-				public boolean visit(IResource resource) {
-					resources.add(resource);
-					return true;
-				}
-			});
-			postLabelEvent(new LabelProviderChangedEvent(this, resources
-					.toArray()));
-		} catch (final CoreException e) {
-			handleException(project, e);
-		}
+		// Until we find a way to refresh visible labels within a project
+		// we have to use this blanket refresh that includes all projects.
+		postLabelEvent(new LabelProviderChangedEvent(this));
 	}
 
 	// -------- Helper methods --------
Signature · 1 line
1.6.1.2.309.g2ea3
#11 lore raw

PATCH v2 11/12 Expose the underlying resource entries in ContainerTreeIterator

This is needed if interacting with any of the Eclipse platform methods that take IResources as arguments.

---
 .../spearce/egit/core/ContainerTreeIterator.java   |   23 +++++++++++++++++++-
 .../src/org/spearce/jgit/treewalk/TreeWalk.java    |    9 +++++++
 2 files changed, 31 insertions(+), 1 deletions(-)
org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java +22 -1
index 6d6b72e..2403252 100644
@@ -106,6 +106,15 @@ public AbstractTreeIterator createSubtreeIterator(final Repository db)
 					Constants.TYPE_TREE);
 	}
 
+	/**
+	 * Get the ResourceEntry for the current entry.
+	 * 
+	 * @return the current entry
+	 */
+	public ResourceEntry getResourceEntry() {
+		return (ResourceEntry) current();
+	}
+
 	private Entry[] entries() {
 		final IResource[] all;
 		try {
@@ -120,7 +129,10 @@ public AbstractTreeIterator createSubtreeIterator(final Repository db)
 		return r;
 	}
 
-	static class ResourceEntry extends Entry {
+	/**
+	 * Wrapper for a resource in the Eclipse workspace
+	 */
+	static public class ResourceEntry extends Entry {
 		final IResource rsrc;
 
 		private final FileMode mode;
@@ -195,6 +207,15 @@ public InputStream openInputStream() throws IOException {
 			throw new IOException("Not a regular file: " + rsrc);
 		}
 
+		/**
+		 * Get the underlying resource of this entry.
+		 * 
+		 * @return the underlying resource
+		 */
+		public IResource getResource() {
+			return rsrc;
+		}
+
 		private File asFile() {
 			return ((IFile) rsrc).getLocation().toFile();
 		}
org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java +9 -0
index 189fc86..ce247f2 100644
@@ -739,6 +739,15 @@ public int isPathPrefix(final byte[] p, final int pLen) {
 	}
 
 	/**
+	 * Get the current subtree depth of this walker.
+	 * 
+	 * @return the current subtree depth of this walker.
+	 */
+	public int getDepth() {
+		return depth;
+	}
+
+	/**
 	 * Is the current entry a subtree?
 	 * <p>
 	 * This method is faster then testing the raw mode bits of all trees to see
Signature · 1 line
1.6.1.2.309.g2ea3
#12 lore raw

PATCH v2 12/12 Implement label decorations for folders and projects

The option "Re-decorate ancestors..." controls if parents of a re-decorated resource also should be updated, for example to to signal that the containing folder is now concidered dirty.

The option "Maximum number of levels..." controls how deep the container decoration algorithm will recurse when trying to determine the state (dirty, staged, etc.) of a container.

---
 .../egit/ui/PluginPreferenceInitializer.java       |    4 +-
 .../src/org/spearce/egit/ui/UIPreferences.java     |    4 +-
 .../src/org/spearce/egit/ui/UIText.java            |   14 +-
 .../decorators/DecoratableResourceAdapter.java     |  391 ++++++++++++++++++++
 .../decorators/GitLightweightDecorator.java        |  300 ++-------------
 .../preferences/GitDecoratorPreferencePage.java    |   91 ++++-
 .../src/org/spearce/egit/ui/uitext.properties      |    7 +-
 7 files changed, 528 insertions(+), 283 deletions(-)
 create mode 100644 org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/DecoratableResourceAdapter.java
org.spearce.egit.ui/src/org/spearce/egit/ui/PluginPreferenceInitializer.java +3 -1
index a3196f4..8d617e9 100644
@@ -35,7 +35,9 @@ public void initializeDefaultPreferences() {
 		prefs.setDefault(UIPreferences.RESOURCEHISTORY_SHOW_REV_COMMENT, true);
 		prefs.setDefault(UIPreferences.RESOURCEHISTORY_SHOW_TOOLTIPS, false);
 
-		prefs.setDefault(UIPreferences.DECORATOR_CALCULATE_DIRTY, true);
+		prefs.setDefault(UIPreferences.DECORATOR_RECOMPUTE_ANCESTORS, true);
+		prefs.setDefault(UIPreferences.DECORATOR_RECURSIVE_LIMIT,
+				Integer.MAX_VALUE);
 		prefs.setDefault(UIPreferences.DECORATOR_FILETEXT_DECORATION,
 				UIText.DecoratorPreferencesPage_fileFormatDefault);
 		prefs.setDefault(UIPreferences.DECORATOR_FOLDERTEXT_DECORATION,
org.spearce.egit.ui/src/org/spearce/egit/ui/UIPreferences.java +3 -1
index e812716..bbc36be 100644
@@ -53,7 +53,9 @@
 	public final static String THEME_CommitMessageFont = "org.spearce.egit.ui.CommitMessageFont";
 
 	/** */
-	public final static String DECORATOR_CALCULATE_DIRTY = "decorator_calculate_dirty";
+	public final static String DECORATOR_RECOMPUTE_ANCESTORS = "decorator_recompute_ancestors";
+	/** */
+	public final static String DECORATOR_RECURSIVE_LIMIT = "decorator_recursive_limit";
 	/** */
 	public final static String DECORATOR_FILETEXT_DECORATION = "decorator_filetext_decoration";
 	/** */
org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +13 -1
index 7e26337..bd64ca1 100644
@@ -935,7 +935,19 @@
 	public static String DecoratorPreferencesPage_addVariablesAction;
 
 	/** */
-	public static String DecoratorPreferencesPage_computeDeep;
+	public static String DecoratorPreferencesPage_recomputeAncestorDecorations;
+
+	/** */
+	public static String DecoratorPreferencesPage_recomputeAncestorDecorationsTooltip;
+
+	/** */
+	public static String DecoratorPreferencesPage_computeRecursiveLimit;
+
+	/** */
+	public static String DecoratorPreferencesPage_computeRecursiveLimitTooltip;
+
+	/** */
+	public static String DecoratorPreferencesPage_invalidInput;
 
 	/** */
 	public static String DecoratorPreferencesPage_description;
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/DecoratableResourceAdapter.java new file +391 -0

392 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java +35 -265

381 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java +78 -13

159 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +5 -2
index e9a2321..847cb2c 100644
@@ -350,9 +350,12 @@ Decorator_exceptionMessage=Errors occurred while applying Git decorations to res
 
 DecoratorPreferencesPage_addVariablesTitle=Add Variables
 DecoratorPreferencesPage_addVariablesAction=Add &Variables...
-DecoratorPreferencesPage_computeDeep=Include &ancestors when re-decorating changed resources
+DecoratorPreferencesPage_recomputeAncestorDecorations=Re-decorate &ancestors when decorating changed resources
+DecoratorPreferencesPage_recomputeAncestorDecorationsTooltip=Enabling this option will cause the ancestor-tree of any updated resources to also be re-decorated (minor performance impact).
+DecoratorPreferencesPage_computeRecursiveLimit=Maximum number of levels to recurse for container decoration:
+DecoratorPreferencesPage_computeRecursiveLimitTooltip=This value determines the maximum number of levels that will be recursed for each container decoration before bailing out. Increasing this number will improve accuracy for container decoration, but has a performance impact for large projects.
 DecoratorPreferencesPage_description=Shows Git specific information on resources in projects under version control.
-
+DecoratorPreferencesPage_invalidInput=''{0}'' is not a valid input
 DecoratorPreferencesPage_decorationSettings=Decoration &settings:
 DecoratorPreferencesPage_preview=Preview:
 DecoratorPreferencesPage_fileFormatLabel=&Files:
Signature · 1 line
1.6.1.2.309.g2ea3
#13 lore raw

Re: [EGIT PATCH v2 12/12] Implement label decorations for folders and projects

Since this is a large change, we can wait a day or so before pushing to master. This and Shawn locking patch is in the update site on www.jgit.org (tentative builds) for those that want to experience it without building. The version is called 0.4.0.200902120052.

-- robin

#14 lore raw

Re: [EGIT PATCH v2 08/12] Add icon decoration for tracked and untracked resources

In reply to Tor Arne Vestbø

This one fails to compile,

Description Resource Path Location Type
fPreview cannot be resolved GitDecoratorPreferencePage.java org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences line 279 Java Problem

With patch 9 things build again, but swapping the patches does not help.

Every patch should build and pass unit tests so we can perform bisect over the patches.

-- robin

#15 lore raw

PATCH v3 8/12 Add icon decoration for tracked and untracked resources

Can be enabled/disabled in the preferences

---

Sorry, got a little trigger happy with the rebasing and messed up a merge :/

org.spearce.egit.ui/icons/ovr/shared.gif | Bin 106 -> 0 bytes

 org.spearce.egit.ui/icons/ovr/untracked.gif        |  Bin 0 -> 79 bytes
 .../egit/ui/PluginPreferenceInitializer.java       |    4 +-
 .../src/org/spearce/egit/ui/UIIcons.java           |    6 +-
 .../src/org/spearce/egit/ui/UIPreferences.java     |    4 +
 .../src/org/spearce/egit/ui/UIText.java            |    6 +
 .../decorators/GitLightweightDecorator.java        |  162 ++++++++++++++++++--
 .../internal/decorators/IDecoratableResource.java  |   15 ++
 .../preferences/GitDecoratorPreferencePage.java    |   89 +++++++++--
 .../src/org/spearce/egit/ui/uitext.properties      |    2 +
 10 files changed, 259 insertions(+), 29 deletions(-)
 delete mode 100644 org.spearce.egit.ui/icons/ovr/shared.gif
 create mode 100644 org.spearce.egit.ui/icons/ovr/untracked.gif
org.spearce.egit.ui/icons/ovr/shared.gif deleted binary +0 -0
deleted file mode 100644
index eb71a3c742e133c2ed61c958e237c71e0f7cb6aa..0000000000000000000000000000000000000000
GIT binary patch
org.spearce.egit.ui/icons/ovr/untracked.gif new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..45ca32060700d71abcb88bbcdb1000d503fe11cf
GIT binary patch
org.spearce.egit.ui/src/org/spearce/egit/ui/PluginPreferenceInitializer.java +3 -1
index 79c2665..7465444 100644
@@ -35,13 +35,15 @@ public void initializeDefaultPreferences() {
 		prefs.setDefault(UIPreferences.RESOURCEHISTORY_SHOW_REV_COMMENT, true);
 		prefs.setDefault(UIPreferences.RESOURCEHISTORY_SHOW_TOOLTIPS, false);
 
+		prefs.setDefault(UIPreferences.DECORATOR_CALCULATE_DIRTY, true);
 		prefs.setDefault(UIPreferences.DECORATOR_FILETEXT_DECORATION,
 				UIText.DecoratorPreferencesPage_fileFormatDefault);
 		prefs.setDefault(UIPreferences.DECORATOR_FOLDERTEXT_DECORATION,
 				UIText.DecoratorPreferencesPage_folderFormatDefault);
 		prefs.setDefault(UIPreferences.DECORATOR_PROJECTTEXT_DECORATION,
 				UIText.DecoratorPreferencesPage_projectFormatDefault);
-		prefs.setDefault(UIPreferences.DECORATOR_CALCULATE_DIRTY, true);
+		prefs.setDefault(UIPreferences.DECORATOR_SHOW_TRACKED_ICON, true);
+		prefs.setDefault(UIPreferences.DECORATOR_SHOW_UNTRACKED_ICON, true);
 
 		w = new int[] { 500, 500 };
 		UIPreferences.setDefault(prefs,
org.spearce.egit.ui/src/org/spearce/egit/ui/UIIcons.java +3 -3
index ced186e..4c0d189 100644
@@ -24,8 +24,8 @@
 	/** Decoration for resource removed from the index but not commit. */
 	public static final ImageDescriptor OVR_PENDING_REMOVE;
 
-	/** Decoration for resource tracked and committed in git. */
-	public static final ImageDescriptor OVR_SHARED;
+	/** Decoration for resource not being tracked by Git */
+	public static final ImageDescriptor OVR_UNTRACKED;
 
 	/** Decoration for tracked resource with a merge conflict.  */
 	public static final ImageDescriptor OVR_CONFLICT;
@@ -86,7 +86,7 @@
 		base = init();
 		OVR_PENDING_ADD = map("ovr/pending_add.gif");
 		OVR_PENDING_REMOVE = map("ovr/pending_remove.gif");
-		OVR_SHARED = map("ovr/shared.gif");
+		OVR_UNTRACKED = map("ovr/untracked.gif");
 		OVR_CONFLICT = map("ovr/conflict.gif");
 		OVR_ASSUMEVALID = map("ovr/assumevalid.gif");
 		ELCL16_FIND = map("elcl16/find.gif");
org.spearce.egit.ui/src/org/spearce/egit/ui/UIPreferences.java +4 -0
index a6168a0..7916cea 100644
@@ -60,6 +60,10 @@
 	public final static String DECORATOR_FOLDERTEXT_DECORATION = "decorator_foldertext_decoration";
 	/** */
 	public final static String DECORATOR_PROJECTTEXT_DECORATION = "decorator_projecttext_decoration";
+	/** */
+	public final static String DECORATOR_SHOW_TRACKED_ICON = "decorator_show_tracked_icon";
+	/** */
+	public final static String DECORATOR_SHOW_UNTRACKED_ICON = "decorator_show_untracked_icon";
 
 	/**
 	 * Get the preference values associated with a fixed integer array.
org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +6 -0
index 345c66b..60e4eaa 100644
@@ -988,6 +988,12 @@
 	/** */
 	public static String DecoratorPreferencesPage_labelDecorationsLink;
 
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowTracked;
+
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowUntracked;
+
 	static {
 		initializeMessages(UIText.class.getPackage().getName() + ".uitext",
 				UIText.class);
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java +152 -10

239 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java +15 -0
index 6b36e0e..f144214 100644
@@ -36,4 +36,19 @@
 	 *         applicable
 	 */
 	String getBranch();
+
+	/**
+	 * Returns whether or not the resource is tracked by Git
+	 * 
+	 * @return whether or not the resource is tracked by Git
+	 */
+	boolean isTracked();
+
+	/**
+	 * Returns whether or not the resource is ignored, either by a global team
+	 * ignore in Eclipse, or by .git/info/exclude et al.
+	 * 
+	 * @return whether or not the resource is ignored
+	 */
+	boolean isIgnored();
 }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java +74 -15

177 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +2 -0
index d050be9..9940177 100644
@@ -369,4 +369,6 @@ DecoratorPreferencesPage_selectFormats=Select the format for file, folders, and
 DecoratorPreferencesPage_selectVariablesToAdd=Select the &variables to add to the decoration format:
 DecoratorPreferencesPage_textLabel=T&ext Decorations
 DecoratorPreferencesPage_iconLabel=&Icon Decorations
+DecoratorPreferencesPage_iconsShowTracked=Tracked resources
+DecoratorPreferencesPage_iconsShowUntracked=Untracked resources
 
Signature · 1 line
1.6.1.2.309.g2ea3
#16 lore raw
In reply to Tor Arne Vestbø

onsdag 11 februari 2009 19:40:02 skrev Tor Arne Vestbø <[email protected]>:

Quoted 4 lines

Known issues are:

- If a project has a repository more than one level above the project directory decorations will fail.

That one *is* annoying. My biggest projects don't get decorations now...

-- robin

#17 lore raw
Quoted 7 lines · Robin Rosenberg

onsdag 11 februari 2009 19:40:02 skrev Tor Arne Vestbø <[email protected]>:

Quoted 4 lines

Known issues are:

- If a project has a repository more than one level above the project directory decorations will fail.

That one *is* annoying. My biggest projects don't get decorations now...

Ouch. I thought that was a rather rare situation, given that we only let users create new repos either in the project or the project parent.

I'll whip something up :)

How has the series held up this past week in the update manager? Any complaints from users or other things I should be aware of?

Tor Arne

#18 lore raw

måndag 16 februari 2009 23:49:59 skrev Tor Arne Vestbø <[email protected]>:

Quoted 11 lines
Quoted 7 lines · Robin Rosenberg

onsdag 11 februari 2009 19:40:02 skrev Tor Arne Vestbø <[email protected]>:

Quoted 4 lines

Known issues are:

- If a project has a repository more than one level above the project directory decorations will fail.

That one *is* annoying. My biggest projects don't get decorations now...

Ouch. I thought that was a rather rare situation, given that we only let users create new repos either in the project or the project parent.

Legacy, but some reasons make sense.

Quoted 3 lines

I'll whip something up :)

How has the series held up this past week in the update manager? Any

642 or 461 downloads (depending on how you count). It's hard to say if different if some downloads are from multiple or single users.

Quoted 1 line

complaints from users or other things I should be aware of?

One :)

-- robin

#19 lore raw

[EGIT PATCH 13/12] Add new file tree iterator that can adapt into a ContainerTreeIterator

As the iterator recurses into subtrees it will look for directories that can be mapped using a given workspace root, and if there's a mapping it will return a ContainerTreeIterator instead.

This feature required exposing the underlying file of the FileEntry, as well as making ContainerTreeIterator's constructor that takes a parent iterator public.

---
 .../core/T0003_AdaptableFileTreeIteratorTest.java  |   74 +++++++++++++++++
 .../egit/core/AdaptableFileTreeIterator.java       |   87 ++++++++++++++++++++
 .../spearce/egit/core/ContainerTreeIterator.java   |   17 ++++-
 .../spearce/jgit/treewalk/FileTreeIterator.java    |   14 +++-
 4 files changed, 190 insertions(+), 2 deletions(-)
 create mode 100644 org.spearce.egit.core.test/src/org/spearce/egit/core/T0003_AdaptableFileTreeIteratorTest.java
 create mode 100644 org.spearce.egit.core/src/org/spearce/egit/core/AdaptableFileTreeIterator.java
org.spearce.egit.core.test/src/org/spearce/egit/core/T0003_AdaptableFileTreeIteratorTest.java new file +74 -0
new file mode 100644
index 0000000..1e2fe03
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (C) 2009, Tor Arne Vestbø <[email protected]>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * See LICENSE for the full license text, also available.
+ *******************************************************************************/
+package org.spearce.egit.core;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.spearce.egit.core.op.ConnectProviderOperation;
+import org.spearce.egit.core.project.RepositoryMapping;
+import org.spearce.egit.core.test.GitTestCase;
+import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.treewalk.TreeWalk;
+import org.spearce.jgit.treewalk.WorkingTreeIterator;
+import org.spearce.jgit.treewalk.filter.PathFilterGroup;
+
+public class T0003_AdaptableFileTreeIteratorTest extends GitTestCase {
+
+	private Repository repository;
+
+	private File repositoryRoot;
+
+	private File file;
+
+	protected void setUp() throws Exception {
+		super.setUp();
+
+		repository = new Repository(gitDir);
+		repositoryRoot = repository.getWorkDir();
+		repository.create();
+
+		file = new File(project.getProject().getLocation().toFile(), "a.txt");
+		final FileWriter fileWriter = new FileWriter(file);
+		fileWriter.write("aaaaaaaaaaa");
+		fileWriter.close();
+
+		final ConnectProviderOperation operation = new ConnectProviderOperation(
+				project.getProject(), null);
+		operation.run(null);
+	}
+
+	public void testFileTreeToContainerAdaptation() throws IOException {
+		final IWorkspaceRoot root = project.getProject().getWorkspace()
+				.getRoot();
+
+		final TreeWalk treeWalk = new TreeWalk(repository);
+		treeWalk.addTree(new AdaptableFileTreeIterator(repositoryRoot, root));
+		treeWalk.setRecursive(true);
+
+		final IFile eclipseFile = project.getProject().getFile(file.getName());
+		final RepositoryMapping mapping = RepositoryMapping
+				.getMapping(eclipseFile);
+		final Set<String> repositoryPaths = Collections.singleton(mapping
+				.getRepoRelativePath(eclipseFile));
+
+		assertTrue(repositoryPaths.size() == 1);
+		treeWalk.setFilter(PathFilterGroup.createFromStrings(repositoryPaths));
+
+		assertTrue(treeWalk.next());
+
+		final WorkingTreeIterator iterator = treeWalk.getTree(1,
+				WorkingTreeIterator.class);
+		assertTrue(iterator instanceof ContainerTreeIterator);
+	}
+}
org.spearce.egit.core/src/org/spearce/egit/core/AdaptableFileTreeIterator.java new file +87 -0

87 lines not on this page · raw message

org.spearce.egit.core/src/org/spearce/egit/core/ContainerTreeIterator.java +16 -1
index 2403252..de592aa 100644
@@ -88,7 +88,22 @@ public ContainerTreeIterator(final IWorkspaceRoot root) {
 		init(entries());
 	}
 
-	private ContainerTreeIterator(final WorkingTreeIterator p,
+	/**
+	 * Construct a new iterator from a container in the workspace, with a given
+	 * parent iterator.
+	 * <p>
+	 * The iterator will support traversal over the named container, but only if
+	 * it is contained within a project which has the Git repository provider
+	 * connected and this resource is mapped into a Git repository. During the
+	 * iteration the paths will be automatically generated to match the proper
+	 * repository paths for this container's children.
+	 * 
+	 * @param p
+	 *            the parent iterator we were created from.
+	 * @param base
+	 *            the part of the workspace the iterator will walk over.
+	 */
+	public ContainerTreeIterator(final WorkingTreeIterator p,
 			final IContainer base) {
 		super(p);
 		node = base;
org.spearce.jgit/src/org/spearce/jgit/treewalk/FileTreeIterator.java +13 -1
index 2c71151..ef9866a 100644
@@ -100,7 +100,10 @@ public AbstractTreeIterator createSubtreeIterator(final Repository repo)
 		return r;
 	}
 
-	static class FileEntry extends Entry {
+	/**
+	 * Wrapper for a standard Java IO file
+	 */
+	static public class FileEntry extends Entry {
 		final File file;
 
 		private final FileMode mode;
@@ -151,5 +154,14 @@ public long getLastModified() {
 		public InputStream openInputStream() throws IOException {
 			return new FileInputStream(file);
 		}
+
+		/**
+		 * Get the underlying file of this entry.
+		 * 
+		 * @return the underlying file of this entry
+		 */
+		public File getFile() {
+			return file;
+		}
 	}
 }
Signature · 1 line
1.6.1.2.309.g2ea3
#20 lore raw

[EGIT PATCH 14/12] Allow project decorations regardless of repository root location

If the repository root is more than one level above the project directory we use the AdaptableFileTreeIterator to recurse the repository tree until we find a directory that can be mapped to a container in the workspace. The iterator is then adapted to a ContainerTreeIterator and decorations are applied like usual.

---
 .../decorators/DecoratableResourceAdapter.java     |   39 +++++++++++++-------
 1 files changed, 26 insertions(+), 13 deletions(-)
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/DecoratableResourceAdapter.java +26 -13
index e2fe54b..5c68d5b 100644
@@ -13,15 +13,17 @@
 
 package org.spearce.egit.ui.internal.decorators;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.Set;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.team.core.Team;
+import org.spearce.egit.core.AdaptableFileTreeIterator;
 import org.spearce.egit.core.ContainerTreeIterator;
 import org.spearce.egit.core.ContainerTreeIterator.ResourceEntry;
 import org.spearce.egit.core.project.RepositoryMapping;
@@ -39,6 +41,7 @@
 import org.spearce.jgit.revwalk.RevWalk;
 import org.spearce.jgit.treewalk.EmptyTreeIterator;
 import org.spearce.jgit.treewalk.TreeWalk;
+import org.spearce.jgit.treewalk.WorkingTreeIterator;
 import org.spearce.jgit.treewalk.filter.AndTreeFilter;
 import org.spearce.jgit.treewalk.filter.PathFilterGroup;
 import org.spearce.jgit.treewalk.filter.TreeFilter;
@@ -210,13 +213,21 @@ public boolean include(TreeWalk treeWalk)
 		}
 
 		private boolean shouldRecurse(TreeWalk treeWalk) {
-			final ContainerTreeIterator workspaceIterator = treeWalk.getTree(
-					T_WORKSPACE, ContainerTreeIterator.class);
-			final ResourceEntry resourceEntry = workspaceIterator != null ? workspaceIterator
-					.getResourceEntry()
-					: null;
-			IResource visitingResource = resourceEntry.getResource();
+			final WorkingTreeIterator workspaceIterator = treeWalk.getTree(
+					T_WORKSPACE, WorkingTreeIterator.class);
+
+			if (workspaceIterator instanceof AdaptableFileTreeIterator)
+				return true;
+
+			ResourceEntry resourceEntry = null;
+			if (workspaceIterator != null)
+				resourceEntry = ((ContainerTreeIterator) workspaceIterator)
+						.getResourceEntry();
+
+			if (resourceEntry == null)
+				return true;
 
+			IResource visitingResource = resourceEntry.getResource();
 			if (targetDepth == -1) {
 				if (visitingResource.equals(resource)
 						|| visitingResource.getParent().equals(resource))
@@ -319,14 +330,16 @@ private TreeWalk createThreeWayTreeWalk() throws IOException {
 
 		// Working directory
 		IProject project = resource.getProject();
-		IWorkspace workspace = resource.getWorkspace();
-		if (repository.getWorkDir().equals(project.getLocation().toFile()))
+		IWorkspaceRoot workspaceRoot = resource.getWorkspace().getRoot();
+		File repoRoot = repository.getWorkDir();
+
+		if (repoRoot.equals(project.getLocation().toFile()))
 			treeWalk.addTree(new ContainerTreeIterator(project));
+		else if (repoRoot.equals(workspaceRoot.getLocation().toFile()))
+			treeWalk.addTree(new ContainerTreeIterator(workspaceRoot));
 		else
-			treeWalk.addTree(new ContainerTreeIterator(workspace.getRoot()));
-
-		// TODO: Add fallback for projects with the repository more than
-		// one parent up, for example by using a stack of DummyIterators
+			treeWalk.addTree(new AdaptableFileTreeIterator(repoRoot,
+					workspaceRoot));
 
 		return treeWalk;
 	}
Signature · 1 line
1.6.1.2.309.g2ea3