Example usage for com.intellij.openapi.ui Messages showInputDialog

List of usage examples for com.intellij.openapi.ui Messages showInputDialog

Introduction

In this page you can find the example usage for com.intellij.openapi.ui Messages showInputDialog.

Prototype

@Nullable
    public static String showInputDialog(@NotNull Component parent, String message,
            @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon,
            @Nullable String initialValue, @Nullable InputValidator validator) 

Source Link

Usage

From source file:com.intellij.uiDesigner.palette.EditGroupAction.java

License:Apache License

public void actionPerformed(AnActionEvent e) {
    Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
    GroupItem groupToBeEdited = GroupItem.DATA_KEY.getData(e.getDataContext());
    if (groupToBeEdited == null || project == null)
        return;//  w  w  w .  j a v  a 2s  .c o  m

    // Ask group name
    final String groupName = Messages.showInputDialog(project,
            UIDesignerBundle.message("edit.enter.group.name"), UIDesignerBundle.message("title.edit.group"),
            Messages.getQuestionIcon(), groupToBeEdited.getName(), null);
    if (groupName == null || groupName.equals(groupToBeEdited.getName())) {
        return;
    }

    Palette palette = Palette.getInstance(project);
    final ArrayList<GroupItem> groups = palette.getGroups();
    for (int i = groups.size() - 1; i >= 0; i--) {
        if (groupName.equals(groups.get(i).getName())) {
            Messages.showErrorDialog(project, UIDesignerBundle.message("error.group.name.unique"),
                    CommonBundle.getErrorTitle());
            return;
        }
    }

    groupToBeEdited.setName(groupName);
    palette.fireGroupsChanged();
}

From source file:com.intellij.uiDesigner.propertyInspector.editors.string.StringEditorDialog.java

License:Apache License

private static String promptNewKeyName(final Project project, final PropertiesFile propFile, final String key) {
    String newName;/*  w w  w .  j a  v a 2 s. c o m*/
    int index = 0;
    do {
        index++;
        newName = key + index;
    } while (propFile.findPropertyByKey(newName) != null);

    InputValidator validator = new InputValidator() {
        public boolean checkInput(String inputString) {
            return inputString.length() > 0 && propFile.findPropertyByKey(inputString) == null;
        }

        public boolean canClose(String inputString) {
            return checkInput(inputString);
        }
    };
    return Messages.showInputDialog(project, UIDesignerBundle.message("edit.text.unique.key.prompt"),
            UIDesignerBundle.message("edit.text.multiple.usages.title"), Messages.getQuestionIcon(), newName,
            validator);
}

From source file:com.intellij.uiDesigner.propertyInspector.properties.CustomCreateProperty.java

License:Apache License

protected void setValueImpl(final RadComponent component, final Boolean value) throws Exception {
    if (value.booleanValue() && component.getBinding() == null) {
        String initialBinding = BindingProperty.getDefaultBinding(component);
        String binding = Messages.showInputDialog(component.getProject(),
                UIDesignerBundle.message("custom.create.field.name.prompt"),
                UIDesignerBundle.message("custom.create.title"), Messages.getQuestionIcon(), initialBinding,
                new IdentifierValidator(component.getProject()));
        if (binding == null) {
            return;
        }/*from   w w  w  .  j  ava2 s . c  o m*/
        try {
            new BindingProperty(component.getProject()).setValue(component, binding);
        } catch (Exception e1) {
            LOG.error(e1);
        }
    }
    component.setCustomCreate(value.booleanValue());
    if (value.booleanValue()) {
        final IRootContainer root = FormEditingUtil.getRoot(component);
        if (root.getClassToBind() != null && Utils.getCustomCreateComponentCount(root) == 1) {
            final PsiClass aClass = FormEditingUtil.findClassToBind(component.getModule(),
                    root.getClassToBind());
            if (aClass != null && FormEditingUtil.findCreateComponentsMethod(aClass) == null) {
                generateCreateComponentsMethod(aClass);
            }
        }
    }
}

