Example usage for com.intellij.openapi.fileChooser FileChooserDescriptor FileChooserDescriptor

List of usage examples for com.intellij.openapi.fileChooser FileChooserDescriptor FileChooserDescriptor

Introduction

In this page you can find the example usage for com.intellij.openapi.fileChooser FileChooserDescriptor FileChooserDescriptor.

Prototype

public FileChooserDescriptor(boolean chooseFiles, boolean chooseFolders, boolean chooseJars,
        boolean chooseJarsAsFiles, boolean chooseJarContents, boolean chooseMultiple) 

Source Link

Document

Creates new instance.

Usage

From source file:bazaar4idea.ui.BzrConfigurationIdePanel.java

License:Apache License

public BzrConfigurationIdePanel(final BzrGlobalSettings globalSettings) {

    myQueue = new MergingUpdateQueue("idepanelqueue", 500, true, basePanel, null, basePanel, true);

    m_globalSettings = globalSettings;// w  w w . ja va2 s  .  c o m
    loadSettings();

    String title = BzrBundle.message("bzr4intellij.configuration.title");
    String description = BzrBundle.message("bzr4intellij.configuration.description");

    pathSelector.addBrowseFolderListener(title, description, null,
            new FileChooserDescriptor(true, false, false, false, false, false),
            new TextComponentAccessor<JTextField>() {
                public String getText(JTextField component) {
                    return component.getText();
                }

                public void setText(JTextField component, String text) {
                    component.setText(text);
                }
            });

    final ActionListener defaultPathListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            pathSelector.setText(BzrGlobalSettings.DEFAULT_EXECUTABLE);
        }
    };

    pathDefaultButton.addActionListener(defaultPathListener);

    pathSelector.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            queueValidationHintsUpdate();
        }
    });
}

From source file:bazaar4idea.ui.BzrSetExecutableDialog.java

License:Apache License

public BzrSetExecutableDialog(Project project) {
    super(project, false);
    Object[] params1 = new Object[] {};
    String title = BzrBundle.message("bzr4intellij.configuration.title", params1);
    Object[] params = new Object[] {};
    String description = BzrBundle.message("bzr4intellij.configuration.description", params);

    hgExecutablePath.addBrowseFolderListener(title, description, null,
            new FileChooserDescriptor(true, false, false, false, false, false));
    init();/*from w w  w . j  ava2  s.co m*/
}

From source file:com.android.tools.idea.actions.AndroidImportProjectAction.java

License:Apache License

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

        @Override/* w  w  w .j  a  v  a  2s. c o m*/
        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;
}

From source file:com.android.tools.idea.apk.viewer.ApkEditor.java

License:Apache License

@Override
public void selectApkAndCompare() {
    FileChooserDescriptor desc = new FileChooserDescriptor(true, false, false, false, false, false);
    desc.withFileFilter(file -> ApkFileSystem.EXTENSIONS.contains(file.getExtension()));
    VirtualFile file = FileChooser.chooseFile(desc, myProject, null);
    if (file == null) {
        // user canceled
        return;/*from  ww w  .  j a  va2s  . c  o m*/
    }
    VirtualFile newApk = ApkFileSystem.getInstance().getRootByLocal(file);
    assert newApk != null;

    DialogBuilder builder = new DialogBuilder(myProject);
    builder.setTitle(myRoot.getName() + " vs " + newApk.getName());
    ApkDiffParser parser = new ApkDiffParser(myRoot, newApk);
    ApkDiffPanel panel = new ApkDiffPanel(parser);
    builder.setCenterPanel(panel.getContainer());
    builder.setPreferredFocusComponent(panel.getPreferredFocusedComponent());
    builder.show();
}

From source file:com.android.tools.idea.avdmanager.ConfigureAvdOptionsStep.java

License:Apache License

