From 17fde013fa67d4ab50c57d07d04912a6a3499597 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 12 Feb 2013 16:44:14 +0400 Subject: [PATCH] multiple remote template groups --- .../newProjectWizard/ProjectTypesList.java | 30 ++++++++++--------- .../platform/templates/IC_template_groups.xml | 11 +++++++ .../templates/RemoteTemplatesFactory.java | 8 +++-- 3 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 java/idea-ui/src/com/intellij/platform/templates/IC_template_groups.xml diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectTypesList.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectTypesList.java index 42b485df4432..8189abce9380 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectTypesList.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/ProjectTypesList.java @@ -46,10 +46,7 @@ import javax.swing.*; import javax.swing.event.DocumentEvent; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; +import java.util.*; /** * @author Dmitry Avdeev @@ -71,8 +68,7 @@ public class ProjectTypesList implements Disposable { List items = buildItems(map); final RemoteTemplatesFactory factory = new RemoteTemplatesFactory(); - final String groupName = RemoteTemplatesFactory.SAMPLES_GALLERY; - final TemplatesGroup samplesGroup = new TemplatesGroup(groupName, "", null); + final TemplatesGroup samplesGroup = new TemplatesGroup("Loading Templates...", "", null); myLoadingItem = new TemplateItem(new LoadingProjectTemplate(), samplesGroup) { @Override Icon getIcon() { @@ -88,23 +84,29 @@ public class ProjectTypesList implements Disposable { final CollectionListModel model = new CollectionListModel(items); myFilteringListModel = new FilteringListModel(model); - ProgressManager.getInstance().run(new Task.Backgroundable(context.getProject(), "Loading Samples") { + ProgressManager.getInstance().run(new Task.Backgroundable(context.getProject(), "Loading Templates") { @Override public void run(@NotNull ProgressIndicator indicator) { try { myList.setPaintBusy(true); - final ProjectTemplate[] templates = factory.createTemplates(groupName, context); - Runnable runnable = new Runnable() { + String[] groups = factory.getGroups(); + final List items = new ArrayList(); + for (String group : groups) { + TemplatesGroup templatesGroup = new TemplatesGroup(group, "", factory.getGroupIcon(group)); + ProjectTemplate[] templates = factory.createTemplates(group, context); + for (ProjectTemplate template : templates) { + items.add(new TemplateItem(template, templatesGroup)); + } + } + //noinspection SSBasedInspection + SwingUtilities.invokeLater(new Runnable() { public void run() { int index = myList.getSelectedIndex(); model.remove(myLoadingItem); - for (ProjectTemplate template : templates) { - model.add(new TemplateItem(template, samplesGroup)); - } + model.add(items); myList.setSelectedIndex(index); } - }; - SwingUtilities.invokeLater(runnable); + }); } finally { myList.setPaintBusy(false); diff --git a/java/idea-ui/src/com/intellij/platform/templates/IC_template_groups.xml b/java/idea-ui/src/com/intellij/platform/templates/IC_template_groups.xml new file mode 100644 index 000000000000..f750a26f8063 --- /dev/null +++ b/java/idea-ui/src/com/intellij/platform/templates/IC_template_groups.xml @@ -0,0 +1,11 @@ + + + Java Samples + Java + + + \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/platform/templates/RemoteTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/RemoteTemplatesFactory.java index c5a3eef95a33..ba013d417577 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/RemoteTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/RemoteTemplatesFactory.java @@ -143,7 +143,10 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory { final ModuleType moduleType = ModuleTypeManager.getInstance().findByID(type); final List inputFields = getFields(element, ns); - return new ArchivedProjectTemplate(element.getChildTextTrim("name", ns)) { + final String path = element.getChildText("path", ns); + final String description = element.getChildTextTrim("description", ns); + String name = element.getChildTextTrim("name", ns); + return new ArchivedProjectTemplate(name) { @Override protected ModuleType getModuleType() { return moduleType; @@ -156,7 +159,6 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory { @Override public ZipInputStream getStream() throws IOException { - String path = element.getChildText("path", ns); final HttpURLConnection connection = getConnection(path); return new ZipInputStream(connection.getInputStream()) { @Override @@ -170,7 +172,7 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory { @Nullable @Override public String getDescription() { - return element.getChildTextTrim("description", ns); + return description; } }; }