Example usage for com.intellij.openapi.ui TextFieldWithBrowseButton TextFieldWithBrowseButton

List of usage examples for com.intellij.openapi.ui TextFieldWithBrowseButton TextFieldWithBrowseButton

Introduction

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

Prototype

public TextFieldWithBrowseButton() 

Source Link

Usage

From source file:com.oracle.plugin.jtreg.configuration.ui.JTRegConfigurable.java

License:Open Source License

private void createUIComponents() {
    jrePathEditor = new JrePathEditor(DefaultJreSelector.projectSdk(project));
    jtregDir = new TextFieldWithBrowseButton();
    jtregDir.addBrowseFolderListener("Directory with Strategies", null, project,
            FileChooserDescriptorFactory.createSingleFolderDescriptor());
    workDirectory = new TextFieldWithBrowseButton();
    workDirectory.addBrowseFolderListener("Directory with Strategies", null, project,
            FileChooserDescriptorFactory.createSingleFolderDescriptor());
    file = new TextFieldWithBrowseButton();
    file.addBrowseFolderListener("File with Strategies", null, project,
            FileChooserDescriptorFactory.createSingleFileDescriptor());
    directory = new TextFieldWithBrowseButton();
    directory.addBrowseFolderListener("Directory with Strategies", null, project,
            FileChooserDescriptorFactory.createSingleFolderDescriptor());
}

From source file:com.oracle.plugin.jtreg.service.ui.JTRegServiceConfigurable.java

License:Open Source License

private void createUIComponents() {
    jrePathEditor = new JrePathEditor(DefaultJreSelector.projectSdk(project));
    jtregDir = new TextFieldWithBrowseButton();
    jtregDir.addBrowseFolderListener("Directory with Strategies", null, project,
            FileChooserDescriptorFactory.createSingleFolderDescriptor());
    workDir = new TextFieldWithBrowseButton();
    workDir.addBrowseFolderListener("Directory with Strategies", null, project,
            FileChooserDescriptorFactory.createSingleFolderDescriptor());
    myModel = new CollectionListModel<>();
    JBList myList = new JBList(myModel);
    myList.getEmptyText().setText(ExecutionBundle.message("before.launch.panel.empty"));
    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.setCellRenderer(new MyListCellRenderer());

    ToolbarDecorator myDecorator = ToolbarDecorator.createDecorator(myList);
    if (!SystemInfo.isMac) {
        myDecorator.setAsUsualTopToolbar();
    }/*from   ww w .  ja  v a2  s  .c o  m*/

    antConfiguration.ensureInitialized();
    boolean antConfigEnabled = JTRegUtils.getAntBuildFiles(antConfiguration).length != 0;

    myDecorator.setEditAction(new AnActionButtonRunnable() {
        @Override
        public void run(AnActionButton button) {
            int index = myList.getSelectedIndex();
            if (index == -1)
                return;
            AntBuildTarget prevTarget = myModel.getElementAt(index);
            AntBuildTarget newTarget = pickTarget(prevTarget);
            if (newTarget != null) {
                myModel.setElementAt(newTarget, index);
            }
        }
    });
    myDecorator.setEditActionUpdater(new AnActionButtonUpdater() {
        @Override
        public boolean isEnabled(AnActionEvent e) {
            int index = myList.getSelectedIndex();
            return index != -1;
        }
    });
    myDecorator.setAddAction(new AnActionButtonRunnable() {
        @Override
        public void run(AnActionButton button) {
            AntBuildTarget target = pickTarget(null);
            myModel.add(target);
        }
    });
    myDecorator.setAddActionUpdater(new AnActionButtonUpdater() {
        @Override
        public boolean isEnabled(AnActionEvent e) {
            return antConfigEnabled;
        }
    });
    myListPane = myDecorator.createPanel();
}

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

License:Apache License

@Nullable
@Override/*from   www.  j  a v  a2  s .c om*/
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.PerlSettingsConfigurable.java

License:Apache License

