Skip to content

Commit

Permalink
another updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinVaadin committed Apr 24, 2024
1 parent e5f4815 commit df32a47
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.vaadin.plugin.module

import com.intellij.notification.NotificationType
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.OpenFileDescriptor
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.vfs.VfsUtil
import com.vaadin.plugin.utils.VaadinProjectUtil
import java.io.File

class PostModuleCreatedActivity : ProjectActivity {

override suspend fun execute(project: Project) {
project.getUserData(VaadinProjectUtil.PROJECT_DOWNLOADED_PROP_KEY)?.afterChange {
VaadinProjectUtil.notify("Vaadin project created", NotificationType.INFORMATION, project)
VfsUtil.findFileByIoFile(File(project.basePath, "README.md"), true)?.let {
val descriptor = OpenFileDescriptor(project, it)
descriptor.setUsePreviewTab(true)
FileEditorManager.getInstance(project).openEditor(descriptor, true)
}
}
}

}
31 changes: 12 additions & 19 deletions src/main/kotlin/com/vaadin/plugin/module/VaadinModuleBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package com.vaadin.plugin.module
import com.intellij.ide.util.projectWizard.ModuleBuilder
import com.intellij.ide.util.projectWizard.ModuleWizardStep
import com.intellij.ide.util.projectWizard.WizardContext
import com.intellij.notification.NotificationType
import com.intellij.openapi.Disposable
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.OpenFileDescriptor
import com.intellij.openapi.module.ModifiableModuleModel
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleType
import com.intellij.openapi.observable.properties.PropertyGraph
import com.intellij.openapi.project.ProjectType
import com.intellij.openapi.roots.ModifiableRootModel
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.vfs.VfsUtil
import com.vaadin.plugin.starter.DownloadableModel
import com.vaadin.plugin.utils.VaadinProjectUtil
import java.io.File

class VaadinModuleBuilder : ModuleBuilder() {

private val propertyGraph = PropertyGraph()

private val projectDownloadedProperty = propertyGraph.property(false)

private var model: DownloadableModel? = null

override fun getBuilderId(): String {
Expand All @@ -36,18 +36,11 @@ class VaadinModuleBuilder : ModuleBuilder() {
this.model = model
}

override fun setupRootModel(modifiableRootModel: ModifiableRootModel) {
val project = modifiableRootModel.project
StartupManager.getInstance(project).runAfterOpened {
VaadinProjectUtil.downloadAndExtract(project, this.model!!.getDownloadLink(project)) {
VaadinProjectUtil.notify("Vaadin project created", NotificationType.INFORMATION, project)
VfsUtil.findFileByIoFile(File(project.basePath, "README.md"), true)?.let {
val descriptor = OpenFileDescriptor(project, it)
descriptor.setUsePreviewTab(true)
FileEditorManager.getInstance(project).openEditor(descriptor, true)
}
}
}
override fun createModule(moduleModel: ModifiableModuleModel): Module {
val project = moduleModel.project
project.putUserData(VaadinProjectUtil.PROJECT_DOWNLOADED_PROP_KEY, projectDownloadedProperty)
VaadinProjectUtil.downloadAndExtract(project, this.model!!.getDownloadLink(project))
return super.createModule(moduleModel)
}

override fun getProjectType(): ProjectType? {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/vaadin/plugin/module/VaadinPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class VaadinPanel {
row {
text(
"<a href=\"https://vaadin.com/flow\">Flow framework</a> is the most productive" +
" choice, allowing 100% of the user interface to be coded in server-side Java."
" choice, allowing 100% of the user<br>interface to be coded in server-side Java."
)
}
row {
text(
"<a href=\"https://hilla.dev/\">Hilla framework</a>, on the other hand, enables" +
" implementation of your user interface with React while automatically connecting it to your" +
" implementation of your user<br>interface with React while automatically connecting it to your" +
" Java backend."
)
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/kotlin/com/vaadin/plugin/utils/VaadinProjectUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.notification.Notifications
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.observable.properties.GraphProperty
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.util.download.DownloadableFileService
Expand All @@ -21,9 +23,11 @@ class VaadinProjectUtil {

private val LOG: Logger = Logger.getInstance(VaadinProjectUtil::class.java)

val PROJECT_DOWNLOADED_PROP_KEY = Key<GraphProperty<Boolean>>("vaadin_project_downloaded")

private const val NOTIFICATION_GROUP = "Vaadin"

fun downloadAndExtract(project: Project, url: String, callback: () -> Unit) {
fun downloadAndExtract(project: Project, url: String) {
val filename = "project.zip"
LOG.info("Downloading $filename")
val basePath: String = project.basePath!!
Expand All @@ -33,7 +37,7 @@ class VaadinProjectUtil {
val downloader =
DownloadableFileService.getInstance().createDownloader(listOf(description), "Vaadin Starter Project")

downloader.downloadWithBackgroundProgress(basePath, project).thenAccept {
downloader.downloadWithBackgroundProgress(basePath, project).thenApply {
LOG.info("Extracting $downloadedFile")
ZipUtil.extract(downloadedFile.toPath(), Path.of(basePath), null)
// move contents from single zip directory
Expand All @@ -44,7 +48,8 @@ class VaadinProjectUtil {
}
FileUtil.delete(downloadedFile)
LOG.info("$downloadedFile deleted")
VirtualFileManager.getInstance().asyncRefresh(callback)
VirtualFileManager.getInstance().syncRefresh()
(project.getUserData(PROJECT_DOWNLOADED_PROP_KEY) as GraphProperty<Boolean>).set(true)
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@
<!-- Extension points defined by the plugin.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
<extensions defaultExtensionNs="com.intellij">
<!-- Vaadin Copilot -->
<notificationGroup id="Vaadin Copilot" displayType="BALLOON"/>
<notificationGroup id="Vaadin" displayType="BALLOON"/>
<projectService serviceImplementation="com.vaadin.plugin.copilot.service.CopilotServerServiceImpl"
serviceInterface="com.vaadin.plugin.copilot.service.CopilotServerService"/>
<postStartupActivity implementation="com.vaadin.plugin.copilot.activity.CopilotPostStartupProjectActivity"/>
<errorHandler implementation="com.vaadin.plugin.copilot.CopilotErrorHandler"/>
<statusBarWidgetFactory implementation="com.vaadin.plugin.copilot.CopilotStatusBarWidgetFactory"
id="CopilotStatusBarWidgetFactory" order="last"/>
<moduleBuilder id="VaadinModuleBuilder" builderClass="com.vaadin.plugin.module.VaadinModuleBuilder" />

<!-- Vaadin Project Wizard -->
<notificationGroup id="Vaadin" displayType="BALLOON"/>
<moduleBuilder id="VaadinModuleBuilder" builderClass="com.vaadin.plugin.module.VaadinModuleBuilder"/>
<postStartupActivity implementation="com.vaadin.plugin.module.PostModuleCreatedActivity"/>
</extensions>

<actions>
Expand Down

0 comments on commit df32a47

Please sign in to comment.