Example usage for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createSingleFileDescriptor

List of usage examples for com.intellij.openapi.fileChooser FileChooserDescriptorFactory createSingleFileDescriptor

Introduction

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

Prototype

public static FileChooserDescriptor createSingleFileDescriptor(final String extension) 

Source Link

Usage

From source file:com.android.tools.idea.wizard.VectorAssetSetStep.java

License:Apache License

@SuppressWarnings("UseJBColor") // Colors are used for the graphics generator, not the plugin UI
public VectorAssetSetStep(TemplateWizardState state, @Nullable Project project, @Nullable Module module,
        @Nullable Icon sidePanelIcon, UpdateListener updateListener, @Nullable VirtualFile invocationTarget) {
    super(state, project, module, sidePanelIcon, updateListener, invocationTarget);

    myImageFile.addBrowseFolderListener(null, null, null,
            FileChooserDescriptorFactory.createSingleFileDescriptor("svg"));

    myTemplateState.put(ATTR_ASSET_TYPE, AssetType.ACTIONBAR.name());
    // TODO: hook up notification type here!
    mySelectedAssetType = AssetType.ACTIONBAR;
    register(ATTR_ASSET_NAME, myResourceNameField);
    myMoreErrors.addHyperlinkListener(myMoreErrorHyperlinkAdapter);
    myErrorPanel.setVisible(false);/*from  w w  w  .  j av  a 2s . c  om*/
}

From source file:consulo.nuget.module.extension.NuGetConfigPanel.java

License:Apache License

public NuGetConfigPanel(final NuGetMutableModuleExtension moduleExtension) {
    super(new VerticalFlowLayout(VerticalFlowLayout.TOP));

    final JBTextField textField = new JBTextField();

    textField.getEmptyText().setText(VfsUtil.urlToPath(
            moduleExtension.getModule().getModuleDirUrl() + "/" + NuGetModuleExtension.PACKAGES_CONFIG));

    String configFileUrl = moduleExtension.getConfigFileUrl();
    if (!StringUtil.isEmpty(configFileUrl)) {
        textField.setText(FileUtil.toSystemDependentName(VfsUtil.urlToPath(configFileUrl)));
    }//from  w  w w.  ja v  a2 s . co m

    TextFieldWithBrowseButton browseButton = new TextFieldWithBrowseButton(textField);
    browseButton.addBrowseFolderListener("Select File", "Select NuGet package config file",
            moduleExtension.getProject(),
            FileChooserDescriptorFactory.createSingleFileDescriptor(XmlFileType.INSTANCE),
            new TextComponentAccessor<JTextField>() {
                @Override
                public String getText(JTextField component) {
                    return FileUtil.toSystemDependentName(component.getText());
                }

                @Override
                public void setText(JTextField component, String text) {
                    component.setText(FileUtil.toSystemDependentName(text));
                }
            });
    textField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            moduleExtension.setConfigFilePath(FileUtil.toSystemIndependentName(textField.getText()));
        }
    });
    add(LabeledComponent.create(browseButton, "Config file:"));
}

From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidMultiDrawableImporter.java

License:Apache License

private void initBrowser(Resolution resolution, final TextFieldWithBrowseButton browseButton) {
    final FileChooserDescriptor imageDescriptor = FileChooserDescriptorFactory
            .createSingleFileDescriptor(ImageFileTypeManager.getInstance().getImageFileType());
    String title1 = "Select your " + resolution.getName() + " asset";
    imageDescriptor.setTitle(title1);/*from w  ww  . j  a  v a2s. c  o m*/
    ImageFileBrowserFolderActionListener actionListener = new ImageFileBrowserFolderActionListener(title1,
            project, browseButton, imageDescriptor) {
        @Override
        @SuppressWarnings("deprecation") // Otherwise not compatible to AndroidStudio
        protected void onFileChoosen(@NotNull VirtualFile chosenFile) {
            super.onFileChoosen(chosenFile);
            fillImageInformation(chosenFile);
        }
    };
    browseButton.addBrowseFolderListener(project, actionListener);
    browseButton.getTextField().addMouseListener(new SimpleMouseListener() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            updateImage(browseButton.getText());
        }
    });
    new FileDrop(browseButton.getTextField(), new FileDrop.Target() {
        @Override
        public FileChooserDescriptor getDescriptor() {
            return imageDescriptor;
        }

        @Override
        public boolean isHiddenShown() {
            return false;
        }

        @Override
        public void dropFiles(List<VirtualFile> virtualFiles) {
            if (virtualFiles != null) {
                if (virtualFiles.size() == 1) {
                    VirtualFile chosenFile = virtualFiles.get(0);
                    browseButton.setText(chosenFile.getCanonicalPath());
                    fillImageInformation(chosenFile);
                }
            }
        }
    });
}

