Skip to contentSkip to conversation

Support customizable label decorations

PATCH Superseded Tor Arne Vestbø 4 participants 31 messages Jun 15, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

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, 'Inspect dirty state...', controls whether decoration of container elements such as projects and folders should traverse child elements to decide if the container is dirty.

Disabling these options will improve performance for large trees.

The code should be solid enough for normal use, but I may have missed situations that the code does not handle -- resuling in crash and burn. 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 parent package in the package hierarcy will appear dirty, even when the layout is set to 'flat'.

I've 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

PS: This is my first major patch to EGit, so apologies in advance if I messed up the steps of the submit process in any way :)

Tor Arne Vestbø (11):
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 decorations of dirty, staged, and conflicting resources Don't decorate every single resource on repository change Implement label decorations for folders and projects

 org.spearce.egit.core/META-INF/MANIFEST.MF         |    5 +-
 .../src/org/spearce/egit/core/GitException.java    |  168 +++
 .../core/internal/util/ExceptionCollector.java     |  128 +++
 .../spearce/egit/core/project/GitProjectData.java  |   33 +-
 org.spearce.egit.ui/.options                       |    8 +-
 org.spearce.egit.ui/icons/ovr/assumevalid.gif      |  Bin 64 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/conflict.gif         |  Bin 64 -> 164 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 -> 114 bytes
 org.spearce.egit.ui/icons/ovr/staged_removed.gif   |  Bin 0 -> 114 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         |   70 ++-
 .../egit/ui/PluginPreferenceInitializer.java       |   13 +
 .../src/org/spearce/egit/ui/UIIcons.java           |   19 +-
 .../src/org/spearce/egit/ui/UIPreferences.java     |   19 +
 .../src/org/spearce/egit/ui/UIText.java            |   87 ++-
 .../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/GitLightweightDecorator.java        | 1062 ++++++++++++++++++++
 .../internal/decorators/GitResourceDecorator.java  |  454 ---------
 .../internal/decorators/IDecoratableResource.java  |   93 ++
 .../preferences/GitDecoratorPreferencePage.java    |  911 +++++++++++++++++
 .../src/org/spearce/egit/ui/uitext.properties      |   35 +-
 30 files changed, 3230 insertions(+), 495 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
 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/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 1/11 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..d4a9e8e 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 void addPropertyChangeListener(
+			IPropertyChangeListener listener) {
+		propertyChangeListeners.add(listener);
+	}
+
+	/**
+	 * Remove a Team property changes.
+	 * 
+	 * @param listener
+	 *            The listener to remove
+	 */
+	public static void removePropertyChangeListener(
+			IPropertyChangeListener listener) {
+		propertyChangeListeners.remove(listener);
+	}
+
+	/**
+	 * Broadcast a Team property change.
+	 * 
+	 * @param event
+	 *            The event to broadcast
+	 */
+	public static 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 2/11 Use Set instead of array to keep track of change listeners

Also, add method for removing listeners, and remove unused private method for getting the current listeners.

---
 .../spearce/egit/core/project/GitProjectData.java  |   33 +++++++++-----------
 1 files changed, 15 insertions(+), 18 deletions(-)
