summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-23 11:44:43 (EDT)
committer Chris Aniszczyk2011-04-28 13:05:16 (EDT)
commitc3d63bf11eb61968623865806057493b7dc3ad0a (patch)
tree688a243b689862c14738b940f11829b4cf611104
parent3aeffedf135a1cbd07e17223cd9e25f268290c0d (diff)
downloadegit-c3d63bf11eb61968623865806057493b7dc3ad0a.zip
egit-c3d63bf11eb61968623865806057493b7dc3ad0a.tar.gz
egit-c3d63bf11eb61968623865806057493b7dc3ad0a.tar.bz2
Add input class to display commits in an editorrefs/changes/65/3165/7
Bug: 343000 Change-Id: I7e373c71570f06d68c88f1db29cafdab05ecb289 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/commit/CommitEditorInputTest.java84
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorInput.java125
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties2
4 files changed, 217 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/commit/CommitEditorInputTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/commit/CommitEditorInputTest.java
new file mode 100644
index 0000000..4d72360
--- /dev/null
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/commit/CommitEditorInputTest.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.test.commit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.egit.core.Activator;
+import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.commit.CommitEditorInput;
+import org.eclipse.egit.ui.internal.commit.RepositoryCommit;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link CommitEditorInput}
+ */
+public class CommitEditorInputTest extends LocalRepositoryTestCase {
+
+ private static Repository repository;
+
+ private static RevCommit commit;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ File repoFile = createProjectAndCommitToRepository();
+ assertNotNull(repoFile);
+ repository = Activator.getDefault().getRepositoryCache()
+ .lookupRepository(repoFile);
+ assertNotNull(repository);
+
+ RevWalk walk = new RevWalk(repository);
+ try {
+ commit = walk.parseCommit(repository.resolve(Constants.HEAD));
+ assertNotNull(commit);
+ } finally {
+ walk.release();
+ }
+ }
+
+ @Test
+ public void testConstructorAsserts() {
+ try {
+ assertNull(new CommitEditorInput(null));
+ } catch (AssertionFailedException afe) {
+ assertNotNull(afe);
+ }
+ }
+
+ @Test
+ public void testAdapters() {
+ RepositoryCommit repoCommit = new RepositoryCommit(repository, commit);
+ CommitEditorInput input = new CommitEditorInput(repoCommit);
+ assertEquals(repoCommit, input.getAdapter(RepositoryCommit.class));
+ assertEquals(repository, input.getAdapter(Repository.class));
+ assertEquals(commit, input.getAdapter(RevCommit.class));
+ }
+
+ @Test
+ public void testInput() {
+ RepositoryCommit repoCommit = new RepositoryCommit(repository, commit);
+ CommitEditorInput input = new CommitEditorInput(repoCommit);
+ assertNotNull(input.getImageDescriptor());
+ assertNotNull(input.getToolTipText());
+ assertNotNull(input.getName());
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
index 17673ee..4a20dc5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java
@@ -2906,6 +2906,12 @@ public class UIText extends NLS {
public static String CommitActionHandler_repository;
/** */
+ public static String CommitEditorInput_Name;
+
+ /** */
+ public static String CommitEditorInput_ToolTip;
+
+ /** */
public static String CommitFileDiffViewer_CanNotOpenCompareEditorTitle;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorInput.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorInput.java
new file mode 100644
index 0000000..769ca0d
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorInput.java
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.commit;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.egit.ui.UIIcons;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * Commit editor input class. This class wraps a {@link RepositoryCommit} to be
+ * viewed in an editor.
+ */
+public class CommitEditorInput extends PlatformObject implements IEditorInput {
+
+ private RepositoryCommit commit;
+
+ /**
+ * Create commit editor input
+ *
+ * @param commit
+ */
+ public CommitEditorInput(RepositoryCommit commit) {
+ Assert.isNotNull(commit, "Repository commit cannot be null"); //$NON-NLS-1$
+ this.commit = commit;
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return commit.getRevCommit().hashCode();
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ else if (obj instanceof CommitEditorInput) {
+ RepositoryCommit inputCommit = ((CommitEditorInput) obj).commit;
+ return commit.getRevCommit().equals(inputCommit.getRevCommit())
+ && commit.getRepository().equals(
+ inputCommit.getRepository());
+ } else
+ return false;
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ return getName();
+ }
+
+ /**
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (RepositoryCommit.class == adapter)
+ return commit;
+
+ if (RevCommit.class == adapter)
+ return commit.getRevCommit();
+
+ if (Repository.class == adapter)
+ return commit.getRepository();
+
+ return super.getAdapter(adapter);
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorInput#exists()
+ */
+ public boolean exists() {
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
+ */
+ public ImageDescriptor getImageDescriptor() {
+ return UIIcons.CHANGESET;
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorInput#getName()
+ */
+ public String getName() {
+ return MessageFormat.format(UIText.CommitEditorInput_Name,
+ commit.abbreviate(), commit.getRepositoryName());
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorInput#getPersistable()
+ */
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorInput#getToolTipText()
+ */
+ public String getToolTipText() {
+ return MessageFormat.format(UIText.CommitEditorInput_ToolTip, commit
+ .getRevCommit().name(), commit.getRepositoryName());
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
index 86ecfe9..8b6ef61 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties
@@ -994,6 +994,8 @@ CommitAction_MergeHeadErrorMessage=The file .git/MERGE_MSG was not found althoug
CommitAction_MergeHeadErrorTitle=Inconsistent Merge state
CommitActionHandler_calculatingChanges=Calculating changes in selected repositories
CommitActionHandler_repository=Repository: {0}
+CommitEditorInput_Name={0} [{1}]
+CommitEditorInput_ToolTip=Commit {0} in repository {1}
MergeHandler_SelectBranchMessage=There is more than one ref for this commit. Please select the ref you want to merge.
MergeHandler_SelectBranchTitle=Select a ref for merge