From source file:com.intellij.util.net.HTTPProxySettingsPanel.java

License:Apache License

public HTTPProxySettingsPanel(final HttpConfigurable httpConfigurable) {
    final ButtonGroup group = new ButtonGroup();
    group.add(myUseHTTPProxyRb);//from  ww  w .j  av  a2 s . c  om
    group.add(myAutoDetectProxyRb);
    group.add(myNoProxyRb);
    myNoProxyRb.setSelected(true);

    final ButtonGroup proxyTypeGroup = new ButtonGroup();
    proxyTypeGroup.add(myHTTP);
    proxyTypeGroup.add(mySocks);
    myHTTP.setSelected(true);

    myProxyExceptions.setBorder(UIUtil.getTextFieldBorder());

    final Boolean property = Boolean.getBoolean(JavaProxyProperty.USE_SYSTEM_PROXY);
    mySystemProxyDefined.setVisible(Boolean.TRUE.equals(property));
    if (Boolean.TRUE.equals(property)) {
        mySystemProxyDefined.setIcon(Messages.getWarningIcon());
        mySystemProxyDefined.setFont(mySystemProxyDefined.getFont().deriveFont(Font.BOLD));
        mySystemProxyDefined.setUI(new MultiLineLabelUI());
    }

    myProxyAuthCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            enableProxyAuthentication(myProxyAuthCheckBox.isSelected());
        }
    });

    final ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            enableProxy(myUseHTTPProxyRb.isSelected());
        }
    };
    myUseHTTPProxyRb.addActionListener(listener);
    myAutoDetectProxyRb.addActionListener(listener);
    myNoProxyRb.addActionListener(listener);
    myHttpConfigurable = httpConfigurable;

    myClearPasswordsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myHttpConfigurable.clearGenericPasswords();
            Messages.showMessageDialog(myMainPanel, "Proxy passwords were cleared.", "Auto-detected proxy",
                    Messages.getInformationIcon());
        }
    });

    if (HttpConfigurable.getInstance() != null) {
        myCheckButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                final String title = "Check Proxy Settings";
                final String answer = Messages.showInputDialog(myMainPanel,
                        "Warning: your settings will be saved.\n\nEnter any URL to check connection to:", title,
                        Messages.getQuestionIcon(), "http://", null);
                if (!StringUtil.isEmptyOrSpaces(answer)) {
                    apply();
                    final HttpConfigurable instance = HttpConfigurable.getInstance();
                    final AtomicReference<IOException> exc = new AtomicReference<IOException>();
                    myCheckButton.setEnabled(false);
                    myCheckButton.setText("Check connection (in progress...)");
                    myConnectionCheckInProgress = true;
                    final Application application = ApplicationManager.getApplication();
                    application.executeOnPooledThread(new Runnable() {
                        @Override
                        public void run() {
                            HttpURLConnection connection = null;
                            try {
                                //already checked for null above
                                //noinspection ConstantConditions
                                connection = instance.openHttpConnection(answer);
                                connection.setReadTimeout(3 * 1000);
                                connection.setConnectTimeout(3 * 1000);
                                connection.connect();
                                final int code = connection.getResponseCode();
                                if (HttpURLConnection.HTTP_OK != code) {
                                    exc.set(new IOException("Error code: " + code));
                                }
                            } catch (IOException e1) {
                                exc.set(e1);
                            } finally {
                                if (connection != null) {
                                    connection.disconnect();
                                }
                            }
                            //noinspection SSBasedInspection
                            SwingUtilities.invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    myConnectionCheckInProgress = false;
                                    reset(); // since password might have been set
                                    Component parent = null;
                                    if (myMainPanel.isShowing()) {
                                        parent = myMainPanel;
                                        myCheckButton.setText("Check connection");
                                        myCheckButton.setEnabled(canEnableConnectionCheck());
                                    } else {
                                        final IdeFrame frame = IdeFocusManager.findInstance()
                                                .getLastFocusedFrame();
                                        if (frame == null) {
                                            return;
                                        }
                                        parent = frame.getComponent();
                                    }
                                    //noinspection ThrowableResultOfMethodCallIgnored
                                    final IOException exception = exc.get();
                                    if (exception == null) {
                                        Messages.showMessageDialog(parent, "Connection successful", title,
                                                Messages.getInformationIcon());
                                    } else {
                                        final String message = exception.getMessage();
                                        if (instance.USE_HTTP_PROXY) {
                                            instance.LAST_ERROR = message;
                                        }
                                        Messages.showErrorDialog(parent, errorText(message));
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });
    } else {
        myCheckButton.setVisible(false);
    }
}

From source file:com.intellij.util.net.HttpProxySettingsUi.java

License:Apache License

private void configureCheckButton() {
    if (HttpConfigurable.getInstance() == null) {
        myCheckButton.setVisible(false);
        return;//from  ww w. j a v a  2 s. co m
    }

    myCheckButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            final String title = "Check Proxy Settings";
            final String answer = Messages.showInputDialog(myMainPanel,
                    "Warning: your settings will be saved.\n\nEnter any URL to check connection to:", title,
                    Messages.getQuestionIcon(), "http://", null);
            if (StringUtil.isEmptyOrSpaces(answer)) {
                return;
            }

            final HttpConfigurable settings = HttpConfigurable.getInstance();
            apply(settings);
            final AtomicReference<IOException> exceptionReference = new AtomicReference<IOException>();
            myCheckButton.setEnabled(false);
            myCheckButton.setText("Check connection (in progress...)");
            myConnectionCheckInProgress = true;
            ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
                @Override
                public void run() {
                    HttpURLConnection connection = null;
                    try {
                        //already checked for null above
                        //noinspection ConstantConditions
                        connection = settings.openHttpConnection(answer);
                        connection.setReadTimeout(3 * 1000);
                        connection.setConnectTimeout(3 * 1000);
                        connection.connect();
                        final int code = connection.getResponseCode();
                        if (HttpURLConnection.HTTP_OK != code) {
                            exceptionReference.set(new IOException("Error code: " + code));
                        }
                    } catch (IOException e) {
                        exceptionReference.set(e);
                    } finally {
                        if (connection != null) {
                            connection.disconnect();
                        }
                    }
                    //noinspection SSBasedInspection
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            myConnectionCheckInProgress = false;
                            reset(settings); // since password might have been set
                            Component parent;
                            if (myMainPanel.isShowing()) {
                                parent = myMainPanel;
                                myCheckButton.setText("Check connection");
                                myCheckButton.setEnabled(canEnableConnectionCheck());
                            } else {
                                IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
                                if (frame == null) {
                                    return;
                                }
                                parent = frame.getComponent();
                            }
                            //noinspection ThrowableResultOfMethodCallIgnored
                            final IOException exception = exceptionReference.get();
                            if (exception == null) {
                                Messages.showMessageDialog(parent, "Connection successful", title,
                                        Messages.getInformationIcon());
                            } else {
                                final String message = exception.getMessage();
                                if (settings.USE_HTTP_PROXY) {
                                    settings.LAST_ERROR = message;
                                }
                                Messages.showErrorDialog(parent, errorText(message));
                            }
                        }
                    });
                }
            });
        }
    });
}