protected void createMicroIdeComponents(FormBuilder builder) {
    perlPathInputField = new TextFieldWithBrowseButton() {

        @Override/*from  www.ja va2s. c o m*/
        public void addBrowseFolderListener(@Nullable String title, @Nullable String description,
                @Nullable Project project, FileChooserDescriptor fileChooserDescriptor,
                TextComponentAccessor<JTextField> accessor, boolean autoRemoveOnHide) {
            addBrowseFolderListener(project, new BrowseFolderActionListener<JTextField>(title, description,
                    this, project, fileChooserDescriptor, accessor) {
                @Nullable
                @Override
                protected VirtualFile getInitialFile() {
                    VirtualFile virtualFile = super.getInitialFile();
                    if (virtualFile == null) {
                        String directoryName = PerlRunUtil.getPathFromPerl();
                        if (StringUtil.isNotEmpty(directoryName)) {
                            directoryName = FileUtil.toSystemIndependentName(directoryName);
                            VirtualFile path = LocalFileSystem.getInstance()
                                    .findFileByPath(expandPath(directoryName));
                            while (path == null && directoryName.length() > 0) {
                                int pos = directoryName.lastIndexOf('/');
                                if (pos <= 0)
                                    break;
                                directoryName = directoryName.substring(0, pos);
                                path = LocalFileSystem.getInstance().findFileByPath(directoryName);
                            }
                            return path;
                        }
                    }
                    return virtualFile;
                }
            }, autoRemoveOnHide);
        }
    };

    perlPathInputField.getTextField().setEditable(false);

    FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
        @Override
        public void validateSelectedFiles(VirtualFile[] files) throws Exception {
            PerlSdkType sdkType = PerlSdkType.getInstance();
            if (!sdkType.isValidSdkHome(files[0].getCanonicalPath()))
                throw new ConfigurationException("Unable to locate perl5 executable");
        }
    };

    perlPathInputField.addBrowseFolderListener("Perl5 Interpreter", "Choose a directory with perl5 executable:",
            null, // project
            descriptor);

    builder.addLabeledComponent("Perl5 interpreter path: ", perlPathInputField, 1);
}

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

License:Apache License

@Nullable
@Override//  ww  w.  ja  v  a2s. 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.run.PerlConfigurationEditor.java

License:Apache License

@NotNull
@Override//from   w ww. j a  v a  2 s.co m
protected JComponent createEditor() {
    myScriptField = new TextFieldWithBrowseButton();
    myScriptField.addBrowseFolderListener("Select Perl Script", "Please select perl script file", myProject,
            FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()
                    .withFileFilter(new Condition<VirtualFile>() {
                        @Override
                        public boolean value(VirtualFile virtualFile) {
                            return PerlConfigurationProducer.isExecutableFile(virtualFile);
                        }
                    }),
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);

    myStartMode = new ComboBox(new MapComboBoxModel<String, String>(PerlDebugOptionsSets.STARTUP_OPTIONS)) {
        @Override
        public void setRenderer(ListCellRenderer renderer) {
            super.setRenderer(new ColoredListCellRenderer<String>() {
                @Override
                protected void customizeCellRenderer(JList list, String value, int index, boolean selected,
                        boolean hasFocus) {
                    append(PerlDebugOptionsSets.STARTUP_OPTIONS.get(value));
                }
            });
        }
    };

    myConsoleCharset = new ComboBox(
            new CollectionComboBoxModel(new ArrayList<String>(Charset.availableCharsets().keySet())));

    myScriptField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent documentEvent) {
            VirtualFile file = LocalFileSystem.getInstance().findFileByPath(myScriptField.getText());
            if (file != null) {
                myConsoleCharset.setSelectedItem(file.getCharset().displayName());
            } else {
                myConsoleCharset.setSelectedItem(null);
            }
        }
    });

    myAlternativeSdkPanel = new PerlAlternativeSdkPanel();

    myParametersPanel = new CommonProgramParametersPanel() {
        @Override
        protected void addComponents() {

            LabeledComponent<?> scriptLabel = LabeledComponent.create(myScriptField, "Script");
            scriptLabel.setLabelLocation(BorderLayout.WEST);
            add(scriptLabel);

            LabeledComponent<?> consoleEncoding = LabeledComponent.create(myConsoleCharset,
                    "Script output encoding");
            consoleEncoding.setLabelLocation(BorderLayout.WEST);
            add(consoleEncoding);

            myScriptCharset = new JTextField();
            LabeledComponent<JTextField> myScriptCharsetLabel = LabeledComponent.create(myScriptCharset,
                    "Script encoding");
            myScriptCharsetLabel.setLabelLocation(BorderLayout.WEST);
            add(myScriptCharsetLabel);

            LabeledComponent<?> startMode = LabeledComponent.create(myStartMode, "Debugger startup mode");
            startMode.setLabelLocation(BorderLayout.WEST);
            add(startMode);

            myPerlParametersPanel = new RawCommandLineEditor();
            LabeledComponent<RawCommandLineEditor> perlParametersPanel = LabeledComponent
                    .create(myPerlParametersPanel, "Perl5 parameters");
            perlParametersPanel.setLabelLocation(BorderLayout.WEST);
            copyDialogCaption(perlParametersPanel);
            add(perlParametersPanel);

            super.addComponents();
            add(myAlternativeSdkPanel);
        }
    };
    myParametersPanel.setProgramParametersLabel("Script parameters:");
    return myParametersPanel;
}

