LibraryType/LibraryKind refactoring: move UI-independent stuff from LibraryType to LibraryKind, use it whenever possible

This commit is contained in:
Dmitry Jemerov
2012-05-17 13:04:27 +02:00
parent 87b01fcb81
commit 4874535d59
48 changed files with 309 additions and 239 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -53,7 +53,7 @@ public class FrameworkLibraryValidatorImpl extends FrameworkLibraryValidator {
@Override
public ValidationResult check() {
final Set<? extends LibraryKind<?>> libraryKinds = myLibraryDescription.getSuitableLibraryKinds();
final Set<? extends LibraryKind> libraryKinds = myLibraryDescription.getSuitableLibraryKinds();
final Ref<Boolean> found = Ref.create(false);
myContext.getRootModel().orderEntries().using(myContext.getModulesProvider()).recursively().librariesOnly().forEachLibrary(new Processor<Library>() {
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -16,9 +16,9 @@
package com.intellij.framework.library;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.LibraryKind;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
import com.intellij.openapi.roots.libraries.ui.LibraryEditorComponent;
import com.intellij.openapi.roots.libraries.ui.LibraryPropertiesEditor;
import com.intellij.openapi.util.text.StringUtil;
@@ -35,7 +35,7 @@ public class DownloadableLibraryType extends LibraryType<LibraryVersionPropertie
private final String myLibraryCategoryName;
private final DownloadableLibraryDescription myLibraryDescription;
public DownloadableLibraryType(@NotNull LibraryKind<LibraryVersionProperties> kind, @NotNull String libraryCategoryName,
public DownloadableLibraryType(@NotNull PersistentLibraryKind<LibraryVersionProperties> kind, @NotNull String libraryCategoryName,
@NotNull DownloadableLibraryDescription description) {
super(kind);
myLibraryCategoryName = libraryCategoryName;
@@ -69,12 +69,6 @@ public class DownloadableLibraryType extends LibraryType<LibraryVersionPropertie
return StringUtil.capitalize(myLibraryCategoryName) + " library" + (versionString != null ? " of version " + versionString : "");
}
@NotNull
@Override
public LibraryVersionProperties createDefaultProperties() {
return new LibraryVersionProperties();
}
@Override
public LibraryPropertiesEditor createPropertiesEditor(@NotNull LibraryEditorComponent<LibraryVersionProperties> editorComponent) {
return DownloadableLibraryService.getInstance().createDownloadableLibraryEditor(myLibraryDescription, editorComponent, this);
@@ -1,8 +1,23 @@
/*
* Copyright 2000-2012 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.framework.library;
import com.intellij.openapi.roots.libraries.JarVersionDetectionUtil;
import com.intellij.openapi.roots.libraries.LibraryKind;
import com.intellij.openapi.roots.libraries.LibraryUtil;
import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -19,7 +34,13 @@ public abstract class DownloadableLibraryTypeBase extends DownloadableLibraryTyp
@NotNull String groupId,
@NotNull Icon icon,
@NotNull URL... localUrls) {
super(new LibraryKind<LibraryVersionProperties>(libraryTypeId), libraryCategoryName,
super(new PersistentLibraryKind<LibraryVersionProperties>(libraryTypeId, false) {
@NotNull
@Override
public LibraryVersionProperties createDefaultProperties() {
return new LibraryVersionProperties();
}
}, libraryCategoryName,
DownloadableLibraryService.getInstance().createLibraryDescription(groupId, localUrls));
myIcon = icon;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -35,7 +35,7 @@ public class CustomLibraryDescriptionImpl extends CustomLibraryDescriptionBase {
@NotNull
@Override
public Set<? extends LibraryKind<?>> getSuitableLibraryKinds() {
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
return Collections.singleton(myLibraryType.getKind());
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -83,7 +83,7 @@ public class OldCustomLibraryDescription extends CustomLibraryDescriptionBase {
@NotNull
@Override
public Set<? extends LibraryKind<?>> getSuitableLibraryKinds() {
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
return Collections.emptySet();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -100,7 +100,7 @@ public abstract class ChangeLibraryLevelActionBase extends AnAction {
}
}
final Library copied = ((LibraryTableBase.ModifiableModelEx)provider.getModifiableModel()).createLibrary(dialog.getLibraryName(), library.getType());
final Library copied = ((LibraryTableBase.ModifiableModelEx)provider.getModifiableModel()).createLibrary(dialog.getLibraryName(), library.getKind());
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)copied.getModifiableModel();
LibraryEditingUtil.copyLibrary(library, copiedFiles, model);
@@ -21,8 +21,10 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryProperties;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor;
@@ -33,7 +35,9 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryR
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.*;
@@ -45,20 +49,23 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
private final JComponent myParentComponent;
private final Module myModule;
private final LibraryTable.ModifiableModel myModuleLibrariesModel;
@Nullable private final Function<LibraryType, LibraryProperties> myDefaultPropertiesFactory;
private final HashMap<LibraryRootsComponentDescriptor,LibraryType> myLibraryTypes;
private final DefaultLibraryRootsComponentDescriptor myDefaultDescriptor;
public CreateModuleLibraryChooser(ClasspathPanel classpathPanel, LibraryTable.ModifiableModel moduleLibraryModel) {
this(LibraryEditingUtil.getSuitableTypes(classpathPanel), classpathPanel.getComponent(), classpathPanel.getRootModel().getModule(),
moduleLibraryModel);
moduleLibraryModel, null);
}
public CreateModuleLibraryChooser(List<? extends LibraryType> libraryTypes, JComponent parentComponent,
Module module,
final LibraryTable.ModifiableModel moduleLibrariesModel) {
final LibraryTable.ModifiableModel moduleLibrariesModel,
@Nullable final Function<LibraryType, LibraryProperties> defaultPropertiesFactory) {
myParentComponent = parentComponent;
myModule = module;
myModuleLibrariesModel = moduleLibrariesModel;
myDefaultPropertiesFactory = defaultPropertiesFactory;
myLibraryTypes = new HashMap<LibraryRootsComponentDescriptor, LibraryType>();
myDefaultDescriptor = new DefaultLibraryRootsComponentDescriptor();
for (LibraryType<?> libraryType : libraryTypes) {
@@ -76,8 +83,11 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
}
private Library createLibraryFromRoots(List<OrderRoot> roots, final LibraryType libraryType) {
final Library library = ((LibraryTableBase.ModifiableModelEx)myModuleLibrariesModel).createLibrary(null, libraryType);
final Library.ModifiableModel libModel = library.getModifiableModel();
final Library library = ((LibraryTableBase.ModifiableModelEx)myModuleLibrariesModel).createLibrary(null, libraryType.getKind());
final LibraryEx.ModifiableModelEx libModel = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
if (myDefaultPropertiesFactory != null) {
libModel.setProperties(myDefaultPropertiesFactory.fun(libraryType));
}
for (OrderRoot root : roots) {
if (root.isJarDirectory()) {
libModel.addJarDirectory(root.getFile(), false, root.getType());
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -36,7 +36,7 @@ public abstract class CustomLibraryDescription {
}
@NotNull
public abstract Set<? extends LibraryKind<?>> getSuitableLibraryKinds();
public abstract Set<? extends LibraryKind> getSuitableLibraryKinds();
@Nullable
public abstract NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -190,8 +190,9 @@ public class LibraryEditingUtil {
}
public static List<Module> getSuitableModules(@NotNull ModuleStructureConfigurable rootConfigurable,
final @Nullable LibraryType type, @Nullable Library library) {
final @Nullable LibraryKind kind, @Nullable Library library) {
final List<Module> modules = new ArrayList<Module>();
LibraryType type = kind == null ? null : LibraryType.findByKind(kind);
for (Module module : rootConfigurable.getModules()) {
if (type != null && !type.isSuitableModule(module, rootConfigurable.getFacetConfigurator())) {
continue;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -50,12 +50,12 @@ public abstract class LibraryPresentationManager {
public abstract List<String> getDescriptions(@NotNull Library library, StructureConfigurableContext context);
@NotNull
public abstract List<String> getDescriptions(@NotNull VirtualFile[] classRoots, Set<LibraryKind<?>> excludedKinds);
public abstract List<String> getDescriptions(@NotNull VirtualFile[] classRoots, Set<LibraryKind> excludedKinds);
public abstract List<Library> getLibraries(@NotNull Set<LibraryKind<?>> kinds, @NotNull Project project, @Nullable StructureConfigurableContext context);
public abstract List<Library> getLibraries(@NotNull Set<LibraryKind> kinds, @NotNull Project project, @Nullable StructureConfigurableContext context);
public abstract boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull LibraryKind<?> kind);
public abstract boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull LibraryKind kind);
public abstract boolean isLibraryOfKind(@NotNull Library library, @NotNull LibrariesContainer librariesContainer,
@NotNull Set<? extends LibraryKind<?>> acceptedKinds);
@NotNull Set<? extends LibraryKind> acceptedKinds);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -36,11 +36,11 @@ import java.util.*;
* @author nik
*/
public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
private Map<LibraryKind<?>, LibraryPresentationProvider<?>> myPresentationProviders;
private Map<LibraryKind, LibraryPresentationProvider<?>> myPresentationProviders;
private <P extends LibraryProperties> LibraryPresentationProvider<P> getPresentationProvider(LibraryKind<P> kind) {
private <P extends LibraryProperties> LibraryPresentationProvider<P> getPresentationProvider(LibraryKind kind) {
if (myPresentationProviders == null) {
final Map<LibraryKind<?>, LibraryPresentationProvider<?>> providers = new HashMap<LibraryKind<?>, LibraryPresentationProvider<?>>();
final Map<LibraryKind, LibraryPresentationProvider<?>> providers = new HashMap<LibraryKind, LibraryPresentationProvider<?>>();
for (LibraryType<?> type : LibraryType.EP_NAME.getExtensions()) {
providers.put(type.getKind(), type);
}
@@ -62,9 +62,9 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
@Override
public Icon getCustomIcon(@NotNull Library library, StructureConfigurableContext context) {
final LibraryType<?> type = ((LibraryEx)library).getType();
if (type != null) {
return type.getIcon();
final LibraryKind kind = ((LibraryEx)library).getKind();
if (kind != null) {
return LibraryType.findByKind(kind).getIcon();
}
final List<Icon> icons = getCustomIcons(library, context);
if (icons.size() == 1) {
@@ -80,7 +80,7 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
final List<Icon> icons = new SmartList<Icon>();
LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() {
@Override
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind<P> kind, @NotNull P properties) {
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) {
final LibraryPresentationProvider<P> provider = getPresentationProvider(kind);
if (provider != null) {
ContainerUtil.addIfNotNull(icons, provider.getIcon());
@@ -92,10 +92,10 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
}
@Override
public boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull final LibraryKind<?> kind) {
public boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull final LibraryKind kind) {
return !LibraryDetectionManager.getInstance().processProperties(files, new LibraryDetectionManager.LibraryPropertiesProcessor() {
@Override
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind<P> processedKind, @NotNull P properties) {
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind processedKind, @NotNull P properties) {
return !kind.equals(processedKind);
}
});
@@ -104,29 +104,29 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
@Override
public boolean isLibraryOfKind(@NotNull Library library,
@NotNull LibrariesContainer librariesContainer,
@NotNull final Set<? extends LibraryKind<?>> acceptedKinds) {
final LibraryType<?> type = ((LibraryEx)library).getType();
if (type != null && acceptedKinds.contains(type.getKind())) return true;
@NotNull final Set<? extends LibraryKind> acceptedKinds) {
final LibraryKind type = ((LibraryEx)library).getKind();
if (type != null && acceptedKinds.contains(type)) return true;
final VirtualFile[] files = librariesContainer.getLibraryFiles(library, OrderRootType.CLASSES);
return !LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() {
@Override
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind<P> processedKind, @NotNull P properties) {
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind processedKind, @NotNull P properties) {
return !acceptedKinds.contains(processedKind);
}
});
}
public static List<LibraryKind<?>> getLibraryKinds(@NotNull Library library, @Nullable StructureConfigurableContext context) {
final List<LibraryKind<?>> result = new SmartList<LibraryKind<?>>();
final LibraryType<?> type = ((LibraryEx)library).getType();
if (type != null) {
result.add(type.getKind());
public static List<LibraryKind> getLibraryKinds(@NotNull Library library, @Nullable StructureConfigurableContext context) {
final List<LibraryKind> result = new SmartList<LibraryKind>();
final LibraryKind kind = ((LibraryEx)library).getKind();
if (kind != null) {
result.add(kind);
}
final VirtualFile[] files = getLibraryFiles(library, context);
LibraryDetectionManager.getInstance().processProperties(Arrays.asList(files), new LibraryDetectionManager.LibraryPropertiesProcessor() {
@Override
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind<P> kind, @NotNull P properties) {
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) {
result.add(kind);
return true;
}
@@ -138,7 +138,7 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
@Override
public List<String> getDescriptions(@NotNull Library library, StructureConfigurableContext context) {
final VirtualFile[] files = getLibraryFiles(library, context);
return getDescriptions(files, Collections.<LibraryKind<?>>emptySet());
return getDescriptions(files, Collections.<LibraryKind>emptySet());
}
@NotNull
@@ -151,11 +151,11 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
@NotNull
@Override
public List<String> getDescriptions(@NotNull VirtualFile[] classRoots, final Set<LibraryKind<?>> excludedKinds) {
public List<String> getDescriptions(@NotNull VirtualFile[] classRoots, final Set<LibraryKind> excludedKinds) {
final SmartList<String> result = new SmartList<String>();
LibraryDetectionManager.getInstance().processProperties(Arrays.asList(classRoots), new LibraryDetectionManager.LibraryPropertiesProcessor() {
@Override
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind<P> kind, @NotNull P properties) {
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind kind, @NotNull P properties) {
if (!excludedKinds.contains(kind)) {
final LibraryPresentationProvider<P> provider = getPresentationProvider(kind);
if (provider != null) {
@@ -169,7 +169,7 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
}
@Override
public List<Library> getLibraries(@NotNull Set<LibraryKind<?>> kinds, @NotNull Project project, @Nullable StructureConfigurableContext context) {
public List<Library> getLibraries(@NotNull Set<LibraryKind> kinds, @NotNull Project project, @Nullable StructureConfigurableContext context) {
List<Library> libraries = new ArrayList<Library>();
if (context != null) {
Collections.addAll(libraries, context.getProjectLibrariesProvider().getModifiableModel().getLibraries());
@@ -184,7 +184,7 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
final Iterator<Library> iterator = libraries.iterator();
while (iterator.hasNext()) {
Library library = iterator.next();
final List<LibraryKind<?>> libraryKinds = getLibraryKinds(library, context);
final List<LibraryKind> libraryKinds = getLibraryKinds(library, context);
if (!ContainerUtil.intersects(libraryKinds, kinds)) {
iterator.remove();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -16,7 +16,6 @@
package com.intellij.openapi.roots.ui.configuration.libraries.impl;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.module.Module;
@@ -30,7 +29,9 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* @author nik
@@ -44,7 +45,7 @@ public class LibraryUsageCollector extends AbstractApplicationUsagesCollector {
public Set<UsageDescriptor> getProjectUsages(@Nullable Project project) {
if (project == null) return Collections.emptySet();
final Set<LibraryKind<?>> usedKinds = new HashSet<LibraryKind<?>>();
final Set<LibraryKind> usedKinds = new HashSet<LibraryKind>();
final Processor<Library> processor = new Processor<Library>() {
@Override
public boolean process(Library library) {
@@ -57,7 +58,7 @@ public class LibraryUsageCollector extends AbstractApplicationUsagesCollector {
}
final HashSet<UsageDescriptor> usageDescriptors = new HashSet<UsageDescriptor>();
for (LibraryKind<?> kind : usedKinds) {
for (LibraryKind kind : usedKinds) {
usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
}
return usageDescriptors;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -80,7 +80,7 @@ public class CreateNewLibraryAction extends DumbAwareAction {
@NotNull final Project project, @NotNull final LibrariesModifiableModel modifiableModel) {
final NewLibraryConfiguration configuration = createNewLibraryConfiguration(type, parentComponent, project);
if (configuration == null) return null;
final Library library = modifiableModel.createLibrary(LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()), configuration.getLibraryType());
final Library library = modifiableModel.createLibrary(LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()), configuration.getLibraryType().getKind());
final NewLibraryEditor editor = new NewLibraryEditor(configuration.getLibraryType(), configuration.getProperties());
configuration.addRoots(editor);
@@ -117,7 +117,7 @@ public class CreateNewLibraryAction extends DumbAwareAction {
if (librariesConfigurable instanceof ProjectLibrariesConfigurable) {
final ModuleStructureConfigurable configurable = ModuleStructureConfigurable.getInstance(project);
for (LibraryType<?> extension : extensions) {
if (!LibraryEditingUtil.getSuitableModules(configurable, extension, null).isEmpty()) {
if (!LibraryEditingUtil.getSuitableModules(configurable, extension.getKind(), null).isEmpty()) {
suitableTypes.add(extension);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -22,6 +22,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.util.ui.FormBuilder;
@@ -69,7 +70,8 @@ public class CreateNewLibraryDialog extends LibraryEditorDialogBase {
@NotNull
public Library createLibrary() {
final LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx)getTableModifiableModel();
final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), myLibraryEditor.getType());
final LibraryType<?> type = myLibraryEditor.getType();
final Library library = modifiableModel.createLibrary(myLibraryEditor.getName(), type != null ? type.getKind() : null);
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
myLibraryEditor.applyTo(model);
new WriteAction() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -18,10 +18,7 @@ package com.intellij.openapi.roots.ui.configuration.libraryEditor;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryDetectionManager;
import com.intellij.openapi.roots.libraries.LibraryProperties;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.libraries.*;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
@@ -60,16 +57,16 @@ public class ExistingLibraryEditor extends LibraryEditorBase implements Disposab
@Override
public LibraryType<?> getType() {
final LibraryType<?> type = ((LibraryEx)myLibrary).getType();
if (type != null) {
return type;
final LibraryKind kind = ((LibraryEx)myLibrary).getKind();
if (kind != null) {
return LibraryType.findByKind(kind);
}
return detectType();
}
@Override
public void setType(@NotNull LibraryType<?> type) {
((LibraryEx.ModifiableModelEx)getModel()).setType(type);
((LibraryEx.ModifiableModelEx)getModel()).setKind(type.getKind());
}
private LibraryType detectType() {
@@ -94,7 +91,7 @@ public class ExistingLibraryEditor extends LibraryEditorBase implements Disposab
}
if (myLibraryProperties == null) {
myLibraryProperties = type.createDefaultProperties();
myLibraryProperties = type.getKind().createDefaultProperties();
//noinspection unchecked
myLibraryProperties.loadState(getOriginalProperties().getState());
}
@@ -121,8 +121,8 @@ public class LibraryRootsComponent implements Disposable, LibraryEditorComponent
public void updatePropertiesLabel() {
StringBuilder text = new StringBuilder();
final LibraryType<?> type = getLibraryEditor().getType();
final Set<LibraryKind<?>> excluded =
type != null ? Collections.<LibraryKind<?>>singleton(type.getKind()) : Collections.<LibraryKind<?>>emptySet();
final Set<LibraryKind> excluded =
type != null ? Collections.<LibraryKind>singleton(type.getKind()) : Collections.<LibraryKind>emptySet();
for (String description : LibraryPresentationManager.getInstance().getDescriptions(getLibraryEditor().getFiles(OrderRootType.CLASSES),
excluded)) {
if (text.length() > 0) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -44,7 +44,7 @@ public class AddLibraryToModuleDependenciesAction extends DumbAwareAction {
boolean visible = false;
if (element instanceof LibraryProjectStructureElement) {
final LibraryEx library = (LibraryEx)((LibraryProjectStructureElement)element).getLibrary();
visible = !LibraryEditingUtil.getSuitableModules(ModuleStructureConfigurable.getInstance(myProject), library.getType(), library).isEmpty();
visible = !LibraryEditingUtil.getSuitableModules(ModuleStructureConfigurable.getInstance(myProject), library.getKind(), library).isEmpty();
}
e.getPresentation().setVisible(visible);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -331,7 +331,7 @@ public abstract class BaseLibrariesConfigurable extends BaseStructureConfigurabl
LOG.assertTrue(library != null);
final LibrariesModifiableModel libsModel = configurable.getModelProvider().getModifiableModel();
final Library lib = libsModel.createLibrary(newName, library.getType());
final Library lib = libsModel.createLibrary(newName, library.getKind());
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)libsModel.getLibraryEditor(lib).getModel();
LibraryEditingUtil.copyLibrary(library, Collections.<String, String>emptyMap(), model);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -25,6 +25,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.libraries.ui.OrderRoot;
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
@@ -91,7 +92,8 @@ public class LibrariesContainerFactory {
private static Library createLibraryInTable(final @NotNull NewLibraryEditor editor, final LibraryTable table) {
LibraryTableBase.ModifiableModelEx modifiableModel = (LibraryTableBase.ModifiableModelEx) table.getModifiableModel();
final String name = StringUtil.isEmpty(editor.getName()) ? null : getUniqueLibraryName(editor.getName(), modifiableModel);
Library library = modifiableModel.createLibrary(name, editor.getType());
final LibraryType<?> type = editor.getType();
Library library = modifiableModel.createLibrary(name, type == null ? null : type.getKind());
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)library.getModifiableModel();
editor.applyTo(model);
model.commit();
@@ -299,7 +301,8 @@ public class LibrariesContainerFactory {
}
LibraryTableBase.ModifiableModelEx model = (LibraryTableBase.ModifiableModelEx)provider.getModifiableModel();
Library library = model.createLibrary(getUniqueLibraryName(libraryEditor.getName(), model), libraryEditor.getType());
final LibraryType<?> type = libraryEditor.getType();
Library library = model.createLibrary(getUniqueLibraryName(libraryEditor.getName(), model), type == null ? null : type.getKind());
ExistingLibraryEditor createdLibraryEditor = ((LibrariesModifiableModel)model).getLibraryEditor(library);
createdLibraryEditor.setProperties(libraryEditor.getProperties());
libraryEditor.applyTo(createdLibraryEditor);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -21,7 +21,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
import com.intellij.openapi.roots.impl.libraries.LibraryTableBase;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryType;
import com.intellij.openapi.roots.libraries.PersistentLibraryKind;
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
@@ -60,7 +60,7 @@ public class LibrariesModifiableModel implements LibraryTableBase.ModifiableMode
return createLibrary(name, null);
}
public Library createLibrary(String name, @Nullable LibraryType type) {
public Library createLibrary(String name, @Nullable PersistentLibraryKind type) {
final Library library = ((LibraryTableBase.ModifiableModelEx)getLibrariesModifiableModel()).createLibrary(name, type);
//createLibraryEditor(library); \
final BaseLibrariesConfigurable configurable = ProjectStructureConfigurable.getInstance(myProject).getConfigurableFor(library);
@@ -63,7 +63,7 @@ public abstract class ProjectStructureValidator {
}
final ModuleStructureConfigurable moduleStructureConfigurable = ModuleStructureConfigurable.getInstance(project);
final List<Module> modules = LibraryEditingUtil.getSuitableModules(moduleStructureConfigurable, ((LibraryEx)library).getType(), library);
final List<Module> modules = LibraryEditingUtil.getSuitableModules(moduleStructureConfigurable, ((LibraryEx)library).getKind(), library);
if (modules.isEmpty()) return;
final ChooseModulesDialog
dlg = new ChooseModulesDialog(moduleStructureConfigurable.getProject(), modules, ProjectBundle.message("choose.modules.dialog.title"),