From source file:com.perl5.lang.mason2.idea.configuration.MasonSettingsConfigurable.java

License:Apache License

protected void createAutobaseNamesComponent(FormBuilder builder) {
    autobaseModel = new CollectionListModel<String>();
    autobaseList = new JBList(autobaseModel);
    builder.addLabeledComponent(new JLabel(
            "Autobase names (autobase_names option. Order is important, later components may be inherited from early):"),
            ToolbarDecorator.createDecorator(autobaseList).setAddAction(new AnActionButtonRunnable() {
                @Override/*from   www.jav a  2  s . co m*/
                public void run(AnActionButton anActionButton) {
                    String fileName = Messages.showInputDialog(myProject, "Type new Autobase filename:",
                            "New Autobase Filename", Messages.getQuestionIcon(), "", null);
                    if (StringUtil.isNotEmpty(fileName) && !autobaseModel.getItems().contains(fileName)) {
                        autobaseModel.add(fileName);
                    }
                }
            }).setPreferredSize(JBUI.size(0, PerlConfigurationUtil.WIDGET_HEIGHT)).createPanel());
}

From source file:com.perl5.lang.perl.extensions.generation.PerlCodeGeneratorImpl.java

License:Apache License

protected List<String> askFieldsNames(Project project, String promptText, String promptTitle) {
    Set<String> result = new THashSet<String>();
    String name = Messages.showInputDialog(project, promptText, promptTitle, Messages.getQuestionIcon(), "",
            null);/*from  w  w w.  j av  a 2 s.  c o  m*/

    if (!StringUtil.isEmpty(name)) {

        for (String nameChunk : name.split("[ ,]+")) {
            if (!nameChunk.isEmpty() && PerlLexer.IDENTIFIER_PATTERN.matcher(nameChunk).matches()) {
                result.add(nameChunk);
            }
        }
    }
    return new ArrayList<String>(result);
}

