use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.
the class KeyValuePane method init.
public void init(GradleBuildFile gradleBuildFile, Collection<BuildFileKey> properties) {
GridLayoutManager layout = new GridLayoutManager(properties.size() + 1, 2);
setLayout(layout);
GridConstraints constraints = new GridConstraints();
constraints.setAnchor(GridConstraints.ANCHOR_WEST);
constraints.setVSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
for (BuildFileKey property : properties) {
constraints.setColumn(0);
constraints.setFill(GridConstraints.FILL_NONE);
constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
JBLabel label = new JBLabel(property.getDisplayName());
add(label, constraints);
constraints.setColumn(1);
constraints.setFill(GridConstraints.FILL_HORIZONTAL);
constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW);
JComponent component;
switch(property.getType()) {
case BOOLEAN:
{
constraints.setFill(GridConstraints.FILL_NONE);
ComboBox comboBox = createComboBox(false);
comboBox.addItem("");
comboBox.addItem("true");
comboBox.addItem("false");
comboBox.setPrototypeDisplayValue("(false) ");
component = comboBox;
break;
}
case FILE:
case FILE_AS_STRING:
{
JBTextField textField = new JBTextField();
TextFieldWithBrowseButton fileField = new TextFieldWithBrowseButton(textField);
FileChooserDescriptor d = new FileChooserDescriptor(true, false, false, true, false, false);
d.setShowFileSystemRoots(true);
fileField.addBrowseFolderListener(new TextBrowseFolderListener(d));
fileField.getTextField().getDocument().addDocumentListener(this);
component = fileField;
break;
}
case REFERENCE:
{
constraints.setFill(GridConstraints.FILL_NONE);
ComboBox comboBox = createComboBox(true);
if (hasKnownValues(property)) {
for (String s : myKeysWithKnownValues.get(property).values()) {
comboBox.addItem(s);
}
}
// If there are no hardcoded values, the combo box's values will get populated later when the panel for the container reference
// type wakes up and notifies us of its current values.
component = comboBox;
break;
}
case CLOSURE:
case STRING:
case INTEGER:
default:
{
if (hasKnownValues(property)) {
constraints.setFill(GridConstraints.FILL_NONE);
ComboBox comboBox = createComboBox(true);
for (String s : myKeysWithKnownValues.get(property).values()) {
comboBox.addItem(s);
}
component = comboBox;
} else {
JBTextField textField = new JBTextField();
textField.getDocument().addDocumentListener(this);
component = textField;
}
break;
}
}
add(component, constraints);
label.setLabelFor(component);
myProperties.put(property, component);
constraints.setRow(constraints.getRow() + 1);
}
constraints.setColumn(0);
constraints.setVSizePolicy(GridConstraints.FILL_VERTICAL);
constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
add(new JBLabel(""), constraints);
updateUiFromCurrentObject();
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.
the class IdeSdksConfigurable method createSingleFolderDescriptor.
@NotNull
private static FileChooserDescriptor createSingleFolderDescriptor(@NotNull String title, @NotNull Function<File, Void> validation) {
FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
@Override
public void validateSelectedFiles(VirtualFile[] files) throws Exception {
for (VirtualFile virtualFile : files) {
File file = virtualToIoFile(virtualFile);
validation.fun(file);
}
}
};
if (SystemInfo.isMac) {
descriptor.withShowHiddenFiles(true);
}
descriptor.setTitle(title);
return descriptor;
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.
the class ConfigureAndroidProjectStep method browseForFile.
// TODO: Do we really need this method? See SdkComponentsStep on how to use addBrowseFolderListener. If we can't do the same, at least
// describe what this method does, and why is needed.
// Returns null if no file was selected
@Nullable
private static String browseForFile(@NotNull String initialPath) {
FileChooserDescriptor fileSaverDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
File currentPath = new File(initialPath);
File parentPath = currentPath.getParentFile();
if (parentPath == null) {
String homePath = System.getProperty("user.home");
parentPath = new File(homePath == null ? File.separator : homePath);
}
VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
OptionalProperty<String> finalPath = new OptionalValueProperty<>();
FileChooser.chooseFiles(fileSaverDescriptor, null, parent, virtualFiles -> {
if (virtualFiles.size() == 1) {
String result = virtualFiles.iterator().next().getCanonicalPath();
if (result != null) {
finalPath.setValue(result);
}
}
});
return finalPath.getValueOrNull();
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.
the class AndroidOpenFileAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
boolean showFiles = project != null || PlatformProjectOpenProcessor.getInstanceIfItExists() != null;
FileChooserDescriptor descriptor = showFiles ? new ProjectOrFileChooserDescriptor() : new ProjectOnlyFileChooserDescriptor();
descriptor.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, showFiles);
VirtualFile explicitPreferredDirectory = ((project != null) && !project.isDefault()) ? project.getBaseDir() : getUserHomeDir();
chooseFiles(descriptor, project, explicitPreferredDirectory, files -> {
for (VirtualFile file : files) {
if (!descriptor.isFileSelectable(file)) {
String message = IdeBundle.message("error.dir.contains.no.project", file.getPresentableUrl());
Messages.showInfoMessage(project, message, IdeBundle.message("title.cannot.open.project"));
return;
}
}
doOpenFile(project, files);
});
}
use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.
the class ProGuardConfigFilesPanel method chooseFile.
private String chooseFile() {
final AndroidFacet facet = getFacet();
if (facet == null) {
return null;
}
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
final VirtualFile contentRoot = AndroidRootUtil.getMainContentRoot(facet);
final VirtualFile file = FileChooser.chooseFile(descriptor, this, facet.getModule().getProject(), contentRoot);
return file != null ? FileUtil.toSystemDependentName(file.getPath()) : null;
}
Aggregations