From 836bff08bd7f6c4c69e98ba31bf9105f80894f6f Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Tue, 11 May 2021 11:42:43 +0300 Subject: [PATCH] IDEA-268767 New JavaFX project wizard GitOrigin-RevId: 122ff5370e645d129f777f4319cbe32780675f57 --- .../ide/starters/local/GeneratorContext.kt | 20 +- .../starters/local/StarterModuleBuilder.kt | 120 +++++++--- .../ide/starters/local/StarterUtils.kt | 7 +- .../local/generator/AssetsProcessor.kt | 2 +- .../roots/ui/configuration/JdkComboBox.kt | 6 + plugins/javaFX/intellij.javaFX.iml | 1 + .../javaFX/javaFX-CE/src/META-INF/plugin.xml | 23 +- .../javaFX/resources/dictionaries/javafx.dic | 9 + .../javafx-HelloApplication-groovy.groovy.ft | 24 ++ .../j2ee/javafx-HelloApplication-java.java.ft | 23 ++ .../j2ee/javafx-HelloApplication-kotlin.kt.ft | 20 ++ .../javafx-HelloController-groovy.groovy.ft | 14 ++ .../j2ee/javafx-HelloController-java.java.ft | 14 ++ .../j2ee/javafx-HelloController-kotlin.kt.ft | 14 ++ .../fileTemplates/j2ee/javafx-build.gradle.ft | 84 +++++++ .../j2ee/javafx-gradle-wrapper.properties.ft | 5 + .../j2ee/javafx-hello-view.fxml.ft | 17 ++ .../j2ee/javafx-module-info.java.ft | 35 +++ .../fileTemplates/j2ee/javafx-pom.xml.ft | 158 ++++++++++++ .../j2ee/javafx-settings.gradle.ft | 1 + .../fileTemplates/velocity_implicit.vm | 2 + .../messages/JavaFXBundle.properties | 13 +- plugins/javaFX/resources/starters/javafx.pom | 105 ++++++++ .../src/META-INF/common-javaFX-plugin.xml | 7 +- .../plugins/javaFX/JavaFXBundle.java | 3 + .../JavaeeBundledDictionaryProvider.java | 11 + .../javaFX/wizard/JavaFxModuleBuilder.kt | 155 ++++++++++++ .../wizard/JavaFxModuleTemplateGroup.kt | 40 ++++ .../plugins/javaFX/JavaFxModuleBuilderTest.kt | 224 ++++++++++++++++++ 29 files changed, 1097 insertions(+), 60 deletions(-) create mode 100644 plugins/javaFX/resources/dictionaries/javafx.dic create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-groovy.groovy.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-java.java.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-kotlin.kt.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-groovy.groovy.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-java.java.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-kotlin.kt.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-build.gradle.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-gradle-wrapper.properties.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-hello-view.fxml.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-module-info.java.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-pom.xml.ft create mode 100644 plugins/javaFX/resources/fileTemplates/j2ee/javafx-settings.gradle.ft create mode 100644 plugins/javaFX/resources/fileTemplates/velocity_implicit.vm create mode 100644 plugins/javaFX/resources/starters/javafx.pom create mode 100644 plugins/javaFX/src/org/jetbrains/plugins/javaFX/JavaeeBundledDictionaryProvider.java create mode 100644 plugins/javaFX/src/org/jetbrains/plugins/javaFX/wizard/JavaFxModuleBuilder.kt create mode 100644 plugins/javaFX/src/org/jetbrains/plugins/javaFX/wizard/JavaFxModuleTemplateGroup.kt create mode 100644 plugins/javaFX/testSrc/org/jetbrains/plugins/javaFX/JavaFxModuleBuilderTest.kt diff --git a/java/idea-ui/src/com/intellij/ide/starters/local/GeneratorContext.kt b/java/idea-ui/src/com/intellij/ide/starters/local/GeneratorContext.kt index afcd00680503..35934704c2bf 100644 --- a/java/idea-ui/src/com/intellij/ide/starters/local/GeneratorContext.kt +++ b/java/idea-ui/src/com/intellij/ide/starters/local/GeneratorContext.kt @@ -1,5 +1,6 @@ package com.intellij.ide.starters.local +import com.intellij.openapi.projectRoots.JavaSdkVersion import com.intellij.openapi.vfs.VirtualFile internal class GeneratorContext( @@ -9,6 +10,8 @@ internal class GeneratorContext( val artifact: String, val version: String, val testRunnerId: String?, + val rootPackage: String, + val sdkVersion: JavaSdkVersion?, private val languageId: String, private val libraryIds: Set, private val dependencyConfig: DependencyConfig, @@ -47,7 +50,22 @@ internal class GeneratorContext( /** * Renders propertyId as ${propertyId}. */ - fun asPlaceholder(propertyId: String) : String { + fun asPlaceholder(propertyId: String): String { return "\${$propertyId}" } + + fun isSdkAtLeast(version: String): Boolean { + val desiredSdkVersion = JavaSdkVersion.fromVersionString(version) + return desiredSdkVersion != null && sdkVersion != null && sdkVersion.isAtLeast(desiredSdkVersion) + } + + val rootPackagePath: String + get() { + return rootPackage.replace(".", "/").removeSuffix("/") + } + + val sdkFeatureVersion: Int + get() { + return sdkVersion?.maxLanguageLevel?.toJavaVersion()?.feature ?: 0 + } } \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/ide/starters/local/StarterModuleBuilder.kt b/java/idea-ui/src/com/intellij/ide/starters/local/StarterModuleBuilder.kt index d3e6ca783d1d..34c65881f30c 100644 --- a/java/idea-ui/src/com/intellij/ide/starters/local/StarterModuleBuilder.kt +++ b/java/idea-ui/src/com/intellij/ide/starters/local/StarterModuleBuilder.kt @@ -25,9 +25,13 @@ import com.intellij.openapi.module.ModuleType import com.intellij.openapi.module.StdModuleTypes import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.project.rootManager +import com.intellij.openapi.projectRoots.JavaSdk import com.intellij.openapi.projectRoots.JavaSdkType +import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.projectRoots.SdkTypeId +import com.intellij.openapi.roots.ContentEntry import com.intellij.openapi.roots.ModifiableRootModel +import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ui.configuration.ModulesProvider import com.intellij.openapi.roots.ui.configuration.setupNewModuleJdk import com.intellij.openapi.startup.StartupManager @@ -37,6 +41,7 @@ import com.intellij.openapi.vfs.VfsUtil import com.intellij.pom.java.LanguageLevel import com.intellij.ui.GuiUtils import com.intellij.util.lang.JavaVersion +import org.jetbrains.annotations.Nullable import java.io.IOException import java.net.URL import javax.swing.Icon @@ -46,6 +51,7 @@ abstract class StarterModuleBuilder : ModuleBuilder() { companion object { @JvmStatic private val VALID_PACKAGE_NAME_PATTERN: Regex = Regex("[^a-zA-Z0-9_.]") + @JvmStatic private val IMPORTER_EP_NAME: ExtensionPointName = ExtensionPointName.create("com.intellij.starter.moduleImporter") @@ -106,13 +112,13 @@ abstract class StarterModuleBuilder : ModuleBuilder() { abstract override fun getPresentableName(): String abstract override fun getDescription(): String - protected abstract fun getProjectTypes() : List + protected abstract fun getProjectTypes(): List protected abstract fun getLanguages(): List protected abstract fun getStarterPack(): StarterPack protected abstract fun getTestFrameworks(): List protected abstract fun getAssets(starter: Starter): List protected open fun isExampleCodeProvided(): Boolean = false - protected open fun getMinJavaVersion() : JavaVersion? = LanguageLevel.JDK_1_8.toJavaVersion() + protected open fun getMinJavaVersion(): JavaVersion? = LanguageLevel.JDK_1_8.toJavaVersion() protected open fun getCustomizedMessages(): CustomizedMessages? = null @@ -148,7 +154,7 @@ abstract class StarterModuleBuilder : ModuleBuilder() { startGenerator(module) } - private fun createSettings() : StarterWizardSettings { + private fun createSettings(): StarterWizardSettings { return StarterWizardSettings( getProjectTypes(), getLanguages(), @@ -174,7 +180,9 @@ abstract class StarterModuleBuilder : ModuleBuilder() { } override fun createWizardSteps(context: WizardContext, modulesProvider: ModulesProvider): Array { - return arrayOf(createLibrariesStep(StarterContextProvider(this, context.disposable, starterContext, context, starterSettings, ::getStarterPack))) + return arrayOf(createLibrariesStep( + StarterContextProvider(this, context.disposable, starterContext, context, starterSettings, ::getStarterPack) + )) } protected open fun createOptionsStep(contextProvider: StarterContextProvider): StarterInitialStep { @@ -189,7 +197,7 @@ abstract class StarterModuleBuilder : ModuleBuilder() { return listOf(ProjectSettingsStep::class.java) } - internal fun getMinJavaVersionInternal() : JavaVersion? = getMinJavaVersion() + internal fun getMinJavaVersionInternal(): JavaVersion? = getMinJavaVersion() override fun setupRootModel(modifiableRootModel: ModifiableRootModel) { setupNewModuleJdk(modifiableRootModel, moduleJdk, starterContext.isCreatingNewProject) @@ -197,10 +205,22 @@ abstract class StarterModuleBuilder : ModuleBuilder() { } private fun startGenerator(module: Module) { - val moduleContentRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(contentEntryPath!!.replace("\\", "/")) - ?: throw IllegalStateException("Module root not found") + val moduleContentRoot = + if (!ApplicationManager.getApplication().isUnitTestMode) { + LocalFileSystem.getInstance().refreshAndFindFileByPath(contentEntryPath!!.replace("\\", "/")) + ?: throw IllegalStateException("Module root not found") + } + else { + val contentEntries = ModuleRootManager.getInstance(module).contentEntries + contentEntries.first { it.sourceFolders.isNotEmpty() }.file!! + } val starter = starterContext.starter ?: throw IllegalStateException("Starter is not set") + val dependencyConfig = starterContext.starterDependencyConfig ?: error("Starter dependency config is not set") + val sdk = ModuleRootManager.getInstance(module).sdk + + val rootPackage = getPackageName(starterContext.group, starterContext.artifact) + val generatorContext = GeneratorContext( starter.id, module.name, @@ -208,47 +228,65 @@ abstract class StarterModuleBuilder : ModuleBuilder() { starterContext.artifact, starterContext.version, starterContext.testFramework!!.id, + rootPackage, + sdk?.let { JavaSdk.getInstance().getVersion(it) }, starterContext.language.id, starterContext.libraryIds, - starterContext.starterDependencyConfig ?: error("Starter dependency config is not set"), - getGeneratorContextProperties(), + dependencyConfig, + getGeneratorContextProperties(sdk, dependencyConfig), getAssets(starter), moduleContentRoot ) - ProgressManager.getInstance().runProcessWithProgressSynchronously( - { - WriteAction.runAndWait { - try { - AssetsProcessor().generateSources(generatorContext, getTemplateProperties()) - } - catch (e: IOException) { - logger().error("Unable to create module by template", e) - - ApplicationManager.getApplication().invokeLater { - Messages.showErrorDialog( - JavaStartersBundle.message("starter.generation.error", e.message ?: ""), - presentableName) + if (!ApplicationManager.getApplication().isUnitTestMode) { + ProgressManager.getInstance().runProcessWithProgressSynchronously( + { + WriteAction.runAndWait { + try { + AssetsProcessor().generateSources(generatorContext, getTemplateProperties()) } + catch (e: IOException) { + logger().error("Unable to create module by template", e) + + ApplicationManager.getApplication().invokeLater { + Messages.showErrorDialog( + JavaStartersBundle.message("starter.generation.error", e.message ?: ""), + presentableName) + } + } + + applyAdditionalChanges(module) } + }, + JavaStartersBundle.message("starter.generation.progress", presentableName), + true, module.project) - applyAdditionalChanges(module) - } - }, - JavaStartersBundle.message("starter.generation.progress", presentableName), - true, module.project) + StartupManager.getInstance(module.project).runAfterOpened { // IDEA-244863 + GuiUtils.invokeLaterIfNeeded(Runnable { + if (module.isDisposed) return@Runnable - StartupManager.getInstance(module.project).runAfterOpened { // IDEA-244863 - GuiUtils.invokeLaterIfNeeded(Runnable { - if (module.isDisposed) return@Runnable + ReformatCodeProcessor(module.project, module, false).run() + // import of module may dispose it and create another, open files first + openSampleFiles(module, getFilePathsToOpen()) - ReformatCodeProcessor(module.project, module, false).run() - // import of module may dispose it and create another, open files first - openSampleFiles(module, getFilePathsToOpen()) - - importModule(module) - }, ModalityState.NON_MODAL, module.disposed) + importModule(module) + }, ModalityState.NON_MODAL, module.disposed) + } } + else { + // test mode, open files immediately, do not import module + AssetsProcessor().generateSources(generatorContext, getTemplateProperties()) + ReformatCodeProcessor(module.project, module, false).run() + openSampleFiles(module, getFilePathsToOpen()) + } + } + + override fun doAddContentEntry(modifiableRootModel: ModifiableRootModel): ContentEntry? { + if (ApplicationManager.getApplication().isUnitTestMode) { + // do not create new content entry + return modifiableRootModel.contentEntries.first { it.sourceFolders.isNotEmpty() } + } + return super.doAddContentEntry(modifiableRootModel) } open fun getTemplateProperties(): Map = emptyMap() @@ -261,9 +299,8 @@ abstract class StarterModuleBuilder : ModuleBuilder() { return javaClass.getResource(resourcePath) ?: error("Failed to get resource: $resourcePath") } - protected open fun getGeneratorContextProperties(): Map { - val packageName = getPackageName(starterContext.group, starterContext.artifact) - return mapOf("rootPackage" to packageName) + protected open fun getGeneratorContextProperties(sdk: @Nullable Sdk?, dependencyConfig: DependencyConfig): Map { + return emptyMap() } protected fun getSamplesExt(language: StarterLanguage): String { @@ -274,4 +311,9 @@ abstract class StarterModuleBuilder : ModuleBuilder() { else -> throw UnsupportedOperationException() } } + + protected fun getPackagePath(group: String, artifact: String): String { + val packageName = getPackageName(group, artifact) + return packageName.replace(".", "/").removeSuffix("/") + } } \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/ide/starters/local/StarterUtils.kt b/java/idea-ui/src/com/intellij/ide/starters/local/StarterUtils.kt index f2c5b5a5579d..1b2c7f794c58 100644 --- a/java/idea-ui/src/com/intellij/ide/starters/local/StarterUtils.kt +++ b/java/idea-ui/src/com/intellij/ide/starters/local/StarterUtils.kt @@ -4,6 +4,7 @@ package com.intellij.ide.starters.local import com.intellij.openapi.util.Version import org.jdom.Element +import org.jetbrains.annotations.ApiStatus import java.io.File import java.io.IOException import java.nio.file.Files @@ -12,13 +13,13 @@ import java.time.Instant import java.time.LocalDate import java.time.ZoneId -internal object StarterUtils { - +@ApiStatus.Internal +object StarterUtils { private val PLACEHOLDER_VERSION_PATTERN: Regex = Regex("\\$\\{(.+)}") private class IncorrectBomFileException(message: String) : IOException(message) - internal fun parseDependencyConfig(projectTag: Element, resourcePath: String, interpolateProperties: Boolean = true): DependencyConfig { + fun parseDependencyConfig(projectTag: Element, resourcePath: String, interpolateProperties: Boolean = true): DependencyConfig { val properties: MutableMap = mutableMapOf() val dependencies: MutableList = mutableListOf() val bomVersion: String diff --git a/java/idea-ui/src/com/intellij/ide/starters/local/generator/AssetsProcessor.kt b/java/idea-ui/src/com/intellij/ide/starters/local/generator/AssetsProcessor.kt index e95ad56eb21f..d59832c5b938 100644 --- a/java/idea-ui/src/com/intellij/ide/starters/local/generator/AssetsProcessor.kt +++ b/java/idea-ui/src/com/intellij/ide/starters/local/generator/AssetsProcessor.kt @@ -22,7 +22,7 @@ internal class AssetsProcessor { else "" - val outputDirectory = VfsUtil.createDirectoryIfMissing(context.outputDirectory.path) + val outputDirectory = VfsUtil.createDirectoryIfMissing(context.outputDirectory.fileSystem, context.outputDirectory.path) ?: throw IllegalStateException("Unable to create directory ${context.outputDirectory.path}") if (asset is GeneratorEmptyDirectory) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/JdkComboBox.kt b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/JdkComboBox.kt index a0547c450ac1..06d83cfb1544 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/JdkComboBox.kt +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/JdkComboBox.kt @@ -7,6 +7,7 @@ import com.intellij.ide.starters.JavaStartersBundle import com.intellij.ide.util.PropertiesComponent import com.intellij.ide.util.projectWizard.ModuleBuilder import com.intellij.ide.util.projectWizard.ProjectWizardUtil +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.module.ModuleType import com.intellij.openapi.module.StdModuleTypes import com.intellij.openapi.observable.properties.GraphProperty @@ -103,6 +104,11 @@ fun validateJavaVersion(sdkProperty: GraphProperty, javaVersion: String?): } fun setupNewModuleJdk(modifiableRootModel: ModifiableRootModel, selectedJdk: Sdk?, isCreatingNewProject: Boolean): Sdk? { + if (ApplicationManager.getApplication().isUnitTestMode && selectedJdk == modifiableRootModel.sdk) { + // do not change SDK in tests + return selectedJdk + } + val sdk = selectedJdk ?: getProjectJdk(modifiableRootModel.project) if (sdk != null) { if (isCreatingNewProject || (!isCreatingNewProject && sdk == getProjectJdk(modifiableRootModel.project))) { diff --git a/plugins/javaFX/intellij.javaFX.iml b/plugins/javaFX/intellij.javaFX.iml index 880fa3708c69..ddde8a83ae42 100644 --- a/plugins/javaFX/intellij.javaFX.iml +++ b/plugins/javaFX/intellij.javaFX.iml @@ -34,5 +34,6 @@ + \ No newline at end of file diff --git a/plugins/javaFX/javaFX-CE/src/META-INF/plugin.xml b/plugins/javaFX/javaFX-CE/src/META-INF/plugin.xml index d750dc67eed2..b0fe547cdd9a 100644 --- a/plugins/javaFX/javaFX-CE/src/META-INF/plugin.xml +++ b/plugins/javaFX/javaFX-CE/src/META-INF/plugin.xml @@ -3,17 +3,16 @@ org.jetbrains.plugins.javaFX JetBrains JVM Frameworks - - JavaFX support. - The following features are available: -
    -
  • Dedicated file type.
  • -
  • Ability to create a project with the special file and directory structure.
  • -
  • JavaFX-aware coding assistance (code completion, search, navigation and refactoring in JavaFX-specific source files).
  • -
  • Integration with JavaFX Scene Builder.
  • -
- ]]> -
+ JavaFX support. + The following features are available: +
    +
  • Dedicated FXML file type.
  • +
  • Ability to create a project with the special file and directory structure.
  • +
  • JavaFX-aware coding assistance (code completion, search, navigation and refactoring in JavaFX-specific source files).
  • +
  • Integration with JavaFX Scene Builder.
  • +
+ ]]>
+ diff --git a/plugins/javaFX/resources/dictionaries/javafx.dic b/plugins/javaFX/resources/dictionaries/javafx.dic new file mode 100644 index 000000000000..2b61a32545a4 --- /dev/null +++ b/plugins/javaFX/resources/dictionaries/javafx.dic @@ -0,0 +1,9 @@ +bootstrapfx +dlsc +formsfx +hansolo +ikonli +javafxplugin +kordamp +synedra +tilesfx \ No newline at end of file diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-groovy.groovy.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-groovy.groovy.ft new file mode 100644 index 000000000000..0b47f7523d49 --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-groovy.groovy.ft @@ -0,0 +1,24 @@ +package ${context.rootPackage} + +import groovy.transform.CompileStatic +import javafx.application.Application +import javafx.fxml.FXMLLoader +import javafx.scene.Parent +import javafx.scene.Scene +import javafx.stage.Stage + +@CompileStatic +class HelloApplication extends Application { + @Override + void start(Stage stage) { + def fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")) + def scene = new Scene(fxmlLoader.load() as Parent, 320, 240) + stage.setTitle("Hello!") + stage.setScene(scene) + stage.show() + } + + static void main(String[] args) { + launch(HelloApplication) + } +} \ No newline at end of file diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-java.java.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-java.java.ft new file mode 100644 index 000000000000..45e0385da53c --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-java.java.ft @@ -0,0 +1,23 @@ +package ${context.rootPackage}; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.io.IOException; + +public class HelloApplication extends Application { + @Override + public void start(Stage stage) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); + Scene scene = new Scene(fxmlLoader.load(), 320, 240); + stage.setTitle("Hello!"); + stage.setScene(scene); + stage.show(); + } + + public static void main(String[] args) { + launch(); + } +} \ No newline at end of file diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-kotlin.kt.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-kotlin.kt.ft new file mode 100644 index 000000000000..3242dcef05e0 --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloApplication-kotlin.kt.ft @@ -0,0 +1,20 @@ +package ${context.rootPackage} + +import javafx.application.Application +import javafx.fxml.FXMLLoader +import javafx.scene.Scene +import javafx.stage.Stage + +class HelloApplication : Application() { + override fun start(stage: Stage) { + val fxmlLoader = FXMLLoader(HelloApplication::class.java.getResource("hello-view.fxml")) + val scene = Scene(fxmlLoader.load(), 320.0, 240.0) + stage.title = "Hello!" + stage.scene = scene + stage.show() + } +} + +fun main() { + Application.launch(HelloApplication::class.java) +} \ No newline at end of file diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-groovy.groovy.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-groovy.groovy.ft new file mode 100644 index 000000000000..49555640ffc9 --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-groovy.groovy.ft @@ -0,0 +1,14 @@ +package ${context.rootPackage} + +import javafx.fxml.FXML +import javafx.scene.control.Label + +class HelloController { + @FXML + private Label welcomeText + + @FXML + protected void onHelloButtonClick() { + welcomeText.setText("Welcome to JavaFX Application!") + } +} \ No newline at end of file diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-java.java.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-java.java.ft new file mode 100644 index 000000000000..9466a9e7d276 --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-java.java.ft @@ -0,0 +1,14 @@ +package ${context.rootPackage}; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; + +public class HelloController { + @FXML + private Label welcomeText; + + @FXML + protected void onHelloButtonClick() { + welcomeText.setText("Welcome to JavaFX Application!"); + } +} \ No newline at end of file diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-kotlin.kt.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-kotlin.kt.ft new file mode 100644 index 000000000000..edf3dd423520 --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-HelloController-kotlin.kt.ft @@ -0,0 +1,14 @@ +package ${context.rootPackage} + +import javafx.fxml.FXML +import javafx.scene.control.Label + +class HelloController { + @FXML + private lateinit var welcomeText: Label + + @FXML + private fun onHelloButtonClick() { + welcomeText.text = "Welcome to JavaFX Application!" + } +} \ No newline at end of file diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-build.gradle.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-build.gradle.ft new file mode 100644 index 000000000000..945dcdd28493 --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-build.gradle.ft @@ -0,0 +1,84 @@ +plugins { + id 'java' + id 'application' +#if ($context.hasLanguage("groovy")) + id 'groovy' +#end +#if ($context.hasLanguage("kotlin")) + id 'org.jetbrains.kotlin.jvm' version '${context.getVersion("org.jetbrains.kotlin", "kotlin-gradle-plugin")}' +#end + id 'org.openjfx.javafxplugin' version '${context.getVersion("org.openjfx", "javafxplugin")}' +} + +group '${context.group}' +version '${context.version}' + +repositories { + mavenCentral() +} +#if ($context.testRunnerId == "junit") + +ext { + junitVersion = '${context.getVersion("org.junit.jupiter", "junit-jupiter-engine")}' +} +#end + +#if ($context.sdkFeatureVersion > 0) +sourceCompatibility = ${context.sdkFeatureVersion} +targetCompatibility = ${context.sdkFeatureVersion} +#end + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} +mainClassName = '${context.rootPackage}.HelloApplication' +#if ($context.hasLanguage("kotlin")) + +[compileKotlin, compileTestKotlin].forEach { + it.kotlinOptions { + jvmTarget = '11' + } +} +#end + +javafx { + version = '${context.getProperty("javafx.version")}' + modules = ['javafx.controls', 'javafx.fxml'#if ($context.hasLibrary("tilesfx")), 'javafx.web'#end] +} + +dependencies { +#if ($context.hasLanguage("groovy")) + implementation('org.codehaus.groovy:groovy:${context.getVersion("org.codehaus.groovy", "groovy")}') +#end +#if ($context.hasLibrary("controlsfx")) + implementation('org.controlsfx:controlsfx:${context.getVersion("org.controlsfx", "controlsfx")}') +#end +#if ($context.hasLibrary("formsfx")) + implementation('com.dlsc.formsfx:formsfx-core:${context.getVersion("com.dlsc.formsfx", "formsfx-core")}') +#end +#if ($context.hasLibrary("validatorfx")) + implementation('net.synedra:validatorfx:${context.getVersion("net.synedra", "validatorfx")}') +#end +#if ($context.hasLibrary("ikonli")) + implementation('org.kordamp.ikonli:ikonli-javafx:${context.getVersion("org.kordamp.ikonli", "ikonli-javafx")}') +#end +#if ($context.hasLibrary("bootstrapfx")) + implementation('org.kordamp.bootstrapfx:bootstrapfx-core:${context.getVersion("org.kordamp.bootstrapfx", "bootstrapfx-core")}') +#end +#if ($context.hasLibrary("tilesfx")) + implementation('eu.hansolo:tilesfx:${context.getVersion("eu.hansolo", "tilesfx")}') +#end + +#if ($context.testRunnerId == "junit") + testImplementation("org.junit.jupiter:junit-jupiter-api:${context.asPlaceholder("junitVersion")}") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${context.asPlaceholder("junitVersion")}") +#end +#if ($context.testRunnerId == "testng") + testImplementation('org.testng:testng:${context.getVersion("org.testng", "testng")}') +#end +} + +test { + #if ($context.testRunnerId == "junit")useJUnitPlatform()#end + #if ($context.testRunnerId == "testng")useTestNG()#end +} \ No newline at end of file diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-gradle-wrapper.properties.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-gradle-wrapper.properties.ft new file mode 100644 index 000000000000..6bd5547712e9 --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-gradle-wrapper.properties.ft @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-${context.getBomProperty("gradle.version")}-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/plugins/javaFX/resources/fileTemplates/j2ee/javafx-hello-view.fxml.ft b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-hello-view.fxml.ft new file mode 100644 index 000000000000..462af2d85520 --- /dev/null +++ b/plugins/javaFX/resources/fileTemplates/j2ee/javafx-hello-view.fxml.ft @@ -0,0 +1,17 @@ +#set($H = '#') + + + + + + + + + + + + +