eliminating dependencies from compiler-impl to idea-ui
authorNikolay Chashnikov <Nikolay.Chashnikov@jetbrains.com>
Wed, 2 Sep 2009 07:28:01 +0000 (11:28 +0400)
committerNikolay Chashnikov <Nikolay.Chashnikov@jetbrains.com>
Wed, 2 Sep 2009 07:28:01 +0000 (11:28 +0400)
20 files changed:
java/compiler/impl/src/com/intellij/packaging/impl/elements/ArtifactElementType.java
java/compiler/impl/src/com/intellij/packaging/impl/elements/FacetBasedPackagingElementType.java
java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryElementType.java
java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryPackagingElement.java
java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputElementType.java
java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleOutputPackagingElement.java
java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesElementType.java
java/compiler/impl/src/com/intellij/packaging/impl/elements/ModuleWithDependenciesPackagingElement.java
java/compiler/impl/src/com/intellij/packaging/impl/ui/ArtifactElementPresentation.java
java/compiler/impl/src/com/intellij/packaging/impl/ui/LibraryElementPresentation.java
java/compiler/impl/src/com/intellij/packaging/impl/ui/ModuleElementPresentation.java
java/compiler/openapi/src/com/intellij/packaging/ui/ArtifactEditorContext.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ArtifactEditorContextImpl.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/ChooseArtifactsDialog.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/LibrarySourceItem.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/artifacts/sourceItems/ModuleOutputSourceItem.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ChooseModulesDialog.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/PackagingEditorUtil.java
platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java [moved from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ChooseElementsDialog.java with 96% similarity]

index 02bedf24aec5a9851061c552574e054245c78356..9b1195c24bba17e8a0bf365259d79764b8ee0a94 100644 (file)
@@ -2,7 +2,6 @@ package com.intellij.packaging.impl.elements;
 
 import com.intellij.openapi.compiler.CompilerBundle;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ui.configuration.artifacts.ChooseArtifactsDialog;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.artifacts.ArtifactPointerManager;
 import com.intellij.packaging.elements.CompositePackagingElement;
@@ -40,14 +39,10 @@ public class ArtifactElementType extends PackagingElementType<ArtifactPackagingE
   public List<? extends ArtifactPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
                                                                    @NotNull CompositePackagingElement<?> parent) {
     final Project project = context.getProject();
-    ChooseArtifactsDialog dialog = new ChooseArtifactsDialog(project, getAvailableArtifacts(context, artifact),
-                                                             CompilerBundle.message("dialog.title.choose.artifacts"), "");
-    dialog.show();
+    List<Artifact> artifacts = context.chooseArtifacts(getAvailableArtifacts(context, artifact), CompilerBundle.message("dialog.title.choose.artifacts"));
     final List<ArtifactPackagingElement> elements = new ArrayList<ArtifactPackagingElement>();
-    if (dialog.isOK()) {
-      for (Artifact selected : dialog.getChosenElements()) {
-        elements.add(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).create(selected.getName())));
-      }
+    for (Artifact selected : artifacts) {
+      elements.add(new ArtifactPackagingElement(project, ArtifactPointerManager.getInstance(project).create(selected.getName())));
     }
     return elements;
   }
index 7d900c65ad76c8c6c8130e80a59639da2e7ec5f9..e655141d15d64ead8cfa91c1dd97761a7e50a88f 100644 (file)
@@ -5,7 +5,7 @@ import com.intellij.facet.FacetTypeId;
 import com.intellij.facet.FacetTypeRegistry;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseElementsDialog;
+import com.intellij.ide.util.ChooseElementsDialog;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.elements.CompositePackagingElement;
 import com.intellij.packaging.elements.PackagingElement;
