Search in sources :

Example 56 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class SshSettingsPanel method init.

private void init() {
    register(myPasswordChoice, SvnConfiguration.SshConnectionType.PASSWORD);
    register(myPrivateKeyChoice, SvnConfiguration.SshConnectionType.PRIVATE_KEY);
    register(mySubversionConfigChoice, SvnConfiguration.SshConnectionType.SUBVERSION_CONFIG);
    ItemListener connectionTypeChangedListener = e -> {
        if (e.getStateChange() == ItemEvent.SELECTED) {
            enableOptions(e.getSource());
        }
    };
    myPasswordChoice.addItemListener(connectionTypeChangedListener);
    myPrivateKeyChoice.addItemListener(connectionTypeChangedListener);
    mySubversionConfigChoice.addItemListener(connectionTypeChangedListener);
    enableOptions(mySubversionConfigChoice);
    registerBrowseDialog(myExecutablePathField, SvnBundle.message("ssh.settings.browse.executable.dialog.title"));
    registerBrowseDialog(myPrivateKeyPathField, SvnBundle.message("ssh.settings.browse.private.key.dialog.title"));
    mySshTunnelField.getEmptyText().setText(SshTunnelRuntimeModule.DEFAULT_SSH_TUNNEL_VALUE);
    mySshTunnelField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            updateSshTunnelDependentValues(mySshTunnelField.getText());
        }
    });
    myUpdateTunnelButton.addActionListener(e -> {
        String tunnel = mySshTunnelField.getText();
        mySvnConfiguration.setSshTunnelSetting(StringUtil.nullize(tunnel));
        setSshTunnelSetting(mySvnConfiguration.getSshTunnelSetting());
    });
}
Also used : ConfigurableUi(com.intellij.openapi.options.ConfigurableUi) UIUtil(com.intellij.util.ui.UIUtil) ItemEvent(java.awt.event.ItemEvent) FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) StringUtil(com.intellij.openapi.util.text.StringUtil) SshTunnelRuntimeModule(org.jetbrains.idea.svn.commandLine.SshTunnelRuntimeModule) JBRadioButton(com.intellij.ui.components.JBRadioButton) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ItemListener(java.awt.event.ItemListener) JBLabel(com.intellij.ui.components.JBLabel) SvnBundle(org.jetbrains.idea.svn.SvnBundle) Nullable(org.jetbrains.annotations.Nullable) JBTextField(com.intellij.ui.components.JBTextField) EnvironmentUtil(com.intellij.util.EnvironmentUtil) PortField(com.intellij.ui.PortField) NotNull(org.jetbrains.annotations.NotNull) SvnConfiguration(org.jetbrains.idea.svn.SvnConfiguration) DocumentEvent(javax.swing.event.DocumentEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) SvnConfigurationState(org.jetbrains.idea.svn.SvnConfigurationState) javax.swing(javax.swing) DocumentAdapter(com.intellij.ui.DocumentAdapter) ItemListener(java.awt.event.ItemListener) DocumentEvent(javax.swing.event.DocumentEvent)

Example 57 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class DependsOnGroupsInspection method createOptionsPanel.

@Override
@Nullable
public JComponent createOptionsPanel() {
    final LabeledComponent<JTextField> definedGroups = new LabeledComponent<>();
    definedGroups.setText("&Defined Groups");
    final JTextField textField = new JTextField(StringUtil.join(ArrayUtil.toStringArray(groups), ","));
    textField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(final DocumentEvent e) {
            groups.clear();
            String text = textField.getText();
            if (!StringUtil.isEmptyOrSpaces(text)) {
                ContainerUtil.addAll(groups, text.split("[, ]"));
            }
        }
    });
    definedGroups.setComponent(textField);
    final JPanel optionsPanel = new JPanel(new BorderLayout());
    optionsPanel.add(definedGroups, BorderLayout.NORTH);
    return optionsPanel;
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class ModuleNameLocationComponent method bindModuleSettings.

