IDEA-250342 [new run config UI] Add a way to edit run configuration from the run...
[idea/community.git] / java / idea-ui / src / com / intellij / jarRepository / RepositoryLibraryType.java
1 /*
2  * Copyright 2000-2017 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.jarRepository;
17
18 import com.intellij.ide.JavaUiBundle;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.openapi.roots.libraries.LibraryType;
21 import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
22 import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
23 import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent;
24 import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor;
25 import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor;
26 import com.intellij.openapi.util.NlsContexts;
27 import com.intellij.openapi.vfs.VirtualFile;
28 import org.jetbrains.annotations.Nls;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 import org.jetbrains.idea.maven.utils.library.RepositoryLibraryDescription;
32 import org.jetbrains.idea.maven.utils.library.RepositoryLibraryProperties;
33
34 import javax.swing.*;
35
36 public class RepositoryLibraryType extends LibraryType<RepositoryLibraryProperties> {
37
38   public static final PersistentLibraryKind<RepositoryLibraryProperties>
39     REPOSITORY_LIBRARY_KIND = new PersistentLibraryKind<RepositoryLibraryProperties>("repository") {
40     @NotNull
41     @Override
42     public RepositoryLibraryProperties createDefaultProperties() {
43       return new RepositoryLibraryProperties();
44     }
45   };
46
47   protected RepositoryLibraryType() {
48     super(REPOSITORY_LIBRARY_KIND);
49   }
50
51   public static RepositoryLibraryType getInstance() {
52     return EP_NAME.findExtension(RepositoryLibraryType.class);
53   }
54
55   @Nullable
56   @Override
57   public @NlsContexts.Label String getCreateActionName() {
58     return JavaUiBundle.message("repository.library.type.action.name.label");
59   }
60
61   @Override
62   public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent,
63                                                   @Nullable VirtualFile contextDirectory,
64                                                   @NotNull Project project) {
65     return JarRepositoryManager.chooseLibraryAndDownload(project, null, parentComponent);
66   }
67
68   @Override
69   public LibraryPropertiesEditor createPropertiesEditor(@NotNull LibraryEditorComponent<RepositoryLibraryProperties> component) {
70     return new RepositoryLibraryWithDescriptionEditor(component);
71   }
72
73   @Nullable
74   @Override
75   public Icon getIcon(@Nullable RepositoryLibraryProperties properties) {
76     if (properties == null || properties.getGroupId() == null || properties.getArtifactId() == null) {
77       return RepositoryLibraryDescription.DEFAULT_ICON;
78     }
79     return RepositoryLibraryDescription.findDescription(properties).getIcon();
80   }
81
82   @NotNull
83   @Override
84   public @Nls String getDescription(@NotNull RepositoryLibraryProperties properties) {
85     RepositoryLibraryDescription description = RepositoryLibraryDescription.findDescription(properties);
86     final String name = description.getDisplayName(properties.getVersion());
87     return JavaUiBundle.message("repository.library.type.maven.description", name);
88   }
89
90   @Nullable
91   @Override
92   public LibraryRootsComponentDescriptor createLibraryRootsComponentDescriptor() {
93     return new RepositoryLibraryRootsComponentDescriptor();
94   }
95 }