Search in sources :

Example 21 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-community by JetBrains.

the class ExtractMethodObjectDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    mySignatureArea.setEditable(false);
    myCreateInnerClassRb.setSelected(true);
    final ActionListener enableDisableListener = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            enable(myCreateInnerClassRb.isSelected());
        }
    };
    myCreateInnerClassRb.addActionListener(enableDisableListener);
    myCreateAnonymousClassWrapperRb.addActionListener(enableDisableListener);
    myCreateAnonymousClassWrapperRb.setEnabled(!myMultipleExitPoints);
    myFoldCb.setSelected(myVariableData.isFoldingSelectedByDefault());
    myFoldCb.setVisible(myVariableData.isFoldable());
    myVariableData.setFoldingAvailable(myFoldCb.isSelected());
    myInputVariables = myVariableData.getInputVariables().toArray(new VariableData[myVariableData.getInputVariables().size()]);
    myFoldCb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            myVariableData.setFoldingAvailable(myFoldCb.isSelected());
            myInputVariables = myVariableData.getInputVariables().toArray(new VariableData[myVariableData.getInputVariables().size()]);
            myParametersTableContainer.removeAll();
            myParametersTableContainer.add(createParametersPanel(), BorderLayout.CENTER);
            myParametersTableContainer.revalidate();
            updateSignature();
            updateVarargsEnabled();
        }
    });
    myParametersTableContainer.add(createParametersPanel(), BorderLayout.CENTER);
    final ActionListener updateSugnatureListener = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            updateSignature();
            IdeFocusManager.getInstance(myProject).requestFocus(myCreateInnerClassRb.isSelected() ? myInnerClassName : myMethodName, false);
        }
    };
    if (myStaticFlag || myCanBeStatic) {
        myCbMakeStatic.setEnabled(!myStaticFlag);
        myCbMakeStatic.setSelected(myStaticFlag);
        myCbMakeStatic.addActionListener(updateSugnatureListener);
    } else {
        myCbMakeStatic.setSelected(false);
        myCbMakeStatic.setEnabled(false);
    }
    updateVarargsEnabled();
    myCbMakeVarargs.setSelected(myWasStatic);
    myCbMakeVarargs.addActionListener(updateSugnatureListener);
    myCbMakeVarargsAnonymous.setSelected(myWasStatic);
    myCbMakeVarargsAnonymous.addActionListener(updateSugnatureListener);
    final DocumentAdapter nameListener = new DocumentAdapter() {

        @Override
        public void documentChanged(final DocumentEvent e) {
            update();
        }
    };
    myInnerClassName.getDocument().addDocumentListener(nameListener);
    myMethodName.getDocument().addDocumentListener(nameListener);
    myPrivateRadioButton.setSelected(true);
    myCreateInnerClassRb.addActionListener(updateSugnatureListener);
    myCreateAnonymousClassWrapperRb.addActionListener(updateSugnatureListener);
    final Enumeration<AbstractButton> visibilities = myVisibilityGroup.getElements();
    while (visibilities.hasMoreElements()) {
        visibilities.nextElement().addActionListener(updateSugnatureListener);
    }
    enable(true);
    return myWholePanel;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) VariableData(com.intellij.refactoring.util.VariableData) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 22 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-community by JetBrains.

the class IntroduceConstantDialog method createNorthPanel.

