package com.intellij.moduleDependencies;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataConstants;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.peer.PeerFactory;
import com.intellij.ui.content.Content;

/**
 * User: anna
 * Date: Feb 9, 2005
 */
public class ShowModuleDependenciesAction extends AnAction{
  public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = (Project)dataContext.getData(DataConstants.PROJECT);
    if (project == null){
      return;
    }
    ModulesDependenciesPanel panel;
    final Module[] modules = (Module[])dataContext.getData(DataConstants.MODULE_CONTEXT_ARRAY);
    if (modules != null){
      panel = new ModulesDependenciesPanel(project, modules);
    } else {
      panel = new ModulesDependenciesPanel(project);
    }

    Content content = PeerFactory.getInstance().getContentFactory().createContent(panel,
                                                                                "Module Dependencies of " + project.getName(),
                                                                                false);
    panel.setContent(content);
    DependenciesAnalyzeManager.getInstance(project).addContent(content);
  }

  public void update(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = (Project)dataContext.getData(DataConstants.PROJECT);
    e.getPresentation().setEnabled(project != null);
  }
}

@@ -327,23 +327,171 @@
 api.
-project.Project
+module.ModuleManager;%0Aimport com.intellij.openapi.module.impl.ModuleUtil;%0Aimport com.intellij.openapi.project.Project;%0Aimport com.intellij.openapi.ui.DialogWrapper
 ;%0Aim
@@ -526,16 +526,52 @@
 actory;%0A
+import com.intellij.psi.PsiElement;%0A
 import c
@@ -603,16 +603,58 @@
 ntent;%0A%0A
+import javax.swing.*;%0Aimport java.awt.*;%0A%0A
 /**%0A * U
@@ -1223,54 +1223,739 @@
     
-panel = new ModulesDependenciesPanel(project);
+final PsiElement element = (PsiElement)dataContext.getData(DataConstants.PSI_FILE);%0A      final Module module = element != null ? ModuleUtil.findModuleForPsiElement(element) : null;%0A      if (module != null && ModuleManager.getInstance(project).getModules().length %3E 1)%7B%0A        MyModuleOrProjectScope dlg = new MyModuleOrProjectScope(module.getName());%0A        dlg.show();%0A        if (dlg.isOK())%7B%0A          if (!dlg.useProjectScope())%7B%0A            panel = new ModulesDependenciesPanel(project, new Module%5B%5D%7Bmodule%7D);%0A          %7D else %7B%0A            panel = new ModulesDependenciesPanel(project);%0A          %7D%0A        %7D else %7B%0A          return;%0A        %7D%0A      %7D else %7B%0A        panel = new ModulesDependenciesPanel(project);%0A      %7D
 %0A   
@@ -2127,16 +2127,18 @@
         
+  
 %22Module 
@@ -2176,16 +2176,18 @@
 Name(),%0A
+  
         
@@ -2608,11 +2608,983 @@
 ll);%0A  %7D
+%0A%0A  private static class MyModuleOrProjectScope extends DialogWrapper%7B%0A    private JRadioButton myProjectScope;%0A    private JRadioButton myModuleScope;%0A    protected MyModuleOrProjectScope(String moduleName) %7B%0A      super(false);%0A      setTitle(%22Choose Analyze Module Dependencies Scope%22);%0A      ButtonGroup group = new ButtonGroup();%0A      myProjectScope = new JRadioButton(%22Inspect the whole project%22);%0A      myProjectScope.setMnemonic('p');%0A      myModuleScope = new JRadioButton(%22Inspect module %5C'%22 + moduleName + %22%5C'%22);%0A      myModuleScope.setMnemonic('m');%0A      group.add(myProjectScope);%0A      group.add(myModuleScope);%0A      myProjectScope.setSelected(true);%0A      init();%0A    %7D%0A%0A    protected JComponent createCenterPanel() %7B%0A      JPanel panel = new JPanel(new GridLayout(2, 1));%0A      panel.add(myProjectScope);%0A      panel.add(myModuleScope);%0A      return panel;%0A    %7D%0A%0A    public boolean useProjectScope()%7B%0A      return myProjectScope.isSelected();%0A    %7D%0A  %7D
 %0A%7D%0A

add scope chooser to analyze module dependencies