From source file:com.theoryinpractice.testng.configuration.TestNGConfigurationEditor.java

License:Apache License

public TestNGConfigurationEditor(Project project) {
    this.project = project;
    BrowseModuleValueActionListener[] browseListeners = new BrowseModuleValueActionListener[] {
            new PackageBrowser(project), new TestClassBrowser(project, this), new MethodBrowser(project, this),
            new GroupBrowser(project, this), new SuiteBrowser(project), new TestClassBrowser(project, this) {
                @Override/*  ww  w  .jav  a2 s  .  c o m*/
                protected void onClassChoosen(PsiClass psiClass) {
                    final JTextField textField = myPatternTextField.getTextField();
                    final String text = textField.getText();
                    textField.setText(text + (text.length() > 0 ? "||" : "") + psiClass.getQualifiedName());
                }

                @Override
                public void actionPerformed(ActionEvent e) {
                    showDialog();
                }
            } };
    model = new TestNGConfigurationModel(project);
    model.setListener(this);
    createView();
    moduleSelector = new ConfigurationModuleSelector(project, getModulesComponent());
    commonJavaParameters.setModuleContext(moduleSelector.getModule());
    moduleClasspath.getComponent().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            commonJavaParameters.setModuleContext(moduleSelector.getModule());
        }
    });

    final JPanel panel = myPattern.getComponent();
    panel.setLayout(new BorderLayout());
    myPatternTextField = new TextFieldWithBrowseButton();
    myPatternTextField.setButtonIcon(IconUtil.getAddIcon());
    panel.add(myPatternTextField, BorderLayout.CENTER);
    final FixedSizeButton editBtn = new FixedSizeButton();
    editBtn.setIcon(AllIcons.Actions.ShowViewer);
    editBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Messages.showTextAreaDialog(myPatternTextField.getTextField(), "Configure suite tests",
                    "EditParametersPopupWindow");
        }
    });
    panel.add(editBtn, BorderLayout.EAST);

    registerListener(
            new JRadioButton[] { packageTest, classTest, methodTest, groupTest, suiteTest, patternTest },
            new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    ButtonModel buttonModel = (ButtonModel) e.getSource();
                    if (buttonModel.isSelected()) {
                        if (buttonModel == packageTest.getModel()) {
                            model.setType(TestType.PACKAGE);
                        } else if (buttonModel == classTest.getModel()) {
                            model.setType(TestType.CLASS);
                        } else if (buttonModel == methodTest.getModel()) {
                            model.setType(TestType.METHOD);
                        } else if (buttonModel == groupTest.getModel()) {
                            model.setType(TestType.GROUP);
                        } else if (buttonModel == suiteTest.getModel()) {
                            model.setType(TestType.SUITE);
                        } else if (buttonModel == patternTest.getModel()) {
                            model.setType(TestType.PATTERN);
                        }
                        redisplay();
                    }
                }
            });
    registerListener(new JRadioButton[] { packagesInProject, packagesInModule, packagesAcrossModules }, null);
    packagesInProject.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            evaluateModuleClassPath();
        }
    });

    LabeledComponent[] components = new LabeledComponent[] { packageField, classField, methodField, groupField,
            suiteField, myPattern };
    for (int i = 0; i < components.length; i++) {
        JComponent field = components[i].getComponent();
        Object document = model.getDocument(i);
        if (field instanceof TextFieldWithBrowseButton) {
            ((TextFieldWithBrowseButton) field).getTextField().setDocument((PlainDocument) document);
        } else if (field instanceof EditorTextFieldWithBrowseButton) {
            final com.intellij.openapi.editor.Document componentDocument = ((EditorTextFieldWithBrowseButton) field)
                    .getChildComponent().getDocument();
            model.setDocument(i, componentDocument);
        } else {
            field = myPatternTextField;
            document = new PlainDocument();
            ((TextFieldWithBrowseButton) field).getTextField().setDocument((Document) document);
            model.setDocument(i, document);
        }

        browseListeners[i].setField((ComponentWithBrowseButton) field);
    }
    model.setType(TestType.CLASS);
    propertiesFile.getComponent().getTextField().setDocument(model.getPropertiesFileDocument());
    outputDirectory.getComponent().getTextField().setDocument(model.getOutputDirectoryDocument());

    commonJavaParameters.setProgramParametersLabel(
            ExecutionBundle.message("junit.configuration.test.runner.parameters.label"));

    setAnchor(outputDirectory.getLabel());
    alternateJDK.setAnchor(moduleClasspath.getLabel());
    commonJavaParameters.setAnchor(moduleClasspath.getLabel());
}

