Search in sources :

Example 46 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 47 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 48 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)

Example 49 with FileChooserDescriptor

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

the class AndroidUiUtil method initSigningSettingsForm.

public static void initSigningSettingsForm(@NotNull final Project project, @NotNull final ApkSigningSettingsForm form) {
    form.getLoadKeyStoreButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final String defaultPath = form.getKeyStorePathField().getText().trim();
            final VirtualFile defaultFile = LocalFileSystem.getInstance().findFileByPath(defaultPath);
            final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor();
            final VirtualFile file = FileChooser.chooseFile(descriptor, form.getPanel(), project, defaultFile);
            if (file != null) {
                form.getKeyStorePathField().setText(FileUtil.toSystemDependentName(file.getPath()));
            }
        }
    });
    form.getCreateKeyStoreButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final NewKeyStoreDialog dialog = new NewKeyStoreDialog(project, form.getKeyStorePathField().getText());
            dialog.show();
            if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
                form.getKeyStorePathField().setText(dialog.getKeyStorePath());
                form.getKeyStorePasswordField().setText(String.valueOf(dialog.getKeyStorePassword()));
                form.getKeyAliasField().setText(dialog.getKeyAlias());
                form.getKeyPasswordField().setText(String.valueOf(dialog.getKeyPassword()));
            }
        }
    });
    form.getKeyAliasField().getButton().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final List<String> keys = loadExistingKeys(form);
            if (keys == null) {
                return;
            }
            final ChooseKeyDialog dialog = new ChooseKeyDialog(project, form.getKeyStorePathField().getText().trim(), form.getKeyStorePasswordField().getPassword(), keys, form.getKeyAliasField().getText().trim());
            dialog.show();
            if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
                final String chosenKey = dialog.getChosenKey();
                if (chosenKey != null) {
                    form.getKeyAliasField().setText(chosenKey);
                }
                final char[] password = dialog.getChosenKeyPassword();
                if (password != null) {
                    form.getKeyPasswordField().setText(String.valueOf(password));
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ChooseKeyDialog(org.jetbrains.android.compiler.artifact.ChooseKeyDialog) NewKeyStoreDialog(org.jetbrains.android.compiler.artifact.NewKeyStoreDialog) List(java.util.List)

Example 50 with FileChooserDescriptor

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

the class IdeaJdkConfigurable method createComponent.

public JComponent createComponent() {
    mySandboxHome.setHistorySize(5);
    JPanel wholePanel = new JPanel(new GridBagLayout());
    wholePanel.add(mySandboxHomeLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    wholePanel.add(GuiUtils.constructFieldWithBrowseButton(mySandboxHome, new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
            descriptor.setTitle(DevKitBundle.message("sandbox.home"));
            descriptor.setDescription(DevKitBundle.message("sandbox.purpose"));
            VirtualFile file = FileChooser.chooseFile(descriptor, mySandboxHome, null, null);
            if (file != null) {
                mySandboxHome.setText(FileUtil.toSystemDependentName(file.getPath()));
            }
            myModified = true;
        }
    }), new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
    wholePanel.add(myInternalJreLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
    wholePanel.add(myInternalJres, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
    myInternalJres.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof Sdk) {
                setText(((Sdk) value).getName());
            }
        }
    });
    myInternalJres.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            if (myFreeze)
                return;
            final Sdk javaJdk = (Sdk) e.getItem();
            for (OrderRootType type : OrderRootType.getAllTypes()) {
                if (!((SdkType) javaJdk.getSdkType()).isRootTypeApplicable(type)) {
                    continue;
                }
                final VirtualFile[] internalRoots = javaJdk.getSdkModificator().getRoots(type);
                final VirtualFile[] configuredRoots = mySdkModificator.getRoots(type);
                for (VirtualFile file : internalRoots) {
                    if (e.getStateChange() == ItemEvent.DESELECTED) {
                        mySdkModificator.removeRoot(file, type);
                    } else {
                        if (ArrayUtil.find(configuredRoots, file) == -1) {
                            mySdkModificator.addRoot(file, type);
                        }
                    }
                }
            }
        }
    });
    mySandboxHome.addDocumentListener(new DocumentAdapter() {

        protected void textChanged(DocumentEvent e) {
            myModified = true;
        }
    });
    mySandboxHome.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            myModified = true;
        }
    });
    mySandboxHome.setText("");
    myModified = true;
    return wholePanel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener) OrderRootType(com.intellij.openapi.roots.OrderRootType) ItemListener(java.awt.event.ItemListener)

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