Search in sources :

Example 16 with DocumentEvent

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()));
        }
    });
}
Also used : TemplateImpl(com.intellij.codeInsight.template.impl.TemplateImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) TextRange(com.intellij.openapi.util.TextRange) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) TemplateState(com.intellij.codeInsight.template.impl.TemplateState)

Example 17 with DocumentEvent

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;
}
Also used : JavaCallerChooser(com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser) ArrayList(java.util.ArrayList) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Ref(com.intellij.openapi.util.Ref) CodeFragmentTableCellRenderer(com.intellij.refactoring.ui.CodeFragmentTableCellRenderer) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with DocumentEvent

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;
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ReferenceEditorComboWithBrowseButton(com.intellij.ui.ReferenceEditorComboWithBrowseButton) PackageNameReferenceEditorCombo(com.intellij.refactoring.ui.PackageNameReferenceEditorCombo)

Example 19 with DocumentEvent

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();
        }
    };
}
Also used : ClassNameReferenceEditor(com.intellij.refactoring.ui.ClassNameReferenceEditor) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 20 with DocumentEvent

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;
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Aggregations

DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)54 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)40 Document (com.intellij.openapi.editor.Document)14 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)12 EditorTextField (com.intellij.ui.EditorTextField)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Disposable (com.intellij.openapi.Disposable)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 Editor (com.intellij.openapi.editor.Editor)4 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 NotNull (org.jetbrains.annotations.NotNull)4 Language (com.intellij.lang.Language)3 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Module (com.intellij.openapi.module.Module)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)2 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)2