From source file:io.ballerina.plugins.idea.runconfig.BallerinaRunUtil.java

License:Open Source License

private static void installFileChooser(@NotNull Project project, @NotNull ComponentWithBrowseButton field,
        @Nullable Condition<VirtualFile> fileFilter) {
    FileChooserDescriptor chooseDirectoryDescriptor = FileChooserDescriptorFactory
            .createSingleFileDescriptor(BallerinaFileType.INSTANCE);
    chooseDirectoryDescriptor.setRoots(project.getBaseDir());
    chooseDirectoryDescriptor.setShowFileSystemRoots(false);
    chooseDirectoryDescriptor.withShowHiddenFiles(false);
    chooseDirectoryDescriptor.withFileFilter(fileFilter);
    if (field instanceof TextFieldWithBrowseButton) {
        ((TextFieldWithBrowseButton) field)
                .addBrowseFolderListener(new TextBrowseFolderListener(chooseDirectoryDescriptor, project));
    } else {/*  www.  j  a va2s .c o  m*/
        //noinspection unchecked
        field.addBrowseFolderListener(project,
                new ComponentWithBrowseButton.BrowseFolderActionListener(null, null, field, project,
                        chooseDirectoryDescriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT));
    }
}

From source file:org.apache.camel.idea.preference.CamelPreferencePage.java

License:Apache License

@Nullable
@Override//from  w  w w  . j av  a 2  s  .c  o  m
public JComponent createComponent() {
    realTimeEndpointValidationCatalogCheckBox = new JBCheckBox(
            "Real time validation of Camel endpoints in editor");
    realTimeSimpleValidationCatalogCheckBox = new JBCheckBox(
            "Real time validation of Camel simple language in editor");
    highlightCustomOptionsCheckBox = new JBCheckBox("Highlight custom endpoint options as warnings in editor");
    downloadCatalogCheckBox = new JBCheckBox("Allow downloading camel-catalog over the internet");
    scanThirdPartyComponentsCatalogCheckBox = new JBCheckBox(
            "Scan classpath for third party Camel components using modern component packaging");
    scanThirdPartyLegacyComponentsCatalogCheckBox = new JBCheckBox(
            "Scan classpath for third party Camel components using legacy component packaging");
    camelIconInGutterCheckBox = new JBCheckBox("Show Camel icon in gutter");
    camelIconsComboBox = new ComboBox<>(new String[] { "Camel Icon", "Camel Badge Icon", "Custom Icon" });
    customIconButton = new TextFieldWithBrowseButton();
    customIconButton.addBrowseFolderListener("Choose Custom Camel Icon", "The icon should be a 16x16 png file",
            null, FileChooserDescriptorFactory.createSingleFileDescriptor("png"));

    camelIconsComboBox.setRenderer(new CamelChosenIconCellRender(customIconButton));
    camelIconsComboBox.addItemListener((l) -> {
        // only enable custom if selected in the drop down
        customIconButton.setEnabled("Custom Icon".equals(l.getItem()));
    });

    // use mig layout which is like a spread-sheet with 2 columns, which we can span if we only have one element
    JPanel panel = new JPanel(new MigLayout("fillx,wrap 2", "[left]rel[grow,fill]"));
    panel.setOpaque(false);

    panel.add(realTimeEndpointValidationCatalogCheckBox, "span 2");
    panel.add(realTimeSimpleValidationCatalogCheckBox, "span 2");
    panel.add(highlightCustomOptionsCheckBox, "span 2");
    panel.add(downloadCatalogCheckBox, "span 2");
    panel.add(scanThirdPartyComponentsCatalogCheckBox, "span 2");
    panel.add(scanThirdPartyLegacyComponentsCatalogCheckBox, "span 2");
    panel.add(camelIconInGutterCheckBox, "span 2");

    panel.add(new JLabel("Camel icon"));
    panel.add(camelIconsComboBox);

    panel.add(new JLabel("Custom icon file path"));
    panel.add(customIconButton);

    JPanel result = new JPanel(new BorderLayout());
    result.add(panel, BorderLayout.NORTH);
    JPanel propertyTablePanel = new JPanel(new VerticalLayout(1));
    propertyTablePanel.add(createPropertyIgnoreTable(), -1);
    propertyTablePanel.add(createExcludePropertyFilesTable(), -1);
    result.add(propertyTablePanel, -1);
    reset();
    return result;
}

From source file:org.jetbrains.jet.plugin.k2jsrun.K2JSRunConfigurationEditor.java

License:Apache License