@@ -44,14 +44,13 @@ public abstract class FacetBasedPackagingElementType<E extends PackagingElement<
   @NotNull
   @Override
   public List<? extends E> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement<?> parent) {
-    final Project project = context.getProject();
     final List<F> facets = getFacets(context);
     ChooseFacetsDialog dialog = new ChooseFacetsDialog(context.getProject(), facets, getDialogTitle(), getDialogDescription());
     dialog.show();
     if (dialog.isOK()) {
       final List<E> elements = new ArrayList<E>();
       for (F facet : dialog.getChosenElements()) {
-        elements.add(createElement(project, facet));
+        elements.add(createElement(context.getProject(), facet));
       }
       return elements;
     }
index 7e40f597cf401638d16e5916dff1a7910403684b..f089dc695ce74995561030d00b446fc314f260c8 100644 (file)
@@ -5,7 +5,6 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
-import com.intellij.openapi.roots.ui.configuration.packaging.ChooseLibrariesDialog;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.elements.CompositePackagingElement;
 import com.intellij.packaging.elements.PackagingElementType;
@@ -41,15 +40,10 @@ public class LibraryElementType extends PackagingElementType<LibraryPackagingEle
   @NotNull
   public List<? extends LibraryPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
                                                                   @NotNull CompositePackagingElement<?> parent) {
-    ChooseLibrariesDialog dialog = new ChooseLibrariesDialog(context.getProject(), getAllLibraries(context),
-                                                             ProjectBundle.message("dialog.title.packaging.choose.library"), "");
-    dialog.show();
-    final List<Library> selected = dialog.getChosenElements();
+    final List<Library> selected = context.chooseLibraries(getAllLibraries(context), ProjectBundle.message("dialog.title.packaging.choose.library"));
     final List<LibraryPackagingElement> elements = new ArrayList<LibraryPackagingElement>();
-    if (dialog.isOK()) {
-      for (Library library : selected) {
-        elements.add(new LibraryPackagingElement(library.getTable().getTableLevel(), library.getName()));
-      }
+    for (Library library : selected) {
+      elements.add(new LibraryPackagingElement(library.getTable().getTableLevel(), library.getName()));
     }
     return elements;
   }
index a862dc9727ff6db7ca07ad3b26229ebc29ae8fe2..42886565d8fc750588000c3b52076765c074974f 100644 (file)
@@ -1,7 +1,6 @@
 package com.intellij.packaging.impl.elements;
 
 import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems.LibrarySourceItem;
 import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -56,7 +55,7 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
   @Override
   public PackagingElementOutputKind getFilesKind(PackagingElementResolvingContext context) {
     final Library library = findLibrary(context);
-    return library != null ? LibrarySourceItem.getKindForLibrary(library) : PackagingElementOutputKind.OTHER;
+    return library != null ? getKindForLibrary(library) : PackagingElementOutputKind.OTHER;
   }
 
   public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) {
@@ -110,4 +109,18 @@ public class LibraryPackagingElement extends ComplexPackagingElement<LibraryPack
   public Library findLibrary(@NotNull PackagingElementResolvingContext context) {
     return LibraryLink.findLibrary(myName, myLevel, context.getProject());
   }
+
+  public static PackagingElementOutputKind getKindForLibrary(final Library library) {
+    boolean containsDirectories = false;
+    boolean containsJars = false;
+    for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
+      if (file.isInLocalFileSystem()) {
+        containsDirectories = true;
+      }
+      else {
+        containsJars = true;
+      }
+    }
+    return new PackagingElementOutputKind(containsDirectories, containsJars);
+  }
 }
index c2089491e5c386e61d7c731256686d3b29db80f3..35e54c78054c2e12afa2d06c3732c7292bcffe5a 100644 (file)
@@ -4,7 +4,6 @@ import com.intellij.openapi.compiler.CompilerBundle;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectBundle;
-import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseModulesDialog;
 import com.intellij.openapi.util.IconLoader;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.elements.CompositePackagingElement;
