/*
 * 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.ide.actions;

import com.intellij.ide.IdeBundle;
import com.intellij.ide.IdeView;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;

public class NewElementAction extends AnAction implements DumbAware {

  public void actionPerformed(final AnActionEvent e) {
    showPopup(e.getDataContext());
  }

  protected void showPopup(DataContext dataContext) {
    final ListPopup popup = JBPopupFactory.getInstance()
      .createActionGroupPopup(getPopupTitle(),
                              getGroup(),
                              dataContext,
                              false, false, false,
                              null, -1, LangDataKeys.PRESELECT_NEW_ACTION_CONDITION.getData(dataContext));

    popup.showInBestPositionFor(dataContext);
  }

  protected String getPopupTitle() {
    return IdeBundle.message("title.popup.new.element");
  }

  public void update(AnActionEvent event){
    Presentation presentation = event.getPresentation();
    DataContext dataContext = event.getDataContext();
    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
      presentation.setEnabled(false);
      return;
    }
    IdeView ideView = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (ideView == null) {
      presentation.setEnabled(false);
      return;
    }

    presentation.setEnabled(!ActionGroupUtil.isGroupEmpty(getGroup(), event));
  }

  private static ActionGroup getGroup() {
    return (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_WEIGHING_NEW);
  }
}

@@ -778,23 +778,25 @@
 project.
-Project
+DumbAware
 ;%0Aimport
@@ -821,33 +821,31 @@
 api.project.
-DumbAware
+Project
 ;%0Aimport com
@@ -935,16 +935,183 @@
 tPopup;%0A
+import com.intellij.openapi.util.Condition;%0Aimport org.jetbrains.annotations.Nullable;%0A%0A/**%0A * @author Konstantin Bulenkov%0A */%0A@SuppressWarnings(%7B%22MethodMayBeStatic%22%7D)
 %0Apublic 
@@ -1150,16 +1150,17 @@
 nAction 
+ 
 implemen
@@ -1174,17 +1174,16 @@
 Aware %7B%0A
-%0A
   public
@@ -1225,16 +1225,20 @@
 nEvent e
+vent
 ) %7B%0A    
@@ -1248,16 +1248,20 @@
 wPopup(e
+vent
 .getData
@@ -1312,29 +1312,25 @@
 DataContext 
-dataC
+c
 ontext) %7B%0A  
@@ -1335,31 +1335,137 @@
     
-final ListPopup popup =
+createPopup(context).showInBestPositionFor(context);%0A  %7D%0A%0A  protected ListPopup createPopup(DataContext dataContext) %7B%0A    return
  JBP
@@ -1576,16 +1576,27 @@
 etGroup(
+dataContext
 ),%0A     
@@ -1667,181 +1667,821 @@
     
-false, false, false,%0A                              null, -1, LangDataKeys.PRESELECT_NEW_ACTION_CONDITION.getData(dataContext));%0A%0A    popup.showInBestPositionFor(dataContext)
+isShowNumbers(),%0A                              isShowDisabledActions(),%0A                              isHonorActionMnemonics(),%0A                              getDisposeCallback(),%0A                              getMaxRowCount(),%0A                              getPreselectActionCondition(dataContext));%0A  %7D%0A%0A  protected int getMaxRowCount() %7B%0A    return -1;%0A  %7D%0A%0A  @Nullable%0A  protected Condition%3CAnAction%3E getPreselectActionCondition(DataContext dataContext) %7B%0A    return LangDataKeys.PRESELECT_NEW_ACTION_CONDITION.getData(dataContext);%0A  %7D%0A%0A  @Nullable%0A  protected Runnable getDisposeCallback() %7B%0A    return null;%0A  %7D%0A%0A  protected boolean isHonorActionMnemonics() %7B%0A    return false;%0A  %7D%0A%0A  protected boolean isShowDisabledActions() %7B%0A    return false;%0A  %7D%0A%0A  protected boolean isShowNumbers() %7B%0A    return false
 ;%0A  
@@ -2622,19 +2622,21 @@
 nt e
-vent
 )%7B%0A    
+final 
 Pres
@@ -2656,28 +2656,24 @@
 entation = e
-vent
 .getPresenta
@@ -2684,16 +2684,22 @@
 ();%0A    
+final 
 DataCont
@@ -2698,29 +2698,25 @@
 DataContext 
-dataC
+c
 ontext = eve
@@ -2713,20 +2713,16 @@
 text = e
-vent
 .getData
@@ -2736,16 +2736,22 @@
 ();%0A    
+final 
 Project 
@@ -2785,37 +2785,33 @@
 PROJECT.getData(
-dataC
+c
 ontext);%0A    if 
@@ -2892,16 +2892,22 @@
   %7D%0A    
+final 
 IdeView 
@@ -2938,37 +2938,33 @@
 DE_VIEW.getData(
-dataC
+c
 ontext);%0A    if 
@@ -3113,16 +3113,19 @@
 oup(
+context
 ), e
-vent
 ));%0A
@@ -3137,20 +3137,15 @@
   pr
-ivate static
+otected
  Act
@@ -3162,16 +3162,39 @@
 etGroup(
+DataContext dataContext
 ) %7B%0A    

make it flexible for overriding