Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-10-14 06:56:31 -0400
committerThomas Wolf2019-10-17 05:00:02 -0400
commit7704906cfc0e237ebb4019d3da911486fa0ba9d8 (patch)
tree92edd271400c230adb55a8e8d32a673e0c13350f /org.eclipse.egit.ui.test/src/org/eclipse/egit/ui
parent7110c6405d11cc3409017f881c8431991a28dcaf (diff)
downloadegit-master.tar.gz
egit-master.tar.xz
egit-master.zip
[repo view] Let "link with selection" be always enabledHEADmaster
It's actually a normal state toggling command for which a default handler is fine. It didn't have a default handler because it was badly implemented and assumed that the currently active part was the repositories view. Change the handling of all three toggle commands in the repositories view. Let them only toggle their state, don't make them refresh the view. Make the view listen to state changes and refresh if needed. The content provider doesn't need to listen to changes; it has no way to inform the viewer to refresh. Also remove duplicating the state into local boolean variables; use the state's current value instead. Bug: 537958 Change-Id: I2027a64bd6f4e88439e7975b9d3c3eb3d381efef Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit/ui')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java24
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java21
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java3
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java17
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java19
5 files changed, 61 insertions, 23 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java
index 28e605dd7..83351a919 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/selection/SelectionForViewsTest.java
@@ -20,16 +20,19 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
+import org.eclipse.core.commands.State;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.egit.core.RepositoryUtil;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
+import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.rebase.RebaseInteractiveView;
import org.eclipse.egit.ui.internal.reflog.ReflogView;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
+import org.eclipse.egit.ui.internal.repository.tree.command.ToggleLinkWithSelectionCommand;
import org.eclipse.egit.ui.internal.staging.StagingView;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase;
@@ -49,6 +52,8 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.team.internal.ui.history.GenericHistoryView;
import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.RegistryToggleState;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -78,6 +83,10 @@ public class SelectionForViewsTest extends GitRepositoriesViewTestBase {
private SWTBotView repoView;
+ private State linkWithSelectionState;
+
+ private Boolean initialLinkingWithSelection;
+
@Before
public void before() throws Exception {
localRepositoryDir = createProjectAndCommitToRepository();
@@ -92,14 +101,19 @@ public class SelectionForViewsTest extends GitRepositoriesViewTestBase {
repoUtil.addConfiguredRepository(localRepositoryDir);
repoUtil.addConfiguredRepository(clonedRepositoryDir);
repoUtil.addConfiguredRepository(remoteRepositoryDir); // it's bare
+ ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
+ ICommandService.class);
+ linkWithSelectionState = srv
+ .getCommand(ToggleLinkWithSelectionCommand.ID)
+ .getState(RegistryToggleState.STATE_ID);
+ initialLinkingWithSelection = (Boolean) linkWithSelectionState
+ .getValue();
+ linkWithSelectionState.setValue(Boolean.TRUE);
stagingView = TestUtil.showView(StagingView.VIEW_ID);
reflogView = TestUtil.showView(ReflogView.VIEW_ID);
rebaseInteractiveView = TestUtil
.showView(RebaseInteractiveView.VIEW_ID);
repoView = TestUtil.showView(RepositoriesView.VIEW_ID);
- RepositoriesView repos = (RepositoriesView) repoView.getViewReference()
- .getView(false);
- repos.setReactOnSelection(true);
historyView = TestUtil.showHistoryView();
IHistoryView history = (IHistoryView) historyView.getViewReference()
.getView(false);
@@ -122,9 +136,7 @@ public class SelectionForViewsTest extends GitRepositoriesViewTestBase {
@After
public void after() {
- RepositoriesView repos = (RepositoriesView) repoView.getViewReference()
- .getView(false);
- repos.setReactOnSelection(false);
+ linkWithSelectionState.setValue(initialLinkingWithSelection);
IHistoryView history = (IHistoryView) historyView.getViewReference()
.getView(false);
((GenericHistoryView) history).setLinkingEnabled(false);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
index 14b4c3309..bf7e051cd 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/submodules/SubmoduleFolderTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.Collections;
+import org.eclipse.core.commands.State;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -40,10 +41,12 @@ import org.eclipse.egit.core.project.GitProjectData;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
+import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.clone.ProjectRecord;
import org.eclipse.egit.ui.internal.clone.ProjectUtils;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
+import org.eclipse.egit.ui.internal.repository.tree.command.ToggleLinkWithSelectionCommand;
import org.eclipse.egit.ui.internal.resources.IResourceState;
import org.eclipse.egit.ui.internal.resources.ResourceStateFactory;
import org.eclipse.egit.ui.test.ContextMenuHelper;
@@ -62,6 +65,9 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.RegistryToggleState;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.After;
@@ -78,8 +84,6 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
private static final String CHILDPROJECT = "ChildProject";
- private static final TestUtil UTIL = new TestUtil();
-
private Repository parentRepository;
private Repository childRepository;
@@ -260,11 +264,14 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
@Test
public void testRepoViewFollowSelection() throws Exception {
+ ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
+ ICommandService.class);
+ State commandState = srv.getCommand(ToggleLinkWithSelectionCommand.ID)
+ .getState(RegistryToggleState.STATE_ID);
+ Boolean followsSelection = (Boolean) commandState.getValue();
+ commandState.setValue(Boolean.TRUE);
SWTBotView view = TestUtil.showView(RepositoriesView.VIEW_ID);
TestUtil.joinJobs(REPO_VIEW_REFRESH);
- view.toolbarButton(
- UTIL.getPluginLocalizedValue("LinkWithSelectionCommand"))
- .click();
try {
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
SWTBotTreeItem node = TestUtil.navigateTo(projectExplorerTree,
@@ -299,9 +306,7 @@ public class SubmoduleFolderTest extends LocalRepositoryTestCase {
parentFound[0]);
} finally {
// Reset "follow selection"
- view.toolbarButton(
- UTIL.getPluginLocalizedValue("LinkWithSelectionCommand"))
- .click();
+ commandState.setValue(followsSelection);
}
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
index 7fb833101..27c32d70b 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewBranchHandlingTest.java
@@ -62,6 +62,7 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.RegistryToggleState;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -378,7 +379,7 @@ public class GitRepositoriesViewBranchHandlingTest extends
ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
ICommandService.class);
State commandState = srv.getCommand(ToggleBranchHierarchyCommand.ID)
- .getState(ToggleBranchHierarchyCommand.TOGGLE_STATE);
+ .getState(RegistryToggleState.STATE_ID);
Boolean isHierarchical = (Boolean) commandState.getValue();
commandState.setValue(Boolean.TRUE);
try {
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
index 15dcbe6ca..1a62755ae 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java
@@ -65,6 +65,7 @@ import org.eclipse.ui.internal.dialogs.WorkbenchWizardElement;
import org.eclipse.ui.internal.wizards.AbstractExtensionWizardRegistry;
import org.eclipse.ui.wizards.IWizardCategory;
import org.eclipse.ui.wizards.IWizardDescriptor;
+import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -90,14 +91,22 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
private File repositoryFile;
+ private boolean initialLinkingState;
+
@Before
- public void beforeClass() throws Exception {
+ public void prepare() throws Exception {
setVerboseBranchMode(false);
+ initialLinkingState = setLinkWithSelection(false);
repositoryFile = createProjectAndCommitToRepository();
Activator.getDefault().getRepositoryUtil()
.addConfiguredRepository(repositoryFile);
}
+ @After
+ public void resetLinkingState() {
+ setLinkWithSelection(initialLinkingState);
+ }
+
/**
* First level should have 5 children
*
@@ -527,9 +536,6 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
// the selection should be project
assertTrue(tree.selection().get(0, 0).equals(PROJ1));
-
- // deactivate the link with selection
- toggleLinkWithSelection();
}
/**
@@ -869,7 +875,8 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
private void toggleLinkWithSelection() throws Exception {
getOrOpenView().toolbarButton(
- myUtil.getPluginLocalizedValue("LinkWithSelectionCommand"))
+ myUtil.getPluginLocalizedValue(
+ "RepoViewLinkWithSelection.tooltip"))
.click();
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
index 030550874..4865f8bae 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestBase.java
@@ -35,6 +35,7 @@ import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
import org.eclipse.egit.ui.internal.repository.tree.command.ToggleBranchCommitCommand;
+import org.eclipse.egit.ui.internal.repository.tree.command.ToggleLinkWithSelectionCommand;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@@ -45,6 +46,7 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.RegistryToggleState;
import org.junit.After;
import org.junit.Before;
@@ -106,12 +108,23 @@ public abstract class GitRepositoriesViewTestBase extends
protected static void setVerboseBranchMode(boolean state) {
ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
ICommandService.class);
- State verboseBranchModeState = srv.getCommand(
- ToggleBranchCommitCommand.ID).getState(
- ToggleBranchCommitCommand.TOGGLE_STATE);
+ State verboseBranchModeState = srv
+ .getCommand(ToggleBranchCommitCommand.ID)
+ .getState(RegistryToggleState.STATE_ID);
verboseBranchModeState.setValue(Boolean.valueOf(state));
}
+ protected static boolean setLinkWithSelection(boolean state) {
+ ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(),
+ ICommandService.class);
+ State linkingState = srv.getCommand(ToggleLinkWithSelectionCommand.ID)
+ .getState(RegistryToggleState.STATE_ID);
+ boolean previousState = ((Boolean) linkingState.getValue())
+ .booleanValue();
+ linkingState.setValue(Boolean.valueOf(state));
+ return previousState;
+ }
+
protected SWTBotView getOrOpenView() throws Exception {
SWTBotView view = TestUtil.showView(RepositoriesView.VIEW_ID);
TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH);

Back to the top