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;
}
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;
}
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();
}
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());
}
}
});
}
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();
}
Aggregations