Search in sources :

Example 6 with DocumentAdapter

use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.

the class GrChangeSignatureDialog method createAdditionalPanels.

@NotNull
@Override
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(              //todo propagate parameters
      RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, PlatformIcons.NEW_EXCEPTION) {
      @Override
      public void actionPerformed(AnActionEvent e) {
        final Ref<JavaCallerChooser> chooser = new Ref<JavaCallerChooser>();
        Consumer<Set<PsiMethod>> callback = new Consumer<Set<PsiMethod>>() {
          @Override
          public void consume(Set<PsiMethod> 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).createPanel();
    //.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 : ExceptionsTableModel(com.intellij.refactoring.changeSignature.ExceptionsTableModel) ArrayList(java.util.ArrayList) CodeFragmentTableCellRenderer(com.intellij.refactoring.ui.CodeFragmentTableCellRenderer) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with DocumentAdapter

use of com.intellij.openapi.editor.event.DocumentAdapter in project kotlin by JetBrains.

the class MoveKotlinTopLevelDeclarationsDialog method createPackageChooser.

private ReferenceEditorComboWithBrowseButton createPackageChooser() {
    ReferenceEditorComboWithBrowseButton packageChooser = new PackageNameReferenceEditorCombo("", myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
    Document document = packageChooser.getChildComponent().getDocument();
    document.addDocumentListener(new DocumentAdapter() {

        @Override
        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 8 with DocumentAdapter

use of com.intellij.openapi.editor.event.DocumentAdapter in project kotlin by JetBrains.

the class PluginStartupComponent method initComponent.

@Override
public void initComponent() {
    registerPathVariable();
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        ThreadTrackerPatcherForTeamCityTesting.INSTANCE.patchThreadTracker();
    }
    JarUserDataManager.INSTANCE.register(KotlinJavaScriptLibraryDetectionUtil.HasKotlinJSMetadataInJar.INSTANCE);
    DebuggerFiltersUtilKt.addKotlinStdlibDebugFilterIfNeeded();
    try {
        // API added in 15.0.2
        UpdateChecker.INSTANCE.getExcludedFromUpdateCheckPlugins().add("org.jetbrains.kotlin");
    } catch (Throwable throwable) {
        LOG.debug("Excluding Kotlin plugin updates using old API", throwable);
        UpdateChecker.getDisabledToUpdatePlugins().add("org.jetbrains.kotlin");
    }
    EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(e.getDocument());
            if (virtualFile != null && virtualFile.getFileType() == KotlinFileType.INSTANCE) {
                KotlinPluginUpdater.Companion.getInstance().kotlinFileEdited();
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 9 with DocumentAdapter

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) FileDocumentManagerAdapter(com.intellij.openapi.fileEditor.FileDocumentManagerAdapter) ModuleRootEvent(com.intellij.openapi.roots.ModuleRootEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Update(com.intellij.util.ui.update.Update) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) Document(com.intellij.openapi.editor.Document) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) ModuleRootListener(com.intellij.openapi.roots.ModuleRootListener)

Example 10 with DocumentAdapter

use of com.intellij.openapi.editor.event.DocumentAdapter in project intellij-community by JetBrains.

the class LiveTemplateSettingsEditor method createComponents.

private void createComponents(boolean allowNoContexts) {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBag gb = new GridBag().setDefaultInsets(4, 4, 4, 4).setDefaultWeightY(1).setDefaultFill(GridBagConstraints.BOTH);
    JPanel editorPanel = new JPanel(new BorderLayout(4, 4));
    editorPanel.setPreferredSize(JBUI.size(250, 100));
    editorPanel.setMinimumSize(editorPanel.getPreferredSize());
    editorPanel.add(myTemplateEditor.getComponent(), BorderLayout.CENTER);
    JLabel templateTextLabel = new JLabel(CodeInsightBundle.message("dialog.edit.template.template.text.title"));
    templateTextLabel.setLabelFor(myTemplateEditor.getContentComponent());
    editorPanel.add(templateTextLabel, BorderLayout.NORTH);
    editorPanel.setFocusable(false);
    panel.add(editorPanel, gb.nextLine().next().weighty(1).weightx(1).coverColumn(2));
    myEditVariablesButton = new JButton(CodeInsightBundle.message("dialog.edit.template.button.edit.variables"));
    myEditVariablesButton.setDefaultCapable(false);
    myEditVariablesButton.setMaximumSize(myEditVariablesButton.getPreferredSize());
    panel.add(myEditVariablesButton, gb.next().weighty(0));
    myTemplateOptionsPanel = new JPanel(new BorderLayout());
    myTemplateOptionsPanel.add(createTemplateOptionsPanel());
    panel.add(myTemplateOptionsPanel, gb.nextLine().next().next().coverColumn(2).weighty(1));
    panel.add(createShortContextPanel(allowNoContexts), gb.nextLine().next().weighty(0).fillCellNone().anchor(GridBagConstraints.WEST));
    myTemplateEditor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            validateEditVariablesButton();
            myTemplate.setString(myTemplateEditor.getDocument().getText());
            applyVariables(updateVariablesByTemplateText());
            myNodeChanged.run();
        }
    });
    myEditVariablesButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            editVariables();
        }
    });
    add(createNorthPanel(), BorderLayout.NORTH);
    add(panel, BorderLayout.CENTER);
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) GridBag(com.intellij.util.ui.GridBag) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Aggregations

DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)41 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)40 Document (com.intellij.openapi.editor.Document)10 EditorTextField (com.intellij.ui.EditorTextField)6 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 Disposable (com.intellij.openapi.Disposable)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 NotNull (org.jetbrains.annotations.NotNull)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Editor (com.intellij.openapi.editor.Editor)3 Module (com.intellij.openapi.module.Module)3 Pair (com.intellij.openapi.util.Pair)3 Ref (com.intellij.openapi.util.Ref)3 Nullable (org.jetbrains.annotations.Nullable)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 Language (com.intellij.lang.Language)2 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)2