Search in sources :

Example 11 with DocumentAdapter

use of com.intellij.openapi.editor.event.DocumentAdapter 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 12 with DocumentAdapter

use of com.intellij.openapi.editor.event.DocumentAdapter 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 13 with DocumentAdapter

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

the class DocumentTest method testCorrectlyAddingAndRemovingListeners.

public void testCorrectlyAddingAndRemovingListeners() throws Exception {
    new WriteCommandAction.Simple(getProject()) {

        @Override
        protected void run() throws Throwable {
            final Document doc = new DocumentImpl("");
            final StringBuilder b = new StringBuilder();
            doc.addDocumentListener(new DocumentAdapter() {

                @Override
                public void beforeDocumentChange(DocumentEvent e) {
                    b.append("before1 ");
                }

                @Override
                public void documentChanged(DocumentEvent e) {
                    b.append("after1 ");
                }
            });
            doc.addDocumentListener(new DocumentAdapter() {

                @Override
                public void beforeDocumentChange(DocumentEvent event) {
                    doc.removeDocumentListener(this);
                }
            });
            doc.addDocumentListener(new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    doc.removeDocumentListener(this);
                }
            });
            doc.addDocumentListener(new DocumentAdapter() {

                @Override
                public void beforeDocumentChange(DocumentEvent e) {
                    b.append("before2 ");
                }

                @Override
                public void documentChanged(DocumentEvent e) {
                    b.append("after2 ");
                }
            });
            doc.setText("foo");
            assertEquals("before2 before1 after1 after2 ", b.toString());
        }
    }.execute().throwException();
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 14 with DocumentAdapter

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

the class GitPushTargetPanel method addTargetEditorListener.

@Override
public void addTargetEditorListener(@NotNull final PushTargetEditorListener listener) {
    myTargetEditor.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            processActiveUserChanges(listener);
        }
    });
    myTargetEditor.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            processActiveUserChanges(listener);
        }
    });
    myTargetEditor.addHierarchyListener(new HierarchyListener() {

        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                myTargetEditor.getDocument().putUserData(UndoConstants.DONT_RECORD_UNDO, !myTargetEditor.isShowing());
            }
        }
    });
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 15 with DocumentAdapter

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

the class GeneratedSourceFileChangeTrackerImpl method projectOpened.

@Override
public void projectOpened() {
    final Update check = new Update("check for changes in generated files") {

        @Override
        public void run() {
            checkFiles();
        }
    };
    EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            VirtualFile file = myDocumentManager.getFile(e.getDocument());
            if (file != null) {
                myFilesToCheck.add(file);
                myCheckingQueue.queue(check);
            }
        }
    }, myProject);
    MessageBusConnection connection = myProject.getMessageBus().connect();
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {

        @Override
        public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) {
            myFilesToCheck.remove(file);
            if (myEditedGeneratedFiles.remove(file)) {
                myEditorNotifications.updateNotifications(file);
            }
        }
    });
    connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            myEditedGeneratedFiles.remove(file);
        }
    });
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {

        @Override
        public void rootsChanged(ModuleRootEvent event) {
            myFilesToCheck.addAll(myEditedGeneratedFiles);
            myEditedGeneratedFiles.clear();
            myCheckingQueue.queue(check);
        }
    });
    myCheckingQueue.activate();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Update(com.intellij.util.ui.update.Update) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Aggregations

DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)41 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)40 Document (com.intellij.openapi.editor.Document)10 EditorTextField (com.intellij.ui.EditorTextField)6 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 Disposable (com.intellij.openapi.Disposable)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 NotNull (org.jetbrains.annotations.NotNull)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Editor (com.intellij.openapi.editor.Editor)3 Module (com.intellij.openapi.module.Module)3 Pair (com.intellij.openapi.util.Pair)3 Ref (com.intellij.openapi.util.Ref)3 Nullable (org.jetbrains.annotations.Nullable)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 Language (com.intellij.lang.Language)2 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)2