multiple remote template groups

This commit is contained in:
Dmitry Avdeev
2013-02-13 13:05:02 +04:00
parent 7bebe26be6
commit 17fde013fa
3 changed files with 32 additions and 17 deletions
@@ -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<TemplateItem> 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<TemplateItem> model = new CollectionListModel<TemplateItem>(items);
myFilteringListModel = new FilteringListModel<TemplateItem>(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<TemplateItem> items = new ArrayList<TemplateItem>();
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);
@@ -0,0 +1,11 @@
<template-groups xmlns="http://www.jetbrains.com/projectTemplates">
<group>
<name>Java Samples</name>
<path>Java</path>
<template>
<name>Java Hello World</name>
<description><![CDATA[ Simple Java "Hello World" application. ]]></description>
<path>HelloWorld.zip</path>
</template>
</group>
</template-groups>
@@ -143,7 +143,10 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
final ModuleType moduleType = ModuleTypeManager.getInstance().findByID(type);
final List<WizardInputField> 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;
}
};
}