/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.util;

import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * @author lesya
 */

public class EditSourceOnEnterKeyHandler{
  public static void install(final JTree tree){
    tree.addKeyListener(
      new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
          if (KeyEvent.VK_ENTER == e.getKeyCode()) {
            DataContext dataContext = DataManager.getInstance().getDataContext(tree);

            Project project = CommonDataKeys.PROJECT.getData(dataContext);
            if (project == null) return;

            OpenSourceUtil.openSourcesFrom(dataContext, false);
          }
        }
      }
    );
  }

  public static void install(final JComponent component,
                           @Nullable final Runnable whenPerformed) {
    component.registerKeyboardAction(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        DataContext dataContext = DataManager.getInstance().getDataContext(component);
        OpenSourceUtil.openSourcesFrom(dataContext, true);
        if (whenPerformed != null) whenPerformed.run();
      }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
  }

  public static void install(@Nullable final Runnable before, final JComponent component,
                           @Nullable final Runnable whenPerformed) {
    component.registerKeyboardAction(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        DataContext dataContext = DataManager.getInstance().getDataContext(component);
        if (before != null) before.run();
        OpenSourceUtil.openSourcesFrom(dataContext, true);
        if (whenPerformed != null) whenPerformed.run();
      }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
  }
}

@@ -1,13 +1,10 @@
 /
-*%0A *
+/
  Copyrig
@@ -17,10 +17,10 @@
 0-20
+2
 0
-9
  Jet
@@ -36,566 +36,109 @@
 r.o.
-%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */
+ Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 %0Apac
@@ -355,16 +355,58 @@
 roject;%0A
+import org.jetbrains.annotations.NotNull;%0A
 import o
@@ -607,34 +607,8 @@
 t;%0A%0A
-/**%0A * @author lesya%0A */%0A%0A
 publ
@@ -674,20 +674,23 @@
 install(
-fina
+@NotNul
 l JTree 
@@ -694,16 +694,17 @@
 ee tree)
+ 
 %7B%0A    tr
@@ -842,17 +842,17 @@
 K_ENTER 
-=
+!
 = e.getK
@@ -861,20 +861,25 @@
 Code()) 
-%7B%0A  
+return;%0A%0A
         
@@ -954,19 +954,16 @@
 (tree);%0A
-%0A  
         
@@ -1033,26 +1033,24 @@
 ;%0A          
- 
- 
 if (project 
@@ -1059,34 +1059,32 @@
  null) return;%0A%0A
-  
           OpenSo
@@ -1125,26 +1125,24 @@
 xt, false);%0A
-  
         %7D%0A  
@@ -1139,26 +1139,16 @@
       %7D%0A
-        %7D%0A
       %7D%0A
@@ -1192,642 +1192,38 @@
 all(
-final JComponent component,%0A                           @Nullable final Runnable whenPerformed) %7B%0A    component.registerKeyboardAction(new ActionListener() %7B%0A      @Override%0A      public void actionPerformed(ActionEvent e) %7B%0A        DataContext dataContext = DataManager.getInstance().getDataContext(component);%0A        OpenSourceUtil.openSourcesFrom(dataContext, true);%0A        if (whenPerformed != null) whenPerformed.run();%0A      %7D%0A    %7D, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);%0A  %7D%0A%0A  public static void install(@Nullable final Runnable before, final JComponent component,%0A                          
+@NotNull JComponent component,
  @Nu
@@ -1233,14 +1233,8 @@
 ble 
-final 
 Runn
@@ -1473,49 +1473,8 @@
 t);%0A
-        if (before != null) before.run();
 %0A   

Refactor "EditSourceOnEnterKeyHandler" - remove unused overload, cleanup