mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
attach files: allow to choose root type if it is not detected
This commit is contained in:
@@ -35,7 +35,7 @@ import java.util.List;
|
||||
* @author Constantine.Plotnikov
|
||||
*/
|
||||
public class PathUIUtils {
|
||||
public static final RootDetector JAVA_SOURCE_ROOT_DETECTOR = new RootDetector(OrderRootType.SOURCES, false) {
|
||||
public static final RootDetector JAVA_SOURCE_ROOT_DETECTOR = new RootDetector(OrderRootType.SOURCES, false, "sources") {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VirtualFile> detectRoots(@NotNull VirtualFile rootCandidate,
|
||||
@@ -57,7 +57,7 @@ public class PathUIUtils {
|
||||
*/
|
||||
public static VirtualFile[] scanAndSelectDetectedJavaSourceRoots(Component parentComponent, final VirtualFile[] rootCandidates) {
|
||||
final List<OrderRoot> orderRoots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, null,
|
||||
Collections.singletonList(JAVA_SOURCE_ROOT_DETECTOR));
|
||||
Collections.singletonList(JAVA_SOURCE_ROOT_DETECTOR), false);
|
||||
final List<VirtualFile> result = new ArrayList<VirtualFile>();
|
||||
for (OrderRoot root : orderRoots) {
|
||||
result.add(root.getFile());
|
||||
|
||||
+6
-5
@@ -49,11 +49,12 @@ public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponen
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends RootDetector> getRootDetectors() {
|
||||
return Arrays.asList(new FileTypeBasedRootFilter(OrderRootType.CLASSES, false, StdFileTypes.CLASS),
|
||||
new FileTypeBasedRootFilter(OrderRootType.CLASSES, true, StdFileTypes.CLASS),
|
||||
return Arrays.asList(new FileTypeBasedRootFilter(OrderRootType.CLASSES, false, StdFileTypes.CLASS, "classes"),
|
||||
new FileTypeBasedRootFilter(OrderRootType.CLASSES, true, StdFileTypes.CLASS, "jar directory"),
|
||||
PathUIUtils.JAVA_SOURCE_ROOT_DETECTOR,
|
||||
new FileTypeBasedRootFilter(OrderRootType.SOURCES, true, StdFileTypes.JAVA),
|
||||
new FileTypeBasedRootFilter(JavadocOrderRootType.getInstance(), false, StdFileTypes.HTML),
|
||||
new FileTypeBasedRootFilter(OrderRootType.SOURCES, true, StdFileTypes.JAVA, "source archive directory"),
|
||||
new FileTypeBasedRootFilter(JavadocOrderRootType.getInstance(), false, StdFileTypes.HTML,
|
||||
"JavaDocs"),
|
||||
new AnnotationsRootFilter());
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ public class DefaultLibraryRootsComponentDescriptor extends LibraryRootsComponen
|
||||
|
||||
private static class AnnotationsRootFilter extends FileTypeBasedRootFilter {
|
||||
private AnnotationsRootFilter() {
|
||||
super(AnnotationOrderRootType.getInstance(), false, StdFileTypes.XML);
|
||||
super(AnnotationOrderRootType.getInstance(), false, StdFileTypes.XML, "external annotations");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -322,7 +322,7 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
|
||||
final VirtualFile[] files = FileChooser.chooseFiles(myPanel, chooserDescriptor, initialSelection);
|
||||
if (files.length == 0) return Collections.emptyList();
|
||||
|
||||
return RootDetectionUtil.detectRoots(Arrays.asList(files), myPanel, myProject, myDetectors);
|
||||
return RootDetectionUtil.detectRoots(Arrays.asList(files), myPanel, myProject, myDetectors, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-2
@@ -20,7 +20,9 @@ import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.libraries.ui.OrderRoot;
|
||||
import com.intellij.openapi.roots.libraries.ui.RootDetector;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,6 +30,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -40,7 +43,8 @@ public class RootDetectionUtil {
|
||||
public static List<OrderRoot> detectRoots(@NotNull final Collection<VirtualFile> rootCandidates,
|
||||
@NotNull Component parentComponent,
|
||||
@Nullable Project project,
|
||||
@NotNull final List<? extends RootDetector> detectors) {
|
||||
@NotNull final List<? extends RootDetector> detectors,
|
||||
boolean allowUserToSelectRootTypeIfNothingIsDetected) {
|
||||
final List<OrderRoot> result = new ArrayList<OrderRoot>();
|
||||
final List<SuggestedChildRootInfo> suggestedRoots = new ArrayList<SuggestedChildRootInfo>();
|
||||
new Task.Modal(project, "Scanning for Roots", true) {
|
||||
@@ -67,13 +71,27 @@ public class RootDetectionUtil {
|
||||
final DetectedSourceRootsDialog dialog = new DetectedSourceRootsDialog(parentComponent, suggestedRoots);
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) {
|
||||
return result;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
for (SuggestedChildRootInfo rootInfo : dialog.getChosenRoots()) {
|
||||
result.add(new OrderRoot(rootInfo.getSuggestedRoot(), rootInfo.getDetector().getRootType(), rootInfo.getDetector().isJarDirectory()));
|
||||
}
|
||||
}
|
||||
|
||||
if (result.isEmpty() && allowUserToSelectRootTypeIfNothingIsDetected) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (RootDetector detector : detectors) {
|
||||
names.add(detector.getPresentableRootTypeName());
|
||||
}
|
||||
final int i = Messages.showChooseDialog("Choose category for selected files:", "Attach Files",
|
||||
ArrayUtil.toStringArray(names), names.get(0), null);
|
||||
if (i != -1) {
|
||||
final RootDetector detector = detectors.get(i);
|
||||
for (VirtualFile candidate : rootCandidates) {
|
||||
result.add(new OrderRoot(candidate, detector.getRootType(), detector.isJarDirectory()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -31,8 +31,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class FileTypeBasedRootFilter extends RootFilter {
|
||||
private final FileType myFileType;
|
||||
|
||||
public FileTypeBasedRootFilter(OrderRootType rootType, boolean jarDirectory, @NotNull FileType fileType) {
|
||||
super(rootType, jarDirectory);
|
||||
public FileTypeBasedRootFilter(OrderRootType rootType, boolean jarDirectory, @NotNull FileType fileType,
|
||||
final String presentableRootTypeName) {
|
||||
super(rootType, jarDirectory, presentableRootTypeName);
|
||||
myFileType = fileType;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,12 @@ import java.util.Collection;
|
||||
public abstract class RootDetector {
|
||||
private OrderRootType myRootType;
|
||||
private boolean myJarDirectory;
|
||||
private String myPresentableRootTypeName;
|
||||
|
||||
protected RootDetector(OrderRootType rootType, boolean jarDirectory) {
|
||||
protected RootDetector(OrderRootType rootType, boolean jarDirectory, String presentableRootTypeName) {
|
||||
myRootType = rootType;
|
||||
myJarDirectory = jarDirectory;
|
||||
myPresentableRootTypeName = presentableRootTypeName;
|
||||
}
|
||||
|
||||
public boolean isJarDirectory() {
|
||||
@@ -42,6 +44,10 @@ public abstract class RootDetector {
|
||||
return myRootType;
|
||||
}
|
||||
|
||||
public String getPresentableRootTypeName() {
|
||||
return myPresentableRootTypeName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract Collection<VirtualFile> detectRoots(@NotNull VirtualFile rootCandidate, @NotNull ProgressIndicator progressIndicator);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ import java.util.Collections;
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class RootFilter extends RootDetector {
|
||||
public RootFilter(OrderRootType rootType, boolean jarDirectory) {
|
||||
super(rootType, jarDirectory);
|
||||
public RootFilter(OrderRootType rootType, boolean jarDirectory, final String presentableRootTypeName) {
|
||||
super(rootType, jarDirectory, presentableRootTypeName);
|
||||
}
|
||||
|
||||
public abstract boolean isAccepted(@NotNull VirtualFile rootCandidate, @NotNull ProgressIndicator progressIndicator);
|
||||
|
||||
@@ -614,7 +614,7 @@ public class Messages {
|
||||
@Nullable
|
||||
public static String showEditableChooseDialog(String message,
|
||||
String title,
|
||||
Icon icon,
|
||||
@Nullable Icon icon,
|
||||
String[] values,
|
||||
String initialValue,
|
||||
InputValidator validator) {
|
||||
@@ -632,7 +632,7 @@ public class Messages {
|
||||
}
|
||||
}
|
||||
|
||||
public static int showChooseDialog(String message, String title, String[] values, String initialValue, Icon icon) {
|
||||
public static int showChooseDialog(String message, String title, String[] values, String initialValue, @Nullable Icon icon) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
@@ -1197,7 +1197,7 @@ public class Messages {
|
||||
public ChooseDialog(Project project,
|
||||
String message,
|
||||
String title,
|
||||
Icon icon,
|
||||
@Nullable Icon icon,
|
||||
String[] values,
|
||||
String initialValue,
|
||||
String[] options,
|
||||
@@ -1207,17 +1207,17 @@ public class Messages {
|
||||
myComboBox.setSelectedItem(initialValue);
|
||||
}
|
||||
|
||||
public ChooseDialog(Project project, String message, String title, Icon icon, String[] values, String initialValue) {
|
||||
public ChooseDialog(Project project, String message, String title, @Nullable Icon icon, String[] values, String initialValue) {
|
||||
this(project, message, title, icon, values, initialValue, new String[]{OK_BUTTON, CANCEL_BUTTON}, 0);
|
||||
}
|
||||
|
||||
public ChooseDialog(Component parent, String message, String title, Icon icon, String[] values, String initialValue) {
|
||||
public ChooseDialog(Component parent, String message, String title, @Nullable Icon icon, String[] values, String initialValue) {
|
||||
super(parent, message, title, new String[]{OK_BUTTON, CANCEL_BUTTON}, 0, icon);
|
||||
myComboBox.setModel(new DefaultComboBoxModel(values));
|
||||
myComboBox.setSelectedItem(initialValue);
|
||||
}
|
||||
|
||||
public ChooseDialog(String message, String title, Icon icon, String[] values, String initialValue) {
|
||||
public ChooseDialog(String message, String title, @Nullable Icon icon, String[] values, String initialValue) {
|
||||
super(message, title, new String[]{OK_BUTTON, CANCEL_BUTTON}, 0, icon);
|
||||
myComboBox.setModel(new DefaultComboBoxModel(values));
|
||||
myComboBox.setSelectedItem(initialValue);
|
||||
|
||||
Reference in New Issue
Block a user