private void setUpChooseHtmlToShow() {
    FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory
            .createSingleFileDescriptor(StdFileTypes.HTML);
    fileChooserDescriptor.setRoots(ProjectRootManager.getInstance(project).getContentRoots());
    htmlChooseFile.addBrowseFolderListener("Choose file to show after translation is finished", null, project,
            fileChooserDescriptor);// w  ww.j av  a2  s .  c  o m
}

From source file:org.jetbrains.plugins.javaFX.packaging.JavaFxArtifactPropertiesEditor.java

License:Apache License

public JavaFxArtifactPropertiesEditor(JavaFxArtifactProperties properties, final Project project,
        Artifact artifact) {// ww  w  .  java2 s .  com
    super();
    myProperties = properties;
    new JavaFxApplicationClassBrowser(project, artifact).setField(myAppClass);
    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory
            .createSingleFileDescriptor(PropertiesFileType.INSTANCE);
    myHtmlParams.addBrowseFolderListener("Choose Properties File",
            "Parameters for the resulting application to run standalone.", project, descriptor);
    myParams.addBrowseFolderListener("Choose Properties File",
            "Parameters for the resulting application to run in the browser.", project, descriptor);
    myEditSignCertificateButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myDialog = new JavaFxEditCertificatesDialog(myWholePanel, myProperties, project);
            myDialog.show();
        }
    });
    myEnableSigningCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myEditSignCertificateButton.setEnabled(myEnableSigningCB.isSelected());
        }
    });

    final List<String> bundleNames = new ArrayList<String>();
    for (JavaFxPackagerConstants.NativeBundles bundle : JavaFxPackagerConstants.NativeBundles.values()) {
        bundleNames.add(bundle.name());
    }
    myNativeBundleCB.setModel(new DefaultComboBoxModel(ArrayUtil.toObjectArray(bundleNames)));
}

From source file:org.metaborg.intellij.idea.gui.languagesettings.AddLanguageFromArtifactAction.java

License:Apache License

/**
 * {@inheritDoc}//from www  .  j ava2s . com
 */
@Override
public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);

    final FileChooserDescriptor chooserDescriptor = FileChooserDescriptorFactory
            .createSingleFileDescriptor(this.artifactFileType);
    @Nullable
    final VirtualFile file = FileChooser.chooseFile(chooserDescriptor, project, null);
    if (file == null)
        return;

    try {
        final Iterable<ILanguageDiscoveryRequest> requests = this.languageManager.requestFromArtifact(file);
        addRequests(requests);
    } catch (final IOException ex) {
        throw LoggerUtils2.exception(this.logger, UnhandledException.class,
                "Unhandled exception while requesting languages from artifact: {}", ex, file);
    }
}

From source file:org.twodividedbyzero.idea.findbugs.gui.settings.ShareTab.java

License:Open Source License

ShareTab(@NotNull final Project project, @Nullable final Module module) {
    super(new VerticalFlowLayout(HAlignment.Left, VAlignment.Top, 0, 0, true, false));
    this.project = project;
    importFilePathKey = module != null ? module.getName() : WorkspaceSettings.PROJECT_IMPORT_FILE_PATH_KEY;

    description = new JLabel("<html>" + ResourcesLoader.getString("share.description"));
    description.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    description.setIcon(MessageType.INFO.getDefaultIcon());
    description.setDisabledIcon(MessageType.INFO.getDefaultIcon());

    final String url = ResourcesLoader.getString("share.url");
    link = new HyperlinkLabel(); // LATER: HotspotPainter (Search) does not work with HyperlinkLabel
    link.setHyperlinkText(url);//from w w w  . ja v  a  2 s .co m
    link.setHyperlinkTarget(url);

    final JPanel linkPane = new JPanel(
            new FlowLayout(FlowLayout.LEFT, MessageType.INFO.getDefaultIcon().getIconWidth() + 5, 0));
    linkPane.add(link);

    final FileChooserDescriptor descriptor = FileChooserDescriptorFactory
            .createSingleFileDescriptor(XmlFileType.INSTANCE);
    final FileTextField field = FileChooserFactory.getInstance().createFileTextField(descriptor, this);
    final TextFieldWithBrowseButton importPath = new TextFieldWithBrowseButton(field.getField());
    importPath.addBrowseFolderListener(ResourcesLoader.getString("settings.choose.title"),
            ResourcesLoader.getString("settings.choose.description"), null, descriptor);
    importPathLabel = new LabeledComponent<TextFieldWithBrowseButton>();
    importPathLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
    importPathLabel.setComponent(importPath);
    importPathLabel.setLabelLocation(BorderLayout.WEST);
    importPathLabel.setText(ResourcesLoader.getString("share.file.title"));

    add(description);
    add(linkPane);
    add(importPathLabel);
}