private void bindComponents() {
    myBindings.bindTwoWay(new TextProperty(myAvdDisplayName), getModel().avdDisplayName());
    myBindings.bind(new TextProperty(myAvdId), new StringExpression(getModel().avdDisplayName()) {
        @NotNull//from  ww  w.j av  a2  s  .c o  m
        @Override
        public String get() {
            String displayName = getModel().avdDisplayName().get();
            getModel().avdId()
                    .set(StringUtil.isNotEmpty(displayName)
                            ? AvdWizardUtils.cleanAvdName(connection, displayName,
                                    !displayName.equals(myOriginalName))
                            : "");
            return getModel().avdId().get();
        }
    });

    myBindings.bindTwoWay(new TextProperty(mySystemImageName), getModel().systemImageName());
    myBindings.bindTwoWay(new TextProperty(mySystemImageDetails), getModel().systemImageDetails());

    myBindings.bindTwoWay(new SelectedProperty(myQemu2CheckBox), getModel().useQemu2());
    myBindings.bindTwoWay(new SelectedItemProperty<Integer>(myCoreCount), getModel().cpuCoreCount());
    myBindings.bindTwoWay(myRamStorage.storage(), getModel().getAvdDeviceData().ramStorage());
    myBindings.bindTwoWay(myVmHeapStorage.storage(), getModel().vmHeapStorage());
    myBindings.bindTwoWay(myInternalStorage.storage(), getModel().internalStorage());
    myBindings.bindTwoWay(myBuiltInSdCardStorage.storage(),
            new OptionalToValuePropertyAdapter<Storage>(getModel().sdCardStorage()));

    myBindings.bindTwoWay(new SelectedItemProperty<GpuMode>(myHostGraphics), getModel().hostGpuMode());

    myBindings.bindTwoWay(new SelectedProperty(myDeviceFrameCheckbox), getModel().hasDeviceFrame());

    myBindings.bindTwoWay(new SelectedItemProperty<File>(mySkinComboBox.getComboBox()),
            getModel().getAvdDeviceData().customSkinFile() /*myDisplaySkinFile*/);
    myOrientationToggle.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            ScreenOrientation orientation = myOrientationToggle.getSelectedElement();
            if (orientation == null) {
                getModel().selectedAvdOrientation().set(ScreenOrientation.PORTRAIT);
            } else {
                getModel().selectedAvdOrientation().set(orientation);
            }
        }
    });

    FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false,
            false) {
        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, true);
        }
    };

    fileChooserDescriptor.setHideIgnored(false);
    myExternalSdCard.addBrowseFolderListener("Select SD Card", "Select an existing SD card image", myProject,
            fileChooserDescriptor);

    myBindings.bindTwoWay(new TextProperty(myExternalSdCard.getTextField()),
            getModel().externalSdCardLocation());

    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(
            new SelectedItemProperty<AvdCamera>(myFrontCameraCombo)), getModel().selectedFrontCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(
            new SelectedItemProperty<AvdCamera>(myBackCameraCombo)), getModel().selectedBackCamera());

    myBindings.bindTwoWay(
            new OptionalToValuePropertyAdapter<AvdNetworkSpeed>(
                    new SelectedItemProperty<AvdNetworkSpeed>(mySpeedCombo)),
            getModel().selectedNetworkSpeed());
    myBindings.bindTwoWay(
            new OptionalToValuePropertyAdapter<AvdNetworkLatency>(
                    new SelectedItemProperty<AvdNetworkLatency>(myLatencyCombo)),
            getModel().selectedNetworkLatency());

    myBindings.bindTwoWay(new SelectedProperty(myEnableComputerKeyboard), getModel().enableHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedProperty(myExternalRadioButton), getModel().useExternalSdCard());
    myBindings.bindTwoWay(new SelectedProperty(myBuiltInRadioButton), getModel().useBuiltInSdCard());

    myCheckSdForChanges = true;
}

From source file:com.android.tools.idea.avdmanager.ImportDevicesAction.java

License:Apache License

@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);//w  w  w  .  j  a va 2 s.  c o m
    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();
    }
}

From source file:com.android.tools.idea.avdmanager.SkinChooser.java

License:Apache License