From source file:com.theoryinpractice.testng.configuration.TestNGConfigurationEditor.java

License:Apache License

private void createView() {
    commonParametersPanel.add(commonJavaParameters, BorderLayout.CENTER);

    packageTest.setSelected(false);// w  ww. j  ava  2 s. co  m
    suiteTest.setSelected(false);
    suiteTest.setEnabled(true);
    groupTest.setSelected(false);
    groupTest.setEnabled(true);
    classTest.setSelected(false);
    classTest.setEnabled(true);
    patternTest.setSelected(false);
    patternTest.setEnabled(true);

    classField.setComponent(
            new EditorTextFieldWithBrowseButton(project, true, new JavaCodeFragment.VisibilityChecker() {
                @Override
                public Visibility isDeclarationVisible(PsiElement declaration, PsiElement place) {
                    try {
                        if (declaration instanceof PsiClass
                                && new TestClassBrowser(project, TestNGConfigurationEditor.this).getFilter()
                                        .isAccepted((PsiClass) declaration)) {
                            return Visibility.VISIBLE;
                        }
                    } catch (MessageInfoException e) {
                        return Visibility.NOT_VISIBLE;
                    }
                    return Visibility.NOT_VISIBLE;
                }
            }));

    final EditorTextFieldWithBrowseButton methodEditorTextField = new EditorTextFieldWithBrowseButton(project,
            true, JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE,
            PlainTextLanguage.INSTANCE.getAssociatedFileType());
    new TextFieldCompletionProvider() {
        @Override
        protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix,
                @NotNull CompletionResultSet result) {
            final String className = getClassName();
            if (className.trim().length() == 0) {
                return;
            }
            final PsiClass testClass = getModuleSelector().findClass(className);
            if (testClass == null)
                return;
            for (PsiMethod psiMethod : testClass.getAllMethods()) {
                if (TestNGUtil.hasTest(psiMethod)) {
                    result.addElement(LookupElementBuilder.create(psiMethod.getName()));
                }
            }
        }
    }.apply(methodEditorTextField.getChildComponent());
    methodField.setComponent(methodEditorTextField);

    groupField.setComponent(new TextFieldWithBrowseButton.NoPathCompletion());
    suiteField.setComponent(new TextFieldWithBrowseButton());
    packageField.setVisible(true);
    packageField.setEnabled(true);
    packageField.setComponent(new EditorTextFieldWithBrowseButton(project, false));

    TextFieldWithBrowseButton outputDirectoryButton = new TextFieldWithBrowseButton();
    outputDirectory.setComponent(outputDirectoryButton);
    outputDirectoryButton.addBrowseFolderListener("TestNG", "Select test output directory", project,
            FileChooserDescriptorFactory.createSingleFolderDescriptor());
    moduleClasspath.setEnabled(true);
    moduleClasspath.setComponent(new JComboBox());

    propertiesTableModel = new TestNGParametersTableModel();
    listenerModel = new TestNGListenersTableModel();

    TextFieldWithBrowseButton textFieldWithBrowseButton = new TextFieldWithBrowseButton();
    propertiesFile.setComponent(textFieldWithBrowseButton);

    FileChooserDescriptor propertiesFileDescriptor = new FileChooserDescriptor(true, false, false, false, false,
            false) {
        @Override
        public boolean isFileVisible(VirtualFile virtualFile, boolean showHidden) {
            if (!showHidden && virtualFile.getName().charAt(0) == '.')
                return false;
            return virtualFile.isDirectory() || "properties".equals(virtualFile.getExtension());
        }
    };

    textFieldWithBrowseButton.addBrowseFolderListener("TestNG", "Select .properties file for test properties",
            project, propertiesFileDescriptor);

    propertiesTableView = new TableView();
    propertiesTableView.setModelAndUpdateColumns(propertiesTableModel);
    propertiesTableView.setShowGrid(true);

    myPropertiesPanel.add(
            ToolbarDecorator.createDecorator(propertiesTableView).setAddAction(new AnActionButtonRunnable() {
                @Override
                public void run(AnActionButton button) {
                    propertiesTableModel.addParameter();
                    int index = propertiesTableModel.getRowCount() - 1;
                    propertiesTableView.setRowSelectionInterval(index, index);
                }
            }).setRemoveAction(new AnActionButtonRunnable() {
                @Override
                public void run(AnActionButton button) {
                    int idx = propertiesTableView.getSelectedRow() - 1;
                    for (int row : propertiesTableView.getSelectedRows()) {
                        propertiesTableModel.removeProperty(row);
                    }
                    if (idx > -1)
                        propertiesTableView.setRowSelectionInterval(idx, idx);
                }
            }).disableUpDownActions().createPanel(), BorderLayout.CENTER);

    myListenersList = new JBList(listenerModel);
    myListenersPanel.add(ToolbarDecorator.createDecorator(myListenersList)
            .setAddAction(new AddActionButtonRunnable()).setRemoveAction(new AnActionButtonRunnable() {
                @Override
                public void run(AnActionButton button) {
                    int idx = myListenersList.getSelectedIndex() - 1;
                    for (int row : myListenersList.getSelectedIndices()) {
                        listenerModel.removeListener(row);
                    }
                    if (idx > -1)
                        myListenersList.setSelectedIndex(idx);
                }
            }).setAddActionUpdater(new AnActionButtonUpdater() {
                @Override
                public boolean isEnabled(AnActionEvent e) {
                    return !project.isDefault();
                }
            }).disableUpDownActions().createPanel(), BorderLayout.CENTER);
}