From source file:com.perl5.lang.perl.idea.configuration.settings.PerlSettingsConfigurable.java

License:Apache License

@Nullable
@Override/*  w ww.  ja  v a  2 s .c o m*/
public JComponent createComponent() {
    FormBuilder builder = FormBuilder.createFormBuilder();
    builder.getPanel().setLayout(new VerticalFlowLayout());

    if (!PlatformUtils.isIntelliJ()) {
        createMicroIdeComponents(builder);
    }

    simpleMainCheckbox = new JCheckBox(
            "Use simple main:: subs resolution (many scripts with same named subs in main:: namespace)");
    builder.addComponent(simpleMainCheckbox);

    autoInjectionCheckbox = new JCheckBox("Automatically inject other languages in here-docs by marker text");
    builder.addComponent(autoInjectionCheckbox);

    allowInjectionWithInterpolation = new JCheckBox(
            "Allow injections in QQ here-docs with interpolated entities");
    builder.addComponent(allowInjectionWithInterpolation);

    perlTryCatchCheckBox = new JCheckBox("Enable TryCatch syntax extension");
    builder.addComponent(perlTryCatchCheckBox);

    perlAnnotatorCheckBox = new JCheckBox("Enable perl -cw annotations [NYI]");
    //      builder.addComponent(perlAnnotatorCheckBox);

    perlCriticCheckBox = new JCheckBox("Enable Perl::Critic annotations (should be installed)");
    builder.addComponent(perlCriticCheckBox);

    perlCriticPathInputField = new TextFieldWithBrowseButton();
    perlCriticPathInputField.setEditable(false);
    FileChooserDescriptor perlCriticDescriptor = new FileChooserDescriptor(true, false, false, false, false,
            false) {
        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            if (!super.isFileVisible(file, showHiddenFiles))
                return false;

            return file.isDirectory()
                    || StringUtil.equals(file.getName(), PerlCriticAnnotator.PERL_CRITIC_NAME);
        }
    };

    perlCriticPathInputField.addBrowseFolderListener("Select file", "Choose a Perl::Critic executable", null, // project
            perlCriticDescriptor);
    builder.addLabeledComponent(new JLabel("Path to PerlCritic executable:"), perlCriticPathInputField);
    perlCriticArgsInputField = new RawCommandLineEditor();
    builder.addComponent(copyDialogCaption(
            LabeledComponent.create(perlCriticArgsInputField, "Perl::Critic command line arguments:"),
            "Perl::Critic command line arguments:"));

    perlTidyPathInputField = new TextFieldWithBrowseButton();
    perlTidyPathInputField.setEditable(false);
    FileChooserDescriptor perlTidyDescriptor = new FileChooserDescriptor(true, false, false, false, false,
            false) {
        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            if (!super.isFileVisible(file, showHiddenFiles))
                return false;

            return file.isDirectory()
                    || StringUtil.equals(file.getName(), PerlFormatWithPerlTidyAction.PERL_TIDY_NAME);
        }
    };

    perlTidyPathInputField.addBrowseFolderListener("Select file", "Choose a Perl::Tidy executable", null, // project
            perlTidyDescriptor);
    builder.addLabeledComponent(new JLabel("Path to PerlTidy executable:"), perlTidyPathInputField);
    perlTidyArgsInputField = new RawCommandLineEditor();
    builder.addComponent(copyDialogCaption(
            LabeledComponent.create(perlTidyArgsInputField,
                    "Perl::Tidy command line arguments (-se -se arguments will be added automatically):"),
            "Perl::Tidy command line arguments:"));

    regeneratePanel = new JPanel(new BorderLayout());
    regenerateButton = new JButton("Re-generate XSubs declarations");
    regenerateButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PerlXSubsState.getInstance(myProject).reparseXSubs();
        }
    });
    regeneratePanel.add(regenerateButton, BorderLayout.WEST);
    builder.addComponent(regeneratePanel);

    deparseArgumentsTextField = new JTextField();
    builder.addLabeledComponent("Comma-separated B::Deparse options for deparse action",
            deparseArgumentsTextField);

    selfNamesModel = new CollectionListModel<String>();
    selfNamesList = new JBList(selfNamesModel);
    builder.addLabeledComponent(
            new JLabel("Scalar names considered as an object self-reference (without a $):"),
            ToolbarDecorator.createDecorator(selfNamesList).setAddAction(new AnActionButtonRunnable() {
                @Override
                public void run(AnActionButton anActionButton) {
                    String variableName = Messages.showInputDialog(myProject, "Type variable name:",
                            "New Self-Reference Variable Name", Messages.getQuestionIcon(), "", null);
                    if (StringUtil.isNotEmpty(variableName)) {
                        while (variableName.startsWith("$")) {
                            variableName = variableName.substring(1);
                        }

                        if (StringUtil.isNotEmpty(variableName)
                                && !selfNamesModel.getItems().contains(variableName)) {
                            selfNamesModel.add(variableName);
                        }
                    }
                }
            }).createPanel());

    return builder.getPanel();
}

