diff options
author | Thomas Wolf | 2018-07-24 21:19:12 +0000 |
---|---|---|
committer | Thomas Wolf | 2018-08-06 19:53:27 +0000 |
commit | 6ee58057c2dc1ab8498651e1ab91955289f7e981 (patch) | |
tree | a96324ec43af9989bd54840e7ddebe3d63e9f421 /org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java | |
parent | f83e6aeca768531f345f9092afd384bf763ff7ae (diff) | |
download | egit-6ee58057c2dc1ab8498651e1ab91955289f7e981.tar.gz egit-6ee58057c2dc1ab8498651e1ab91955289f7e981.tar.xz egit-6ee58057c2dc1ab8498651e1ab91955289f7e981.zip |
Use an asynchronous lightweight decorator in the repositories view
In the previous implementation, the label provider produced styled
labels that included the decorations. But label providers run
in the UI thread, and expensive decorations like a branch state
(N commits ahead, M behind) could thus lead to UI blocks.
Newly, leverage Eclipse's built-in support. Use a lightweight
decorator for RepositoryTreeNode and register it in plugin.xml.
Separate out getting labels into a WorkbenchAdapter and adapt the
GitAdapterFactory accordingly. (We already created a WorkbenchAdapter
there, but first we always created a new one, and second, it always
created a RepositoriesViewLabelProvider just to get the label text.
That's terribly inefficient and the logic is completely backwards.)
Also use ImageDescriptors instead of Images where possible.
Factor out the handling of LabelProviderChangedEvent from
GitLightweightDecorator into GitDecorator and re-use it in the new
decorator for RepositoryTreeNodes.
Make the RepositoriesViewLabelProvider a decorating label provider
based on a WorkbenchLabelProvider, which uses the singleton
RepositoryTreeNodeWorkbenchAdapter to get labels and images.
Change the other uses of RepositoriesViewLabelProvider in dialogs to
work with the new setup.
Adapt git repositories view tests. These often use the label provider
to determine expected node labels, and then try to find a node with
a matching label. Decorations are now asynchronous, and thus the
label returned from the label provider may or may not contain the
decoration. Even with waiting for decoration jobs we may end up
with the label being determined in the test and the one in the UI
being different. The latter may or may not contain the decoration,
which makes finding expected nodes a bit difficult. For now, use
the TestUtil navigation methods, which just check for containment.
This works well, but because some decorations include the repo
directory path which in turn includes the test method name, some
test methods and even some test repo names had to be changed to
avoid false "duplicate nodes" failures.
User-visible UI changes from all that: next to none. Three differences
I noticed in the default theme on OS X:
1. Decorations all use the default decoration style (light brown),
with the exception of the directory paths shown on repository
nodes and on working tree nodes. Those are handled specially
and use the qualifier style.
2. Decorations in the "File->Import...->Projects from Git->Existing
git repositories" page now actually work.
3. Image decorations briefly flicker on a refresh because of the way
asynchronous lightweight decorators work.
The flickering is due to the repository view being wholly refreshed
frequently. On such a refresh, the viewer tries to get a new decorated
label, but the decoration isn't available yet. Once it is available,
an event is fired, and the viewer updates the label again. For text
labels, the new RepositoriesViewLabelProvider contains a work-around,
but for images, that method won't work. The only image decorations
(so far) are the check markers for the currently checked-out ref.
Otherwise, I notice much faster Eclipse startup with the repositories
view open and containing some repositories.
Bug: 536814
Change-Id: Ifa8279dd6755c57696b8b64e96bc41a1f948aa59
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java')
-rw-r--r-- | org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java index 62a901d94c..fb19b945c6 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTestUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2012 SAP AG and others. + * Copyright (c) 2010, 2018 SAP AG and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -38,7 +38,7 @@ public class GitRepositoriesViewTestUtils { * @return label provider */ public static RepositoriesViewLabelProvider createLabelProvider() { - final AtomicReference<RepositoriesViewLabelProvider> providerRef = new AtomicReference<RepositoriesViewLabelProvider>(); + final AtomicReference<RepositoriesViewLabelProvider> providerRef = new AtomicReference<>(); Display.getDefault().syncExec(new Runnable() { @Override @@ -61,6 +61,10 @@ public class GitRepositoriesViewTestUtils { labelProvider = createLabelProvider(); } + public void dispose() { + Display.getDefault().syncExec(() -> labelProvider.dispose()); + } + public SWTBotTreeItem getLocalBranchesItem(SWTBotTree tree, File repo) throws Exception { Repository repository = lookupRepository(repo); @@ -69,12 +73,11 @@ public class GitRepositoriesViewTestUtils { LocalNode localBranches = new LocalNode(branches, repository); - String rootText = labelProvider.getStyledText(root).getString(); - SWTBotTreeItem rootItem = tree.getTreeItem(rootText); - SWTBotTreeItem branchesItem = TestUtil.expandAndWait(rootItem) - .getNode(labelProvider.getStyledText(branches).getString()); - SWTBotTreeItem localItem = TestUtil.expandAndWait(branchesItem).getNode( - labelProvider.getStyledText(localBranches).getString()); + String rootText = labelProvider.getText(root); + String branchesText = labelProvider.getText(branches); + String localText = labelProvider.getText(localBranches); + SWTBotTreeItem localItem = TestUtil.navigateTo(tree, rootText, + branchesText, localText); return localItem; } @@ -84,10 +87,9 @@ public class GitRepositoriesViewTestUtils { RepositoryNode root = new RepositoryNode(null, repository); TagsNode tags = new TagsNode(root, repository); - String rootText = labelProvider.getStyledText(root).getString(); - SWTBotTreeItem rootItem = tree.getTreeItem(rootText); - SWTBotTreeItem tagsItem = TestUtil.expandAndWait(rootItem) - .getNode(labelProvider.getStyledText(tags).getString()); + String rootText = labelProvider.getText(root); + String tagsText = labelProvider.getText(tags); + SWTBotTreeItem tagsItem = TestUtil.navigateTo(tree, rootText, tagsText); return tagsItem; } @@ -99,13 +101,11 @@ public class GitRepositoriesViewTestUtils { RemoteTrackingNode remoteBranches = new RemoteTrackingNode(branches, repository); - String rootText = labelProvider.getStyledText(root).getString(); - SWTBotTreeItem rootItem = tree.getTreeItem(rootText); - SWTBotTreeItem branchesItem = TestUtil.expandAndWait(rootItem) - .getNode(labelProvider.getStyledText(branches).getString()); - SWTBotTreeItem remoteItem = TestUtil.expandAndWait(branchesItem) - .getNode(labelProvider.getStyledText(remoteBranches) - .getString()); + String rootText = labelProvider.getText(root); + String branchesText = labelProvider.getText(branches); + String remoteText = labelProvider.getText(remoteBranches); + SWTBotTreeItem remoteItem = TestUtil.navigateTo(tree, rootText, + branchesText, remoteText); return remoteItem; } @@ -113,13 +113,12 @@ public class GitRepositoriesViewTestUtils { throws Exception { Repository repository = lookupRepository(repositoryFile); RepositoryNode root = new RepositoryNode(null, repository); - WorkingDirNode workdir = new WorkingDirNode(root, repository); - String rootText = labelProvider.getStyledText(root).getString(); - SWTBotTreeItem rootItem = tree.getTreeItem(rootText); - SWTBotTreeItem workdirItem = TestUtil.expandAndWait(rootItem) - .getNode(labelProvider.getStyledText(workdir).getString()); + String rootText = labelProvider.getText(root); + String workDirText = labelProvider.getText(workdir); + SWTBotTreeItem workdirItem = TestUtil.navigateTo(tree, rootText, + workDirText); return workdirItem; } @@ -127,8 +126,9 @@ public class GitRepositoriesViewTestUtils { throws Exception { Repository repository = lookupRepository(repositoryFile); RepositoryNode root = new RepositoryNode(null, repository); - String rootText = labelProvider.getStyledText(root).getString(); - SWTBotTreeItem rootItem = tree.getTreeItem(rootText); + + String rootText = labelProvider.getText(root); + SWTBotTreeItem rootItem = TestUtil.navigateTo(tree, rootText); return rootItem; } @@ -137,10 +137,11 @@ public class GitRepositoriesViewTestUtils { Repository repository = lookupRepository(repositoryFile); RepositoryNode root = new RepositoryNode(null, repository); AdditionalRefsNode symrefsnode = new AdditionalRefsNode(root, repository); - SWTBotTreeItem rootItem = tree - .getTreeItem(labelProvider.getStyledText(root).getString()); - SWTBotTreeItem symrefsitem = TestUtil.expandAndWait(rootItem) - .getNode(labelProvider.getStyledText(symrefsnode).getString()); + + String rootText = labelProvider.getText(root); + String symrefsText = labelProvider.getText(symrefsnode); + SWTBotTreeItem symrefsitem = TestUtil.navigateTo(tree, rootText, + symrefsText); return symrefsitem; } @@ -150,10 +151,10 @@ public class GitRepositoriesViewTestUtils { RepositoryNode root = new RepositoryNode(null, repository); RemotesNode remotes = new RemotesNode(root, repository); - String rootText = labelProvider.getStyledText(root).getString(); - SWTBotTreeItem rootItem = tree.getTreeItem(rootText); - SWTBotTreeItem remotesItem = TestUtil.expandAndWait(rootItem) - .getNode(labelProvider.getStyledText(remotes).getString()); + String rootText = labelProvider.getText(root); + String remotesText = labelProvider.getText(remotes); + SWTBotTreeItem remotesItem = TestUtil.navigateTo(tree, rootText, + remotesText); return remotesItem; } |