blob: 7fdb6539b2068ed530019be5c24939324d6362ca (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*******************************************************************************
* Copyright (c) 2012 SAP AG.
* 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
*
* Contributors:
* Stefan Lay (SAP AG) - initial implementation
*******************************************************************************/
package org.eclipse.egit.ui.internal.clone;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.clone.GitCloneSourceProviderExtension.CloneSourceProvider;
import org.eclipse.egit.ui.internal.provisional.wizards.IRepositoryServerProvider;
import org.eclipse.egit.ui.internal.provisional.wizards.RepositoryServerInfo;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
class RepositoryLocationContentProvider implements ITreeContentProvider {
private Map<RepositoryServerInfo, CloneSourceProvider> parents = new HashMap<>();
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// nothing to do
}
@Override
public void dispose() {
// nothing to do
}
@Override
public boolean hasChildren(Object element) {
Object[] children = calculateChildren(element);
return children != null && children.length > 0;
}
@Override
public Object getParent(Object element) {
if (element instanceof RepositoryServerInfo)
return parents.get(element);
return null;
}
@Override
@SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
List<CloneSourceProvider> repositoryImports = (List<CloneSourceProvider>) inputElement;
return repositoryImports.toArray(new CloneSourceProvider[repositoryImports
.size()]);
}
@Override
public Object[] getChildren(Object parentElement) {
return calculateChildren(parentElement);
}
private Object[] calculateChildren(Object parentElement) {
if (parentElement instanceof CloneSourceProvider) {
CloneSourceProvider repositoryImport = (CloneSourceProvider) parentElement;
if (repositoryImport.hasFixLocation())
return null;
Collection<RepositoryServerInfo> repositoryServerInfos = getRepositoryServerInfos(repositoryImport);
if (repositoryServerInfos == null)
return null;
cacheParents(repositoryImport, repositoryServerInfos);
return repositoryServerInfos
.toArray(new RepositoryServerInfo[repositoryServerInfos
.size()]);
}
return null;
}
private Collection<RepositoryServerInfo> getRepositoryServerInfos(
CloneSourceProvider repositoryImport) {
Collection<RepositoryServerInfo> repositoryServerInfos = null;
IRepositoryServerProvider repositoryServerProvider;
try {
repositoryServerProvider = repositoryImport
.getRepositoryServerProvider();
} catch (CoreException e) {
Activator.error(e.getLocalizedMessage(), e);
return null;
}
if (repositoryServerProvider == null)
return null;
try {
repositoryServerInfos = repositoryServerProvider
.getRepositoryServerInfos();
} catch (Exception e) {
Activator.error(UIText.RepositoryLocationContentProvider_errorProvidingRepoServer, e);
}
return repositoryServerInfos;
}
private void cacheParents(CloneSourceProvider repositoryImport,
Collection<RepositoryServerInfo> repositoryServerInfos) {
for (RepositoryServerInfo info : repositoryServerInfos)
parents.put(info, repositoryImport);
}
}
|