Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-28 21:01:23 +0000
committerChris Aniszczyk2011-04-28 21:16:05 +0000
commit5247f096fb12dbafdecaad7d1f6f4792b9640ff9 (patch)
tree8ccc75b14d0269f44f7429552905167b385fd29f /org.eclipse.egit.ui/src/org/eclipse/egit
parent73e5d2fd4fa868ab95dbffac567aa32746fa7b3a (diff)
downloadegit-5247f096fb12dbafdecaad7d1f6f4792b9640ff9.tar.gz
egit-5247f096fb12dbafdecaad7d1f6f4792b9640ff9.tar.xz
egit-5247f096fb12dbafdecaad7d1f6f4792b9640ff9.zip
Add editor page class to display commit information
Bug: 343000 Change-Id: Ic4091eef5d6864ac2dd08a1143370f702772f578 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.egit.ui/src/org/eclipse/egit')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java18
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java200
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties6
3 files changed, 224 insertions, 0 deletions
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 688feb2ce1..72d170c85a 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
@@ -2921,6 +2921,24 @@ public class UIText extends NLS {
public static String CommitEditorInput_ToolTip;
/** */
+ public static String CommitEditorPage_LabelAuthor;
+
+ /** */
+ public static String CommitEditorPage_LabelCommitter;
+
+ /** */
+ public static String CommitEditorPage_LabelParent;
+
+ /** */
+ public static String CommitEditorPage_SectionFiles;
+
+ /** */
+ public static String CommitEditorPage_SectionMessage;
+
+ /** */
+ public static String CommitEditorPage_Title;
+
+ /** */
public static String CommitFileDiffViewer_CanNotOpenCompareEditorTitle;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
new file mode 100644
index 0000000000..9fe7221aa3
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * 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.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.dialogs.SpellcheckableMessageArea;
+import org.eclipse.egit.ui.internal.history.FileDiff;
+import org.eclipse.egit.ui.internal.history.FileDiffLabelProvider;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.IFormColors;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.events.ExpansionAdapter;
+import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+
+/**
+ * Commit editor page class displaying author, committer, parent commits,
+ * message, and file information in form sections.
+ */
+public class CommitEditorPage extends FormPage {
+
+ /**
+ * Abbreviated length of parent id links displayed
+ */
+ public static final int PARENT_LENGTH = 20;
+
+ /**
+ * Create commit editor page
+ *
+ * @param editor
+ */
+ public CommitEditorPage(FormEditor editor) {
+ this(editor, "commitPage", UIText.CommitEditorPage_Title); //$NON-NLS-1$
+ }
+
+ /**
+ * Create commit editor page
+ *
+ * @param editor
+ * @param id
+ * @param title
+ */
+ public CommitEditorPage(FormEditor editor, String id, String title) {
+ super(editor, id, title);
+ }
+
+ private void hookExpansionGrabbing(final Section section) {
+ section.addExpansionListener(new ExpansionAdapter() {
+
+ public void expansionStateChanged(ExpansionEvent e) {
+ ((GridData) section.getLayoutData()).grabExcessVerticalSpace = e
+ .getState();
+ getManagedForm().reflow(true);
+ }
+ });
+ }
+
+ private void createHeaderArea(Composite parent, FormToolkit toolkit) {
+ RevCommit commit = getCommit().getRevCommit();
+ Composite top = toolkit.createComposite(parent);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(top);
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(top);
+
+ Composite userArea = toolkit.createComposite(top);
+ GridLayoutFactory.fillDefaults().numColumns(1).applyTo(userArea);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(userArea);
+
+ PersonIdent author = commit.getAuthorIdent();
+ if (author != null) {
+ Text authorText = toolkit.createText(userArea, MessageFormat
+ .format(UIText.CommitEditorPage_LabelAuthor,
+ author.getName(), author.getWhen()));
+ GridDataFactory.fillDefaults().span(1, 1).applyTo(authorText);
+ }
+
+ PersonIdent committer = commit.getCommitterIdent();
+ if (committer != null && !committer.equals(author)) {
+ Text committerText = toolkit.createText(userArea, MessageFormat
+ .format(UIText.CommitEditorPage_LabelCommitter,
+ committer.getName(), committer.getWhen()));
+ committerText.setFont(parent.getFont());
+ GridDataFactory.fillDefaults().span(1, 1).applyTo(committerText);
+ }
+
+ int count = commit.getParentCount();
+ if (count > 0) {
+ Composite parents = toolkit.createComposite(top);
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(parents);
+ GridDataFactory.fillDefaults().grab(false, false).applyTo(parents);
+
+ for (int i = 0; i < count; i++) {
+ final RevCommit parentCommit = commit.getParent(i);
+ toolkit.createLabel(parents,
+ UIText.CommitEditorPage_LabelParent).setForeground(
+ toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
+ toolkit.createHyperlink(parents,
+ parentCommit.abbreviate(PARENT_LENGTH).name(), SWT.NONE);
+ }
+ }
+ }
+
+ private void createDescriptionArea(Composite parent, FormToolkit toolkit) {
+ Section description = toolkit.createSection(parent,
+ ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
+ | ExpandableComposite.EXPANDED);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(description);
+ description.setText(UIText.CommitEditorPage_SectionMessage);
+
+ String content = getCommit().getRevCommit().getFullMessage();
+ SpellcheckableMessageArea textContent = new SpellcheckableMessageArea(
+ description, content) {
+
+ @Override
+ protected IAdaptable getDefaultTarget() {
+ return new PlatformObject() {
+ public Object getAdapter(Class adapter) {
+ return Platform.getAdapterManager().getAdapter(
+ getEditorInput(), adapter);
+ }
+ };
+ }
+
+ };
+ GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80)
+ .applyTo(textContent);
+ textContent.getTextWidget().setEditable(false);
+ description.setClient(textContent);
+
+ hookExpansionGrabbing(description);
+ }
+
+ private void createFilesArea(Composite parent, FormToolkit toolkit) {
+ Section files = toolkit.createSection(parent,
+ ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE
+ | ExpandableComposite.EXPANDED);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(files);
+
+ TableViewer viewer = new TableViewer(toolkit.createTable(files,
+ SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER));
+ GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80)
+ .applyTo(viewer.getControl());
+ viewer.setLabelProvider(new FileDiffLabelProvider());
+ viewer.setContentProvider(ArrayContentProvider.getInstance());
+ files.setClient(viewer.getControl());
+
+ RepositoryCommit commit = getCommit();
+ FileDiff[] diffs = commit.getDiffs();
+ viewer.setInput(diffs);
+ files.setText(MessageFormat.format(
+ UIText.CommitEditorPage_SectionFiles,
+ Integer.valueOf(diffs.length)));
+
+ hookExpansionGrabbing(files);
+ }
+
+ private RepositoryCommit getCommit() {
+ return (RepositoryCommit) getEditor()
+ .getAdapter(RepositoryCommit.class);
+ }
+
+ /**
+ * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
+ */
+ protected void createFormContent(IManagedForm managedForm) {
+ Composite body = managedForm.getForm().getBody();
+ GridLayoutFactory.swtDefaults().numColumns(1).applyTo(body);
+
+ FormToolkit toolkit = managedForm.getToolkit();
+
+ createHeaderArea(body, toolkit);
+ createDescriptionArea(body, toolkit);
+ createFilesArea(body, toolkit);
+ }
+}
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 b6c40070c0..0b5ba74c06 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
@@ -999,6 +999,12 @@ CommitActionHandler_calculatingChanges=Calculating changes in selected repositor
CommitActionHandler_repository=Repository: {0}
CommitEditorInput_Name={0} [{1}]
CommitEditorInput_ToolTip=Commit {0} in repository {1}
+CommitEditorPage_LabelAuthor={0} (author) on {1}
+CommitEditorPage_LabelCommitter={0} (committer) on {1}
+CommitEditorPage_LabelParent=Parent:
+CommitEditorPage_SectionFiles=Files ({0})
+CommitEditorPage_SectionMessage=Message
+CommitEditorPage_Title=Commit
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

Back to the top