void (final @NotNull PushTargetEditorListener listener) { myTargetEditor.addDocumentListener(new DocumentListener() { @Override public void documentChanged(@NotNull DocumentEvent e) { processActiveUserChanges(listener); } }); myTargetEditor.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { processActiveUserChanges(listener); } }); myTargetEditor.addHierarchyListener(new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent e) { if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) { if (myTargetEditor.isShowing()) { UndoUtil.enableUndoFor(myTargetEditor.getDocument()); } else { UndoUtil.disableUndoFor(myTargetEditor.getDocument()); } } } }); }