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();
}
}
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());
}
});
}
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 " " part so set the text here.
mySignatureHelpLabel.setText("<html><a href=\"\">Signature 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);
}
}
}
}
});
}
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));
}
}
}
});
}
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;
}
Aggregations