aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Baumgart2010-09-04 15:32:11 (EDT)
committerMatthias Sohn2010-09-06 12:09:19 (EDT)
commite6a6357ee040abd4d63187b6618fe3a20ef97315 (patch)
treedea2846e7983a8db54afcf205e3795fee59bcad4
parentbd0d67f1783d314a7eec23c903acebfac62df168 (diff)
downloadegit-e6a6357ee040abd4d63187b6618fe3a20ef97315.zip
egit-e6a6357ee040abd4d63187b6618fe3a20ef97315.tar.gz
egit-e6a6357ee040abd4d63187b6618fe3a20ef97315.tar.bz2
Implement dialog to display a merge resultrefs/changes/03/1503/4
A dialog was implemented to display the result of a merge. Change-Id: I0f24afff6aefc93c300ba20491a83256139d08cb Signed-off-by: Jens Baumgart <jens.baumgart@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java21
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/MergeResultDialog.java206
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/MergeCommand.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties7
5 files changed, 238 insertions, 6 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 c2a0dfc..f52abd5 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
@@ -2236,6 +2236,27 @@ public class UIText extends NLS {
public static String MergeAction_WrongRepositoryState;
/** */
+ public static String MergeResultDialog_couldNotFindCommit;
+
+ /** */
+ public static String MergeResultDialog_description;
+
+ /** */
+ public static String MergeResultDialog_id;
+
+ /** */
+ public static String MergeResultDialog_mergeInput;
+
+ /** */
+ public static String MergeResultDialog_mergeResult;
+
+ /** */
+ public static String MergeResultDialog_newHead;
+
+ /** */
+ public static String MergeResultDialog_result;
+
+ /** */
public static String MergeTargetSelectionDialog_ButtonMerge;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
index e4721b6..fa52ad4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/MergeActionHandler.java
@@ -26,6 +26,7 @@ import org.eclipse.egit.core.op.MergeOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog;
+import org.eclipse.egit.ui.internal.merge.MergeResultDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.lib.Constants;
@@ -98,9 +99,7 @@ public class MergeActionHandler extends RepositoryActionHandler {
public void run() {
Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
- MessageDialog.openInformation(shell,
- UIText.MergeAction_MergeResultTitle, op
- .getResult().toString());
+ new MergeResultDialog(shell, repository, op.getResult()).open();
}
});
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/MergeResultDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/MergeResultDialog.java
new file mode 100644
index 0000000..d46f4d7
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/MergeResultDialog.java
@@ -0,0 +1,206 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Jens Baumgart <jens.baumgart@sap.com>
+ *
+ * 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.ui.internal.merge;
+
+import java.io.IOException;
+
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jgit.api.MergeResult;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectReader;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Dialog for displaying a MergeResult
+ *
+ */
+public class MergeResultDialog extends Dialog {
+
+ private static final String SPACE = " "; //$NON-NLS-1$
+
+ private static final String EMPTY = ""; //$NON-NLS-1$
+
+ private final MergeResult mergeResult;
+
+ private final Repository repository;
+
+ private ObjectReader objectReader;
+
+ /**
+ * @param parentShell
+ * @param repository
+ * @param mergeResult
+ */
+ public MergeResultDialog(Shell parentShell, Repository repository,
+ MergeResult mergeResult) {
+ super(parentShell);
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+ this.repository = repository;
+ this.mergeResult = mergeResult;
+ objectReader = repository.newObjectReader();
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(final Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
+ true);
+ }
+
+ @Override
+ protected Control createDialogArea(final Composite parent) {
+ final Composite composite = (Composite) super.createDialogArea(parent);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ composite.setLayout(gridLayout);
+ // result
+ Label resultLabel = new Label(composite, SWT.NONE);
+ resultLabel.setText(UIText.MergeResultDialog_result);
+ resultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false,
+ false));
+ Text resultText = new Text(composite, SWT.READ_ONLY);
+ resultText.setText(mergeResult.getMergeStatus().toString());
+ resultText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ // new head
+ Label newHeadLabel = new Label(composite, SWT.NONE);
+ newHeadLabel.setText(UIText.MergeResultDialog_newHead);
+ newHeadLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false,
+ false));
+ Text newHeadText = new Text(composite, SWT.READ_ONLY);
+ ObjectId newHead = mergeResult.getNewHead();
+ if (newHead != null)
+ newHeadText.setText(getCommitMessage(newHead) + SPACE
+ + abbreviate(mergeResult.getNewHead(), true));
+ newHeadText
+ .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ // Merge Input
+ Label mergeInputLabel = new Label(composite, SWT.NONE);
+ mergeInputLabel.setText(UIText.MergeResultDialog_mergeInput);
+ GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).span(2, 1)
+ .applyTo(mergeInputLabel);
+ TableViewer viewer = new TableViewer(composite);
+ viewer.setContentProvider(new IStructuredContentProvider() {
+
+ public void dispose() {
+ // empty
+ }
+
+ public void inputChanged(Viewer theViewer, Object oldInput,
+ Object newInput) {
+ // empty
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return mergeResult.getMergedCommits();
+ }
+ });
+ TableViewerColumn idColumn = new TableViewerColumn(viewer, SWT.LEFT);
+ idColumn.getColumn().setText(UIText.MergeResultDialog_id);
+ idColumn.getColumn().setWidth(100);
+ TableViewerColumn textColumn = new TableViewerColumn(viewer, SWT.LEFT);
+ textColumn.getColumn().setText(UIText.MergeResultDialog_description);
+ textColumn.getColumn().setWidth(300);
+ Table table = viewer.getTable();
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ viewer.setLabelProvider(new ITableLabelProvider() {
+
+ public void removeListener(ILabelProviderListener listener) {
+ // empty
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void dispose() {
+ // empty
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ // empty
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ ObjectId commitId = (ObjectId) element;
+ if (columnIndex == 0)
+ return abbreviate(commitId, false);
+ else if (columnIndex == 1)
+ return getCommitMessage(commitId);
+ return EMPTY;
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+ });
+ getShell().setText(UIText.MergeResultDialog_mergeResult);
+ applyDialogFont(composite);
+ getShell().addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ if (objectReader != null)
+ objectReader.release();
+ }
+ });
+ GridDataFactory.fillDefaults().grab(true, true)
+ .align(SWT.FILL, SWT.FILL).span(2, 1)
+ .applyTo(viewer.getControl());
+ viewer.setInput(mergeResult);
+ return composite;
+ }
+
+ private String getCommitMessage(ObjectId id) {
+ RevCommit commit;
+ try {
+ commit = new RevWalk(repository).parseCommit(id);
+ } catch (IOException e) {
+ Activator.logError(UIText.MergeResultDialog_couldNotFindCommit, e);
+ return UIText.MergeResultDialog_couldNotFindCommit;
+ }
+ return commit.getShortMessage();
+ }
+
+ private String abbreviate(ObjectId id, boolean addBrackets) {
+ StringBuilder result = new StringBuilder(EMPTY);
+ if (addBrackets)
+ result.append("["); //$NON-NLS-1$
+ try {
+ result.append(objectReader.abbreviate(id).name());
+ } catch (IOException e) {
+ result.append(id.name());
+ }
+ if (addBrackets)
+ result.append("]"); //$NON-NLS-1$
+ return result.toString();
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/MergeCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/MergeCommand.java
index 0f8705e..7fe7121 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/MergeCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/MergeCommand.java
@@ -26,6 +26,7 @@ import org.eclipse.egit.core.op.MergeOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.dialogs.MergeTargetSelectionDialog;
+import org.eclipse.egit.ui.internal.merge.MergeResultDialog;
import org.eclipse.egit.ui.internal.repository.tree.RefNode;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
import org.eclipse.egit.ui.internal.repository.tree.TagNode;
@@ -123,9 +124,7 @@ public class MergeCommand extends
public void run() {
Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell();
- MessageDialog.openInformation(shell,
- UIText.MergeAction_MergeResultTitle, op
- .getResult().toString());
+ new MergeResultDialog(shell, repository, op.getResult()).open();
}
});
}
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 29ab00e..eabe764 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
@@ -602,6 +602,13 @@ MergeAction_MergeResultTitle=Merge Result
MergeAction_ProblemMerge=Problem during merge
MergeAction_UnableMerge=Unable to merge.
MergeAction_WrongRepositoryState=The Repository State {0} does not allow to merge
+MergeResultDialog_couldNotFindCommit=Could not find commit
+MergeResultDialog_description=Description
+MergeResultDialog_id=Commit Id
+MergeResultDialog_mergeInput=Merge Input
+MergeResultDialog_mergeResult=Merge Result
+MergeResultDialog_newHead=New Head
+MergeResultDialog_result=Result
MergeTargetSelectionDialog_ButtonMerge=&Merge
MergeTargetSelectionDialog_SelectRef=Select a branch or a tag other than the currently checked out branch or tag.
MergeTargetSelectionDialog_TitleMerge=Merge: {0}