diff options
author | Dariusz Luksza | 2011-02-20 23:09:59 +0000 |
---|---|---|
committer | Matthias Sohn | 2011-02-20 23:09:59 +0000 |
commit | 6083e08ebbb979dadc85db1fe82596660ff995d0 (patch) | |
tree | 0c9dab42063c3919307653aa80fbca4a2fd5845e | |
parent | ed0ef5fff4b076b9d148b7ea2c2511e7658a5487 (diff) | |
download | egit-6083e08ebbb979dadc85db1fe82596660ff995d0.tar.gz egit-6083e08ebbb979dadc85db1fe82596660ff995d0.tar.xz egit-6083e08ebbb979dadc85db1fe82596660ff995d0.zip |
[sync] Fix showing compare editor in workspace model
This change also adds tests for launching compare editors from Git
Change Set and Workspace models.
Bug: 337198
Change-Id: I396155fe48faffbab60c430b5300e614bdffdbcd
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2 files changed, 76 insertions, 1 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java index 8da3a4367b..a83d74c652 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewTest.java @@ -12,6 +12,7 @@ import static org.eclipse.egit.ui.test.ContextMenuHelper.clickContextMenu; import static org.eclipse.jgit.lib.Constants.HEAD; import static org.eclipse.jgit.lib.Constants.MASTER; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.File; @@ -25,6 +26,7 @@ import org.eclipse.egit.ui.test.Eclipse; import org.eclipse.egit.ui.test.TestUtil; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.SWTBot; import org.eclipse.swtbot.swt.finder.waits.ICondition; import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; @@ -178,6 +180,67 @@ public class SynchronizeViewTest extends LocalRepositoryTestCase { assertEquals(1, syncViewTree.getAllItems().length); } + @Test public void shouldOpenCompareEditorInGitChangeSet() throws Exception { + // given + resetRepository(PROJ1); + createTag(PROJ1, "compare1"); + changeFilesInProject(); + showDialog(PROJ1, "Team", "Synchronize..."); + + // when + bot.shell("Synchronize repository: " + REPO1 + File.separator + ".git") + .activate(); + + bot.comboBox(2) + .setSelection(UIText.SynchronizeWithAction_tagsName); + bot.comboBox(3).setSelection("compare1"); + + // fire action + bot.button(IDialogConstants.OK_LABEL).click(); + + SWTBotTree syncViewTree = bot.viewByTitle("Synchronize").bot().tree(); + // expand all nodes + syncViewTree.getAllItems()[0].collapse().doubleClick(); + // try to open compare editor for FILE1 + syncViewTree.getAllItems()[0].getItems()[0].getNode(FOLDER) + .getNode(FILE1).doubleClick(); + + // then + SWTBot compare = bot.editorByTitle(FILE1).bot(); + assertNotNull(compare); + } + + @Test public void shouldOpenCompareEditorInWorkspaceModel() throws Exception { + // given + resetRepository(PROJ1); + createTag(PROJ1, "compare2"); + changeFilesInProject(); + showDialog(PROJ1, "Team", "Synchronize..."); + + // when + bot.shell("Synchronize repository: " + REPO1 + File.separator + ".git") + .activate(); + + bot.comboBox(2) + .setSelection(UIText.SynchronizeWithAction_tagsName); + bot.comboBox(3).setSelection("compare2"); + + // fire action + bot.button(IDialogConstants.OK_LABEL).click(); + + SWTBotView syncView = bot.viewByTitle("Synchronize"); + syncView.toolbarDropDownButton("Show File System Resources").click() + .menuItem("Workspace").click(); + SWTBotTree syncViewTree = syncView.bot().tree(); + // try to open compare editor for FILE1 + syncViewTree.getAllItems()[0].expand().getItems()[0].expand() + .getItems()[0].doubleClick(); + + // then + SWTBot compare = bot.editorByTitle(FILE1).bot(); + assertNotNull(compare); + } + @Test public void shouldListFileDeletedChange() throws Exception { // given diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java index 6a17023590..d221223699 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronizeParticipant.java @@ -15,8 +15,10 @@ import java.util.List; import org.eclipse.compare.structuremergeviewer.ICompareInput; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.mapping.ModelProvider; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.egit.core.synchronize.GitSubscriberMergeContext; import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData; @@ -114,7 +116,17 @@ public class GitModelSynchronizeParticipant extends ModelSynchronizeParticipant @Override public boolean hasCompareInputFor(Object object) { - return object instanceof GitModelBlob; + if (object instanceof GitModelBlob || object instanceof IFile) + return true; + // in Java Workspace model Java source files are passed as type + // CompilationUnit which can be adapted to IResource + if (object instanceof IAdaptable) { + IResource res = (IResource) ((IAdaptable) object) + .getAdapter(IResource.class); + if (res != null && res.getType() == IResource.FILE) + return true; + } + return false; } @Override |