From source file:consulo.devkit.run.ConsuloRunConfigurationEditorBase.java

License:Apache License

protected void setupPanel(@NotNull FormBuilder builder) {
    ProjectSdksModel projectSdksModel = new ProjectSdksModel();
    if (!projectSdksModel.isInitialized()) {
        projectSdksModel.reset();//from  w w w .  ja v  a2  s  . c  om
    }
    myJavaSdkComboBox = new SdkComboBox(projectSdksModel, new Condition<SdkTypeId>() {
        @Override
        public boolean value(SdkTypeId sdkTypeId) {
            return sdkTypeId instanceof JavaSdk;
        }
    }, false);
    builder.addLabeledComponent("Java SDK", myJavaSdkComboBox);

    myConsuloSdkComboBox = new SdkComboBox(projectSdksModel, new Condition<SdkTypeId>() {
        @Override
        public boolean value(SdkTypeId sdkTypeId) {
            return sdkTypeId instanceof ConsuloSdkType;
        }
    }, true);
    builder.addLabeledComponent("Consulo SDK", myConsuloSdkComboBox);

    myAlternativeConsuloSdkCheckBox = new JBCheckBox("Alt Consulo SDK:");
    myAlternativeConsuloSdkCheckBox.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            myAltConsuloSdkTextField.setEditable(myAlternativeConsuloSdkCheckBox.isSelected());
            myConsuloSdkComboBox.setEnabled(!myAlternativeConsuloSdkCheckBox.isSelected());
        }
    });
    builder.addComponent(myAlternativeConsuloSdkCheckBox);

    myAltConsuloSdkTextField = new TextFieldWithBrowseButton();
    myAltConsuloSdkTextField.addBrowseFolderListener("Select SDK", "Select alternative consulo sdk for run",
            myProject, FileChooserDescriptorFactory.createSingleFolderDescriptor());
    myAltConsuloSdkTextField.setEditable(myAlternativeConsuloSdkCheckBox.isSelected());
    builder.addComponent(myAltConsuloSdkTextField);

    final Artifact[] sortedArtifacts = ArtifactManager.getInstance(myProject).getSortedArtifacts();
    myArtifactComboBox = new ComboBox();
    myArtifactComboBox.addItem(ObjectUtil.NULL);
    for (Artifact sortedArtifact : sortedArtifacts) {
        myArtifactComboBox.addItem(new ArtifactItem(sortedArtifact.getName(), sortedArtifact));
    }

    myArtifactComboBox.setRenderer(new ColoredListCellRenderer() {
        @Override
        protected void customizeCellRenderer(JList list, Object value, int index, boolean selected,
                boolean hasFocus) {
            if (value == ObjectUtil.NULL) {
                append("<None>", SimpleTextAttributes.REGULAR_ATTRIBUTES);
                setIcon(AllIcons.Actions.Help);
                return;
            }

            ArtifactItem artifactItem = (ArtifactItem) value;
            if (artifactItem == null) {
                return;
            }

            final Artifact artifact = artifactItem.myArtifact;
            if (artifact == null) {
                append(artifactItem.myName, SimpleTextAttributes.ERROR_ATTRIBUTES);
                setIcon(AllIcons.Nodes.Artifact);
            } else {
                append(artifactItem.myName, SimpleTextAttributes.REGULAR_ATTRIBUTES);
                setIcon(artifact.getArtifactType().getIcon());
            }
        }
    });

    builder.addLabeledComponent("Plugin Artifact", myArtifactComboBox);

    myProgramParameters = new RawCommandLineEditor();
    builder.addLabeledComponent("Program Parameters", myProgramParameters);
    myVMParameters = new RawCommandLineEditor();
    builder.addLabeledComponent("VM Parameters", myVMParameters);
    myInternalModeBox = new JBCheckBox("Internal Mode");
    builder.addComponent(myInternalModeBox);
}

From source file:io.ballerina.plugins.idea.runconfig.ui.BallerinaApplicationSettingsEditor.java

License:Open Source License

private void createUIComponents() {
    myRunKindComboBox = new LabeledComponent<>();
    myRunKindComboBox.setComponent(new JComboBox<>());

    myFileField = new LabeledComponent<>();
    myFileField.setComponent(new TextFieldWithBrowseButton());

    myPackageField = new LabeledComponent<>();
    myPackageField.setComponent(new BallerinaPackageFieldCompletionProvider(
            () -> myModulesComboBox.getComponent().getSelectedModule()).createEditor(myProject));

    myWorkingDirectoryField = new LabeledComponent<>();
    myWorkingDirectoryField.setComponent(new TextFieldWithBrowseButton());

    myParamsField = new LabeledComponent<>();
    myParamsField.setComponent(new RawCommandLineEditor());

    myBallerinaParamsField = new LabeledComponent<>();
    myBallerinaParamsField.setComponent(new RawCommandLineEditor());

    myModulesComboBox = new LabeledComponent<>();
    myModulesComboBox.setComponent(new ModulesComboBox());
}