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