From source file:com.perl5.lang.perl.idea.configuration.settings.sdk.Perl5ProjectConfigurable.java

License:Apache License

@Nullable
@Override/*  www.j  a va  2  s  .  c o  m*/
public JComponent createComponent() {
    FormBuilder builder = FormBuilder.createFormBuilder();
    builder.getPanel().setLayout(new VerticalFlowLayout());

    builder.addComponent(myPerl5SdkConfigurable.createComponent());

    FormBuilder versionBuilder = FormBuilder.createFormBuilder();
    ComboBoxModel<PerlVersion> versionModel = new CollectionComboBoxModel<>(PerlVersion.ALL_VERSIONS);
    myTargetPerlVersionComboBox = new ComboBox<>(versionModel);
    myTargetPerlVersionComboBox.setRenderer(new ColoredListCellRenderer<PerlVersion>() {
        @Override
        protected void customizeCellRenderer(@NotNull JList<? extends PerlVersion> list, PerlVersion value,
                int index, boolean selected, boolean hasFocus) {
            append(value.getStrictDottedVersion());
            String versionDescription = PerlVersion.PERL_VERSION_DESCRIPTIONS.get(value);
            if (StringUtil.isNotEmpty(versionDescription)) {
                append(" (" + versionDescription + ")");
            }
        }
    });
    versionBuilder.addLabeledComponent(PerlBundle.message("perl.config.language.level"),
            myTargetPerlVersionComboBox);
    builder.addComponent(versionBuilder.getPanel());

    myLibsModel = new CollectionListModel<>();
    myLibsList = new JBList<>(myLibsModel);
    myLibsList.setVisibleRowCount(ourRowsCount);
    myLibsList.setCellRenderer(new ColoredListCellRenderer<VirtualFile>() {
        @Override
        protected void customizeCellRenderer(@NotNull JList<? extends VirtualFile> list, VirtualFile value,
                int index, boolean selected, boolean hasFocus) {
            setIcon(PerlIcons.PERL_LANGUAGE_ICON);
            append(FileUtil.toSystemDependentName(value.getPath()));
        }
    });
    builder.addLabeledComponent(PerlBundle.message("perl.settings.external.libs"), ToolbarDecorator
            .createDecorator(myLibsList).setAddAction(this::doAddExternalLibrary).createPanel());

    simpleMainCheckbox = new JCheckBox(PerlBundle.message("perl.config.simple.main"));
    builder.addComponent(simpleMainCheckbox);

    autoInjectionCheckbox = new JCheckBox(PerlBundle.message("perl.config.heredoc.injections"));
    builder.addComponent(autoInjectionCheckbox);

    allowInjectionWithInterpolation = new JCheckBox(PerlBundle.message("perl.config.heredoc.injections.qq"));
    builder.addComponent(allowInjectionWithInterpolation);

    allowRegexpInjections = new JCheckBox(PerlBundle.message("perl.config.regex.injections"));
    builder.addComponent(allowRegexpInjections);
    allowRegexpInjections.setEnabled(false);
    allowRegexpInjections.setVisible(false);

    perlAnnotatorCheckBox = new JCheckBox(PerlBundle.message("perl.config.annotations.cw"));
    //      builder.addComponent(perlAnnotatorCheckBox);

    perlCriticCheckBox = new JCheckBox(PerlBundle.message("perl.config.annotations.critic"));
    builder.addComponent(perlCriticCheckBox);

    enablePerlSwitchCheckbox = new JCheckBox(PerlBundle.message("perl.config.enable.switch"));
    builder.addComponent(enablePerlSwitchCheckbox);

    perlCriticPathInputField = new TextFieldWithBrowseButton();
    perlCriticPathInputField.setEditable(false);
    FileChooserDescriptor perlCriticDescriptor = new FileChooserDescriptor(true, false, false, false, false,
            false) {
        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || StringUtil
                    .equals(file.getNameWithoutExtension(), PerlCriticAnnotator.PERL_CRITIC_LINUX_NAME));
        }
    };

    //noinspection DialogTitleCapitalization
    perlCriticPathInputField.addBrowseFolderListener(PerlBundle.message("perl.config.select.file.title"),
            PerlBundle.message("perl.config.select.critic"), null, // project
            perlCriticDescriptor);
    builder.addLabeledComponent(new JLabel(PerlBundle.message("perl.config.path.critic")),
            perlCriticPathInputField);
    perlCriticArgsInputField = new RawCommandLineEditor();
    builder.addComponent(copyDialogCaption(
            LabeledComponent.create(perlCriticArgsInputField,
                    PerlBundle.message("perl.config.critic.cmd.arguments")),
            PerlBundle.message("perl.config.critic.cmd.arguments")));

    perlTidyPathInputField = new TextFieldWithBrowseButton();
    perlTidyPathInputField.setEditable(false);
    FileChooserDescriptor perlTidyDescriptor = new FileChooserDescriptor(true, false, false, false, false,
            false) {
        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || StringUtil
                    .equals(file.getNameWithoutExtension(), PerlFormatWithPerlTidyAction.PERL_TIDY_LINUX_NAME));
        }
    };

    //noinspection DialogTitleCapitalization
    perlTidyPathInputField.addBrowseFolderListener(PerlBundle.message("perl.config.select.file.title"),
            PerlBundle.message("perl.config.select.tidy"), null, // project
            perlTidyDescriptor);
    builder.addLabeledComponent(new JLabel(PerlBundle.message("perl.config.path.tidy")),
            perlTidyPathInputField);
    perlTidyArgsInputField = new RawCommandLineEditor();
    builder.addComponent(copyDialogCaption(
            LabeledComponent.create(perlTidyArgsInputField,
                    PerlBundle.message("perl.config.tidy.options.label")),
            PerlBundle.message("perl.config.tidy.options.label.short")));

    JPanel regeneratePanel = new JPanel(new BorderLayout());
    JButton regenerateButton = new JButton(PerlBundle.message("perl.config.generate.xsubs"));
    regenerateButton.addActionListener(e -> PerlXSubsState.getInstance(myProject).reparseXSubs());
    regeneratePanel.add(regenerateButton, BorderLayout.WEST);
    builder.addComponent(regeneratePanel);

    deparseArgumentsTextField = new JTextField();
    builder.addLabeledComponent(PerlBundle.message("perl.config.deparse.options.label"),
            deparseArgumentsTextField);

    selfNamesModel = new CollectionListModel<>();
    JBList selfNamesList = new JBList<>(selfNamesModel);
    selfNamesList.setVisibleRowCount(ourRowsCount);
    builder.addLabeledComponent(new JLabel(PerlBundle.message("perl.config.self.names.label")),
            ToolbarDecorator.createDecorator(selfNamesList).setAddAction(anActionButton -> {
                String variableName = Messages.showInputDialog(myProject,
                        PerlBundle.message("perl.config.self.add.text"),
                        PerlBundle.message("perl.config.self.add.title"), Messages.getQuestionIcon(), "", null);
                if (StringUtil.isNotEmpty(variableName)) {
                    while (variableName.startsWith("$")) {
                        variableName = variableName.substring(1);
                    }

                    if (StringUtil.isNotEmpty(variableName)
                            && !selfNamesModel.getItems().contains(variableName)) {
                        selfNamesModel.add(variableName);
                    }
                }
            }).createPanel());

    JBScrollPane scrollPane = new JBScrollPane(builder.getPanel(),
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(new JBEmptyBorder(JBUI.emptyInsets()));
    return scrollPane;
}

