mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
project templates: required plugins for groups
This commit is contained in:
@@ -52,36 +52,40 @@ public class JavaSettingsStep extends SdkSettingsStep {
|
||||
myModuleBuilder = moduleBuilder;
|
||||
|
||||
if (moduleBuilder instanceof JavaModuleBuilder) {
|
||||
Project project = settingsStep.getContext().getProject();
|
||||
ComponentWithBrowseButton.BrowseFolderActionListener<JTextField> listener =
|
||||
new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>(
|
||||
IdeBundle.message("prompt.select.source.directory"), null, mySourcePath, project, BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR,
|
||||
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) {
|
||||
@Override
|
||||
protected void onFileChoosen(VirtualFile chosenFile) {
|
||||
String contentEntryPath = myModuleBuilder.getContentEntryPath();
|
||||
String path = chosenFile.getPath();
|
||||
if (contentEntryPath != null) {
|
||||
|
||||
int i = StringUtil.commonPrefixLength(contentEntryPath, path);
|
||||
mySourcePath.setText(path.substring(i));
|
||||
}
|
||||
else {
|
||||
mySourcePath.setText(path);
|
||||
}
|
||||
}
|
||||
};
|
||||
mySourcePath.addBrowseFolderListener(project, listener);
|
||||
myCreateSourceRoot.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mySourcePath.setEnabled(myCreateSourceRoot.isSelected());
|
||||
}
|
||||
});
|
||||
settingsStep.addExpertPanel(myPanel);
|
||||
addSourcePath(settingsStep);
|
||||
}
|
||||
}
|
||||
|
||||
private void addSourcePath(SettingsStep settingsStep) {
|
||||
Project project = settingsStep.getContext().getProject();
|
||||
ComponentWithBrowseButton.BrowseFolderActionListener<JTextField> listener =
|
||||
new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>(
|
||||
IdeBundle.message("prompt.select.source.directory"), null, mySourcePath, project, BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR,
|
||||
TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) {
|
||||
@Override
|
||||
protected void onFileChoosen(VirtualFile chosenFile) {
|
||||
String contentEntryPath = myModuleBuilder.getContentEntryPath();
|
||||
String path = chosenFile.getPath();
|
||||
if (contentEntryPath != null) {
|
||||
|
||||
int i = StringUtil.commonPrefixLength(contentEntryPath, path);
|
||||
mySourcePath.setText(path.substring(i));
|
||||
}
|
||||
else {
|
||||
mySourcePath.setText(path);
|
||||
}
|
||||
}
|
||||
};
|
||||
mySourcePath.addBrowseFolderListener(project, listener);
|
||||
myCreateSourceRoot.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mySourcePath.setEnabled(myCreateSourceRoot.isSelected());
|
||||
}
|
||||
});
|
||||
settingsStep.addExpertPanel(myPanel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDataModel() {
|
||||
super.updateDataModel();
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
<group>
|
||||
<name>Spring</name>
|
||||
<path>Spring</path>
|
||||
<requiredPlugin>com.intellij.spring</requiredPlugin>
|
||||
<requiredPlugin>org.jetbrains.idea.maven</requiredPlugin>
|
||||
<template>
|
||||
<name>Spring Core</name>
|
||||
<description><![CDATA[ A simple console application with Spring Framework 3.2. ]]></description>
|
||||
|
||||
@@ -4,16 +4,18 @@
|
||||
<xs:element name="template-groups" type="template-groupsType"/>
|
||||
<xs:complexType name="groupType">
|
||||
<xs:sequence>
|
||||
<xs:element type="xs:string" name="name"/>
|
||||
<xs:element type="xs:string" name="path"/>
|
||||
<xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element type="xs:string" name="path" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element type="xs:string" name="requiredPlugin" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element type="templateType" name="template"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="templateType">
|
||||
<xs:sequence>
|
||||
<xs:element type="xs:string" name="name"/>
|
||||
<xs:element type="xs:string" name="description"/>
|
||||
<xs:element type="xs:string" name="path"/>
|
||||
<xs:element type="xs:string" name="name" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element type="xs:string" name="description" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element type="xs:string" name="path" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element type="xs:string" name="requiredPlugin" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:element name="input-field" maxOccurs="unbounded" minOccurs="0">
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
|
||||
@@ -54,10 +54,10 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
|
||||
private static final String URL = "http://download.jetbrains.com/idea/project_templates/";
|
||||
private static final String SAMPLES_GALLERY = "Samples Gallery";
|
||||
private static final Namespace NAMESPACE = Namespace.getNamespace("http://www.jetbrains.com/projectTemplates");
|
||||
private final ClearableLazyValue<MultiMap<String, ProjectTemplate>> myTemplates = new ClearableLazyValue<MultiMap<String, ProjectTemplate>>() {
|
||||
private final ClearableLazyValue<MultiMap<String, ArchivedProjectTemplate>> myTemplates = new ClearableLazyValue<MultiMap<String, ArchivedProjectTemplate>>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected MultiMap<String, ProjectTemplate> compute() {
|
||||
protected MultiMap<String, ArchivedProjectTemplate> compute() {
|
||||
return getTemplates();
|
||||
}
|
||||
};
|
||||
@@ -72,11 +72,11 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public ProjectTemplate[] createTemplates(String group, WizardContext context) {
|
||||
Collection<ProjectTemplate> templates = myTemplates.getValue().get(group);
|
||||
Collection<ArchivedProjectTemplate> templates = myTemplates.getValue().get(group);
|
||||
return templates.toArray(new ProjectTemplate[templates.size()]);
|
||||
}
|
||||
|
||||
private static MultiMap<String, ProjectTemplate> getTemplates() {
|
||||
private static MultiMap<String, ArchivedProjectTemplate> getTemplates() {
|
||||
InputStream stream = null;
|
||||
HttpURLConnection connection = null;
|
||||
String code = ApplicationInfo.getInstance().getBuild().getProductCode();
|
||||
@@ -103,17 +103,19 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static MultiMap<String, ProjectTemplate> createFromText(String text) throws IOException, JDOMException {
|
||||
public static MultiMap<String, ArchivedProjectTemplate> createFromText(String text) throws IOException, JDOMException {
|
||||
|
||||
Element rootElement = JDOMUtil.loadDocument(text).getRootElement();
|
||||
List<Element> groups = rootElement.getChildren("group", NAMESPACE);
|
||||
MultiMap<String, ProjectTemplate> map = new MultiMap<String, ProjectTemplate>();
|
||||
MultiMap<String, ArchivedProjectTemplate> map = new MultiMap<String, ArchivedProjectTemplate>();
|
||||
if (groups.isEmpty()) { // sample gallery by default
|
||||
map.put(SAMPLES_GALLERY, createGroupTemplates(rootElement, Namespace.NO_NAMESPACE));
|
||||
}
|
||||
else {
|
||||
for (Element group : groups) {
|
||||
map.put(group.getChildText("name", NAMESPACE), createGroupTemplates(group, NAMESPACE));
|
||||
if (checkRequiredPlugins(group, NAMESPACE)) {
|
||||
map.put(group.getChildText("name", NAMESPACE), createGroupTemplates(group, NAMESPACE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,20 +123,14 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<ProjectTemplate> createGroupTemplates(Element groupElement, final Namespace ns) {
|
||||
private static List<ArchivedProjectTemplate> createGroupTemplates(Element groupElement, final Namespace ns) {
|
||||
List<Element> elements = groupElement.getChildren("template", ns);
|
||||
|
||||
return ContainerUtil.mapNotNull(elements, new NullableFunction<Element, ProjectTemplate>() {
|
||||
return ContainerUtil.mapNotNull(elements, new NullableFunction<Element, ArchivedProjectTemplate>() {
|
||||
@Override
|
||||
public ProjectTemplate fun(final Element element) {
|
||||
public ArchivedProjectTemplate fun(final Element element) {
|
||||
|
||||
List<Element> plugins = element.getChildren("requiredPlugin", ns);
|
||||
for (Element plugin : plugins) {
|
||||
String id = plugin.getTextTrim();
|
||||
if (!PluginManager.isPluginInstalled(PluginId.getId(id))) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!checkRequiredPlugins(element, ns)) return null;
|
||||
String type = element.getChildText("moduleType");
|
||||
final ModuleType moduleType = ModuleTypeManager.getInstance().findByID(type);
|
||||
return new ArchivedProjectTemplate(element.getChildTextTrim("name", ns)) {
|
||||
@@ -166,6 +162,17 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean checkRequiredPlugins(Element element, Namespace ns) {
|
||||
@SuppressWarnings("unchecked") List<Element> plugins = element.getChildren("requiredPlugin", ns);
|
||||
for (Element plugin : plugins) {
|
||||
String id = plugin.getTextTrim();
|
||||
if (!PluginManager.isPluginInstalled(PluginId.getId(id))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static HttpURLConnection getConnection(String path) throws IOException {
|
||||
HttpURLConnection connection = HttpConfigurable.getInstance().openHttpConnection(URL + path);
|
||||
connection.setConnectTimeout(2000);
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.ide.fileTemplates.FileTemplateUtil;
|
||||
import com.intellij.ide.util.newProjectWizard.modes.ImportImlMode;
|
||||
import com.intellij.ide.util.projectWizard.ModuleBuilder;
|
||||
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
|
||||
import com.intellij.ide.util.projectWizard.SettingsStep;
|
||||
import com.intellij.ide.util.projectWizard.WizardContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -90,6 +91,12 @@ public class TemplateModuleBuilder extends ModuleBuilder {
|
||||
return myType.createModuleBuilder().createWizardSteps(wizardContext, modulesProvider);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ModuleWizardStep modifySettingsStep(SettingsStep settingsStep) {
|
||||
return super.modifySettingsStep(settingsStep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module commitModule(@NotNull final Project project, ModifiableModuleModel model) {
|
||||
if (myProjectMode) {
|
||||
|
||||
Reference in New Issue
Block a user