protected JComponent createNorthPanel() {
    myTypeSelector = myTypeSelectorManager.getTypeSelector();
    myTypePanel.setLayout(new BorderLayout());
    myTypePanel.add(myTypeSelector.getComponent(), BorderLayout.CENTER);
    if (myTypeSelector.getFocusableComponent() != null) {
        myTypeLabel.setLabelFor(myTypeSelector.getFocusableComponent());
    }
    myNameField = new NameSuggestionsField(myProject);
    myNameSuggestionPanel.setLayout(new BorderLayout());
    myNameField.addDataChangedListener(new NameSuggestionsField.DataChanged() {

        public void dataChanged() {
            updateButtons();
        }
    });
    myNameSuggestionPanel.add(myNameField.getComponent(), BorderLayout.CENTER);
    myNameSuggestionLabel.setLabelFor(myNameField.getFocusableComponent());
    Set<String> possibleClassNames = new LinkedHashSet<>();
    for (final PsiExpression occurrence : myOccurrences) {
        final PsiClass parentClass = new IntroduceConstantHandler().getParentClass(occurrence);
        if (parentClass != null && parentClass.getQualifiedName() != null) {
            possibleClassNames.add(parentClass.getQualifiedName());
        }
    }
    myTfTargetClassName = new ReferenceEditorComboWithBrowseButton(new ChooseClassAction(), "", myProject, true, RECENTS_KEY);
    myTargetClassNamePanel.setLayout(new BorderLayout());
    myTargetClassNamePanel.add(myTfTargetClassName, BorderLayout.CENTER);
    myTargetClassNameLabel.setLabelFor(myTfTargetClassName);
    for (String possibleClassName : possibleClassNames) {
        myTfTargetClassName.prependItem(possibleClassName);
    }
    myTfTargetClassName.getChildComponent().setSelectedItem(myParentClass.getQualifiedName());
    myTfTargetClassName.getChildComponent().addDocumentListener(new DocumentAdapter() {

        public void documentChanged(DocumentEvent e) {
            targetClassChanged();
            enableEnumDependant(introduceEnumConstant());
        }
    });
    myIntroduceEnumConstantCb.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            enableEnumDependant(introduceEnumConstant());
        }
    });
    final JPanel enumPanel = new JPanel(new BorderLayout());
    enumPanel.add(myIntroduceEnumConstantCb, BorderLayout.EAST);
    myTargetClassNamePanel.add(enumPanel, BorderLayout.SOUTH);
    final String propertyName;
    if (myLocalVariable != null) {
        propertyName = myCodeStyleManager.variableNameToPropertyName(myLocalVariable.getName(), VariableKind.LOCAL_VARIABLE);
    } else {
        propertyName = null;
    }
    final NameSuggestionsManager nameSuggestionsManager = new NameSuggestionsManager(myTypeSelector, myNameField, createNameSuggestionGenerator(propertyName, myInitializerExpression, myCodeStyleManager, myEnteredName, myParentClass));
    nameSuggestionsManager.setLabelsFor(myTypeLabel, myNameSuggestionLabel);
    //////////
    if (myOccurrencesCount > 1) {
        myCbReplaceAll.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                updateTypeSelector();
                myNameField.requestFocusInWindow();
            }
        });
        myCbReplaceAll.setText(RefactoringBundle.message("replace.all.occurences", myOccurrencesCount));
    } else {
        myCbReplaceAll.setVisible(false);
    }
    if (myLocalVariable != null) {
        if (myInvokedOnDeclaration) {
            myCbDeleteVariable.setEnabled(false);
            myCbDeleteVariable.setSelected(true);
        } else if (myCbReplaceAll != null) {
            updateCbDeleteVariable();
            myCbReplaceAll.addItemListener(new ItemListener() {

                public void itemStateChanged(ItemEvent e) {
                    updateCbDeleteVariable();
                }
            });
        }
    } else {
        myCbDeleteVariable.setVisible(false);
    }
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    if ((myTypeSelectorManager.isSuggestedType(CommonClassNames.JAVA_LANG_STRING) || (myLocalVariable != null && AnnotationUtil.isAnnotated(myLocalVariable, AnnotationUtil.NON_NLS, false, false))) && LanguageLevelProjectExtension.getInstance(psiManager.getProject()).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5) && JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnnotationUtil.NON_NLS, myParentClass.getResolveScope()) != null) {
        final PropertiesComponent component = PropertiesComponent.getInstance(myProject);
        myCbNonNls.setSelected(component.getBoolean(NONNLS_SELECTED_PROPERTY));
        myCbNonNls.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                component.setValue(NONNLS_SELECTED_PROPERTY, myCbNonNls.isSelected());
            }
        });
    } else {
        myCbNonNls.setVisible(false);
    }
    updateTypeSelector();
    enableEnumDependant(introduceEnumConstant());
    return myPanel;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 23 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-community by JetBrains.

the class SmartPsiElementPointersTest method testCreatePointerInBeforeDocumentChange.

public void testCreatePointerInBeforeDocumentChange() {
    final PsiClass aClass = myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject()));
    assertNotNull(aClass);
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(aClass.getContainingFile());
    final SmartPsiElementPointer[] pointer = new SmartPsiElementPointer[1];
    int offset = aClass.getTextOffset();
    DocumentListener listener = new DocumentListener() {

        @Override
        public void beforeDocumentChange(DocumentEvent event) {
            pointer[0] = createPointer(aClass);
        }

        @Override
        public void documentChanged(DocumentEvent event) {
        }
    };
    EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster();
    multicaster.addDocumentListener(listener);
    try {
        insertString(document, offset, "/******/");
    } finally {
        multicaster.removeDocumentListener(listener);
    }
    pointer[0].getElement();
    insertString(document, 0, "/**/");
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    PsiElement element = pointer[0].getElement();
    assertNotNull(element);
    assertTrue(element instanceof PsiClass);
    assertTrue(element.isValid());
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) EditorEventMulticaster(com.intellij.openapi.editor.event.EditorEventMulticaster) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 24 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-community by JetBrains.

the class PackageChooserDialog method setupPathComponent.

