From b0b2cf84393b8f13ed66391b4bbd60c42d1b0d2e Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Fri, 20 Sep 2013 16:26:51 +0400 Subject: [PATCH] template-based project types? --- .../CommonJavaProjectCategory.java | 2 + .../ide/projectWizard/ProjectCategory.java | 5 ++ .../ide/projectWizard/ProjectTypeStep.java | 10 +++ .../TemplateBasedProjectType.java | 68 +++++++++++++++++++ .../templates/ArchivedTemplatesFactory.java | 6 +- plugins/javaFX/javaFX.iml | 1 + .../src/META-INF/common-javaFX-plugin.xml | 3 + .../plugins/javaFX/JavaFxProjectType.java | 19 ++++++ 8 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 java/idea-ui/src/com/intellij/ide/projectWizard/TemplateBasedProjectType.java create mode 100644 plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxProjectType.java diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/CommonJavaProjectCategory.java b/java/idea-ui/src/com/intellij/ide/projectWizard/CommonJavaProjectCategory.java index bac30cbd8732..dfc7215e093a 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/CommonJavaProjectCategory.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/CommonJavaProjectCategory.java @@ -45,4 +45,6 @@ public class CommonJavaProjectCategory extends ProjectCategory { public String getDescription() { return "Common Java Project"; } + + } diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategory.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategory.java index 0553895d269f..014476f76508 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategory.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectCategory.java @@ -24,6 +24,7 @@ import com.intellij.util.containers.Convertor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; import java.util.Arrays; import java.util.Map; @@ -46,6 +47,10 @@ public abstract class ProjectCategory { return createModuleBuilder().getPresentableName(); } + public Icon getIcon() { + return createModuleBuilder().getNodeIcon(); + } + public String getDescription() { return createModuleBuilder().getDescription(); } diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java index c64310aba2fe..aee57d3cafb4 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java @@ -34,6 +34,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.CheckedTreeNode; import com.intellij.ui.CollectionListModel; +import com.intellij.ui.ColoredListCellRenderer; import com.intellij.ui.components.JBList; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.FactoryMap; @@ -91,6 +92,15 @@ public class ProjectTypeStep extends StepAdapter { } }; + myProjectTypeList.setCellRenderer(new ColoredListCellRenderer() { + @Override + protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { + ProjectCategory category = (ProjectCategory)value; + append(category.getDisplayName()); + setIcon(category.getIcon()); + } + }); + ProjectCategory[] projectCategories = ProjectCategory.EXTENSION_POINT_NAME.getExtensions(); myProjectTypeList.setModel(new CollectionListModel(Arrays.asList(projectCategories))); myProjectTypeList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/TemplateBasedProjectType.java b/java/idea-ui/src/com/intellij/ide/projectWizard/TemplateBasedProjectType.java new file mode 100644 index 000000000000..b6d8cf70c6f3 --- /dev/null +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/TemplateBasedProjectType.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2013 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.ide.projectWizard; + +import com.intellij.ide.util.projectWizard.ModuleBuilder; +import com.intellij.platform.templates.ArchivedTemplatesFactory; +import com.intellij.platform.templates.LocalArchivedTemplate; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.io.File; +import java.net.URL; + +/** + * @author Dmitry Avdeev + * Date: 20.09.13 + */ +public abstract class TemplateBasedProjectType extends ProjectCategory { + + private final LocalArchivedTemplate myTemplate; + + public TemplateBasedProjectType(String templatePath) { + ClassLoader loader = getClass().getClassLoader(); + URL resource = loader.getResource(templatePath); + assert resource != null : templatePath; + String name = ArchivedTemplatesFactory.getTemplateName(new File(templatePath).getName()); + myTemplate = new LocalArchivedTemplate(name, resource, loader); + } + + @NotNull + @Override + public ModuleBuilder createModuleBuilder() { + return myTemplate.createModuleBuilder(); + } + + @Override + public String getId() { + return getDisplayName(); + } + + @Override + public String getDisplayName() { + return myTemplate.getName(); + } + + @Override + public String getDescription() { + return myTemplate.getDescription(); + } + + @Override + public Icon getIcon() { + return myTemplate.getIcon(); + } +} 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 919f95239803..08c673fb1f55 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java @@ -132,7 +132,7 @@ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory { for (String child : children) { if (child.endsWith(ZIP)) { URL templateUrl = new URL(url.first.toExternalForm() + "/" + child); - String name = child.substring(0, child.length() - ZIP.length()).replace('_', ' '); + String name = getTemplateName(child); templates.add(new LocalArchivedTemplate(name, templateUrl, url.second)); } } @@ -144,6 +144,10 @@ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory { return templates.toArray(new ProjectTemplate[templates.size()]); } + public static String getTemplateName(String child) { + return child.substring(0, child.length() - ZIP.length()).replace('_', ' '); + } + @Override public int getGroupWeight(String group) { return CUSTOM_GROUP.equals(group) ? -2 : 0; diff --git a/plugins/javaFX/javaFX.iml b/plugins/javaFX/javaFX.iml index 35132590edf2..3abff64396de 100644 --- a/plugins/javaFX/javaFX.iml +++ b/plugins/javaFX/javaFX.iml @@ -22,6 +22,7 @@ + diff --git a/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml b/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml index df18ddfb2191..af48a120a277 100644 --- a/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml +++ b/plugins/javaFX/src/META-INF/common-javaFX-plugin.xml @@ -50,6 +50,9 @@ + diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxProjectType.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxProjectType.java new file mode 100644 index 000000000000..653c573a3a8f --- /dev/null +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaFxProjectType.java @@ -0,0 +1,19 @@ +package org.jetbrains.plugins.javaFX; + +import com.intellij.ide.projectWizard.TemplateBasedProjectType; + +/** + * @author Dmitry Avdeev + * Date: 20.09.13 + */ +public class JavaFxProjectType extends TemplateBasedProjectType { + + public JavaFxProjectType() { + super("/resources/projectTemplates/Java/JavaFX Application.zip"); + } + + @Override + public String getId() { + return "JavaFX"; + } +}