From source file:com.perl5.lang.perl.idea.configuration.settings.sdk.Perl5SdkConfigurable.java

License:Apache License

private void renameSdk(ActionEvent e) {
    Sdk selectedSdk = getSelectedSdk();//from  w w w  . j av  a  2  s .com
    if (selectedSdk == null) {
        return;
    }
    PerlSdkTable perlSdkTable = PerlSdkTable.getInstance();
    Messages.showInputDialog(myPanel.getSdkComboBox(), PerlBundle.message("perl.rename.sdk.text"),
            PerlBundle.message("perl.rename.sdk.title"), PerlIcons.PERL_LANGUAGE_ICON, selectedSdk.getName(),
            new InputValidator() {
                @Override
                public boolean checkInput(String inputString) {
                    if (StringUtil.isEmpty(inputString)) {
                        return false;
                    }
                    Sdk perlSdk = perlSdkTable.findJdk(inputString);
                    return perlSdk == null || perlSdk.equals(selectedSdk);
                }

                @Override
                public boolean canClose(String inputString) {
                    if (StringUtil.equals(selectedSdk.getName(), inputString)) {
                        return true;
                    }
                    SdkModificator modificator = selectedSdk.getSdkModificator();
                    modificator.setName(inputString);
                    assert modificator instanceof Sdk;
                    perlSdkTable.updateJdk(selectedSdk, (Sdk) modificator);
                    myPanel.getSdkComboBox().repaint();
                    return true;
                }
            });
}