org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +15 -18
index db5f20b..4ca4f8e 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,8 @@ 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);
-	}
-
-	private static synchronized RepositoryChangeListener[] getRepositoryChangeListeners() {
-		return repositoryChangeListeners;
+		for (RepositoryChangeListener listener : repositoryChangeListeners)
+			listener.repositoryChanged(which);
 	}
 
 	/**
Signature · 1 line
1.6.1.2.309.g2ea3
#3 lore raw

PATCH 3/11 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 4/11 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 5/11 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 6/11 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    |  735 ++++++++++++++++++++
 .../src/org/spearce/egit/ui/uitext.properties      |   25 +-
 14 files changed, 1438 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 d4a9e8e..9d03c70 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 +735 -0

735 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +24 -1
index a86e58b..4a0a387 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
@@ -340,3 +339,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 7/11 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 23498c8..f939558 100644
@@ -956,6 +956,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 2ef0292..2a1a3a8 100644
@@ -94,10 +94,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);
 	}
@@ -488,6 +488,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;
 	}
 
@@ -510,8 +512,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
@@ -635,12 +637,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;
 		}
@@ -652,6 +657,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 4a0a387..58cb9e6 100644
@@ -354,10 +354,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 8/11 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 1697542..0cead29 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;
@@ -77,7 +77,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 f939558..fe62d0a 100644
@@ -973,6 +973,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 58cb9e6..05fdba9 100644
@@ -363,4 +363,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 9/11 Implement decorations of dirty, staged, and conflicting resources

---
 org.spearce.egit.ui/icons/ovr/assumevalid.gif      |  Bin 64 -> 0 bytes
 org.spearce.egit.ui/icons/ovr/conflict.gif         |  Bin 64 -> 164 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 -> 114 bytes
 org.spearce.egit.ui/icons/ovr/staged_removed.gif   |  Bin 0 -> 114 bytes
 .../egit/ui/PluginPreferenceInitializer.java       |    2 +
 .../src/org/spearce/egit/ui/UIIcons.java           |   13 +-
 .../src/org/spearce/egit/ui/UIPreferences.java     |    4 +
 .../src/org/spearce/egit/ui/UIText.java            |   14 +-
 .../decorators/GitLightweightDecorator.java        |  284 ++++++++++++++++----
 .../internal/decorators/IDecoratableResource.java  |   39 +++
 .../preferences/GitDecoratorPreferencePage.java    |  131 ++++++++--
 .../src/org/spearce/egit/ui/uitext.properties      |   14 +-
 15 files changed, 427 insertions(+), 74 deletions(-)
 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/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..186345711bb5443b440c4265fe62b099cce5def0 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..f2b87e274667c441897d0853e6a437ba5487f51c
GIT binary patch
org.spearce.egit.ui/icons/ovr/staged_removed.gif new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..b6b4911d9eba72838d54fbcf6109eaf3836bf0db
GIT binary patch
org.spearce.egit.ui/src/org/spearce/egit/ui/PluginPreferenceInitializer.java +2 -0
index 7465444..ef886cf 100644
@@ -44,6 +44,8 @@ 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);
 
 		w = new int[] { 500, 500 };
 		UIPreferences.setDefault(prefs,
org.spearce.egit.ui/src/org/spearce/egit/ui/UIIcons.java +9 -4
index 0cead29..302637e 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;
@@ -75,8 +79,9 @@
 
 	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");
org.spearce.egit.ui/src/org/spearce/egit/ui/UIPreferences.java +4 -0
index 7916cea..409b335 100644
@@ -64,6 +64,10 @@
 	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";
 
 	/**
 	 * Get the preference values associated with a fixed integer array.
org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +13 -1
index fe62d0a..b62ca4c 100644
@@ -953,12 +953,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;
 
 	/** */
@@ -979,6 +985,12 @@
 	/** */
 	public static String DecoratorPreferencesPage_iconsShowUntracked;
 
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowStaged;
+
+	/** */
+	public static String DecoratorPreferencesPage_iconsShowConflicts;
+
 	static {
 		initializeMessages(UIText.class.getPackage().getName() + ".uitext",
 				UIText.class);
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java +237 -47

387 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/IDecoratableResource.java +39 -0
index f144214..d2b6b5c 100644
@@ -16,6 +16,22 @@
 public interface IDecoratableResource {
 
 	/**
+	 * Set of possible staging states for a resource
+	 */
+	public enum Staged {
+		/** Represents a resource that is not staged */
+		NOT_STAGED,
+		/** Represents a resource that has been modified */
+		MODIFIED,
+		/** Represents a resource that is added to Git */
+		ADDED,
+		/** Represents a resource that is removed from Git */
+		REMOVED,
+		/** Represents a resource that has been renamed */
+		RENAMED
+	}
+
+	/**
 	 * Gets the type of the resource as defined by {@link IResource}
 	 * 
 	 * @return the type of the resource
@@ -51,4 +67,27 @@
 	 * @return whether or not the resource is ignored
 	 */
 	boolean isIgnored();
+
+	/**
+	 * Returns whether or not the resource has changes that are not staged
+	 * 
+	 * @return whether or not the resource is dirty
+	 */
+	boolean isDirty();
+
+	/**
+	 * Returns the staged state of the resource
+	 * 
+	 * The set of allowed values are defined by the <code>Staged</code> enum
+	 * 
+	 * @return the staged state of the resource
+	 */
+	Staged staged();
+
+	/**
+	 * Returns whether or not the resource has merge conflicts
+	 * 
+	 * @return whether or not the resource has merge conflicts
+	 */
+	boolean hasConflicts();
 }
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java +113 -18

277 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +10 -4
index 05fdba9..2762d11 100644
@@ -352,13 +352,15 @@ 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
@@ -366,3 +368,7 @@ DecoratorPreferencesPage_iconLabel=&Icon Decorations
 DecoratorPreferencesPage_iconsShowTracked=Tracked resources
 DecoratorPreferencesPage_iconsShowUntracked=Untracked resources
 
+Decorator_exceptionMessage=Errors occurred while applying Git decorations to resources.
+
+DecoratorPreferencesPage_iconsShowStaged=Staged resources
+DecoratorPreferencesPage_iconsShowConflicts=Conflicting resources
Signature · 1 line
1.6.1.2.309.g2ea3
#10 lore raw

PATCH 10/11 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 aa6a261..45b9f83 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;
@@ -682,7 +679,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));
 		}
 	}
 
