Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-10-18 10:51:07 +0000
committerThomas Wolf2019-10-26 09:29:04 +0000
commit67a046c5e80a572f663a79fcb8c33098e75eb8d9 (patch)
treefb6ebd9763eb143f597bad62da074fb7ce39f1a3
parent236c33d2dabc3ff1314ec66f22a6755000de2842 (diff)
downloadegit-67a046c5e80a572f663a79fcb8c33098e75eb8d9.tar.gz
egit-67a046c5e80a572f663a79fcb8c33098e75eb8d9.tar.xz
egit-67a046c5e80a572f663a79fcb8c33098e75eb8d9.zip
[repo view] Link with selection: immediate reaction, show open editors
React immediately when linking with selection is enabled. Track workbench parts even when linking is disabled. When linking is enabled, immediately react on the last selection before the repositories view became active. When the selection inside the view changes react to a FileNode being selected by bringing an already open editor of that file to the front. Activate and correct the already existing test for this. Remove the old LinkHelper. It wasn't used anymore since commit d6cf5241 in 2013. Bug: 409722 Change-Id: I49ebc0b361469f3058348199ff8bd3557d949634 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/repositories/GitRepositoriesViewTest.java9
-rw-r--r--org.eclipse.egit.ui/plugin.properties8
-rw-r--r--org.eclipse.egit.ui/plugin.xml22
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/EgitUiEditorUtils.java23
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java160
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/LinkHelper.java145
6 files changed, 153 insertions, 214 deletions
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 1a62755aed..c593fafe51 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
@@ -67,7 +67,6 @@ 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;
import org.junit.runner.RunWith;
@@ -527,13 +526,6 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
// activate the link with selection
toggleLinkWithSelection();
- // the selection should be still be root
- assertTrue(tree.selection().get(0, 0).contains(REPO1));
-
- // select again the project
- projectExplorerTree = TestUtil.getExplorerTree();
- getProjectItem(projectExplorerTree, PROJ1).select();
-
// the selection should be project
assertTrue(tree.selection().get(0, 0).equals(PROJ1));
}
@@ -544,7 +536,6 @@ public class GitRepositoriesViewTest extends GitRepositoriesViewTestBase {
* @throws Exception
*/
@Test
- @Ignore("'Link with Selection' does not activate editor on selection change (bug 409722).")
public void testLinkWithSelectionEditor() throws Exception {
deleteAllProjects();
shareProjects(repositoryFile);
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index a745aff336..876eb3c336 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -153,7 +153,7 @@ Synchronize_ChangeSet=Git Commits
GitRepositoriesContentName = Git Repositories
AddRepositoryCommand = Add a Git Repository...
-AddRepositoryCommand.description = Adds a existing Git repository to the Git Repositories view
+AddRepositoryCommand.description = Adds an existing Git repository to the Git Repositories view
CloneRepositoryCommand = Clone a Git Repository...
CloneRepositoryCommand.description = Clones a Git repository and adds the clone to the Git Repositories view
CreateRepositoryCommand = Create a Git Repository...
@@ -185,7 +185,7 @@ RemoveFetchCommand = Delete Fetch
OpenInEditorCommand = Open in Editor
DeleteFileCommand = Delete
OpenCommand = Open
-LinkWithSelectionCommand = Toggle "Link with Selection" (Git Repositories View)
+LinkWithSelectionCommand = Toggle "Link with Editor and Selection" (Git Repositories View)
SynchronizeCommand = Synchronize...
UntrackCommand.name = Untrack
@@ -297,8 +297,8 @@ RepoViewCreateRepository.tooltip = Create a new Git Repository and add it to thi
RepoViewAddRepository.label = &Add a Repository...
RepoViewCloneRepository.label = &Clone a Repository...
RepoViewCreateRepository.label = Create a &Repository...
-RepoViewLinkWithSelectionMenu.label = Link with &Selection
-RepoViewLinkWithSelection.tooltip = Link with Selection
+RepoViewLinkWithSelectionMenu.label = Link with Editor and &Selection
+RepoViewLinkWithSelection.tooltip = Link with Editor and Selection
RepoViewCreateRepositoryCommand.name = Create a Repository
CreateRepositoryWizard.name = Git Repository
CreateRepositoryWizard.description = Create a Git repository
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index e7444bad2a..84f60aee02 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -3230,6 +3230,9 @@
name="org.eclipse.ui.navigator.hideAvailableExtensionsTab"
value="true"/>
<!-- Hide the "Link with Editor" action from the toolbar of the viewer -->
+ <!-- We implement our own "Link with Editor and Selection"; the built-in -->
+ <!-- ILinkHelper works only for linking with an active editor, but not -->
+ <!-- for synchronizing the selection with that in other views. -->
<property
name="org.eclipse.ui.navigator.hideLinkWithEditorAction"
value="true"/>
@@ -3304,9 +3307,6 @@
pattern="org.eclipse.egit.ui.RepositoriesViewContent">
</contentExtension>
<contentExtension
- pattern="org.eclipse.egit.ui.RepositoriesViewLinkHelper">
- </contentExtension>
- <contentExtension
pattern="org.eclipse.egit.ui.repositoriesView.filters.remoteBranches">
</contentExtension>
<contentExtension
@@ -6407,22 +6407,6 @@
</propertyTester>
</extension>
<extension
- point="org.eclipse.ui.navigator.linkHelper">
- <linkHelper
- class="org.eclipse.egit.ui.internal.repository.tree.LinkHelper"
- id="org.eclipse.egit.ui.RepositoriesViewLinkHelper">
- <editorInputEnablement>
- <instanceof
- value="org.eclipse.ui.IURIEditorInput">
- </instanceof></editorInputEnablement>
- <selectionEnablement>
- <instanceof
- value="org.eclipse.egit.ui.internal.repository.tree.FileNode">
- </instanceof>
- </selectionEnablement>
- </linkHelper>
- </extension>
- <extension
id="changeSetModel"
name="%ChangeSetModel.name"
point="org.eclipse.core.resources.modelProviders">
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/EgitUiEditorUtils.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/EgitUiEditorUtils.java
index 4fe6911125..aa5cd3e645 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/EgitUiEditorUtils.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/EgitUiEditorUtils.java
@@ -43,7 +43,9 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
@@ -176,6 +178,27 @@ public class EgitUiEditorUtils {
return null;
}
+ /**
+ * Looks for and returns an open editor on the given page that has the given file as input.
+ *
+ * @param file to find an editor for
+ * @param page on which to look for open editors
+ * @return the open editor, or {@code null} if none could be found
+ */
+ public static IEditorPart findEditor(File file, IWorkbenchPage page) {
+ if (!file.exists() || page == null) {
+ return null;
+ }
+ IPath path = new Path(file.getAbsolutePath());
+ IFile iFile = ResourceUtil.getFileForLocation(path, true);
+ if (iFile != null) {
+ return page.findEditor(new FileEditorInput(iFile));
+ } else {
+ IFileStore store = EFS.getLocalFileSystem().getStore(path);
+ return page.findEditor(new FileStoreEditorInput(store));
+ }
+ }
+
private static IEditorDescriptor getEditor(
FileRevisionEditorInput editorInput) {
IEditorRegistry registry = PlatformUI.getWorkbench()
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
index d4619b4f57..f0d0fd8ff1 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
@@ -52,6 +52,7 @@ import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.UIUtils;
import org.eclipse.egit.ui.internal.CommonUtils;
+import org.eclipse.egit.ui.internal.EgitUiEditorUtils;
import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.actions.ActionCommands;
@@ -91,6 +92,7 @@ import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.OpenEvent;
@@ -124,7 +126,9 @@ import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IURIEditorInput;
import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
@@ -140,6 +144,7 @@ import org.eclipse.ui.navigator.CommonViewer;
import org.eclipse.ui.part.IPage;
import org.eclipse.ui.part.IShowInSource;
import org.eclipse.ui.part.IShowInTargetList;
+import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import org.eclipse.ui.progress.WorkbenchJob;
@@ -200,51 +205,52 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
private State reactOnSelection;
+ private IWorkbenchPart lastSelectionPart;
+
+ private File lastSelectedRepository;
+
private final ISelectionListener selectionChangedListener = (part,
selection) -> {
- if (!((Boolean) reactOnSelection.getValue()).booleanValue()
- || part == RepositoriesView.this) {
+ if (part == RepositoriesView.this) {
+ if (!selection.isEmpty()
+ && selection instanceof IStructuredSelection) {
+ Repository repo = SelectionUtils
+ .getRepository((IStructuredSelection) selection);
+ if (repo != null) {
+ lastSelectedRepository = repo.getDirectory();
+ } else {
+ lastSelectedRepository = null;
+ }
+ }
return;
}
-
- // this may happen if we switch between editors
- if (part instanceof IEditorPart) {
- IEditorInput input = ((IEditorPart) part).getEditorInput();
- if (input instanceof IFileEditorInput) {
- reactOnSelection(new StructuredSelection(
- ((IFileEditorInput) input).getFile()));
- } else if (input instanceof IURIEditorInput) {
- reactOnSelection(new StructuredSelection(input));
- }
-
+ IWorkbenchPart currentPart = determinePart(part);
+ if (!((Boolean) reactOnSelection.getValue()).booleanValue()) {
+ lastSelectionPart = currentPart;
} else {
- reactOnSelection(selection);
+ lastSelectionPart = null;
+ reactOnSelection(convertSelection(currentPart, selection));
}
};
private final IStateListener reactOnSelectionListener = (state,
oldValue) -> {
- if (((Boolean) state.getValue()).booleanValue()) {
+ if (((Boolean) state.getValue()).booleanValue()
+ && lastSelectionPart != null) {
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
- ISelectionService service = CommonUtils
- .getService(getViewSite(), ISelectionService.class);
- if (service == null) {
+ if (lastSelectionPart == null) {
return;
}
- ISelection currentSelection = service.getSelection();
- if (currentSelection == null || currentSelection.isEmpty()) {
+ IWorkbenchPartSite site = lastSelectionPart.getSite();
+ if (site == null) {
return;
}
- IWorkbenchWindow window = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- if (window == null) {
+ ISelectionProvider provider = site.getSelectionProvider();
+ if (provider == null) {
return;
}
- IWorkbenchPart part = window.getPartService().getActivePart();
- if (part != null) {
- selectionChangedListener.selectionChanged(part,
- currentSelection);
- }
+ reactOnSelection(convertSelection(lastSelectionPart,
+ provider.getSelection()));
});
}
};
@@ -493,7 +499,25 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
configurationListener);
initRepositoriesAndListeners();
activateContextService();
-
+ // link with editor
+ viewer.addPostSelectionChangedListener(event -> {
+ if (!((Boolean) reactOnSelection.getValue()).booleanValue()) {
+ return;
+ }
+ ISelection selection = event.getSelection();
+ if (selection.isEmpty()
+ || !(selection instanceof IStructuredSelection)) {
+ return;
+ }
+ IStructuredSelection sel = (IStructuredSelection) selection;
+ if (sel.size() > 1) {
+ return;
+ }
+ Object selected = sel.getFirstElement();
+ if (selected instanceof FileNode) {
+ showEditor((FileNode) selected);
+ }
+ });
emptyArea.setBackground(viewer.getControl().getBackground());
if (!repositories.isEmpty())
layout.topControl = viewer.getControl();
@@ -682,9 +706,10 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
private void selectAndReveal(
Map<Repository, Collection<String>> pathsByRepo) {
final List<RepositoryTreeNode> nodesToShow = new ArrayList<>();
+ Repository repository = null;
for (Map.Entry<Repository, Collection<String>> entry : pathsByRepo
.entrySet()) {
- Repository repository = entry.getKey();
+ repository = entry.getKey();
for (String repoPath : entry.getValue()) {
final RepositoryTreeNode node = getNodeForPath(repository,
repoPath);
@@ -693,7 +718,20 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
}
}
}
- selectReveal(new StructuredSelection(nodesToShow));
+
+ if (repository != null && !nodesToShow.isEmpty()
+ && pathsByRepo.size() == 1) {
+ lastSelectedRepository = repository.getDirectory();
+ } else {
+ lastSelectedRepository = null;
+ }
+ List<?> current = getCommonViewer().getStructuredSelection().toList();
+ Set<?> currentlySelected = new HashSet<>(current);
+ if (currentlySelected.containsAll(nodesToShow)) {
+ getCommonViewer().getTree().showSelection();
+ } else {
+ selectReveal(new StructuredSelection(nodesToShow));
+ }
}
/**
@@ -704,12 +742,14 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
public void showRepository(Repository repositoryToShow) {
ITreeContentProvider cp = (ITreeContentProvider) getCommonViewer()
.getContentProvider();
- for (Object repo : cp.getElements(getCommonViewer().getInput())) {
- RepositoryTreeNode node = (RepositoryTreeNode) repo;
- if (repositoryToShow.getDirectory().equals(node.getRepository().getDirectory()))
- selectReveal(new StructuredSelection(node));
+ RepositoryTreeNode node = findRepositoryNode(cp,
+ cp.getElements(getCommonViewer().getInput()), repositoryToShow);
+ if (node != null) {
+ lastSelectedRepository = repositoryToShow.getDirectory();
+ selectReveal(new StructuredSelection(node));
}
}
+
/**
* Refresh Repositories View
*/
@@ -1006,8 +1046,38 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
return null;
}
+ private IWorkbenchPart determinePart(IWorkbenchPart part) {
+ IWorkbenchPart currentPart = part;
+ // this may happen if we switch between editors
+ if (currentPart instanceof IEditorPart) {
+ if (currentPart instanceof MultiPageEditorPart) {
+ Object nestedEditor = ((MultiPageEditorPart) part)
+ .getSelectedPage();
+ if (nestedEditor instanceof IEditorPart) {
+ currentPart = ((IEditorPart) nestedEditor);
+ }
+ }
+ }
+ return currentPart;
+ }
+
+ private ISelection convertSelection(IWorkbenchPart part,
+ ISelection selection) {
+ if (part instanceof IEditorPart) {
+ IEditorInput input = ((IEditorPart) part).getEditorInput();
+ if (input instanceof IFileEditorInput) {
+ return new StructuredSelection(
+ ((IFileEditorInput) input).getFile());
+ } else if (input instanceof IURIEditorInput) {
+ return new StructuredSelection(input);
+ }
+ }
+ return selection;
+ }
+
private void reactOnSelection(ISelection selection) {
- if (selection instanceof StructuredSelection) {
+ if (layout.topControl != emptyArea
+ && selection instanceof StructuredSelection) {
StructuredSelection ssel = (StructuredSelection) selection;
if (ssel.size() != 1) {
return;
@@ -1026,13 +1096,29 @@ public class RepositoriesView extends CommonNavigator implements IShowInSource,
}
Repository repository = Adapters.adapt(ssel.getFirstElement(),
Repository.class);
- if (repository != null) {
+ if (repository != null && !repository.getDirectory()
+ .equals(lastSelectedRepository)) {
showRepository(repository);
return;
}
}
}
+ private void showEditor(FileNode node) {
+ File file = node.getObject();
+ IWorkbenchWindow window = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ if (window != null) {
+ IWorkbenchPage page = window.getActivePage();
+ IEditorPart editor = EgitUiEditorUtils.findEditor(file, page);
+ IEditorPart active = page.getActiveEditor();
+ if (editor != null && editor != active) {
+ window.getWorkbench().getDisplay()
+ .asyncExec(() -> page.bringToTop(editor));
+ }
+ }
+ }
+
private RepositoryTreeNode getRepositoryChildNode(Repository repository,
RepositoryTreeNodeType type) {
ITreeContentProvider cp = (ITreeContentProvider) getCommonViewer()
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/LinkHelper.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/LinkHelper.java
deleted file mode 100644
index 51f8f71101..0000000000
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/LinkHelper.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 SAP AG.
- * 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
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * Mathias Kinzler (SAP AG) - initial implementation
- *******************************************************************************/
-package org.eclipse.egit.ui.internal.repository.tree;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.egit.core.RepositoryCache;
-import org.eclipse.egit.core.RepositoryUtil;
-import org.eclipse.egit.ui.Activator;
-import org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorReference;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.IURIEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.navigator.ILinkHelper;
-
-/**
- * Link Helper for Git Repositories View
- */
-public class LinkHelper implements ILinkHelper {
- @Override
- public void activateEditor(IWorkbenchPage aPage,
- IStructuredSelection aSelection) {
-
- try {
- FileNode node = (FileNode) aSelection.getFirstElement();
-
- File file = node.getObject();
-
- for (IEditorReference ref : aPage.getEditorReferences()) {
- IEditorPart part = ref.getEditor(false);
- if (part != null) {
- IEditorInput input = part.getEditorInput();
- if (input instanceof IFileEditorInput) {
- IFile r = ((IFileEditorInput) input).getFile();
- if (r.getLocation().toFile().equals(file)) {
- aPage.activate(part);
- return;
- }
- }
- if (input instanceof IURIEditorInput) {
- if (((IURIEditorInput) input).getURI().equals(
- file.toURI())) {
- aPage.activate(part);
- return;
- }
- }
- }
- }
- } catch (Exception e) {
- // simply ignore here
- }
- }
-
- /**
- * TODO javadoc missing
- */
- @Override
- @SuppressWarnings("unchecked")
- public IStructuredSelection findSelection(IEditorInput anInput) {
- if (!(anInput instanceof IURIEditorInput)) {
- return null;
- }
-
- URI uri = ((IURIEditorInput) anInput).getURI();
-
- if (!uri.getScheme().equals("file")) //$NON-NLS-1$
- return null;
-
- File file = new File(uri.getPath());
-
- if (!file.exists())
- return null;
-
- RepositoryUtil config = Activator.getDefault().getRepositoryUtil();
- RepositoryCache cache = org.eclipse.egit.core.Activator.getDefault()
- .getRepositoryCache();
- for (String repo : config.getConfiguredRepositories()) {
- Repository repository;
- try {
- repository = cache.lookupRepository(new File(repo));
- } catch (IOException e) {
- continue;
- }
- if (repository.isBare())
- continue;
- if (file.getPath().startsWith(repository.getWorkTree().getPath())) {
- RepositoriesViewContentProvider cp = new RepositoriesViewContentProvider();
-
- RepositoryNode repoNode = new RepositoryNode(null, repository);
- RepositoryTreeNode result = null;
-
- for (Object child : cp.getChildren(repoNode)) {
- if (child instanceof WorkingDirNode) {
- result = (WorkingDirNode) child;
- break;
- }
- }
-
- if (result == null)
- return null;
-
- IPath remainingPath = new Path(file.getPath().substring(
- repository.getWorkTree().getPath().length()));
- for (String segment : remainingPath.segments()) {
- for (Object child : cp.getChildren(result)) {
- RepositoryTreeNode<File> fileNode;
- try {
- fileNode = (RepositoryTreeNode<File>) child;
- } catch (ClassCastException e) {
- return null;
- }
- if (fileNode.getObject().getName().equals(segment)) {
- result = fileNode;
- break;
- }
- }
- }
-
- return new StructuredSelection(result);
- }
- }
- return null;
- }
-}

Back to the top