private void setupPathComponent(final JPanel northPanel) {
    northPanel.add(new TextFieldAction() {

        @Override
        public void linkSelected(LinkLabel aSource, Object aLinkData) {
            toggleShowPathComponent(northPanel, this);
        }
    }, BorderLayout.EAST);
    myPathEditor = new EditorTextField(JavaReferenceEditorUtil.createDocument("", myProject, false), myProject, StdFileTypes.JAVA);
    myPathEditor.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            myAlarm.cancelAllRequests();
            myAlarm.addRequest(() -> updateTreeFromPath(), 300);
        }
    });
    myPathEditor.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
    northPanel.add(myPathEditor, BorderLayout.SOUTH);
}
Also used : TextFieldAction(com.intellij.openapi.fileChooser.ex.TextFieldAction) EditorTextField(com.intellij.ui.EditorTextField) LinkLabel(com.intellij.ui.components.labels.LinkLabel) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 25 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-community by JetBrains.

the class DestinationFolderComboBox method setData.

public void setData(final Project project, final PsiDirectory initialTargetDirectory, final Pass<String> errorMessageUpdater, final EditorComboBox editorComboBox) {
    myInitialTargetDirectory = initialTargetDirectory;
    mySourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(project);
    new ComboboxSpeedSearch(getComboBox()) {

        @Override
        protected String getElementText(Object element) {
            if (element == NULL_WRAPPER)
                return LEAVE_IN_SAME_SOURCE_ROOT;
            if (element instanceof DirectoryChooser.ItemWrapper) {
                final VirtualFile virtualFile = ((DirectoryChooser.ItemWrapper) element).getDirectory().getVirtualFile();
                final Module module = ModuleUtil.findModuleForFile(virtualFile, project);
                if (module != null) {
                    return module.getName();
                }
            }
            return super.getElementText(element);
        }
    };
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    getComboBox().setRenderer(new ListCellRendererWrapper<DirectoryChooser.ItemWrapper>() {

        @Override
        public void customize(JList list, DirectoryChooser.ItemWrapper itemWrapper, int index, boolean selected, boolean hasFocus) {
            if (itemWrapper != NULL_WRAPPER && itemWrapper != null) {
                setIcon(itemWrapper.getIcon(fileIndex));
                setText(itemWrapper.getRelativeToProjectPath());
            } else {
                setText(LEAVE_IN_SAME_SOURCE_ROOT);
            }
        }
    });
    final VirtualFile initialSourceRoot = initialTargetDirectory != null ? fileIndex.getSourceRootForFile(initialTargetDirectory.getVirtualFile()) : null;
    final VirtualFile[] selection = new VirtualFile[] { initialSourceRoot };
    addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile root = MoveClassesOrPackagesUtil.chooseSourceRoot(new PackageWrapper(PsiManager.getInstance(project), getTargetPackage()), mySourceRoots, initialTargetDirectory);
            if (root == null)
                return;
            final ComboBoxModel model = getComboBox().getModel();
            for (int i = 0; i < model.getSize(); i++) {
                DirectoryChooser.ItemWrapper item = (DirectoryChooser.ItemWrapper) model.getElementAt(i);
                if (item != NULL_WRAPPER && Comparing.equal(fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()), root)) {
                    getComboBox().setSelectedItem(item);
                    getComboBox().repaint();
                    return;
                }
            }
            setComboboxModel(getComboBox(), root, root, fileIndex, mySourceRoots, project, true, errorMessageUpdater);
        }
    });
    editorComboBox.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            JComboBox comboBox = getComboBox();
            DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper) comboBox.getSelectedItem();
            setComboboxModel(comboBox, selectedItem != null && selectedItem != NULL_WRAPPER ? fileIndex.getSourceRootForFile(selectedItem.getDirectory().getVirtualFile()) : initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater);
        }
    });
    setComboboxModel(getComboBox(), initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater);
    getComboBox().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Object selectedItem = getComboBox().getSelectedItem();
            updateErrorMessage(errorMessageUpdater, fileIndex, selectedItem);
            if (selectedItem instanceof DirectoryChooser.ItemWrapper && selectedItem != NULL_WRAPPER) {
                PsiDirectory directory = ((DirectoryChooser.ItemWrapper) selectedItem).getDirectory();
                if (directory != null) {
                    selection[0] = fileIndex.getSourceRootForFile(directory.getVirtualFile());
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) PackageWrapper(com.intellij.refactoring.PackageWrapper) ActionListener(java.awt.event.ActionListener) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) DirectoryChooser(com.intellij.ide.util.DirectoryChooser)

Aggregations

DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)54 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)40 Document (com.intellij.openapi.editor.Document)14 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)12 EditorTextField (com.intellij.ui.EditorTextField)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Disposable (com.intellij.openapi.Disposable)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 Editor (com.intellij.openapi.editor.Editor)4 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 NotNull (org.jetbrains.annotations.NotNull)4 Language (com.intellij.lang.Language)3 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Module (com.intellij.openapi.module.Module)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)2 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)2