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

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

Introduction

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

Prototype

TextFieldWithBrowseButton.NoPathCompletion

Source Link

Usage

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

License:Apache License

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

    packageTest.setSelected(false);// w w  w  .  ja v  a 2 s .c o 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);
}