/*
 * Copyright 2000-2010 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.libraries;

import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent;
import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor;
import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * Override this class to provide custom library type. The implementation should be registered in plugin.xml:
 * <p>
 * &lt;extensions defaultExtensionNs="com.intellij"&gt;<br>
 * &nbsp;&nbsp;&lt;library.type implementation="qualified-class-name"/&gt;<br>
 * &lt;/extensions&gt;
 *
 * @author nik
 */
public abstract class LibraryType<P extends LibraryProperties> extends LibraryPresentationProvider<P> {
  public static final ExtensionPointName<LibraryType<?>> EP_NAME = ExtensionPointName.create("com.intellij.library.type");

  protected LibraryType(@NotNull LibraryKind<P> libraryKind) {
    super(libraryKind);
  }

  /**
   * @return text to show in 'New Library' popup
   */
  @NotNull
  public abstract String getCreateActionName();

  @NotNull
  public abstract P createDefaultProperties();

  /**
   * @return {@code true} if library of this type can be added as a dependency to a module of type {@code moduleType}
   */
  public boolean isSuitableModuleType(@NotNull ModuleType moduleType) {
    return true;
  }

  /**
   * Override this method to customize the library roots editor
   * @return {@link com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor} instance
   */
  @Nullable
  public LibraryRootsComponentDescriptor createLibraryRootsComponentDescriptor() {
    return null;
  }

  @Nullable
  public abstract LibraryPropertiesEditor createPropertiesEditor(@NotNull LibraryEditorComponent<P> properties);

  @Override
  public P detect(@NotNull List<VirtualFile> classesRoots) {
    return null;
  }
}

@@ -747,16 +747,65 @@
 leType;%0A
+import com.intellij.openapi.roots.OrderRootType;%0A
 import c
@@ -867,16 +867,16 @@
 ponent;%0A
-
 import c
@@ -1705,16 +1705,112 @@
 .type%22);
+%0A  %0A  public final static OrderRootType%5B%5D DEFAULT_EXTERNAL_ROOT_TYPES = %7BOrderRootType.CLASSES%7D;
 %0A%0A  prot
@@ -2789,24 +2789,24 @@
 sesRoots) %7B%0A
-
     return n
@@ -2813,11 +2813,268 @@
 ull;%0A  %7D
+%0A%0A  /**%0A   * @return Root types to collect library files which do not belong to the project and therefore%0A   *         indicate that the library is external.%0A   */%0A  public OrderRootType%5B%5D getExternalRootTypes() %7B%0A    return DEFAULT_EXTERNAL_ROOT_TYPES;%0A  %7D
 %0A%7D%0A

Support for Mootools JavaScript library external documentation [r=K.Safonov]