Search in sources :

Example 81 with FileChooserDescriptor

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();
}
Also used : TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) JBLabel(com.intellij.ui.components.JBLabel) ComboBox(com.intellij.openapi.ui.ComboBox) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) TextBrowseFolderListener(com.intellij.openapi.ui.TextBrowseFolderListener) JBTextField(com.intellij.ui.components.JBTextField) AndroidTargetHash.getAddonHashString(com.android.sdklib.AndroidTargetHash.getAddonHashString) BuildFileKey(com.android.tools.idea.gradle.parser.BuildFileKey)

Example 82 with FileChooserDescriptor

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) FileChooser.chooseFile(com.intellij.openapi.fileChooser.FileChooser.chooseFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with FileChooserDescriptor

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 84 with FileChooserDescriptor

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);
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Projects.canImportAsGradleProject(com.android.tools.idea.gradle.util.Projects.canImportAsGradleProject) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) OpenProjectFileChooserDescriptor(com.intellij.ide.actions.OpenProjectFileChooserDescriptor)

Example 85 with FileChooserDescriptor

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)143 VirtualFile (com.intellij.openapi.vfs.VirtualFile)97 NotNull (org.jetbrains.annotations.NotNull)35 Project (com.intellij.openapi.project.Project)21 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)19 Nullable (org.jetbrains.annotations.Nullable)18 ActionEvent (java.awt.event.ActionEvent)17 File (java.io.File)17 ActionListener (java.awt.event.ActionListener)16 DocumentEvent (javax.swing.event.DocumentEvent)13 DocumentAdapter (com.intellij.ui.DocumentAdapter)10 ArrayList (java.util.ArrayList)10 FileChooser (com.intellij.openapi.fileChooser.FileChooser)9 List (java.util.List)9 IOException (java.io.IOException)8 JBLabel (com.intellij.ui.components.JBLabel)7 javax.swing (javax.swing)7 Module (com.intellij.openapi.module.Module)5 StringUtil (com.intellij.openapi.util.text.StringUtil)5 JBTable (com.intellij.ui.table.JBTable)5