Add kotlin templates for project create wizard

#KT-4689 Fixed
This commit is contained in:
Nikolay Krasko
2014-03-13 19:42:18 +04:00
parent a3b45b919c
commit 7b8e6fa462
8 changed files with 249 additions and 1 deletions
@@ -0,0 +1,15 @@
<root>
<item
name='com.intellij.platform.ProjectTemplatesFactory com.intellij.platform.ProjectTemplate[] createTemplates(java.lang.String, com.intellij.ide.util.projectWizard.WizardContext)'>
<annotation name='kotlin.jvm.KotlinSignature'>
<val name="value" val="&quot;fun createTemplates(group: String, context: WizardContext?): Array&lt;out ProjectTemplate&gt;&quot;"/>
</annotation>
</item>
<item
name='com.intellij.platform.ProjectTemplatesFactory com.intellij.platform.ProjectTemplate[] createTemplates(java.lang.String, com.intellij.ide.util.projectWizard.WizardContext) 0'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
<item name='com.intellij.platform.ProjectTemplatesFactory javax.swing.Icon getGroupIcon(java.lang.String) 0'>
<annotation name='org.jetbrains.annotations.NotNull'/>
</item>
</root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

+2
View File
@@ -305,6 +305,8 @@
<framework.type implementation="org.jetbrains.jet.plugin.framework.JavaFrameworkType"/>
<framework.type implementation="org.jetbrains.jet.plugin.framework.JSFrameworkType"/>
<projectTemplatesFactory implementation="org.jetbrains.jet.plugin.framework.KotlinTemplatesFactory" />
<library.presentationProvider implementation="org.jetbrains.jet.plugin.framework.JavaRuntimePresentationProvider"/>
<library.presentationProvider implementation="org.jetbrains.jet.plugin.framework.JSLibraryStdPresentationProvider"/>
<library.presentationProvider implementation="org.jetbrains.jet.plugin.framework.JsHeaderLibraryPresentationProvider"/>
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 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.
@@ -23,6 +23,7 @@ import javax.swing.*;
public interface JetIcons {
Icon SMALL_LOGO = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin.png");
Icon KOTLIN_LOGO_24 = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin24.png");
Icon SMALL_LOGO_13 = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin13.png");
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2014 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 org.jetbrains.jet.plugin.framework
import com.intellij.ide.util.projectWizard.JavaModuleBuilder
import com.intellij.ide.util.projectWizard.ModuleWizardStep
import com.intellij.ide.util.projectWizard.SettingsStep
import com.intellij.openapi.module.ModifiableModuleModel
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleWithNameAlreadyExists
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.util.InvalidDataException
import org.jdom.JDOMException
import org.jetbrains.annotations.Nullable
import org.jetbrains.jet.plugin.JetIcons
import org.jetbrains.jet.plugin.project.TargetPlatform
import javax.swing.*
import java.io.IOException
import com.intellij.openapi.roots.ui.configuration.ModulesProvider
import com.intellij.ide.util.projectWizard.WizardContext
public class KotlinModuleBuilder(
val targetPlatform: TargetPlatform, val builderName: String, val builderDescription: String) : JavaModuleBuilder() {
override fun getBuilderId() = "kotlin.module.builder"
override fun getName() = builderName
override fun getPresentableName() = builderName
override fun getDescription() = builderDescription
override fun getBigIcon() = JetIcons.KOTLIN_LOGO_24
override fun getNodeIcon() = JetIcons.SMALL_LOGO
override fun getGroupName() = KotlinTemplatesFactory.KOTLIN_GROUP_NAME
override fun createWizardSteps(wizardContext: WizardContext, modulesProvider: ModulesProvider) = ModuleWizardStep.EMPTY_ARRAY
override fun modifySettingsStep(settingsStep: SettingsStep): ModuleWizardStep {
return KotlinModuleSettingStep(targetPlatform, this, settingsStep)
}
}
@@ -0,0 +1,140 @@
/*
* Copyright 2010-2014 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 org.jetbrains.jet.plugin.framework;
import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings;
import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel;
import com.intellij.framework.library.FrameworkLibraryVersionFilter;
import com.intellij.ide.util.projectWizard.ModuleBuilder;
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
import com.intellij.ide.util.projectWizard.SettingsStep;
import com.intellij.openapi.module.JavaModuleType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.plugin.project.TargetPlatform;
import javax.swing.*;
import java.util.ArrayList;
public class KotlinModuleSettingStep extends ModuleWizardStep {
private final TargetPlatform targetPlatform;
@Nullable
private final ModuleWizardStep myJavaStep;
private final CustomLibraryDescription customLibraryDescription;
private final LibrariesContainer librariesContainer;
private LibraryOptionsPanel libraryOptionsPanel;
private LibraryCompositionSettings libraryCompositionSettings;
private final String basePath;
public KotlinModuleSettingStep(TargetPlatform targetPlatform, ModuleBuilder moduleBuilder, @NotNull SettingsStep settingsStep) {
this.targetPlatform = targetPlatform;
myJavaStep = JavaModuleType.getModuleType().modifySettingsStep(settingsStep, moduleBuilder);
basePath = moduleBuilder.getContentEntryPath();
librariesContainer = LibrariesContainerFactory.createContainer(settingsStep.getContext().getProject());
customLibraryDescription = getCustomLibraryDescription(settingsStep.getContext().getProject());
moduleBuilder.addModuleConfigurationUpdater(createModuleConfigurationUpdater());
settingsStep.addSettingsField(getLibraryLabelText(), getLibraryPanel().getSimplePanel());
}
protected ModuleBuilder.ModuleConfigurationUpdater createModuleConfigurationUpdater() {
return new ModuleBuilder.ModuleConfigurationUpdater() {
@Override
public void update(@NotNull Module module, @NotNull ModifiableRootModel rootModel) {
if (libraryCompositionSettings != null) {
libraryCompositionSettings.addLibraries(rootModel, new ArrayList<Library>(), librariesContainer);
if (customLibraryDescription instanceof CustomLibraryDescriptorWithDefferConfig) {
((CustomLibraryDescriptorWithDefferConfig) customLibraryDescription).finishLibConfiguration(module, rootModel);
}
}
}
};
}
@Override
public void disposeUIResources() {
if (libraryOptionsPanel != null) {
Disposer.dispose(libraryOptionsPanel);
}
}
@Override
public JComponent getComponent() {
return getLibraryPanel().getMainPanel();
}
@NotNull
protected String getLibraryLabelText() {
if (targetPlatform == TargetPlatform.JVM) return "\u001BKotlin runtime:";
if (targetPlatform == TargetPlatform.JS) return "\u001BKotlin JS library:";
throw new IllegalStateException("Only JS and JVM target are supported");
}
@NotNull
protected CustomLibraryDescription getCustomLibraryDescription(@Nullable Project project) {
if (targetPlatform == TargetPlatform.JVM) return new JavaRuntimeLibraryDescription(project);
if (targetPlatform == TargetPlatform.JS) return new JSLibraryStdDescription(project);
throw new IllegalStateException("Only JS and JVM target are supported");
}
@Override
public void updateDataModel() {
libraryCompositionSettings = getLibraryPanel().apply();
if (myJavaStep != null) {
myJavaStep.updateDataModel();
}
}
@Override
public boolean validate() throws ConfigurationException {
return super.validate() && (myJavaStep == null || myJavaStep.validate());
}
protected LibraryOptionsPanel getLibraryPanel() {
if (libraryOptionsPanel == null) {
String baseDirPath = basePath != null ? FileUtil.toSystemIndependentName(basePath) : "";
libraryOptionsPanel = new LibraryOptionsPanel(
customLibraryDescription,
baseDirPath,
FrameworkLibraryVersionFilter.ALL,
librariesContainer,
false);
}
return libraryOptionsPanel;
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2014 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 org.jetbrains.jet.plugin.framework
import com.intellij.ide.util.projectWizard.WizardContext
import com.intellij.platform.ProjectTemplate
import com.intellij.platform.ProjectTemplatesFactory
import com.intellij.platform.templates.BuilderBasedTemplate
import org.jetbrains.jet.plugin.JetIcons
import org.jetbrains.jet.plugin.project.TargetPlatform
import javax.swing.*
public class KotlinTemplatesFactory : ProjectTemplatesFactory() {
class object {
public val KOTLIN_GROUP_NAME: String = "Kotlin"
}
override fun getGroups() = array(KOTLIN_GROUP_NAME)
override fun getGroupIcon(group: String) = JetIcons.KOTLIN_LOGO_24
override fun createTemplates(group: String, context: WizardContext?) =
array(
BuilderBasedTemplate(KotlinModuleBuilder(TargetPlatform.JVM, "Kotlin - JVM", "Kotlin module for JVM target")),
BuilderBasedTemplate(KotlinModuleBuilder(TargetPlatform.JS, "Kotlin - JavaScript", "Kotlin module for JavaScript target"))
)
}