-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from JakubNeukirch/spring-support
Spring support
- Loading branch information
Showing
21 changed files
with
613 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/tech/stonks/kvizard/action/StartupAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package tech.stonks.kvizard.action | ||
|
||
import com.intellij.openapi.components.ProjectComponent | ||
import tech.stonks.kvizard.utils.KVisionDialogUtil | ||
|
||
@Suppress("DEPRECATION") | ||
class StartupAction : ProjectComponent { | ||
override fun initComponent() { | ||
KVisionDialogUtil.showNewsDialog() | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/tech/stonks/kvizard/action/notification.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tech.stonks.kvizard.action | ||
|
||
import com.intellij.ide.BrowserUtil | ||
import com.intellij.notification.Notification | ||
import com.intellij.notification.NotificationAction | ||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import tech.stonks.kvizard.settings.AppSettingsState | ||
|
||
class NewsAction(text: String) : NotificationAction(text) { | ||
override fun actionPerformed(e: AnActionEvent, notification: Notification) { | ||
BrowserUtil.browse("https://kotlin.news") | ||
notification.expire() | ||
val appSettings = AppSettingsState.getInstance() | ||
appSettings?.state?.isNotificationDisabled = true | ||
} | ||
} | ||
|
||
class NotShowAction(text: String) : NotificationAction(text) { | ||
override fun actionPerformed(e: AnActionEvent, notification: Notification) { | ||
notification.expire() | ||
val appSettings = AppSettingsState.getInstance() | ||
appSettings?.state?.isNotificationDisabled = true | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/tech/stonks/kvizard/generator/SpringTreeGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package tech.stonks.kvizard.generator | ||
|
||
class SpringTreeGenerator : TreeGenerator( | ||
"spring", | ||
false, | ||
backendFiles = arrayOf("Main.kt", "Service.kt"), | ||
backendResourcesFiles = arrayOf("application.yml", "logback.xml") | ||
) |
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/tech/stonks/kvizard/settings/AppSettingsState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tech.stonks.kvizard.settings | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.* | ||
import com.intellij.openapi.project.ProjectManager | ||
import com.intellij.serviceContainer.ComponentManagerImpl | ||
|
||
@State( | ||
name = "KVisionWizardSettings", | ||
storages = [Storage("KVisionWizardSettings.xml", )] | ||
) | ||
class AppSettingsState : PersistentStateComponent<AppSettingsState.State> { | ||
data class State( | ||
var lastDisplayed: Long = 0L, | ||
var isNotificationDisabled: Boolean = false | ||
) | ||
|
||
companion object { | ||
fun getInstance(): AppSettingsState? { | ||
return ApplicationManager.getApplication().getComponent(AppSettingsState::class.java) | ||
} | ||
} | ||
|
||
private var _state: State = State() | ||
|
||
override fun getState(): State? { | ||
return _state | ||
} | ||
|
||
override fun loadState(state: State) { | ||
_state = state | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/tech/stonks/kvizard/utils/KVisionDialogUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package tech.stonks.kvizard.utils | ||
|
||
import com.intellij.notification.Notification | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.notification.Notifications | ||
import com.intellij.openapi.util.IconLoader | ||
import tech.stonks.kvizard.action.NewsAction | ||
import tech.stonks.kvizard.action.NotShowAction | ||
import tech.stonks.kvizard.settings.AppSettingsState | ||
|
||
object KVisionDialogUtil { | ||
fun showNewsDialog() { | ||
val appSettings = AppSettingsState.getInstance() | ||
if (appSettings?.state?.isNotificationDisabled == false && appSettings.state?.wasPublishedRecently() == false) { | ||
|
||
Notifications.Bus.notify( | ||
Notification( | ||
Notifications.SYSTEM_MESSAGES_GROUP_ID, | ||
"Invitation", | ||
"You have got invitation to join our community! Join Kotlin.News and become ninja developer in Kotlin.", | ||
NotificationType.INFORMATION | ||
).apply { | ||
icon = IconLoader.getIcon("/images/email-black-18dp.svg") | ||
this.addAction(NewsAction("Join Kotlin.News")) | ||
this.addAction(NotShowAction("Do not show again")) | ||
} | ||
) | ||
appSettings.state?.lastDisplayed = System.currentTimeMillis() | ||
} | ||
} | ||
|
||
private fun AppSettingsState.State.wasPublishedRecently(): Boolean { | ||
return (System.currentTimeMillis() - this.lastDisplayed) < 1000 * 60 * 60 * 12 | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/tech/stonks/kvizard/utils/RunConfigurationUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package tech.stonks.kvizard.utils | ||
|
||
import com.intellij.execution.RunnerAndConfigurationSettings | ||
import com.intellij.execution.configurations.ConfigurationFactory | ||
import com.intellij.execution.configurations.RunConfiguration | ||
import com.intellij.execution.impl.RunManagerImpl | ||
import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.util.IconLoader | ||
import org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType | ||
import org.jetbrains.plugins.gradle.service.execution.GradleRunConfiguration | ||
import javax.swing.Icon | ||
|
||
class KVisionConfigurationFactory(val task: String, private val args: String = "") : | ||
ConfigurationFactory(GradleExternalTaskConfigurationType.getInstance()) { | ||
override fun createTemplateConfiguration(project: Project): RunConfiguration { | ||
val conf = GradleRunConfiguration( | ||
project, | ||
GradleExternalTaskConfigurationType.getInstance().factory, | ||
"Run $task" | ||
) | ||
conf.settings.externalProjectPath = project.basePath | ||
conf.settings.taskNames = listOf(task) | ||
conf.settings.scriptParameters = args | ||
return conf | ||
} | ||
|
||
override fun getName(): String = "Run $task" | ||
|
||
override fun getIcon(): Icon = IconLoader.getIcon("/images/logo16.png") | ||
} | ||
|
||
class RunnerComparator : Comparator<RunnerAndConfigurationSettings> { | ||
override fun compare(o1: RunnerAndConfigurationSettings?, o2: RunnerAndConfigurationSettings?): Int { | ||
return when { | ||
o1?.factory is KVisionConfigurationFactory -> 1 | ||
o2?.factory is KVisionConfigurationFactory -> -1 | ||
else -> 0 | ||
} | ||
} | ||
} | ||
|
||
object RunConfigurationUtil { | ||
fun createConfiguration(project: Project) { | ||
val runManager = RunManagerImpl.getInstanceImpl(project) | ||
runManager.addConfiguration( | ||
RunnerAndConfigurationSettingsImpl( | ||
RunManagerImpl.getInstanceImpl(project), | ||
KVisionConfigurationFactory("backendRun").createTemplateConfiguration(project) | ||
) | ||
) | ||
runManager.addConfiguration( | ||
RunnerAndConfigurationSettingsImpl( | ||
RunManagerImpl.getInstanceImpl(project), | ||
KVisionConfigurationFactory("frontendRun", "-t").createTemplateConfiguration(project) | ||
) | ||
) | ||
runManager.setOrder(RunnerComparator()) | ||
runManager.requestSort() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.