new library chooser dialog used in artifacts editor
authornik <Nikolay.Chashnikov@jetbrains.com>
Wed, 15 Sep 2010 12:21:13 +0000 (16:21 +0400)
committernik <Nikolay.Chashnikov@jetbrains.com>
Wed, 15 Sep 2010 12:21:51 +0000 (16:21 +0400)
java/compiler/impl/src/com/intellij/packaging/impl/elements/LibraryElementType.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/classpath/ProjectStructureChooseLibrariesDialog.java
java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java [deleted file]
platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesDialogBase.java
platform/lang-impl/src/com/intellij/util/ui/classpath/ChooseLibrariesFromTablesDialog.java

index b93546665a69b60d4db65bbfd23ab1cc2dee0559..33a691563521b00f2b7a7233102633e34573fde1 100644 (file)
@@ -55,7 +55,7 @@ public class LibraryElementType extends ComplexPackagingElementType<LibraryPacka
   @NotNull
   public List<? extends LibraryPackagingElement> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact,
                                                                   @NotNull CompositePackagingElement<?> parent) {
-    final List<Library> selected = context.chooseLibraries(getAllLibraries(context), ProjectBundle.message("dialog.title.packaging.choose.library"));
+    final List<Library> selected = context.chooseLibraries(ProjectBundle.message("dialog.title.packaging.choose.library"));
     final List<LibraryPackagingElement> elements = new ArrayList<LibraryPackagingElement>();
     for (Library library : selected) {
       elements.add(new LibraryPackagingElement(library.getTable().getTableLevel(), library.getName(), null));
index d5fe39d67bf4229cf7ce2e5cecfd96581d35d3b5..7ede5bedb2f992555943a5aac4b01353b07c4a37 100644 (file)
@@ -74,7 +74,7 @@ public interface ArtifactEditorContext extends PackagingElementResolvingContext
 
   List<Module> chooseModules(List<Module> modules, final String title);
 
-  List<Library> chooseLibraries(List<Library> libraries, String title);
+  List<Library> chooseLibraries(String title);
 
   Artifact getArtifact();
 }
index c516993ad49bd4f7ea965db9e4a4e3911710a796..866913fb8a3c82ab38bc02031a87dfafe07bb5bc 100644 (file)
@@ -30,7 +30,6 @@ 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.libraryEditor.ChooseModulesDialog;
-import com.intellij.openapi.roots.ui.configuration.packaging.ChooseLibrariesDialog;
 import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
 import com.intellij.packaging.artifacts.Artifact;
 import com.intellij.packaging.artifacts.ArtifactModel;
@@ -41,6 +40,7 @@ import com.intellij.packaging.impl.ui.ChooseArtifactsDialog;
 import com.intellij.packaging.ui.ArtifactEditor;
 import com.intellij.packaging.ui.ArtifactEditorContext;
 import com.intellij.packaging.ui.ManifestFileConfiguration;
+import com.intellij.util.ui.classpath.ChooseLibrariesFromTablesDialog;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.Collections;
@@ -175,10 +175,10 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext {
     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, null);
+  public List<Library> chooseLibraries(final String title) {
+    final ChooseLibrariesFromTablesDialog dialog = ChooseLibrariesFromTablesDialog.createDialog(title, getProject(), false);
     dialog.show();
-    return dialog.isOK() ? dialog.getChosenElements() : Collections.<Library>emptyList();
+    return dialog.isOK() ? dialog.getSelectedLibraries() : Collections.<Library>emptyList();
   }
 
   public Artifact getArtifact() {
index 56871dcef63a2a40a3938fe071e145f067522791..646bd391f4f59763ca7fe26c28b3fe4753f7646a 100644 (file)
@@ -43,7 +43,7 @@ public class ProjectStructureChooseLibrariesDialog extends ChooseLibrariesFromTa
                                                @Nullable Project project,
                                                StructureConfigurableContext context,
                                                Collection<Library> alreadyAddedLibraries) {
-    super(parentComponent, "Choose Libraries", project);
+    super(parentComponent, "Choose Libraries", project, true);
     myContext = context;
     myAlreadyAddedLibraries = alreadyAddedLibraries;
     init();
diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/packaging/ChooseLibrariesDialog.java
deleted file mode 100644 (file)
index d73f74b..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.openapi.roots.ui.configuration.packaging;
-
-import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.roots.libraries.Library;
-import com.intellij.ide.util.ChooseElementsDialog;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.project.Project;
-import com.intellij.util.Icons;
-
-import javax.swing.*;
-import java.util.List;
-
-/**
- * @author nik
- */
-public class ChooseLibrariesDialog extends ChooseElementsDialog<Library> {
-
-  public ChooseLibrariesDialog(Project project, List<? extends Library> items, String title, String description) {
-    super(project, items, title, description, true);
-  }
-
-  protected String getItemText(final Library item) {
-    return item != null ? PackagingEditorUtil.getLibraryItemText(item, true) : "";
-  }
-
-  protected Icon getItemIcon(final Library item) {
-    if (item.getName() != null) {
-      return Icons.LIBRARY_ICON;
-    }
-    VirtualFile[] files = item.getFiles(OrderRootType.CLASSES);
-    if (files.length == 1) {
-      return files[0].getFileType().getIcon();
-    }
-    return Icons.LIBRARY_ICON;
-  }
-}
index d7a0fc13c43a88d20b46352f31cc389f1691e0b0..7823372473ed17a31c093098274c509c3509c6c4 100644 (file)
@@ -65,11 +65,16 @@ public abstract class ChooseLibrariesDialogBase extends DialogWrapper {
   private List<Library> myResult;
   private final Map<Object, Object> myParentsMap = new THashMap<Object, Object>();
 
-  public ChooseLibrariesDialogBase(final JComponent parentComponent, final String title) {
+  protected ChooseLibrariesDialogBase(final JComponent parentComponent, final String title) {
     super(parentComponent, false);
     setTitle(title);
   }
 
+  protected ChooseLibrariesDialogBase(Project project, String title) {
+    super(project, false);
+    setTitle(title);
+  }
+
   @Override
   protected void init() {
     super.init();
index 22ebff226eb3e9a25f8c7a7bb5566c88348a0983..7862eb43c22ae6c6f7634092dbb7dfee1362904b 100644 (file)
@@ -32,12 +32,31 @@ import java.util.List;
  */
 public class ChooseLibrariesFromTablesDialog extends ChooseLibrariesDialogBase {
   private @Nullable Project myProject;
+  private boolean myShowCustomLibraryTables;
 
-  public ChooseLibrariesFromTablesDialog(JComponent parentComponent, String title, @Nullable Project project) {
+  private ChooseLibrariesFromTablesDialog(@NotNull String title, @NotNull Project project, final boolean showCustomLibraryTables) {
+    super(project, title);
+    myShowCustomLibraryTables = showCustomLibraryTables;
+    myProject = project;
+  }
+
+  protected ChooseLibrariesFromTablesDialog(@NotNull JComponent parentComponent,
+                                         @NotNull String title,
+                                         @Nullable Project project,
+                                         final boolean showCustomLibraryTables) {
     super(parentComponent, title);
+    myShowCustomLibraryTables = showCustomLibraryTables;
     myProject = project;
   }
 
+  public static ChooseLibrariesFromTablesDialog createDialog(@NotNull String title,
+                                                             @NotNull Project project,
+                                                             final boolean showCustomLibraryTables) {
+    final ChooseLibrariesFromTablesDialog dialog = new ChooseLibrariesFromTablesDialog(title, project, showCustomLibraryTables);
+    dialog.init();
+    return dialog;
+  }
+
   @NotNull
   @Override
   protected Project getProject() {
@@ -60,8 +79,10 @@ public class ChooseLibrariesFromTablesDialog extends ChooseLibrariesDialogBase {
         addLibraryTable(result, registrar.getLibraryTable(myProject));
       }
       addLibraryTable(result, registrar.getLibraryTable());
-      for (LibraryTable table : registrar.getCustomLibraryTables()) {
-        addLibraryTable(result, table);
+      if (myShowCustomLibraryTables) {
+        for (LibraryTable table : registrar.getCustomLibraryTables()) {
+          addLibraryTable(result, table);
+        }
       }
     }
     else if (element instanceof LibraryTable) {