2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.jetbrains
.idea
.maven
.utils
;
18 import com
.intellij
.navigation
.ChooseByNameContributor
;
19 import com
.intellij
.navigation
.NavigationItem
;
20 import com
.intellij
.openapi
.project
.DumbAware
;
21 import com
.intellij
.openapi
.project
.Project
;
22 import com
.intellij
.openapi
.vfs
.VirtualFile
;
23 import com
.intellij
.psi
.PsiFile
;
24 import com
.intellij
.psi
.PsiManager
;
25 import com
.intellij
.util
.ArrayUtil
;
26 import gnu
.trove
.THashSet
;
27 import org
.jetbrains
.idea
.maven
.project
.MavenProjectsManager
;
29 import java
.util
.ArrayList
;
30 import java
.util
.List
;
33 public class MavenGotoSettingsFileContibutor
implements ChooseByNameContributor
, DumbAware
{
34 public String
[] getNames(Project project
, boolean includeNonProjectItems
) {
35 Set
<String
> result
= new THashSet
<String
>();
36 for (VirtualFile each
: getSettingsFiles(project
)) {
37 result
.add(each
.getName());
39 return ArrayUtil
.toStringArray(result
);
42 public NavigationItem
[] getItemsByName(String name
, String pattern
, Project project
, boolean includeNonProjectItems
) {
43 List
<NavigationItem
> result
= new ArrayList
<NavigationItem
>();
44 for (VirtualFile each
: getSettingsFiles(project
)) {
45 if (each
.getName().equals(name
)) {
46 PsiFile psiFile
= PsiManager
.getInstance(project
).findFile(each
);
47 if (psiFile
!= null) result
.add(psiFile
);
50 return result
.toArray(new NavigationItem
[result
.size()]);
53 private List
<VirtualFile
> getSettingsFiles(Project project
) {
54 return MavenProjectsManager
.getInstance(project
).getGeneralSettings().getEffectiveSettingsFiles();