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 gnu
.trove
.THashSet
;
26 import org
.jetbrains
.idea
.maven
.project
.MavenProjectsManager
;
28 import java
.util
.ArrayList
;
29 import java
.util
.List
;
32 public class MavenGotoSettingsFileContibutor
implements ChooseByNameContributor
, DumbAware
{
33 public String
[] getNames(Project project
, boolean includeNonProjectItems
) {
34 Set
<String
> result
= new THashSet
<String
>();
35 for (VirtualFile each
: getSettingsFiles(project
)) {
36 result
.add(each
.getName());
38 return result
.toArray(new String
[result
.size()]);
41 public NavigationItem
[] getItemsByName(String name
, String pattern
, Project project
, boolean includeNonProjectItems
) {
42 List
<NavigationItem
> result
= new ArrayList
<NavigationItem
>();
43 for (VirtualFile each
: getSettingsFiles(project
)) {
44 if (each
.getName().equals(name
)) {
45 PsiFile psiFile
= PsiManager
.getInstance(project
).findFile(each
);
46 if (psiFile
!= null) result
.add(psiFile
);
49 return result
.toArray(new NavigationItem
[result
.size()]);
52 private List
<VirtualFile
> getSettingsFiles(Project project
) {
53 return MavenProjectsManager
.getInstance(project
).getGeneralSettings().getEffectiveSettingsFiles();