Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Hohenegger2015-06-19 19:29:34 +0000
committerMatthias Sohn2015-08-22 21:50:01 +0000
commit67a39e4abfc418c48dd44e05eaee7c7b1fb43e95 (patch)
tree95f1b8fe9884960574d30dcfa420c6669bdcd651
parente71a75a6311770a6ca14471416832381c61f90f1 (diff)
downloadegit-67a39e4abfc418c48dd44e05eaee7c7b1fb43e95.tar.gz
egit-67a39e4abfc418c48dd44e05eaee7c7b1fb43e95.tar.xz
egit-67a39e4abfc418c48dd44e05eaee7c7b1fb43e95.zip
[gitflow] Add icon decorations to identify gitflow repositories
Bug: 470626 Change-Id: Ibd489882dce1335e68dbe32a0881591bb260096f Signed-off-by: Max Hohenegger <eclipse@hohenegger.eu> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.gitflow.ui/build.properties5
-rw-r--r--org.eclipse.egit.gitflow.ui/icons/ovr/git-flow.pngbin0 -> 340 bytes
-rw-r--r--org.eclipse.egit.gitflow.ui/plugin.properties2
-rw-r--r--org.eclipse.egit.gitflow.ui/plugin.xml17
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIIcons.java52
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java6
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/decorators/GitFlowLightweightDecorator.java185
-rw-r--r--org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties2
8 files changed, 267 insertions, 2 deletions
diff --git a/org.eclipse.egit.gitflow.ui/build.properties b/org.eclipse.egit.gitflow.ui/build.properties
index f2ac9f1d7a..e2704d5b0d 100644
--- a/org.eclipse.egit.gitflow.ui/build.properties
+++ b/org.eclipse.egit.gitflow.ui/build.properties
@@ -3,5 +3,6 @@ bin.includes = META-INF/,\
.,\
plugin.xml,\
plugin.properties,\
- about.html
-additional.bundles = org.eclipse.jdt.annotation \ No newline at end of file
+ about.html,\
+ icons/
+additional.bundles = org.eclipse.jdt.annotation
diff --git a/org.eclipse.egit.gitflow.ui/icons/ovr/git-flow.png b/org.eclipse.egit.gitflow.ui/icons/ovr/git-flow.png
new file mode 100644
index 0000000000..f3f7c6fbb3
--- /dev/null
+++ b/org.eclipse.egit.gitflow.ui/icons/ovr/git-flow.png
Binary files differ
diff --git a/org.eclipse.egit.gitflow.ui/plugin.properties b/org.eclipse.egit.gitflow.ui/plugin.properties
index 4f14dda79b..372fe60a78 100644
--- a/org.eclipse.egit.gitflow.ui/plugin.properties
+++ b/org.eclipse.egit.gitflow.ui/plugin.properties
@@ -22,3 +22,5 @@ TeamGitFlowFeatureCheckout.name = Checkout Feature
TeamGitFlowFeatureRebase.name = Rebase Feature
TeamGitFlowHotfixStart.name = Start Hotfix
TeamGitFlowHotfixFinish.name = Finish Hotfix
+Decorator_name=Gitflow
+Decorator_description=Shows Gitflow specific information on repository nodes. \ No newline at end of file
diff --git a/org.eclipse.egit.gitflow.ui/plugin.xml b/org.eclipse.egit.gitflow.ui/plugin.xml
index 4987603aed..ba0467ba7d 100644
--- a/org.eclipse.egit.gitflow.ui/plugin.xml
+++ b/org.eclipse.egit.gitflow.ui/plugin.xml
@@ -749,4 +749,21 @@
</menu>
</menuContribution>
</extension>
+ <extension point="org.eclipse.ui.decorators">
+ <decorator
+ lightweight="true"
+ adaptable="true"
+ label="%Decorator_name"
+ class="org.eclipse.egit.gitflow.ui.internal.decorators.GitFlowLightweightDecorator"
+ state="true"
+ location="TOP_RIGHT"
+ id="org.eclipse.egit.gitflow.ui.internal.decorators.GitflowLightweightDecorator">
+ <enablement>
+ <objectClass name="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode"/>
+ </enablement>
+ <description>
+ %Decorator_description
+ </description>
+ </decorator>
+ </extension>
</plugin>
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIIcons.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIIcons.java
new file mode 100644
index 0000000000..5f83a1864e
--- /dev/null
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIIcons.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.gitflow.ui.internal;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.egit.gitflow.ui.Activator;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Icons for Gitflow integration.
+ */
+public class UIIcons {
+ /** Decoration for initialized Gitflow repository. */
+ public final static ImageDescriptor OVR_GITFLOW;
+
+ /** base URL */
+ public final static URL base;
+
+ static {
+ base = init();
+ OVR_GITFLOW = map("ovr/git-flow.png"); //$NON-NLS-1$
+ }
+
+ private static ImageDescriptor map(final String icon) {
+ if (base != null)
+ try {
+ return ImageDescriptor.createFromURL(new URL(base, icon));
+ } catch (MalformedURLException mux) {
+ Activator.logError(NLS.bind(UIText.UIIcons_errorLoadingPluginImage, icon), mux);
+ }
+ return ImageDescriptor.getMissingImageDescriptor();
+ }
+
+ private static URL init() {
+ try {
+ return new URL(Activator.getDefault().getBundle().getEntry("/"), //$NON-NLS-1$
+ "icons/"); //$NON-NLS-1$
+ } catch (MalformedURLException mux) {
+ Activator.logError(UIText.UIIcons_errorDeterminingIconBase, mux);
+ return null;
+ }
+ }
+}
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java
index 6cb5b3a5b2..9dc61e2bd9 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java
@@ -176,4 +176,10 @@ public class UIText extends NLS {
/** */
public static String ReleaseFinishOperation_unexpectedConflictsReleaseAborted;
+
+ /** */
+ public static String UIIcons_errorDeterminingIconBase;
+
+ /** */
+ public static String UIIcons_errorLoadingPluginImage;
}
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/decorators/GitFlowLightweightDecorator.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/decorators/GitFlowLightweightDecorator.java
new file mode 100644
index 0000000000..5434841fa9
--- /dev/null
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/decorators/GitFlowLightweightDecorator.java
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.egit.gitflow.ui.internal.decorators;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.egit.gitflow.GitFlowRepository;
+import org.eclipse.egit.gitflow.ui.Activator;
+import org.eclipse.egit.gitflow.ui.internal.UIIcons;
+import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IDecoration;
+import org.eclipse.jface.viewers.ILightweightLabelDecorator;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Supplies decorations for displayed repositories
+ */
+public class GitFlowLightweightDecorator extends LabelProvider implements
+ ILightweightLabelDecorator {
+
+ /**
+ * Property constant pointing back to the extension point id of the
+ * decorator
+ */
+ public static final String DECORATOR_ID = "org.eclipse.egit.gitflow.ui.internal.decorators.GitflowLightweightDecorator"; //$NON-NLS-1$
+
+ private ILog log;
+
+ /** */
+ public GitFlowLightweightDecorator() {
+ log = Activator.getDefault().getLog();
+ }
+
+ /**
+ * This method should only be called by the decorator thread.
+ *
+ * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object,
+ * org.eclipse.jface.viewers.IDecoration)
+ */
+ @Override
+ public void decorate(Object element, IDecoration decoration) {
+ // Don't decorate if UI plugin is not running
+ if (Activator.getDefault() == null) {
+ return;
+ }
+
+ // Don't decorate if the workbench is not running
+ if (!PlatformUI.isWorkbenchRunning()) {
+ return;
+ }
+
+
+ final GitFlowRepository repository = getRepository(element);
+ try {
+ if (repository != null) {
+ decorateRepository(repository, decoration);
+ }
+ } catch (Exception e) {
+ handleException(repository, e);
+ }
+ }
+
+ private static @Nullable GitFlowRepository getRepository(Object element) {
+ GitFlowRepository repository = null;
+ if (element instanceof GitFlowRepository) {
+ repository = (GitFlowRepository) element;
+ }
+
+ if (element instanceof RepositoryNode) {
+ RepositoryNode node = (RepositoryNode) element;
+ repository = new GitFlowRepository(node.getObject());
+ }
+
+ return repository;
+ }
+
+ /**
+ * Decorates a single repository.
+ *
+ * @param repository
+ * the repository to decorate
+ * @param decoration
+ * the decoration
+ * @throws IOException
+ */
+ private void decorateRepository(GitFlowRepository repository,
+ IDecoration decoration) throws IOException {
+ final DecorationHelper helper = new DecorationHelper();
+ helper.decorate(decoration, repository);
+ }
+
+
+ /**
+ * Helper class for doing repository decoration
+ *
+ * Used for real-time decoration, as well as in the decorator preview
+ * preferences page
+ */
+ private static class DecorationHelper {
+
+ /**
+ * Define a cached image descriptor which only creates the image data
+ * once
+ */
+ private static class CachedImageDescriptor extends ImageDescriptor {
+ private ImageDescriptor descriptor;
+
+ private ImageData data;
+
+ public CachedImageDescriptor(ImageDescriptor descriptor) {
+ this.descriptor = descriptor;
+ }
+
+ @Override
+ public ImageData getImageData() {
+ if (data == null) {
+ data = descriptor.getImageData();
+ }
+ return data;
+ }
+ }
+
+ private final static ImageDescriptor INITIALIZED_IMAGE;
+
+ static {
+ INITIALIZED_IMAGE = new CachedImageDescriptor(UIIcons.OVR_GITFLOW);
+ }
+
+ /**
+ * Decorates the given <code>decoration</code> based on the state of the
+ * given <code>repository</code>.
+ *
+ * @param decoration
+ * the decoration to decorate
+ * @param repository
+ * the repository to retrieve state from
+ * @throws IOException
+ */
+ public void decorate(IDecoration decoration, GitFlowRepository repository)
+ throws IOException {
+ decorateIcons(decoration, repository);
+ }
+
+ private void decorateIcons(IDecoration decoration,
+ GitFlowRepository repository) throws IOException {
+ ImageDescriptor overlay = null;
+
+ if (repository.getConfig().isInitialized()) {
+ overlay = INITIALIZED_IMAGE;
+ }
+
+ // TODO: change decoration depending on branch type, e.g. "F"-icon
+ // for feature branch
+
+ // Overlays can only be added once, so do it at the end
+ decoration.addOverlay(overlay);
+ }
+
+ }
+
+ /**
+ * Handle exceptions that occur in the decorator.
+ *
+ * @param repository
+ * The repository that triggered the exception
+ * @param e
+ * The exception that occurred
+ */
+ private void handleException(GitFlowRepository repository, Exception e) {
+ if (repository != null) {
+ log.log(Activator.error(e.getMessage(), e));
+ }
+ }
+}
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties
index a6324a6e8f..ee4dcf2cb9 100644
--- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties
+++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties
@@ -56,3 +56,5 @@ FinishFeatureDialog_title=Feature finish options
FinishFeatureDialog_setParameterForFinishing=Set options for finishing {0}.
ReleaseFinishOperation_unexpectedConflictsReleaseAborted=Unexpected conflicts while merging to {0}. Finish release aborted.
HotfixFinishOperation_unexpectedConflictsHotfixAborted=Unexpected conflicts while merging to {0}. Finish hotfix aborted.
+UIIcons_errorDeterminingIconBase=Can't determine icon base.
+UIIcons_errorLoadingPluginImage=Can't load plugin image ''{0}''. \ No newline at end of file

Back to the top