@@ -15,7 +14,6 @@ import org.jetbrains.annotations.NotNull;
 import javax.swing.*;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 
 /**
@@ -41,7 +39,7 @@ public class ModuleOutputElementType extends PackagingElementType<ModuleOutputPa
   @NotNull
   public List<? extends ModuleOutputPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
                                                                        @NotNull CompositePackagingElement<?> parent) {
-    List<Module> modules = chooseModules(context, artifact);
+    List<Module> modules = chooseModules(context);
     final List<ModuleOutputPackagingElement> elements = new ArrayList<ModuleOutputPackagingElement>();
     for (Module module : modules) {
       elements.add(new ModuleOutputPackagingElement(module.getName()));
@@ -49,14 +47,8 @@ public class ModuleOutputElementType extends PackagingElementType<ModuleOutputPa
     return elements;
   }
 
-  public static List<Module> chooseModules(ArtifactEditorContext context, Artifact artifact) {
-    ChooseModulesDialog dialog = new ChooseModulesDialog(context.getProject(), Arrays.asList(context.getModulesProvider().getModules()), ProjectBundle.message("dialog.title.packaging.choose.module"), "");
-    dialog.show();
-    List<Module> modules = dialog.getChosenElements();
-    if (!dialog.isOK()) {
-      modules = Collections.emptyList();
-    }
-    return modules;
+  public static List<Module> chooseModules(ArtifactEditorContext context) {
+    return context.chooseModules(Arrays.asList(context.getModulesProvider().getModules()), ProjectBundle.message("dialog.title.packaging.choose.module"));
   }
 
   @NotNull
index 4acf0f780d71faa0734540cdcc6120e462756b6b..f6bbe9ed7b4da56b966e79c3d8024804f9dd946a 100644 (file)
@@ -35,7 +35,7 @@ public class ModuleOutputPackagingElement extends PackagingElement<ModuleOutputP
   }
 
   public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) {
-    return new DelegatedPackagingElementPresentation(new ModuleElementPresentation(myModuleName, findModule(context)));
+    return new DelegatedPackagingElementPresentation(new ModuleElementPresentation(myModuleName, findModule(context), context));
   }
 
   @Override
index a57e51cc4e29a427c0ee7b9bdc641c7f0ebfb35c..3269c57b6ae37a9301159ed0a3deed1f6e42f3d9 100644 (file)
@@ -37,7 +37,7 @@ public class ModuleWithDependenciesElementType extends PackagingElementType<Modu
   public List<? extends ModuleWithDependenciesPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context,
                                                                                  @NotNull Artifact artifact,
                                                                                  @NotNull CompositePackagingElement<?> parent) {
-    final List<Module> modules = ModuleOutputElementType.chooseModules(context, artifact);
+    final List<Module> modules = ModuleOutputElementType.chooseModules(context);
     final List<ModuleWithDependenciesPackagingElement> elements = new ArrayList<ModuleWithDependenciesPackagingElement>();
     for (Module module : modules) {
       elements.add(new ModuleWithDependenciesPackagingElement(module.getName()));
index 2898f108e513147c7311f8e500ba70bdf4bf7945..c72a612da62605949a88239ad94542da3aec055a 100644 (file)
@@ -70,7 +70,7 @@ public class ModuleWithDependenciesPackagingElement extends ComplexPackagingElem
   }
 
   public PackagingElementPresentation createPresentation(@NotNull ArtifactEditorContext context) {
-    return new DelegatedPackagingElementPresentation(new ModuleElementPresentation(myModuleName, findModule(context)) {
+    return new DelegatedPackagingElementPresentation(new ModuleElementPresentation(myModuleName, findModule(context), context) {
       @Override
       protected String getNodeText() {
         return CompilerBundle.message("node.text.0.with.dependencies", getPresentableName());
index 5e1323721c6609398aa8f7e030aa633d4f6dd53a..1cb56c618df7439317db9053e842aa48612aa440 100644 (file)
@@ -1,7 +1,6 @@
 package com.intellij.packaging.impl.ui;
 
 import com.intellij.ide.projectView.PresentationData;
-import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.artifacts.ArtifactPointer;
 import com.intellij.packaging.impl.artifacts.PlainArtifactType;
@@ -36,7 +35,7 @@ public class ArtifactElementPresentation extends TreeNodePresentation {
 
   @Override
   public void navigateToSource() {
-    ProjectStructureConfigurable.getInstance(myContext.getProject()).select(myArtifact, true);
+    myContext.selectArtifact(myArtifact);
   }
 
   public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
index 4ee5423a233c02424850851ff58c0dedcb3d832d..0582cc93af1d749adb13d33071f5a9b5a6abcd8d 100644 (file)
@@ -2,8 +2,11 @@ package com.intellij.packaging.impl.ui;
 
 import com.intellij.ide.projectView.PresentationData;
 import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
-import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorUtil;
+import com.intellij.openapi.roots.libraries.LibraryTable;
+import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
+import com.intellij.openapi.roots.impl.ModuleLibraryTable;
+import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
+import com.intellij.openapi.module.Module;
 import com.intellij.packaging.ui.ArtifactEditorContext;
 import com.intellij.packaging.ui.PackagingElementPresentation;
 import com.intellij.packaging.ui.PackagingElementWeights;
@@ -41,14 +44,14 @@ public class LibraryElementPresentation extends PackagingElementPresentation {
 
   @Override
   public void navigateToSource() {
-    ProjectStructureConfigurable.getInstance(myContext.getProject()).selectProjectOrGlobalLibrary(myLibrary, true);
+    myContext.selectLibrary(myLibrary);
   }
 
   public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
     if (myLibrary != null) {
       presentationData.setIcons(Icons.LIBRARY_ICON);
       presentationData.addText(myName, mainAttributes);
-      presentationData.addText(PackagingEditorUtil.getLibraryTableComment(myLibrary), commentAttributes);
+      presentationData.addText(getLibraryTableComment(myLibrary), commentAttributes);
     }
     else {
       presentationData.addText(myName, SimpleTextAttributes.ERROR_ATTRIBUTES);
@@ -60,4 +63,23 @@ public class LibraryElementPresentation extends PackagingElementPresentation {
     return PackagingElementWeights.LIBRARY;
   }
 
+  public static String getLibraryTableDisplayName(final Library library) {
+    LibraryTable table = library.getTable();
+    LibraryTablePresentation presentation = table != null ? table.getPresentation() : ModuleLibraryTable.MODULE_LIBRARY_TABLE_PRESENTATION;
+    return presentation.getDisplayName(false);
+  }
+
+  public static String getLibraryTableComment(final Library library) {
+    LibraryTable libraryTable = library.getTable();
+    String displayName;
+    if (libraryTable != null) {
+      displayName = libraryTable.getPresentation().getDisplayName(false);
+    }
+    else {
+      Module module = ((LibraryImpl)library).getModule();
+      String tableName = getLibraryTableDisplayName(library);
+      displayName = module != null ? "'" + module.getName() + "' " + tableName : tableName;
+    }
+    return " (" + displayName + ")";
+  }
 }
index b11f1eaca87ed6793be77eacc51fa8932e4a8a28..6d8d0bd532b8f154cff41353791d1f257e04b6c6 100644 (file)
@@ -3,9 +3,9 @@ package com.intellij.packaging.impl.ui;
 import com.intellij.ide.projectView.PresentationData;
 import com.intellij.openapi.compiler.CompilerBundle;
 import com.intellij.openapi.module.Module;
-import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
 import com.intellij.packaging.ui.PackagingElementWeights;
 import com.intellij.packaging.ui.TreeNodePresentation;
+import com.intellij.packaging.ui.ArtifactEditorContext;
 import com.intellij.ui.SimpleTextAttributes;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -15,11 +15,13 @@ import org.jetbrains.annotations.Nullable;
  */
 public class ModuleElementPresentation extends TreeNodePresentation {
   private final String myName;
+  private final ArtifactEditorContext myContext;
   private final Module myModule;
 
-  public ModuleElementPresentation(@NotNull String name, @Nullable Module module) {
+  public ModuleElementPresentation(@NotNull String name, @Nullable Module module, ArtifactEditorContext context) {
     myModule = module;
     myName = name;
+    myContext = context;
   }
 
   public String getPresentableName() {
@@ -38,7 +40,7 @@ public class ModuleElementPresentation extends TreeNodePresentation {
 
   @Override
   public void navigateToSource() {
-    ProjectStructureConfigurable.getInstance(myModule.getProject()).select(myModule.getName(), null, true);
+    myContext.selectModule(myModule);
   }
 
   public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
index f8a0553529178b5f4aefbd5cd7e4986516954ffe..76b142febcd88cf1cb3c336adae72b00b29129c6 100644 (file)
@@ -1,12 +1,17 @@
 package com.intellij.packaging.ui;
 
+import com.intellij.facet.Facet;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.artifacts.ArtifactType;
 import com.intellij.packaging.artifacts.ModifiableArtifactModel;
-import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.elements.CompositePackagingElement;
 import com.intellij.packaging.elements.PackagingElementResolvingContext;
 import org.jetbrains.annotations.NotNull;
 
+import java.util.List;
+
 /**
  * @author nik
  */
@@ -28,4 +33,20 @@ public interface ArtifactEditorContext extends PackagingElementResolvingContext
   void ensureRootIsWritable(@NotNull Artifact originalArtifact);
 
   ArtifactEditor getOrCreateEditor(Artifact originalArtifact);
+
+
+  void selectArtifact(@NotNull Artifact artifact);
+
+  void selectFacet(@NotNull Facet<?> facet);
+
+  void selectModule(@NotNull Module module);
+
+  void selectLibrary(@NotNull Library library);
+
+
+  List<Artifact> chooseArtifacts(List<? extends Artifact> artifacts, String title);
+
+  List<Module> chooseModules(List<Module> modules, final String title);
+
+  List<Library> chooseLibraries(List<Library> libraries, String title);
 }
index 29749020e213641cb17eaf337cfd9e0f936f0a16..fd272c567f7006ed4f94d3bdfcdb2e242acd4af6 100644 (file)
@@ -3,6 +3,11 @@ package com.intellij.openapi.roots.ui.configuration.artifacts;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
 import com.intellij.openapi.roots.ui.configuration.ModulesProvider;
+import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
+import com.intellij.openapi.roots.ui.configuration.packaging.ChooseLibrariesDialog;
+import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseModulesDialog;
+import com.intellij.openapi.roots.libraries.Library;
+import com.intellij.openapi.module.Module;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.artifacts.ArtifactModel;
 import com.intellij.packaging.artifacts.ArtifactType;
@@ -11,8 +16,12 @@ import com.intellij.packaging.elements.CompositePackagingElement;
 import com.intellij.packaging.ui.ArtifactEditor;
 import com.intellij.packaging.ui.ArtifactEditorContext;
 import com.intellij.packaging.ui.ManifestFileConfiguration;
+import com.intellij.facet.Facet;
 import org.jetbrains.annotations.NotNull;
 
+import java.util.List;
+import java.util.Collections;
+
 /**
  * @author nik
  */
@@ -53,6 +62,29 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext {
     return myParent.getOrCreateEditor(artifact);
   }
 
+  public void selectArtifact(@NotNull Artifact artifact) {
+    ProjectStructureConfigurable.getInstance(getProject()).select(artifact, true);
+  }
+
+  public void selectFacet(@NotNull Facet<?> facet) {
+    ProjectStructureConfigurable.getInstance(getProject()).select(facet, true);
+  }
+
+  public void selectModule(@NotNull Module module) {
+    ProjectStructureConfigurable.getInstance(getProject()).select(module.getName(), null, true);
+  }
+
+  public void selectLibrary(@NotNull Library library) {
+    ProjectStructureConfigurable.getInstance(getProject()).selectProjectOrGlobalLibrary(library, true);
+  }
+
+  public List<Artifact> chooseArtifacts(final List<? extends Artifact> artifacts, final String title) {
+    ChooseArtifactsDialog dialog = new ChooseArtifactsDialog(getProject(), artifacts, title, "");
+    dialog.show();
+    return dialog.isOK() ? dialog.getChosenElements() : Collections.<Artifact>emptyList();
+  }
+
+
   @NotNull
   public ArtifactModel getArtifactModel() {
     return myParent.getArtifactModel();
@@ -84,4 +116,18 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext {
   public void setValidationMananger(ArtifactValidationManagerImpl validationManager) {
     myValidationManager = validationManager;
   }
+
+  public List<Module> chooseModules(final List<Module> modules, final String title) {
+    ChooseModulesDialog dialog = new ChooseModulesDialog(getProject(), modules, title, "");
+    dialog.show();
+    List<Module> selected = dialog.getChosenElements();
+    return dialog.isOK() ? selected : Collections.<Module>emptyList();
+  }
+
+  public List<Library> chooseLibraries(final List<Library> libraries, final String title) {
+    ChooseLibrariesDialog dialog = new ChooseLibrariesDialog(getProject(), libraries, title, "");
+    dialog.show();
+    return dialog.isOK() ? dialog.getChosenElements() : Collections.<Library>emptyList();
+  }
+  
 }
index c97365f7432fddcf1783a96489911e0c9ba3bc95..23da2268b333e150e09ccd0a65cbbc97a7054032 100644 (file)
@@ -1,7 +1,7 @@
 package com.intellij.openapi.roots.ui.configuration.artifacts;
 
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseElementsDialog;
+import com.intellij.ide.util.ChooseElementsDialog;
 import com.intellij.packaging.artifacts.Artifact;
 
 import javax.swing.*;
index 71fcd44fc9582a758b3d3939750c80bdf084d8f9..e8a27b1728057a08c9e7d69d2f68dd34e1aaeb57 100644 (file)
@@ -3,12 +3,13 @@ package com.intellij.openapi.roots.ui.configuration.artifacts.sourceItems;
 import com.intellij.ide.projectView.PresentationData;
 import com.intellij.openapi.roots.OrderRootType;
 import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.openapi.roots.ui.configuration.packaging.PackagingEditorUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.packaging.elements.PackagingElement;
 import com.intellij.packaging.elements.PackagingElementFactory;
 import com.intellij.packaging.elements.PackagingElementOutputKind;
 import com.intellij.packaging.ui.*;
+import com.intellij.packaging.impl.ui.LibraryElementPresentation;
+import com.intellij.packaging.impl.elements.LibraryPackagingElement;
 import com.intellij.ui.SimpleTextAttributes;
 import com.intellij.util.Icons;
 import org.jetbrains.annotations.NotNull;
@@ -46,21 +47,7 @@ public class LibrarySourceItem extends PackagingSourceItem {
   @NotNull
   @Override
   public PackagingElementOutputKind getKindOfProducedElements() {
-    return getKindForLibrary(myLibrary);
-  }
-
-  public static PackagingElementOutputKind getKindForLibrary(final Library library) {
-    boolean containsDirectories = false;
-    boolean containsJars = false;
-    for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
-      if (file.isInLocalFileSystem()) {
-        containsDirectories = true;
-      }
-      else {
-        containsJars = true;
-      }
-    }
-    return new PackagingElementOutputKind(containsDirectories, containsJars);
+    return LibraryPackagingElement.getKindForLibrary(myLibrary);
   }
 
   @NotNull
@@ -92,7 +79,7 @@ public class LibrarySourceItem extends PackagingSourceItem {
       if (name != null) {
         presentationData.setIcons(Icons.LIBRARY_ICON);
         presentationData.addText(name, mainAttributes);
-        presentationData.addText(PackagingEditorUtil.getLibraryTableComment(myLibrary), commentAttributes);
+        presentationData.addText(LibraryElementPresentation.getLibraryTableComment(myLibrary), commentAttributes);
       }
       else {
         final VirtualFile[] files = myLibrary.getFiles(OrderRootType.CLASSES);
index c7dea3a1e04f6f1afc45d4b1ab58eac9e3278b79..957bf0ee0531ce92adaea734055ae9db6e2b5cfb 100644 (file)
@@ -31,7 +31,7 @@ public class ModuleOutputSourceItem extends PackagingSourceItem {
 
   @Override
   public SourceItemPresentation createPresentation(@NotNull ArtifactEditorContext context) {
-    return new DelegatedSourceItemPresentation(new ModuleElementPresentation(myModule.getName(), myModule)) {
+    return new DelegatedSourceItemPresentation(new ModuleElementPresentation(myModule.getName(), myModule, context)) {
       @Override
       public int getWeight() {
         return SourceItemWeights.MODULE_OUTPUT_WEIGHT;
index 696ed71b5e1104f906d5a5034e82e0e5911e9329..82141c6dea4d0e1cb244107fe917bd39a72acd52 100644 (file)
@@ -12,6 +12,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
 
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.Project;
+import com.intellij.ide.util.ChooseElementsDialog;
 
 import javax.swing.*;
 import java.awt.*;
index 87f46b200b838ea24f17b775054dd9dcad36c81c..b95c2d57e156d0512afd7ebdb29abedd9b59a365 100644 (file)
@@ -2,7 +2,7 @@ package com.intellij.openapi.roots.ui.configuration.packaging;
 
 import com.intellij.openapi.roots.OrderRootType;
 import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.openapi.roots.ui.configuration.libraryEditor.ChooseElementsDialog;
+import com.intellij.ide.util.ChooseElementsDialog;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.project.Project;
 import com.intellij.util.Icons;
index 1bdde8c54d8306644c461935b7d22811003caf3b..e558b47793e99d64ab186943ea5f03812a90eea9 100644 (file)
@@ -3,17 +3,16 @@ package com.intellij.openapi.roots.ui.configuration.packaging;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.project.ProjectBundle;
 import com.intellij.openapi.roots.*;
-import com.intellij.openapi.roots.impl.ModuleLibraryTable;
 import com.intellij.openapi.roots.impl.OrderEntryUtil;
 import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
 import com.intellij.openapi.roots.libraries.Library;
 import com.intellij.openapi.roots.libraries.LibraryTable;
-import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
 import com.intellij.openapi.roots.ui.util.OrderEntryCellAppearanceUtils;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.ui.ColoredTreeCellRenderer;
 import com.intellij.ui.SimpleTextAttributes;
 import com.intellij.util.Icons;
+import com.intellij.packaging.impl.ui.LibraryElementPresentation;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.List;
@@ -27,19 +26,13 @@ public class PackagingEditorUtil {
   private PackagingEditorUtil() {
   }
 
-  private static String getLibraryTableDisplayName(final Library library) {
-    LibraryTable table = library.getTable();
-    LibraryTablePresentation presentation = table != null ? table.getPresentation() : ModuleLibraryTable.MODULE_LIBRARY_TABLE_PRESENTATION;
-    return presentation.getDisplayName(false);
-  }
-
   public static void renderLibraryNode(final ColoredTreeCellRenderer renderer, final Library library,
                                        final SimpleTextAttributes mainAttributes, final SimpleTextAttributes commentAttributes) {
     String name = library.getName();
     if (name != null) {
       renderer.setIcon(Icons.LIBRARY_ICON);
       renderer.append(name, mainAttributes);
-      renderer.append(getLibraryTableComment(library), commentAttributes);
+      renderer.append(LibraryElementPresentation.getLibraryTableComment(library), commentAttributes);
     }
     else {
       VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
@@ -47,7 +40,7 @@ public class PackagingEditorUtil {
         VirtualFile file = files[0];
         renderer.setIcon(file.getIcon());
         renderer.append(file.getName(), mainAttributes);
-        renderer.append(getLibraryTableComment(library), commentAttributes);
+        renderer.append(LibraryElementPresentation.getLibraryTableComment(library), commentAttributes);
       }
       else {
         OrderEntryCellAppearanceUtils.forLibrary(library).customize(renderer);
@@ -55,20 +48,6 @@ public class PackagingEditorUtil {
     }
   }
 
-  public static String getLibraryTableComment(final Library library) {
-    LibraryTable libraryTable = library.getTable();
-    String displayName;
-    if (libraryTable != null) {
-      displayName = libraryTable.getPresentation().getDisplayName(false);
-    }
-    else {
-      Module module = ((LibraryImpl)library).getModule();
-      String tableName = getLibraryTableDisplayName(library);
-      displayName = module != null ? "'" + module.getName() + "' " + tableName : tableName;
-    }
-    return " (" + displayName + ")";
-  }
-
   public static void renderLibraryFile(final ColoredTreeCellRenderer renderer, final Library library, final VirtualFile file,
                                        final SimpleTextAttributes mainAttributes, final SimpleTextAttributes commentAttributes) {
     renderer.setIcon(file.getIcon());
@@ -78,7 +57,7 @@ public class PackagingEditorUtil {
     if (name != null) {
       StringBuilder comment = new StringBuilder();
       comment.append(" ('").append(name).append("' ");
-      comment.append(getLibraryTableDisplayName(library));
+      comment.append(LibraryElementPresentation.getLibraryTableDisplayName(library));
       comment.append(")");
       renderer.append(comment.toString(), commentAttributes);
     }
@@ -86,7 +65,7 @@ public class PackagingEditorUtil {
       Module module = ((LibraryImpl)library).getModule();
       String comment;
       if (module == null) {
-        comment = " (" + getLibraryTableDisplayName(library) + ")";
+        comment = " (" + LibraryElementPresentation.getLibraryTableDisplayName(library) + ")";
       }
       else {
         comment = " " + ProjectBundle.message("node.text.library.of.module", module.getName());
@@ -99,13 +78,13 @@ public class PackagingEditorUtil {
     String name = library.getName();
     VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
     if (name != null) {
-      return "'" + name + "' " + getLibraryTableDisplayName(library);
+      return "'" + name + "' " + LibraryElementPresentation.getLibraryTableDisplayName(library);
     }
     else if (files.length > 0) {
       Module module = ((LibraryImpl)library).getModule();
       final String description;
       if (module == null) {
-        description = "(" + getLibraryTableDisplayName(library) + ")";
+        description = "(" + LibraryElementPresentation.getLibraryTableDisplayName(library) + ")";
       }
       else {
         description = ProjectBundle.message("node.text.library.of.module", module.getName());
@@ -121,10 +100,10 @@ public class PackagingEditorUtil {
     String name = library.getName();
     VirtualFile[] files = library.getFiles(OrderRootType.CLASSES);
     if (name != null) {
-      return name + (includeTableName ? getLibraryTableComment(library) : "");
+      return name + (includeTableName ? LibraryElementPresentation.getLibraryTableComment(library) : "");
     }
     else if (files.length > 0) {
-      return files[0].getName() + (includeTableName ? getLibraryTableComment(library) : "");
+      return files[0].getName() + (includeTableName ? LibraryElementPresentation.getLibraryTableComment(library) : "");
     }
     else {
       return ProjectBundle.message("library.empty.item");
similarity index 96%
rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraryEditor/ChooseElementsDialog.java
rename to platform/platform-impl/src/com/intellij/ide/util/ChooseElementsDialog.java
index ed7170c0fede61cb929bff94f6de8daf7cc7dcbf..c862c8e85c48c1ece89a8008a6eb0f5406cfa3ba 100644 (file)
@@ -1,19 +1,18 @@
-package com.intellij.openapi.roots.ui.configuration.libraryEditor;
+package com.intellij.ide.util;
 
-import com.intellij.ide.util.ElementsChooser;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.ui.ScrollPaneFactory;
-import org.jetbrains.annotations.Nullable;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
 import java.util.Comparator;
+import java.util.List;
 
 /**
  * @author nik