public SkinChooser(@Nullable Project project, boolean resolveSystemImageSkins) {
    myResolveSystemImageSkins = resolveSystemImageSkins;
    setItems(getSkins());/*  w  ww  . j a v  a2  s  .  c  om*/
    //noinspection unchecked
    getComboBox().setRenderer(new ColoredListCellRenderer() {
        @Override
        protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected,
                boolean hasFocus) {
            File skinFile = ((value) == null) ? NO_SKIN : (File) value;
            String skinPath = skinFile.getPath();
            if (FileUtil.filesEqual(skinFile, NO_SKIN)) {
                append("No Skin");
            } else if (skinPath.contains("/sdk/platforms/")) {
                append(skinPath.replaceAll(".*/sdk/platforms/(.*)/skins/(.*)", "$2 ($1)"));
            } else if (skinPath.contains("/sdk/system-images/")) {
                append(skinPath.replaceAll(".*/sdk/system-images/(.*)/(.*)/(.*)/skins/(.*)", "$4 ($1 $3)"));
            } else {
                append(skinFile.getName());
            }
        }
    });
    FileChooserDescriptor skinChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false,
            false);
    addBrowseFolderListener("Select Custom Skin", "Select the directory containing your custom skin definition",
            project, skinChooserDescriptor, new TextComponentAccessor<JComboBox>() {
                @Override
                public String getText(JComboBox component) {
                    return ((File) component.getSelectedItem()).getPath();
                }

                @Override
                public void setText(JComboBox component, @NotNull String text) {
                    List<File> items = getSkins();
                    File f = new File(text);
                    items.add(f);
                    setItems(items);
                    getComboBox().setSelectedItem(f);
                }
            });
    getComboBox().addItemListener(this);
    setTextFieldPreferredWidth(20);

}

From source file:com.android.tools.idea.gradle.actions.LinkExternalCppProjectDialog.java

License:Apache License

public LinkExternalCppProjectDialog(@NotNull Module module) {
    super(false);

    myModule = module;/* ww  w  . j ava2 s  .  com*/

    init();

    setTitle("Link C++ Project with Gradle");

    myBuildSystemCombo.addItem(BuildSystem.CMAKE);
    myBuildSystemCombo.addItem(BuildSystem.NDK_BUILD);

    myBuildSystemCombo.setSelectedItem(BuildSystem.CMAKE);
    myProjectPathDescriptionLabel.setText(CMAKE_PATH_DESCRIPTION);

    myBuildSystemCombo.addItemListener(e -> {
        if (myBuildSystemCombo.getSelectedItem() == BuildSystem.CMAKE) {
            myProjectPathDescriptionLabel.setText(CMAKE_PATH_DESCRIPTION);
        } else {
            myProjectPathDescriptionLabel.setText(NDK_BUILD_PATH_DESCRIPTION);
        }
    });

    getOKAction().setEnabled(false);

    myProjectPathTextField.setTextFieldPreferredWidth(50);
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {
        @Override
        public void validateSelectedFiles(VirtualFile[] files) throws Exception {
            for (VirtualFile virtualFile : files) {
                String errorMessage = validateProjectFilePath(virtualToIoFile(virtualFile));
                if (errorMessage != null) {
                    throw new IllegalArgumentException(errorMessage);
                }
            }
        }
    };

    descriptor.setTitle("Choose C++ Project Location");

    myProjectPathTextField.addActionListener(
            new ComponentWithBrowseButton.BrowseFolderActionListener<>("Select C++ Project Location", null,
                    myProjectPathTextField, null, descriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT));

    myProjectPathResultLabel.setVisible(false);
}

From source file:com.android.tools.idea.gradle.structure.DefaultSdksConfigurable.java

License:Apache License

@NotNull
private static FileChooserDescriptor createSingleFolderDescriptor(@NotNull String title,
        @NotNull final Function<File, Void> validation) {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false,
            false) {/*from  ww  w.ja  v a 2 s . c  o  m*/
        @Override
        public void validateSelectedFiles(VirtualFile[] files) throws Exception {
            for (VirtualFile virtualFile : files) {
                File file = VfsUtilCore.virtualToIoFile(virtualFile);
                validation.fun(file);
            }
        }
    };
    if (SystemInfo.isMac) {
        descriptor.putUserData(PathChooserDialog.NATIVE_MAC_CHOOSER_SHOW_HIDDEN_FILES, Boolean.TRUE);
    }
    descriptor.setTitle(title);
    return descriptor;
}

From source file:com.android.tools.idea.gradle.structure.editors.KeyValuePane.java

License:Apache License

public void init(GradleBuildFile gradleBuildFile, Collection<BuildFileKey> properties) {
    GridLayoutManager layout = new GridLayoutManager(properties.size() + 1, 2);
    setLayout(layout);/*from www. java  2s. com*/
    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();
}