[site] "Supporting new module type" tutorial

This commit is contained in:
Anna Bulenkova 2015-05-13 14:10:31 +02:00
parent 337dba789b
commit ebb69e3831
4 changed files with 123 additions and 2 deletions

View File

@ -131,7 +131,7 @@
* [3. Handling Editor Events](tutorials/editor_basics/editor_events.html)
* [Project Wizard](tutorials/project_wizard.html)
* [Adding New Steps to Project Wizard](tutorials/project_wizard/adding_new_steps.html)
* [Supporting Module Types](tutorials/project_wizard/module_types.md)
* [Supporting Module Types](tutorials/project_wizard/module_types.html)
* [Code Inspections](tutorials/code_inspections.html)
* [Run Configurations](tutorials/run_configurations.html)
* [Supporting Frameworks](tutorials/framework.html)

View File

@ -8,7 +8,7 @@ Configuring Project Wizard automatically allows you to do the following:
1. [Adding New Steps to Project Wizard](tutorials/project_wizard/adding_new_steps.html)
2. [Supporting Module Types](tutorials/project_wizard/module_types.md)
2. [Supporting Module Types](tutorials/project_wizard/module_types.html)
3. [Handling activities during project creation]()
4. [Initial environment configuration]()

View File

@ -2,3 +2,124 @@
layout: editable
title: Supporting Module Types
---
*IntelliJ Platform* provides a set of standard module types which can be chosen, however, you might need to create a module of a type that haven't been supported yet.
This tutorial shows how to register a new module and link it to the project creation procedure and the UI.
## Pre-requirements.
Create an empty plugin project.
See
[Creating a Plugin Project](basics/getting_started/creating_plugin_project.html)
to know how to do it.
## 1. Register a New Module Type
Add a new *moduleType* extension into the
[plugin.xml](TODO)
configuration file.
```xml
<extensions defaultExtensionNs="com.intellij">
<moduleType id="DEMO_MODULE_TYPE" implementationClass="com.intellij.tutorials.module.DemoModuleType"/>
</extensions>
```
## 2. Implement ModuleType Interface
```java
public class DemoModuleType extends ModuleType<DemoModuleBuilder> {
private static final String ID = "DEMO_MODULE_TYPE";
public DemoModuleType() {
super(ID);
}
public static DemoModuleType getInstance() {
return (DemoModuleType) ModuleTypeManager.getInstance().findByID(ID);
}
@NotNull
@Override
public DemoModuleBuilder createModuleBuilder() {
return new DemoModuleBuilder();
}
@NotNull
@Override
public String getName() {
return "Demo Module Type";
}
@NotNull
@Override
public String getDescription() {
return "Demo Module Type";
}
@Override
public Icon getBigIcon() {
return AllIcons.General.Information;
}
@Override
public Icon getNodeIcon(@Deprecated boolean b) {
return AllIcons.General.Information;
}
@NotNull
@Override
public ModuleWizardStep[] createWizardSteps(@NotNull WizardContext wizardContext, @NotNull DemoModuleBuilder moduleBuilder, @NotNull ModulesProvider modulesProvider) {
return super.createWizardSteps(wizardContext, moduleBuilder, modulesProvider);
}
}
```
## 3. Implement Custom Module Builder
```java
public class DemoModuleBuilder extends ModuleBuilder {
@Override
public void setupRootModel(ModifiableRootModel model) throws ConfigurationException {
}
@Override
public ModuleType getModuleType() {
return DemoModuleType.getInstance();
}
@Nullable
@Override
public ModuleWizardStep getCustomOptionsStep(WizardContext context, Disposable parentDisposable) {
return new DemoModuleWizardStep();
}
}
```
## 4. Provide Custom Wizard Steps
Provide implementation of UI components for the project creating stage.
```java
public class DemoModuleWizardStep extends ModuleWizardStep {
@Override
public JComponent getComponent() {
return new JLabel("Provide some setting here");
}
@Override
public void updateDataModel() {
//todo update model according to UI
}
}
```
## 5. Creating a Module of New Type
After compiling and running the plugin, create a new project with the instance of *IntelliJ IDEA* being run from sources.
You will see a new module type and it's settings panel available in the Project Wizard.
![New Module Type](module_types/img/new_module_type.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB