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 com
.intellij
.openapi
.roots
.ui
.configuration
;
18 import com
.intellij
.ide
.util
.JavaUtilForVfs
;
19 import com
.intellij
.openapi
.progress
.ProgressManager
;
20 import com
.intellij
.openapi
.roots
.ui
.configuration
.libraryEditor
.DetectedSourceRootsDialog
;
21 import com
.intellij
.openapi
.vfs
.VirtualFile
;
25 import java
.util
.List
;
28 * This utility class contains utility methods for selecting paths.
30 * @author Constantine.Plotnikov
32 public class PathUIUtils
{
33 /** a private constructor */
34 private PathUIUtils() {}
37 * This method takes a candidates for the project root, then scans the candidates and
38 * if multiple candidates or non root source directories are found whithin some
39 * directories, it shows a dialog that allows selecting or deselecting them.
40 * @param component a parent component
41 * @param rootCandidates a candidates for roots
42 * @return a array of source folders or empty array if non was selected or dialog was canceled.
44 public static VirtualFile
[] scandAndSelectDetectedJavaSourceRoots(Component component
, final VirtualFile
[] rootCandidates
) {
45 final Set
<VirtualFile
> result
= new HashSet
<VirtualFile
>();
46 final Map
<VirtualFile
, List
<VirtualFile
>> detectedRootsMap
= new LinkedHashMap
<VirtualFile
, List
<VirtualFile
>>();
48 ProgressManager
.getInstance().runProcessWithProgressSynchronously(new Runnable() {
50 for (final VirtualFile candidate
: rootCandidates
) {
51 List
<VirtualFile
> detectedRoots
= JavaUtilForVfs
.suggestRoots(candidate
);
52 if (!detectedRoots
.isEmpty() && (detectedRoots
.size() > 1 || detectedRoots
.get(0) != candidate
)) {
53 detectedRootsMap
.put(candidate
, detectedRoots
);
55 result
.add(candidate
);
59 }, "Scanning for source roots", true, null);
60 if(!detectedRootsMap
.isEmpty()) {
61 DetectedSourceRootsDialog dlg
= new DetectedSourceRootsDialog(component
, detectedRootsMap
);
64 result
.addAll(dlg
.getChosenRoots());
67 // the empty result means that the entire root adding process will be cancelled.
71 return result
.toArray(new VirtualFile
[result
.size()]);