From 288f5f396cc0d9c18e95a9570fae5aaa4e6b77be Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 14 Feb 2013 14:26:45 +0400 Subject: [PATCH] LocalArchivedTemplate: icons --- .../templates/ArchivedTemplatesFactory.java | 42 +++++++++++-------- .../templates/LocalArchivedTemplate.java | 4 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java index 1dad516f7e2b..1695a82b75ff 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java @@ -22,10 +22,10 @@ import com.intellij.ide.util.projectWizard.WizardContext; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.ClearableLazyValue; +import com.intellij.openapi.util.Pair; import com.intellij.platform.ProjectTemplate; import com.intellij.platform.ProjectTemplatesFactory; import com.intellij.util.ArrayUtil; -import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import org.jetbrains.annotations.NotNull; @@ -43,17 +43,21 @@ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory { private static final String ZIP = ".zip"; - private final ClearableLazyValue> myGroups = new ClearableLazyValue>() { + private final ClearableLazyValue>> myGroups = new ClearableLazyValue>>() { @NotNull @Override - protected MultiMap compute() { - MultiMap map = new MultiMap(); + protected MultiMap> compute() { + MultiMap> map = new MultiMap>(); IdeaPluginDescriptor[] plugins = PluginManager.getPlugins(); - Set urls = new HashSet(); + Map urls = new HashMap(); for (IdeaPluginDescriptor plugin : plugins) { try { - Enumeration resources = plugin.getPluginClassLoader().getResources("resources/projectTemplates"); - urls.addAll(Collections.list(resources)); + ClassLoader loader = plugin.getPluginClassLoader(); + Enumeration resources = loader.getResources("resources/projectTemplates"); + ArrayList list = Collections.list(resources); + for (URL url : list) { + urls.put(url, loader); + } } catch (IOException e) { LOG.error(e); @@ -61,13 +65,15 @@ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory { } URL configURL = getCustomTemplatesURL(); - ContainerUtil.addIfNotNull(urls, configURL); + if (configURL != null) { + urls.put(configURL, ClassLoader.getSystemClassLoader()); + } - for (URL url : urls) { + for (Map.Entry url : urls.entrySet()) { try { - List children = UrlUtil.getChildrenRelativePaths(url); - if (configURL == url && !children.isEmpty()) { - map.putValue(CUSTOM_GROUP, url); + List children = UrlUtil.getChildrenRelativePaths(url.getKey()); + if (configURL == url.getKey() && !children.isEmpty()) { + map.putValue(CUSTOM_GROUP, Pair.create(url.getKey(), url.getValue())); continue; } @@ -76,7 +82,7 @@ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory { if (index != -1) { child = child.substring(0, index); } - map.putValue(child.replace('_', ' '), new URL(url.toExternalForm() + "/" + child)); + map.putValue(child.replace('_', ' '), Pair.create(new URL(url.getKey().toExternalForm() + "/" + child), url.getValue())); } } catch (IOException e) { @@ -117,16 +123,16 @@ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory { @NotNull @Override public ProjectTemplate[] createTemplates(String group, WizardContext context) { - Collection urls = myGroups.getValue().get(group); + Collection> urls = myGroups.getValue().get(group); List templates = new ArrayList(); - for (URL url : urls) { + for (Pair url : urls) { try { - List children = UrlUtil.getChildrenRelativePaths(url); + List children = UrlUtil.getChildrenRelativePaths(url.first); for (String child : children) { if (child.endsWith(ZIP)) { - URL templateUrl = new URL(url.toExternalForm() + "/" + child); + URL templateUrl = new URL(url.first.toExternalForm() + "/" + child); String name = child.substring(0, child.length() - ZIP.length()).replace('_', ' '); - templates.add(new LocalArchivedTemplate(name, templateUrl)); + templates.add(new LocalArchivedTemplate(name, templateUrl, url.second)); } } } diff --git a/java/idea-ui/src/com/intellij/platform/templates/LocalArchivedTemplate.java b/java/idea-ui/src/com/intellij/platform/templates/LocalArchivedTemplate.java index 0e20e0595239..0a76c6968392 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/LocalArchivedTemplate.java +++ b/java/idea-ui/src/com/intellij/platform/templates/LocalArchivedTemplate.java @@ -52,7 +52,7 @@ public class LocalArchivedTemplate extends ArchivedProjectTemplate { private Icon myIcon; public LocalArchivedTemplate(String displayName, - URL archivePath) { + URL archivePath, ClassLoader classLoader) { super(displayName); myArchivePath = archivePath; @@ -69,7 +69,7 @@ public class LocalArchivedTemplate extends ArchivedProjectTemplate { myInputFields = RemoteTemplatesFactory.getFields(templateElement, Namespace.NO_NAMESPACE); String iconPath = templateElement.getChildText("icon-path"); if (iconPath != null) { - myIcon = IconLoader.findIcon(iconPath); + myIcon = IconLoader.findIcon(iconPath, classLoader); } } catch (Exception e) {