Search in sources :

Example 41 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.

the class AndroidImportProjectAction method createFileChooserDescriptor.

@NotNull
protected FileChooserDescriptor createFileChooserDescriptor() {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, false) {

        FileChooserDescriptor myDelegate = new OpenProjectFileChooserDescriptor(true);

        @Override
        public Icon getIcon(VirtualFile file) {
            Icon icon = myDelegate.getIcon(file);
            return icon == null ? super.getIcon(file) : icon;
        }
    };
    descriptor.setHideIgnored(false);
    descriptor.setTitle(WIZARD_TITLE);
    descriptor.setDescription(WIZARD_DESCRIPTION);
    return descriptor;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) OpenProjectFileChooserDescriptor(com.intellij.ide.actions.OpenProjectFileChooserDescriptor) OpenProjectFileChooserDescriptor(com.intellij.ide.actions.OpenProjectFileChooserDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.

the class SelectNdkDialog method configureNdkTextField.

private void configureNdkTextField() {
    myNdkTextFieldWithButton.setTextFieldPreferredWidth(50);
    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);
                ValidationResult validationResult = validateAndroidNdk(file, false);
                if (!validationResult.success) {
                    String msg = validationResult.message;
                    if (isEmpty(msg)) {
                        msg = "Please choose a valid Android NDK directory.";
                    }
                    throw new IllegalArgumentException(msg);
                }
            }
        }
    };
    if (SystemInfo.isMac) {
        descriptor.withShowHiddenFiles(true);
    }
    descriptor.setTitle("Choose Android NDK Location");
    myNdkTextFieldWithButton.addActionListener(new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>("Select Android NDK Home", null, myNdkTextFieldWithButton, null, descriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ValidationResult(com.android.tools.idea.sdk.SdkPaths.ValidationResult) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 43 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.

the class ImportDevicesAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, true);
    String homePath = System.getProperty("user.home");
    File parentPath = homePath == null ? new File("/") : new File(homePath);
    VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
    VirtualFile[] files = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null).choose(parent, null);
    List<Device> importedDevices = Lists.newArrayList();
    for (VirtualFile vf : files) {
        for (Device d : DeviceManagerConnection.getDevicesFromFile(VfsUtilCore.virtualToIoFile(vf))) {
            importedDevices.add(d);
        }
    }
    if (!importedDevices.isEmpty()) {
        DeviceManagerConnection.getDefaultDeviceManagerConnection().createDevices(importedDevices);
        myProvider.refreshDevices();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Device(com.android.sdklib.devices.Device) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 44 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.

the class IdeSdksConfigurable method createTextFieldWithBrowseButton.

@NotNull
private TextFieldWithBrowseButton createTextFieldWithBrowseButton(@NotNull String title, @NotNull String errorMessage, @NotNull Function<File, ValidationResult> validation) {
    FileChooserDescriptor descriptor = createSingleFolderDescriptor(title, file -> {
        ValidationResult validationResult = validation.fun(file);
        if (!validationResult.success) {
            String msg = validationResult.message;
            if (isEmpty(msg)) {
                msg = errorMessage;
            }
            throw new IllegalArgumentException(msg);
        }
        return null;
    });
    JTextField textField = new JTextField(10);
    return new TextFieldWithBrowseButton(textField, e -> {
        VirtualFile suggestedDir = null;
        File ndkLocation = getNdkLocation();
        if (ndkLocation.isDirectory()) {
            suggestedDir = findFileByIoFile(ndkLocation, false);
        }
        VirtualFile chosen = chooseFile(descriptor, null, suggestedDir);
        if (chosen != null) {
            File f = virtualToIoFile(chosen);
            textField.setText(f.getPath());
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ValidationResult(com.android.tools.idea.sdk.SdkPaths.ValidationResult) 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 45 with FileChooserDescriptor

use of com.intellij.openapi.fileChooser.FileChooserDescriptor in project android by JetBrains.

the class GradleSignStep method _init.

@Override
public void _init() {
    myAndroidModel = AndroidModuleModel.get(myWizard.getFacet());
    PropertiesComponent properties = PropertiesComponent.getInstance(myWizard.getProject());
    String lastSelectedBuildType = properties.getValue(PROPERTY_BUILD_TYPE);
    myBuildTypeComboModel.removeAllElements();
    Set<String> buildTypes = myAndroidModel == null ? Collections.<String>emptySet() : myAndroidModel.getBuildTypes();
    for (String buildType : buildTypes) {
        myBuildTypeComboModel.addElement(buildType);
        if ((lastSelectedBuildType == null && buildType.equals("release")) || buildType.equals(lastSelectedBuildType)) {
            myBuildTypeComboModel.setSelectedItem(buildType);
        }
    }
    myFlavorsListModel.clear();
    List<String> productFlavors;
    if (myAndroidModel == null || myAndroidModel.getProductFlavors().isEmpty()) {
        productFlavors = Collections.emptyList();
    } else {
        // if there are multiple flavors, we want the merged flavor list
        Set<String> mergedFlavors = Sets.newHashSet();
        for (Variant v : myAndroidModel.getAndroidProject().getVariants()) {
            mergedFlavors.add(ExportSignedPackageWizard.getMergedFlavorName(v));
        }
        productFlavors = Lists.newArrayList(mergedFlavors);
        Collections.sort(productFlavors);
    }
    TIntArrayList lastSelectedIndices = new TIntArrayList(productFlavors.size());
    String[] flavors = properties.getValues(PROPERTY_FLAVORS);
    Set<String> lastSelectedFlavors = flavors == null ? Collections.<String>emptySet() : Sets.newHashSet(flavors);
    for (int i = 0; i < productFlavors.size(); i++) {
        String flavor = productFlavors.get(i);
        myFlavorsListModel.addElement(flavor);
        if (lastSelectedFlavors.contains(flavor)) {
            lastSelectedIndices.add(i);
        }
    }
    myFlavorsList.setSelectedIndices(lastSelectedIndices.toNativeArray());
    String lastApkFolderPath = properties.getValue(PROPERTY_APK_PATH);
    File lastApkFolder;
    if (lastApkFolderPath != null) {
        lastApkFolder = new File(lastApkFolderPath);
    } else {
        if (myAndroidModel == null) {
            lastApkFolder = VfsUtilCore.virtualToIoFile(myWizard.getProject().getBaseDir());
        } else {
            lastApkFolder = myAndroidModel.getRootDirPath();
        }
    }
    myApkPathField.setText(lastApkFolder.getAbsolutePath());
    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    myApkPathField.addBrowseFolderListener("Select APK Destination Folder", null, myWizard.getProject(), descriptor);
    GradleVersion modelVersion = null;
    if (myAndroidModel != null) {
        modelVersion = myAndroidModel.getModelVersion();
    }
    boolean enabled = modelVersion != null && modelVersion.compareIgnoringQualifiers(MIN_SIGNATURE_SELECTION_VERSION) >= 0;
    myV1JarSignatureCheckBox.setEnabled(enabled);
    myV1JarSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V1_SIGN));
    myV2FullAPKSignatureCheckBox.setEnabled(enabled);
    myV2FullAPKSignatureCheckBox.setSelected(properties.getBoolean(PROPERTY_V2_SIGN));
    // Set HTML label here; the visual editor does not like the "&nbsp;" part so set the text here.
    mySignatureHelpLabel.setText("<html><a href=\"\">Signature&nbsp;Help</a></html>");
    mySignatureHelpLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    mySignatureHelpLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Desktop.Action.BROWSE)) {
                    URI uri;
                    try {
                        uri = new URI("http://developer.android.com/about/versions/nougat/android-7.0.html#apk_signature_v2");
                    } catch (URISyntaxException ex) {
                        throw new AssertionError(ex);
                    }
                    try {
                        desktop.browse(uri);
                    } catch (IOException ex) {
                        LOG.error("Failed to open URI '" + uri + "'", ex);
                    }
                }
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) MouseAdapter(java.awt.event.MouseAdapter) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) TIntArrayList(gnu.trove.TIntArrayList) Variant(com.android.builder.model.Variant) GradleVersion(com.android.ide.common.repository.GradleVersion) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) File(java.io.File)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)166 VirtualFile (com.intellij.openapi.vfs.VirtualFile)110 NotNull (org.jetbrains.annotations.NotNull)35 File (java.io.File)24 Project (com.intellij.openapi.project.Project)22 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)21 Nullable (org.jetbrains.annotations.Nullable)19 ActionEvent (java.awt.event.ActionEvent)17 ActionListener (java.awt.event.ActionListener)16 DocumentEvent (javax.swing.event.DocumentEvent)14 DocumentAdapter (com.intellij.ui.DocumentAdapter)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 FileChooser (com.intellij.openapi.fileChooser.FileChooser)9 List (java.util.List)9 FileChooserDialog (com.intellij.openapi.fileChooser.FileChooserDialog)7 JBLabel (com.intellij.ui.components.JBLabel)7 javax.swing (javax.swing)7 MacroComboBoxWithBrowseButton (com.intellij.execution.ui.MacroComboBoxWithBrowseButton)5 Module (com.intellij.openapi.module.Module)5