public void bindModuleSettings(final NamePathComponent namePathComponent) {
    namePathComponent.getNameComponent().getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            if (!myModuleNameChangedByUser) {
                setModuleName(namePathComponent.getNameValue());
            }
        }
    });
    myModuleContentRoot.addBrowseFolderListener(ProjectBundle.message("project.new.wizard.module.content.root.chooser.title"), ProjectBundle.message("project.new.wizard.module.content.root.chooser.description"), myWizardContext.getProject(), BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);
    namePathComponent.getPathComponent().getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            if (!myContentRootChangedByUser) {
                setModuleContentRoot(namePathComponent.getPath());
            }
        }
    });
    myModuleName.getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            if (!myUpdatePathsWhenNameIsChanged) {
                return;
            }
            if (myModuleNameDocListenerEnabled) {
                myModuleNameChangedByUser = true;
            }
            String path = getDefaultBaseDir(myWizardContext, namePathComponent);
            final String moduleName = getModuleName();
            if (path.length() > 0 && !Comparing.strEqual(moduleName, namePathComponent.getNameValue())) {
                path += "/" + moduleName;
            }
            if (!myContentRootChangedByUser) {
                final boolean f = myModuleNameChangedByUser;
                myModuleNameChangedByUser = true;
                setModuleContentRoot(path);
                myModuleNameChangedByUser = f;
            }
            if (!myImlLocationChangedByUser) {
                setImlFileLocation(path);
            }
        }
    });
    myModuleContentRoot.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            if (myContentRootDocListenerEnabled) {
                myContentRootChangedByUser = true;
            }
            if (!myImlLocationChangedByUser) {
                setImlFileLocation(getModuleContentRoot());
            }
            if (!myModuleNameChangedByUser) {
                final String path = FileUtil.toSystemIndependentName(getModuleContentRoot());
                final int idx = path.lastIndexOf("/");
                boolean f = myContentRootChangedByUser;
                myContentRootChangedByUser = true;
                boolean i = myImlLocationChangedByUser;
                myImlLocationChangedByUser = true;
                setModuleName(idx >= 0 ? path.substring(idx + 1) : "");
                myContentRootChangedByUser = f;
                myImlLocationChangedByUser = i;
            }
        }
    });
    myModuleFileLocation.addBrowseFolderListener(ProjectBundle.message("project.new.wizard.module.file.chooser.title"), ProjectBundle.message("project.new.wizard.module.file.description"), myWizardContext.getProject(), BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);
    myModuleFileLocation.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            if (myImlLocationDocListenerEnabled) {
                myImlLocationChangedByUser = true;
            }
        }
    });
    namePathComponent.getPathComponent().getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            if (!myImlLocationChangedByUser) {
                setImlFileLocation(namePathComponent.getPath());
            }
        }
    });
    myUpdatePathsWhenNameIsChanged = true;
    if (myWizardContext.isCreatingNewProject()) {
        setModuleName(namePathComponent.getNameValue());
        setModuleContentRoot(namePathComponent.getPath());
        setImlFileLocation(namePathComponent.getPath());
    } else {
        final Project project = myWizardContext.getProject();
        assert project != null;
        VirtualFile baseDir = project.getBaseDir();
        if (baseDir != null) {
            //e.g. was deleted
            final String baseDirPath = baseDir.getPath();
            String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", "");
            String contentRoot = baseDirPath + "/" + moduleName;
            if (!Comparing.strEqual(project.getName(), myWizardContext.getProjectName()) && !myWizardContext.isCreatingNewProject() && myWizardContext.getProjectName() != null) {
                moduleName = ProjectWizardUtil.findNonExistingFileName(myWizardContext.getProjectFileDirectory(), myWizardContext.getProjectName(), "");
                contentRoot = myWizardContext.getProjectFileDirectory();
                myUpdatePathsWhenNameIsChanged = !myWizardContext.isProjectFileDirectorySetExplicitly();
            }
            setModuleName(moduleName);
            setModuleContentRoot(contentRoot);
            setImlFileLocation(contentRoot);
            myModuleName.select(0, moduleName.length());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 59 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class NamePathComponent method addChangeListener.

public void addChangeListener(final Runnable callback) {
    DocumentAdapter adapter = new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            callback.run();
        }
    };
    myTfName.getDocument().addDocumentListener(adapter);
    myTfPath.getDocument().addDocumentListener(adapter);
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 60 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.

the class WrapReturnValueDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    sourceMethodTextField.setEditable(false);
    final DocumentListener docListener = new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            validateButtons();
        }
    };
    classNameField.getDocument().addDocumentListener(docListener);
    myFieldsCombo.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            validateButtons();
        }
    });
    myInnerClassNameTextField.getDocument().addDocumentListener(docListener);
    final PsiFile file = sourceMethod.getContainingFile();
    if (file instanceof PsiJavaFile) {
        final String packageName = ((PsiJavaFile) file).getPackageName();
        packageTextField.setText(packageName);
    }
    final PsiClass containingClass = sourceMethod.getContainingClass();
    assert containingClass != null : sourceMethod;
    final String containingClassName = containingClass instanceof PsiAnonymousClass ? "Anonymous " + ((PsiAnonymousClass) containingClass).getBaseClassType().getClassName() : containingClass.getName();
    final String sourceMethodName = sourceMethod.getName();
    sourceMethodTextField.setText(containingClassName + '.' + sourceMethodName);
    final ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(useExistingClassButton);
    buttonGroup.add(createNewClassButton);
    buttonGroup.add(myCreateInnerClassButton);
    createNewClassButton.setSelected(true);
    final ActionListener enableListener = new ActionListener() {

        public void actionPerformed(ActionEvent actionEvent) {
            toggleRadioEnablement();
        }
    };
    useExistingClassButton.addActionListener(enableListener);
    createNewClassButton.addActionListener(enableListener);
    myCreateInnerClassButton.addActionListener(enableListener);
    toggleRadioEnablement();
    final DefaultComboBoxModel model = new DefaultComboBoxModel();
    myFieldsCombo.setModel(model);
    myFieldsCombo.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof PsiField) {
                final PsiField field = (PsiField) value;
                setText(field.getName());
                setIcon(field.getIcon(Iconable.ICON_FLAG_VISIBILITY));
            }
        }
    });
    existingClassField.getChildComponent().getDocument().addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {

        @Override
        public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
            final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject);
            final PsiClass currentClass = facade.findClass(existingClassField.getText(), GlobalSearchScope.allScope(myProject));
            if (currentClass != null) {
                model.removeAllElements();
                final PsiType returnType = sourceMethod.getReturnType();
                assert returnType != null;
                for (PsiField field : currentClass.getFields()) {
                    final PsiType fieldType = field.getType();
                    if (TypeConversionUtil.isAssignable(fieldType, returnType)) {
                        model.addElement(field);
                    } else {
                        if (WrapReturnValueProcessor.getInferredType(fieldType, returnType, currentClass, sourceMethod) != null) {
                            model.addElement(field);
                        }
                    }
                }
            }
        }
    });
    return myWholePanel;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) ActionEvent(java.awt.event.ActionEvent) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener)

Aggregations

DocumentAdapter (com.intellij.ui.DocumentAdapter)64 DocumentEvent (javax.swing.event.DocumentEvent)64 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)15 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)10 ItemEvent (java.awt.event.ItemEvent)7 ItemListener (java.awt.event.ItemListener)7 Document (javax.swing.text.Document)7 JTextComponent (javax.swing.text.JTextComponent)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FieldPanel (com.intellij.ui.FieldPanel)4 JBTextField (com.intellij.ui.components.JBTextField)4 ChangeEvent (javax.swing.event.ChangeEvent)4 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 VariantsCompletionAction (com.intellij.find.editorHeaderActions.VariantsCompletionAction)2 MemberChooser (com.intellij.ide.util.MemberChooser)2 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2