use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class ViewOfflineResultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final Project project = event.getData(CommonDataKeys.PROJECT);
LOG.assertTrue(project != null);
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
@Override
public Icon getIcon(VirtualFile file) {
if (file.isDirectory()) {
if (file.findChild(InspectionApplication.DESCRIPTIONS + "." + StdFileTypes.XML.getDefaultExtension()) != null) {
return AllIcons.Nodes.InspectionResults;
}
}
return super.getIcon(file);
}
};
descriptor.setTitle("Select Path");
descriptor.setDescription("Select directory which contains exported inspections results");
final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
if (virtualFile == null || !virtualFile.isDirectory())
return;
final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap = new HashMap<>();
final String[] profileName = new String[1];
ProgressManager.getInstance().run(new Task.Backgroundable(project, InspectionsBundle.message("parsing.inspections.dump.progress.title"), true, new PerformAnalysisInBackgroundOption(project)) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final VirtualFile[] files = virtualFile.getChildren();
try {
for (final VirtualFile inspectionFile : files) {
if (inspectionFile.isDirectory())
continue;
final String shortName = inspectionFile.getNameWithoutExtension();
final String extension = inspectionFile.getExtension();
if (shortName.equals(InspectionApplication.DESCRIPTIONS)) {
profileName[0] = ReadAction.compute(() -> OfflineViewParseUtil.parseProfileName(LoadTextUtil.loadText(inspectionFile).toString()));
} else if (XML_EXTENSION.equals(extension)) {
resMap.put(shortName, ReadAction.compute(() -> OfflineViewParseUtil.parse(LoadTextUtil.loadText(inspectionFile).toString())));
}
}
} catch (final Exception e) {
//all parse exceptions
ApplicationManager.getApplication().invokeLater(() -> Messages.showInfoMessage(e.getMessage(), InspectionsBundle.message("offline.view.parse.exception.title")));
//cancel process
throw new ProcessCanceledException();
}
}
@Override
public void onSuccess() {
ApplicationManager.getApplication().invokeLater(() -> {
final String name = profileName[0];
showOfflineView(project, name, resMap, InspectionsBundle.message("offline.view.title") + " (" + (name != null ? name : InspectionsBundle.message("offline.view.editor.settings.title")) + ")");
});
}
});
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class SourcePathsStep method createComponentForEmptyRootCase.
private JComponent createComponentForEmptyRootCase() {
final JPanel panel = new JPanel(new GridBagLayout());
final String text = IdeBundle.message("prompt.please.specify.java.sources.directory");
final JLabel label = new JLabel(text);
label.setUI(new MultiLineLabelUI());
panel.add(label, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(8, 10, 0, 10), 0, 0));
myRbCreateSource = new JRadioButton(IdeBundle.message("radio.create.source.directory"), true);
panel.add(myRbCreateSource, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(8, 10, 0, 10), 0, 0));
myTfSourceDirectoryName = new JTextField(suggestSourceDirectoryName());
final JLabel srcPathLabel = new JLabel(IdeBundle.message("prompt.enter.relative.path.to.module.content.root", File.separator));
panel.add(srcPathLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insets(8, 30, 0, 0), 0, 0));
final FileChooserDescriptor chooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
chooserDescriptor.withTreeRootVisible(true);
final FieldPanel fieldPanel = createFieldPanel(myTfSourceDirectoryName, null, new BrowsePathListener(myTfSourceDirectoryName, chooserDescriptor));
panel.add(fieldPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insets(8, 30, 0, 10), 0, 0));
myRbNoSource = new JRadioButton(IdeBundle.message("radio.do.not.create.source.directory"), true);
panel.add(myRbNoSource, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insets(8, 10, 0, 10), 0, 0));
final JLabel fullPathLabel = new JLabel(IdeBundle.message("label.source.directory"));
panel.add(fullPathLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, JBUI.insets(8, 10, 0, 10), 0, 0));
myTfFullPath = new JTextField();
myTfFullPath.setEditable(false);
myTfFullPath.setOpaque(false);
final Insets borderInsets = myTfFullPath.getBorder().getBorderInsets(myTfFullPath);
myTfFullPath.setBorder(BorderFactory.createEmptyBorder(borderInsets.top, borderInsets.left, borderInsets.bottom, borderInsets.right));
panel.add(myTfFullPath, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, JBUI.insets(8, 10), 0, 0));
ButtonGroup group = new ButtonGroup();
group.add(myRbCreateSource);
group.add(myRbNoSource);
myTfSourceDirectoryName.getDocument().addDocumentListener(new DocumentAdapter() {
public void textChanged(DocumentEvent event) {
updateFullPathField();
}
});
myRbCreateSource.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
final boolean enabled = e.getStateChange() == ItemEvent.SELECTED;
srcPathLabel.setEnabled(enabled);
fieldPanel.setEnabled(enabled);
fullPathLabel.setVisible(enabled);
myTfFullPath.setVisible(enabled);
if (enabled) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(myTfSourceDirectoryName, true);
});
}
}
});
return panel;
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class CreateModuleLibraryChooser method chooseElements.
@Override
@NotNull
public List<Library> chooseElements() {
final FileChooserDescriptor chooserDescriptor;
final List<Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor>> descriptors = new ArrayList<>();
for (LibraryRootsComponentDescriptor componentDescriptor : myLibraryTypes.keySet()) {
descriptors.add(Pair.create(componentDescriptor, componentDescriptor.createAttachFilesChooserDescriptor(null)));
}
if (descriptors.size() == 1) {
chooserDescriptor = descriptors.get(0).getSecond();
} else {
chooserDescriptor = new FileChooserDescriptor(true, true, true, false, true, false) {
@Override
public boolean isFileSelectable(VirtualFile file) {
for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
if (pair.getSecond().isFileSelectable(file)) {
return true;
}
}
return false;
}
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
if (pair.getSecond().isFileVisible(file, showHiddenFiles)) {
return true;
}
}
return false;
}
};
}
chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myModule);
final Project project = myModule.getProject();
final VirtualFile[] files = FileChooser.chooseFiles(chooserDescriptor, myParentComponent, project, project.getBaseDir());
if (files.length == 0)
return Collections.emptyList();
List<LibraryRootsComponentDescriptor> suitableDescriptors = new ArrayList<>();
for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
if (acceptAll(pair.getSecond(), files)) {
suitableDescriptors.add(pair.getFirst());
}
}
final LibraryRootsComponentDescriptor rootsComponentDescriptor;
LibraryType libraryType = null;
if (suitableDescriptors.size() == 1) {
rootsComponentDescriptor = suitableDescriptors.get(0);
libraryType = myLibraryTypes.get(rootsComponentDescriptor);
} else {
rootsComponentDescriptor = myDefaultDescriptor;
}
List<OrderRoot> chosenRoots = RootDetectionUtil.detectRoots(Arrays.asList(files), myParentComponent, project, rootsComponentDescriptor);
return createLibrariesFromRoots(chosenRoots, libraryType, myModuleLibrariesModel, myDefaultPropertiesFactory);
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class DefaultLibraryRootsComponentDescriptor method createAttachFilesChooserDescriptor.
@NotNull
@Override
public FileChooserDescriptor createAttachFilesChooserDescriptor(@Nullable String libraryName) {
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, false, true, true).withFileFilter(LIBRARY_ROOT_CONDITION);
descriptor.setTitle(StringUtil.isEmpty(libraryName) ? ProjectBundle.message("library.attach.files.action") : ProjectBundle.message("library.attach.files.to.library.action", libraryName));
descriptor.setDescription(ProjectBundle.message("library.java.attach.files.description"));
return descriptor;
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project intellij-community by JetBrains.
the class JavaSdkImpl method getHomeChooserDescriptor.
@NotNull
@Override
public FileChooserDescriptor getHomeChooserDescriptor() {
FileChooserDescriptor descriptor = super.getHomeChooserDescriptor();
descriptor.putUserData(KEY, Boolean.TRUE);
return descriptor;
}
Aggregations