use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class MoveClassesOrPackagesDialog method createPackageChooser.
private ReferenceEditorComboWithBrowseButton createPackageChooser() {
final ReferenceEditorComboWithBrowseButton packageChooser = new PackageNameReferenceEditorCombo("", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
final Document document = packageChooser.getChildComponent().getDocument();
document.addDocumentListener(new DocumentAdapter() {
public void documentChanged(DocumentEvent e) {
validateButtons();
}
});
return packageChooser;
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class MoveClassesOrPackagesDialog method createUIComponents.
private void createUIComponents() {
myMainPanel = new JPanel();
myWithBrowseButtonReference = createPackageChooser();
myClassPackageChooser = createPackageChooser();
GlobalSearchScope scope = JavaProjectRootsUtil.getScopeWithoutGeneratedSources(ProjectScope.getProjectScope(myProject), myProject);
myInnerClassChooser = new ClassNameReferenceEditor(myProject, null, scope);
myInnerClassChooser.addDocumentListener(new DocumentAdapter() {
public void documentChanged(DocumentEvent e) {
validateButtons();
}
});
// override CardLayout sizing behavior
myCardPanel = new JPanel() {
public Dimension getMinimumSize() {
return myHavePackages ? myMovePackagePanel.getMinimumSize() : myMoveClassPanel.getMinimumSize();
}
public Dimension getPreferredSize() {
return myHavePackages ? myMovePackagePanel.getPreferredSize() : myMoveClassPanel.getPreferredSize();
}
};
myDestinationFolderCB = new DestinationFolderComboBox() {
@Override
public String getTargetPackage() {
return MoveClassesOrPackagesDialog.this.getTargetPackage();
}
};
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class MoveMembersDialog method createNorthPanel.
protected JComponent createNorthPanel() {
JPanel panel = new JPanel(new BorderLayout());
JPanel _panel;
Box box = Box.createVerticalBox();
_panel = new JPanel(new BorderLayout());
JTextField sourceClassField = new JTextField();
sourceClassField.setText(mySourceClassName);
sourceClassField.setEditable(false);
_panel.add(new JLabel(RefactoringBundle.message("move.members.move.members.from.label")), BorderLayout.NORTH);
_panel.add(sourceClassField, BorderLayout.CENTER);
box.add(_panel);
box.add(Box.createVerticalStrut(10));
_panel = new JPanel(new BorderLayout());
JLabel label = new JLabel(RefactoringBundle.message("move.members.to.fully.qualified.name.label"));
label.setLabelFor(myTfTargetClassName);
_panel.add(label, BorderLayout.NORTH);
_panel.add(myTfTargetClassName, BorderLayout.CENTER);
_panel.add(myIntroduceEnumConstants, BorderLayout.SOUTH);
box.add(_panel);
myTfTargetClassName.getChildComponent().getDocument().addDocumentListener(new DocumentAdapter() {
public void documentChanged(DocumentEvent e) {
myMemberInfoModel.updateTargetClass();
validateButtons();
}
});
panel.add(box, BorderLayout.CENTER);
panel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
validateButtons();
return panel;
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class TextCompletionUtil method installCompletionHint.
public static void installCompletionHint(@NotNull EditorEx editor) {
String completionShortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
if (!StringUtil.isEmpty(completionShortcutText)) {
final Ref<Boolean> toShowHintRef = new Ref<>(true);
editor.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
toShowHintRef.set(false);
}
});
editor.addFocusListener(new FocusChangeListener() {
@Override
public void focusGained(final Editor editor) {
if (toShowHintRef.get() && editor.getDocument().getText().isEmpty()) {
ApplicationManager.getApplication().invokeLater(() -> HintManager.getInstance().showInformationHint(editor, "Code completion available ( " + completionShortcutText + " )"));
}
}
@Override
public void focusLost(Editor editor) {
// Do nothing
}
});
}
}
use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.
the class JavaMethodCallElement method setupNonFilledArgumentRemoving.
private static void setupNonFilledArgumentRemoving(final Editor editor, final TemplateState templateState) {
AtomicInteger maxEditedVariable = new AtomicInteger(-1);
editor.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
maxEditedVariable.set(Math.max(maxEditedVariable.get(), templateState.getCurrentVariableNumber()));
}
}, templateState);
templateState.addTemplateStateListener(new TemplateEditingAdapter() {
@Override
public void currentVariableChanged(TemplateState templateState, Template template, int oldIndex, int newIndex) {
maxEditedVariable.set(Math.max(maxEditedVariable.get(), oldIndex));
}
@Override
public void beforeTemplateFinished(TemplateState state, Template template, boolean brokenOff) {
if (brokenOff) {
removeUntouchedArguments((TemplateImpl) template);
}
}
private void removeUntouchedArguments(TemplateImpl template) {
int firstUnchangedVar = maxEditedVariable.get() + 1;
if (firstUnchangedVar >= template.getVariableCount())
return;
TextRange startRange = templateState.getVariableRange(template.getVariableNameAt(firstUnchangedVar));
TextRange endRange = templateState.getVariableRange(template.getVariableNameAt(template.getVariableCount() - 1));
if (startRange == null || endRange == null)
return;
WriteCommandAction.runWriteCommandAction(editor.getProject(), () -> editor.getDocument().deleteString(startRange.getStartOffset(), endRange.getEndOffset()));
}
});
}
Aggregations