use of com.intellij.openapi.editor.event.DocumentEvent 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()));
}
});
}
use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-community by JetBrains.
the class JavaChangeSignatureDialog method createAdditionalPanels.
@NotNull
protected List<Pair<String, JPanel>> createAdditionalPanels() {
// this method is invoked before constructor body
myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList());
myExceptionsModel.setTypeInfos(myMethod.getMethod());
final JBTable table = new JBTable(myExceptionsModel);
table.setStriped(true);
table.setRowHeight(20);
table.getColumnModel().getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject);
cellEditor.addDocumentListener(new DocumentAdapter() {
@Override
public void documentChanged(DocumentEvent e) {
final int row = table.getSelectedRow();
final int col = table.getSelectedColumn();
myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col);
updateSignature();
}
});
table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().setSelectionInterval(0, 0);
table.setSurrendersFocusOnKeystroke(true);
myPropExceptionsButton = new AnActionButton(RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, AllIcons.Hierarchy.Caller) {
@Override
public void actionPerformed(AnActionEvent e) {
final Ref<JavaCallerChooser> chooser = new Ref<>();
Consumer<Set<PsiMethod>> callback = psiMethods -> {
myMethodsToPropagateExceptions = psiMethods;
myExceptionPropagationTree = chooser.get().getTree();
};
chooser.set(new JavaCallerChooser(myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback));
chooser.get().show();
}
};
myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X"));
final JPanel panel = ToolbarDecorator.createDecorator(table).addExtraAction(myPropExceptionsButton).createPanel();
panel.setBorder(IdeBorderFactory.createEmptyBorder());
myExceptionsModel.addTableModelListener(mySignatureUpdater);
final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
result.add(Pair.create(message, panel));
return result;
}
use of com.intellij.openapi.editor.event.DocumentEvent 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.DocumentEvent 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.DocumentEvent 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;
}
Aggregations