@@ -809,29 +806,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 11/11 Implement label decorations for folders and projects

The option "Inspect dirty state of children..." controls if the decoration process should look at child resources to decide if a container is dirty or not. For large/deep projects this can be quite time consuming.

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

---
 org.spearce.egit.ui/.options                       |    8 +-
 .../src/org/spearce/egit/ui/Activator.java         |    2 +-
 .../egit/ui/PluginPreferenceInitializer.java       |    3 +-
 .../src/org/spearce/egit/ui/UIPreferences.java     |    4 +-
 .../src/org/spearce/egit/ui/UIText.java            |    5 +-
 .../decorators/GitLightweightDecorator.java        |  344 +++++++++++++++-----
 .../preferences/GitDecoratorPreferencePage.java    |   33 ++-
 .../src/org/spearce/egit/ui/uitext.properties      |    3 +-
 8 files changed, 311 insertions(+), 91 deletions(-)
org.spearce.egit.ui/.options +7 -1
index a084b35..8fc1c19 100644
@@ -1 +1,7 @@
-org.spearce.egit.ui/trace/verbose = false
+# Debugging options for the org.spearce.egit.ui plugin.
+
+# Show general verbose output
+org.spearce.egit.ui/verbose = false
+
+# Show debug output for label decorations
+org.spearce.egit.ui/decorations = false
\ No newline at end of file
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +1 -1
index 9d03c70..45010ce 100644
@@ -190,7 +190,7 @@ public Activator() {
 
 	public void start(final BundleContext context) throws Exception {
 		super.start(context);
-		traceVerbose = isOptionSet("/trace/verbose");
+		traceVerbose = isOptionSet("/verbose");
 		setupSSH(context);
 		setupProxy(context);
 		setupRepoChangeScanner();
org.spearce.egit.ui/src/org/spearce/egit/ui/PluginPreferenceInitializer.java +2 -1
index ef886cf..9af35bc 100644
@@ -35,7 +35,8 @@ 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_COMPUTE_DEEP_DIRTY, true);
 		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 409b335..f0a5e28 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_COMPUTE_DEEP_DIRTY = "decorator_compute_deep_dirty";
 	/** */
 	public final static String DECORATOR_FILETEXT_DECORATION = "decorator_filetext_decoration";
 	/** */
org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java +4 -1
index b62ca4c..5dd28df 100644
@@ -920,7 +920,10 @@
 	public static String DecoratorPreferencesPage_addVariablesAction;
 
 	/** */
-	public static String DecoratorPreferencesPage_computeDeep;
+	public static String DecoratorPreferencesPage_recomputeAncestorDecorations;
+
+	/** */
+	public static String DecoratorPreferencesPage_computeDeepDirtyState;
 
 	/** */
 	public static String DecoratorPreferencesPage_description;
org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitLightweightDecorator.java +269 -75

520 lines not on this page · raw message

org.spearce.egit.ui/src/org/spearce/egit/ui/internal/preferences/GitDecoratorPreferencePage.java +23 -10
index 74bc209..1a13a15 100644
@@ -89,7 +89,9 @@
 
 	private Text projectTextFormat;
 
-	private Button computeDeepDirtyState;
+	private Button recomputeAncestorDecorations;
+
+	private Button computeDeepDirtyStateForContainers;
 
 	private Button showTracked;
 
@@ -204,8 +206,10 @@ private Control createGeneralDecoratorPage(Composite parent) {
 		data.horizontalAlignment = GridData.FILL;
 		composite.setLayoutData(data);
 
-		computeDeepDirtyState = SWTUtils.createCheckBox(composite,
-				UIText.DecoratorPreferencesPage_computeDeep);
+		recomputeAncestorDecorations = SWTUtils.createCheckBox(composite,
+				UIText.DecoratorPreferencesPage_recomputeAncestorDecorations);
+		computeDeepDirtyStateForContainers = SWTUtils.createCheckBox(composite,
+				UIText.DecoratorPreferencesPage_computeDeepDirtyState);
 
 		return composite;
 	}
@@ -317,8 +321,10 @@ public void handleEvent(Event event) {
 	private void initializeValues() {
 		final IPreferenceStore store = getPreferenceStore();
 
-		computeDeepDirtyState.setSelection(store
-				.getBoolean(UIPreferences.DECORATOR_CALCULATE_DIRTY));
+		recomputeAncestorDecorations.setSelection(store
+				.getBoolean(UIPreferences.DECORATOR_RECOMPUTE_ANCESTORS));
+		computeDeepDirtyStateForContainers.setSelection(store
+				.getBoolean(UIPreferences.DECORATOR_COMPUTE_DEEP_DIRTY));
 
 		fileTextFormat.setText(store
 				.getString(UIPreferences.DECORATOR_FILETEXT_DECORATION));
@@ -342,7 +348,9 @@ public void widgetSelected(SelectionEvent e) {
 			}
 		};
 
-		computeDeepDirtyState.addSelectionListener(selectionListener);
+		recomputeAncestorDecorations.addSelectionListener(selectionListener);
+		computeDeepDirtyStateForContainers
+				.addSelectionListener(selectionListener);
 		showTracked.addSelectionListener(selectionListener);
 		showUntracked.addSelectionListener(selectionListener);
 		showStaged.addSelectionListener(selectionListener);
@@ -384,8 +392,10 @@ public boolean performOk() {
 	 */
 	private boolean performOk(IPreferenceStore store) {
 
-		store.setValue(UIPreferences.DECORATOR_CALCULATE_DIRTY,
-				computeDeepDirtyState.getSelection());
+		store.setValue(UIPreferences.DECORATOR_RECOMPUTE_ANCESTORS,
+				recomputeAncestorDecorations.getSelection());
+		store.setValue(UIPreferences.DECORATOR_COMPUTE_DEEP_DIRTY,
+				computeDeepDirtyStateForContainers.getSelection());
 
 		store.setValue(UIPreferences.DECORATOR_FILETEXT_DECORATION,
 				fileTextFormat.getText());
@@ -414,8 +424,11 @@ protected void performDefaults() {
 		super.performDefaults();
 		IPreferenceStore store = getPreferenceStore();
 
-		computeDeepDirtyState.setSelection(store
-				.getDefaultBoolean(UIPreferences.DECORATOR_CALCULATE_DIRTY));
+		recomputeAncestorDecorations
+				.setSelection(store
+						.getDefaultBoolean(UIPreferences.DECORATOR_RECOMPUTE_ANCESTORS));
+		computeDeepDirtyStateForContainers.setSelection(store
+				.getDefaultBoolean(UIPreferences.DECORATOR_COMPUTE_DEEP_DIRTY));
 
 		fileTextFormat.setText(store
 				.getDefaultString(UIPreferences.DECORATOR_FILETEXT_DECORATION));
org.spearce.egit.ui/src/org/spearce/egit/ui/uitext.properties +2 -1
index 2762d11..770de4a 100644
@@ -344,7 +344,8 @@ 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=Also re-decorate &ancestors when decorating changed resources
+DecoratorPreferencesPage_computeDeepDirtyState=Inspect dirty state of &children when decorating folders and projects
 DecoratorPreferencesPage_description=Shows Git specific information on resources in projects under version control.
 
 DecoratorPreferencesPage_decorationSettings=Decoration &settings:
Signature · 1 line
1.6.1.2.309.g2ea3
#12 lore raw

Re: [EGIT PATCH 06/11] Implement basic customizable label decorations with preferences

In reply to Tor Arne Vestbø

torsdag 05 februari 2009 02:00:13 skrev Tor Arne Vestbø:

Quoted 2 lines

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

The size of the components of the page is wrong forcing unnecessary scrollbars.

The terms use should probably have a cleared explanation/definition and the same terms used for the flags/icons. The explanation could probably be done using longer tooltips.

I miss the red attention-gathering red conflict icon we had. I also have a hard time distinguishing the staged/added/removed icons without reading glasses. The decorations are only 1.3 mm on my screen (150 dpi), so I think the icons should have different colors and different shapes instead of a few different pixels withing a square box.

I'd also like to see the conflict state for files inherited by parent folder and projects.

The checkboxes in the general tab have no effect on the preview.

-- robin

#13 lore raw

Re: [EGIT PATCH 06/11] Implement basic customizable label decorations with preferences

Quoted 5 lines · Robin Rosenberg

torsdag 05 februari 2009 02:00:13 skrev Tor Arne Vestbø:

Quoted 2 lines

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

The size of the components of the page is wrong forcing unnecessary scrollbars.

Argh, I've been battling those layouts on Linux, but though it was finally fixed. On Windows the dialog looks fine. I'll investigate further.

Quoted 3 lines

The terms use should probably have a cleared explanation/definition and the same terms used for the flags/icons. The explanation could probably be done using longer tooltips.

Noted.

Quoted 1 line

I miss the red attention-gathering red conflict icon we had.

Happy to replace. If I remember correctly that's the symbol used by other plugins to indicate conflicts, so I was aiming for consistency and recognizability.

Quoted 5 lines

I also have a hard time distinguishing the staged/added/removed icons without reading glasses. The decorations are only 1.3 mm on my screen (150 dpi), so I think the icons should have different colors and different shapes instead of a few different pixels withing a square box.>

Noted, I'll try to make some mocukups of variations to the icons.

Quoted 2 lines

I'd also like to see the conflict state for files inherited by parent folder and projects.

Good idea, like the synchronize view shows it. Noted.

Quoted 1 line

The checkboxes in the general tab have no effect on the preview.

True. Should be easy to fix.

Thanks for the feedback!

Tor Arne

#14 lore raw

Re: [EGIT PATCH 06/11] Implement basic customizable label decorations with preferences

Quoted 5 lines · Tor Arne Vestbø
Quoted 1 line

I miss the red attention-gathering red conflict icon we had.

Happy to replace. If I remember correctly that's the symbol used by other plugins to indicate conflicts, so I was aiming for consistency and recognizability.

Okey, I've replaced the blue one with the default conflict icon from the team org.eclipse.team.ui plugin, what can be more consistent then that? :) See mockup below.

Quoted 7 lines
Quoted 5 lines

I also have a hard time distinguishing the staged/added/removed icons without reading glasses. The decorations are only 1.3 mm on my screen (150 dpi), so I think the icons should have different colors and different shapes instead of a few different pixels withing a square box.>

Noted, I'll try to make some mocukups of variations to the icons.

Here are two alternatives. The first one (A) uses the same icons as before, but adds red and green shading. The second one (B) uses the green plus sign for added (which is used all over the place in Eclipse to mean 'added'), and the gray x for removed (which is also used all over the place in Eclipse for that same concept).

http://img443.imageshack.us/img443/5138/egitmockupmm7.png

I favor solution B, as it uses recognizable concepts from the existing Eclipse UI, plus that having a red removed-icon conflicts too much with the conflict-icon (pun intended). There's also a very similar red icon in JDT that indicates that something needs fixing (a red medic kit), which is another reason to go with solution B.

What do you say?

Tor Arne

Quoted 13 lines
Quoted 3 lines

I'd also like to see the conflict state for files inherited by parent folder and projects.

Good idea, like the synchronize view shows it. Noted.

Quoted 1 line

The checkboxes in the general tab have no effect on the preview.

True. Should be easy to fix.

Thanks for the feedback!

Tor Arne

#15 lore raw

Re: [EGIT PATCH 06/11] Implement basic customizable label decorations with preferences

torsdag 05 februari 2009 22:00:36 skrev Tor Arne Vestbø:

Quoted 6 lines

Here are two alternatives. The first one (A) uses the same icons as before, but adds red and green shading. The second one (B) uses the green plus sign for added (which is used all over the place in Eclipse to mean 'added'), and the gray x for removed (which is also used all over the place in Eclipse for that same concept).

Quoted 7 lines

http://img443.imageshack.us/img443/5138/egitmockupmm7.png

I favor solution B, as it uses recognizable concepts from the existing Eclipse UI, plus that having a red removed-icon conflicts too much with the conflict-icon (pun intended). There's also a very similar red icon in JDT that indicates that something needs fixing (a red medic kit), which is another reason to go with solution B.

I go with B.

Btw, shouldn't staged, added and removed also count as outgoing, i.e. ">" ?

-- robin

#16 lore raw

Re: [EGIT PATCH 06/11] Implement basic customizable label decorations with preferences

Quoted 9 lines · Robin Rosenberg

torsdag 05 februari 2009 22:00:36 skrev Tor Arne Vestbø:

Quoted 8 lines

Here are two alternatives. The first one (A) uses the same icons as before, but adds red and green shading. The second one (B) uses the green plus sign for added (which is used all over the place in Eclipse to mean 'added'), and the gray x for removed (which is also used all over the place in Eclipse for that same concept).

http://img443.imageshack.us/img443/5138/egitmockupmm7.png

Quoted 7 lines
Quoted 5 lines

I favor solution B, as it uses recognizable concepts from the existing Eclipse UI, plus that having a red removed-icon conflicts too much with the conflict-icon (pun intended). There's also a very similar red icon in JDT that indicates that something needs fixing (a red medic kit), which is another reason to go with solution B.

I go with B.

All right :)

Quoted 1 line

Btw, shouldn't staged, added and removed also count as outgoing, i.e. ">" ?

Currently there's two variables, 'dirty', and 'staged'. The former mappps to a diff between working directory and index, and has the default symbol '>'. The latter mapps to a diff between index and repository, with the default symbol '*'.

The default decoration for files does not have the 'staged' variable, but you can add {staged} for a *, or override with {staged:>} for a >.

The idea was to get both states between wd and index and index and repo in the decorators. We could add an option to treat both as one, ie only care about wd vs repo?

I plan to implement the synchronize view too, in which case we could share these two pieces of information between the Package Explorer (wd vs index), and the Synchronize View (index vs repo), similar to how git gui works.

Tor Arne

#18 lore raw

Re: [EGIT PATCH 02/11] Use Set instead of array to keep track of change listeners

In reply to Tor Arne Vestbø
Quoted 9 lines · Tor Arne Vestbø
org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +3 -0
+	public static synchronized void removeRepositoryChangeListener(
+			final RepositoryChangeListener objectThatCares) {
+		repositoryChangeListeners.remove(objectThatCares);
 	}
 
 	/**
@@ -131,13 +133,8 @@ public static synchronized void addRepositoryChangeListener(
 	 *            the repository which has had changes occur within it.
 	 */

org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java public static synchronized void addRepositoryChangeListener( · line 137

Quoted 10 lines
org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +2 -7
 	static void fireRepositoryChanged(final RepositoryMapping which) {
-		final RepositoryChangeListener[] e = getRepositoryChangeListeners();
-		for (int k = e.length - 1; k >= 0; k--)
-			e[k].repositoryChanged(which);
-	}
-
-	private static synchronized RepositoryChangeListener[] getRepositoryChangeListeners() {
-		return repositoryChangeListeners;
+		for (RepositoryChangeListener listener : repositoryChangeListeners)
+			listener.repositoryChanged(which);

See anything wrong here, like that the Set can be modified while GitProjectData's class lock is held, but its being read here without any locking?

The array trick worked before because we always made a copy anytime the array was modified. So we could safely return the array to the caller and let the caller iterate it unlocked; we just had to read the current array using a synchronized method to ensure we had a stable read.

You'll need to copy the Set somehow while inside of a synchronized method, then return the copy to the fireRepositoryChanged() method so it can iterate the copy to fire the events.

Signature · 1 line
Shawn.
#19 lore raw

Re: [EGIT PATCH 02/11] Use Set instead of array to keep track of change listeners

Quoted 16 lines · Shawn O. Pearce
Quoted 15 lines · Tor Arne Vestbø
org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +3 -5
+	public static synchronized void removeRepositoryChangeListener(
+			final RepositoryChangeListener objectThatCares) {
+		repositoryChangeListeners.remove(objectThatCares);
 	}
 
 	/**
@@ -131,13 +133,8 @@ 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);
-	}
-
Quoted 8 lines

org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java public static synchronized void addRepositoryChangeListener( · line 137

Quoted 4 lines
org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +2 -2
-	private static synchronized RepositoryChangeListener[] getRepositoryChangeListeners() {
-		return repositoryChangeListeners;
+		for (RepositoryChangeListener listener : repositoryChangeListeners)
+			listener.repositoryChanged(which);

See anything wrong here, like that the Set can be modified while GitProjectData's class lock is held, but its being read here without any locking?

You're perfectly right. New patch coming up!

Tor Arne

#20 lore raw

PATCH v2 2/11 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
#21 lore raw

Re: [EGIT PATCH 01/11] Add support code to handle plugin property changes

In reply to Tor Arne Vestbø

org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java line 55

Quoted 13 lines · Tor Arne Vestbø
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +4 -0
index fced643..d4a9e8e 100644
@@ -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;

What does this field do? I don't see it referenced anywhere...

org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java line 61

Quoted 5 lines
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +4 -0
 	/**
+	 * Property listeners for plugin specific events
+	 */
+	private static List<IPropertyChangeListener> propertyChangeListeners =
+		new ArrayList<IPropertyChangeListener>(5);

None of these list accesses are thread-safe. Are we certain they call will come from a single thread, e.g. the SWT event thread? Or do we need to put synchronized protection in here?

Signature · 1 line
Shawn.
#22 lore raw

Re: [EGIT PATCH 01/11] Add support code to handle plugin property changes

Quoted 16 lines · Shawn O. Pearce

org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java line 55

Quoted 13 lines · Tor Arne Vestbø
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +4 -0
index fced643..d4a9e8e 100644
@@ -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;

What does this field do? I don't see it referenced anywhere...

It's the singleton instance, referenced from Activator.getDefault(). I just documented it :)

Quoted 9 lines

org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java line 61

Quoted 5 lines
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +4 -0
 	/**
+	 * Property listeners for plugin specific events
+	 */
+	private static List<IPropertyChangeListener> propertyChangeListeners =
+		new ArrayList<IPropertyChangeListener>(5);

None of these list accesses are thread-safe. Are we certain they call will come from a single thread, e.g. the SWT event thread? Or do we need to put synchronized protection in here?

The addPropertyChangeListener method is called at startup from the GitLightweightDecorator constructor, in one of the worker threads, and same thing with removePropertyChangeListener from dispose(). The broadcastPropertyChange method is called in the main thread every time the Git decorator preference page is closes.

This is the sync model used by other Eclipse plugins for keeping track of propertyChangeListeners, for example in the TeamUIPlugin, that's why I assumed it was OK. I'm perfectly fine with syncrhronizing it though, similar to repositoryChangeListeners in GitProjectData?

Tor Arne

#23 lore raw

Re: [EGIT PATCH 01/11] Add support code to handle plugin property changes

Quoted 18 lines · Tor Arne Vestbø
Quoted 16 lines · Shawn O. Pearce

org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java line 55

Quoted 13 lines · Tor Arne Vestbø
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +4 -0
index fced643..d4a9e8e 100644
@@ -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;

What does this field do? I don't see it referenced anywhere...

Quoted 2 lines

It's the singleton instance, referenced from Activator.getDefault(). I just documented it :)

*sigh*. I haven't had enough caffiene yet this morning. Yes, I see what you mean, its only the Javadoc that was added. OK, forget I said anything here. :-)

Quoted 16 lines
Quoted 9 lines

org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java line 61

Quoted 5 lines
org.spearce.egit.ui/src/org/spearce/egit/ui/Activator.java +4 -0
 	/**
+	 * Property listeners for plugin specific events
+	 */
+	private static List<IPropertyChangeListener> propertyChangeListeners =
+		new ArrayList<IPropertyChangeListener>(5);

None of these list accesses are thread-safe. Are we certain they call will come from a single thread, e.g. the SWT event thread? Or do we need to put synchronized protection in here?

The addPropertyChangeListener method is called at startup from the GitLightweightDecorator constructor, in one of the worker threads, and same thing with removePropertyChangeListener from dispose(). The broadcastPropertyChange method is called in the main thread every time the Git decorator preference page is closes.

Quoted 4 lines

This is the sync model used by other Eclipse plugins for keeping track of propertyChangeListeners, for example in the TeamUIPlugin, that's why I assumed it was OK. I'm perfectly fine with syncrhronizing it though, similar to repositoryChangeListeners in GitProjectData?

OK, I see. I'd perhaps prefer to make this thread-safe just in case. If its always coming off the SWT event thread, then just tossing a synchronized keyword on all 3 methods should be Good Enough(tm).

Signature · 1 line
Shawn.
#24 lore raw

PATCH v2 1/1 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
#25 lore raw
In reply to Tor Arne Vestbø
Quoted 3 lines · Tor Arne Vestbø

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

Aside from my two remarks about the synchronized collections, I like it. There's no display for "added and dirty", aka doing:

echo a >a; # create a
git add a
echo b >>a; # append a and dirty it

This still shows as just "added". It should be "added and dirty", as its partially staged.

Quoted 4 lines

Known issues are:

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

I'd like to see this fixed in the near-ish future, but I don't think its blocking to merging your patches.

Quoted 3 lines

- When a Java resource is dirty, each parent package in the package hierarcy will appear dirty, even when the layout is set to 'flat'.

Bah. I've seen the Java compiler error marks also report like this. I don't think its our issue. But maybe I'm wrong.

Signature · 1 line
Shawn.
#26 lore raw

torsdag 05 februari 2009 17:06:25 skrev Shawn O. Pearce:

Quoted 7 lines
Quoted 4 lines

Known issues are:

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

I'd like to see this fixed in the near-ish future, but I don't think its blocking to merging your patches.

I'm not sure this is Tore's bug. We've had problems with nested repos before.

Quoted 6 lines
Quoted 3 lines

- When a Java resource is dirty, each parent package in the package hierarcy will appear dirty, even when the layout is set to 'flat'.

Bah. I've seen the Java compiler error marks also report like this. I don't think its our issue. But maybe I'm wrong.

It's our choice here. Generally, I think we should shift behavior here depending on layout. Java packages are not hierarchical in nature.

Currently it may look like this with flat package layout:

>org.spearce.jgit.treewalk
CanonicalTreeParserTest.java
EmptyTreeIteratorTest.java
FileTreeIteratorTest.java
NameConflictTreeWalkTest.java
PostOrderTreeWalkTest.java
TreeWalkBasicDiffTest.java

>org.spearce.jgit.treewalk.filter
AlwaysCloneTreeFilter.java
>NotTreeFilterTest.java
TreeFilterTest.java

Which is odd when looking at org.spearce.jgit.treewalk, because no files in that package have been changed. A tricky question is how to decorate empty packages. like org, org.spearce. Probably as unchanged.

-- robin

#27 lore raw
Quoted 13 lines · Robin Rosenberg

It's our choice here. Generally, I think we should shift behavior here depending on layout. Java packages are not hierarchical in nature.

Currently it may look like this with flat package layout:

>org.spearce.jgit.treewalk
CanonicalTreeParserTest.java
EmptyTreeIteratorTest.java
FileTreeIteratorTest.java
NameConflictTreeWalkTest.java
PostOrderTreeWalkTest.java
TreeWalkBasicDiffTest.java

Quoted 8 lines

>org.spearce.jgit.treewalk.filter
AlwaysCloneTreeFilter.java
>NotTreeFilterTest.java
TreeFilterTest.java

Which is odd when looking at org.spearce.jgit.treewalk, because no files in that package have been changed.

Agreed. But, as the CVS plugin seems to handle this gracefully, without any JDT specific code (from my brief investigations), it seems that this is something we can get for free from the team plugins. I will look into it as soon as this series is done cooking.

Tor Arne

#28 lore raw

torsdag 05 februari 2009 19:37:32 skrev Tor Arne Vestbø:

Quoted 20 lines
Quoted 19 lines · Robin Rosenberg

It's our choice here. Generally, I think we should shift behavior here depending on layout. Java packages are not hierarchical in nature.

Currently it may look like this with flat package layout:

>org.spearce.jgit.treewalk
CanonicalTreeParserTest.java
EmptyTreeIteratorTest.java
FileTreeIteratorTest.java
NameConflictTreeWalkTest.java
PostOrderTreeWalkTest.java
TreeWalkBasicDiffTest.java

>org.spearce.jgit.treewalk.filter
AlwaysCloneTreeFilter.java
>NotTreeFilterTest.java
TreeFilterTest.java

Quoted 7 lines
Quoted 2 lines

Which is odd when looking at org.spearce.jgit.treewalk, because no files in that package have been changed.

Agreed. But, as the CVS plugin seems to handle this gracefully, without any JDT specific code (from my brief investigations), it seems that this is something we can get for free from the team plugins. I will look into it as soon as this series is done cooking.

My guess is it has to do with traversal according to the structure layout, so JDT only does the layout and the CVS decorator follows that one.

-- robin

#29 lore raw
In reply to Shawn O. Pearce
Quoted 7 lines · Shawn O. Pearce
Quoted 3 lines · Tor Arne Vestbø

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

Aside from my two remarks about the synchronized collections, I like it.

Thanks :)

Quoted 1 line

There's no display for "added and dirty", aka doing:

That's a bug, should work the same as "staged and dirty", with [*] >, I'll look into it.

Quoted 7 lines
Quoted 4 lines

Known issues are:

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

I'd like to see this fixed in the near-ish future, but I don't think its blocking to merging your patches.

Yepp, It's on my list. This series is basically the minimum feature-set I could produce that has most of what the current decorators have, so I
could get a basis landed.

Quoted 6 lines
Quoted 3 lines

- When a Java resource is dirty, each parent package in the package hierarcy will appear dirty, even when the layout is set to 'flat'.

Bah. I've seen the Java compiler error marks also report like this. I don't think its our issue. But maybe I'm wrong.

The CVS plugin handles this -- possibly through the TeamStateProvider and friends -- so it is possible. Something to look at.

Tor Arne