Skip to content

Commit

Permalink
FBP-73. Extract common
Browse files Browse the repository at this point in the history
  • Loading branch information
valb3r committed Jul 22, 2023
1 parent fc8529c commit f14e25b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.valb3r.bpmn.intellij.plugin.core.render.uieventbus.currentUiEventBus
import com.valb3r.bpmn.intellij.plugin.core.settings.currentSettingsState
import com.valb3r.bpmn.intellij.plugin.core.ui.components.MultiEditJTable
import com.valb3r.bpmn.intellij.plugin.core.ui.components.notifications.genericShowNotificationBalloon
import com.valb3r.bpmn.intellij.plugin.core.util.IJFeatures
import java.awt.event.*
import java.awt.geom.Point2D
import java.awt.geom.Rectangle2D
Expand Down Expand Up @@ -153,9 +154,7 @@ open class BpmnPluginToolWindow(
return
}

try {
JavaCodeFragmentFactory.getInstance(project)
} catch (ex: NoClassDefFoundError) {
if (!IJFeatures.hasJava(project)) {
genericShowNotificationBalloon(
project,
"BPMN plugin issues",
Expand All @@ -167,7 +166,7 @@ open class BpmnPluginToolWindow(
return
}

if (null == Language.getRegisteredLanguages().firstOrNull { it.id == "SpEL" }) {
if (!IJFeatures.hasSpel()) {
genericShowNotificationBalloon(
project,
"BPMN plugin issues",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package com.valb3r.bpmn.intellij.plugin.core.advertisement
import com.intellij.notification.NotificationType
import com.intellij.openapi.project.Project
import com.valb3r.bpmn.intellij.plugin.core.ui.components.notifications.genericShowNotificationBalloon
import com.valb3r.bpmn.intellij.plugin.core.util.IJFeatures
import java.time.LocalDate

fun showTryPolyBpmnAdvertisementNotification(project: Project) {
val checkDate = currentAdvertisementState().lastDisplayDateGlobal
val now = LocalDate.now()
val showOnceInDays = 30L
if (shouldShow(checkDate, showOnceInDays, now)) {
if (shouldShow(project, checkDate, showOnceInDays, now)) {
currentAdvertisementState().lastDisplayDateGlobal = now
genericShowNotificationBalloon(project, "Advertisement", "Try <a href='https://plugins.jetbrains.com/plugin/21361-polybpmn-visualizer'>PolyBPMN plugin</a>. <br> PolyBPMN's has upgraded split editor for each file, diagram history and a wider selection of elements and properties.", NotificationType.INFORMATION, "Do not show again") {
doNotShowAgain(showOnceInDays) // set maximum date
Expand All @@ -21,15 +22,19 @@ fun showTryPolyBpmnAdvertisementSwimpoolNotification(project: Project) {
val checkDate =currentAdvertisementState().lastDisplayDateSwimpoolAd
val now = LocalDate.now()
val showOnceInDays = 30L
if (shouldShow(checkDate, showOnceInDays, now)) {
if (shouldShow(project, checkDate, showOnceInDays, now)) {
currentAdvertisementState().lastDisplayDateSwimpoolAd = now
genericShowNotificationBalloon(project, "Advertisement Swimming pool", "Unlock the full potential of diagram reading and editing with the <a href='https://plugins.jetbrains.com/plugin/21361-polybpmn-visualizer'>PolyBPMN plugin</a>. Seamlessly visualize and interpret swimming pools and swimming lanes with ease. Download from <a href='https://plugins.jetbrains.com/plugin/21361-polybpmn-visualizer'>here</a>", NotificationType.INFORMATION, "Do not show again") {
doNotShowAgain(showOnceInDays) // set maximum date
}
}
}

private fun shouldShow(checkDate: LocalDate, showOnceInDays: Long, now: LocalDate?): Boolean {
private fun shouldShow(project: Project, checkDate: LocalDate, showOnceInDays: Long, now: LocalDate?): Boolean {
if (!IJFeatures.hasJava(project) || !IJFeatures.hasSpel()) { // No sense to show to non IDEA IDEs
return false
}

val neverShown = checkDate == LocalDate.MIN
val shownLongTimeAgo = checkDate.plusDays(showOnceInDays).isBefore(now)
return neverShown || shownLongTimeAgo
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.valb3r.bpmn.intellij.plugin.core.util

import com.intellij.lang.Language
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaCodeFragmentFactory

object IJFeatures {

fun hasJava(project: Project): Boolean {
try {
JavaCodeFragmentFactory.getInstance(project)
} catch (ex: NoClassDefFoundError) {
return false
}

return true
}

fun hasSpel(): Boolean {
return null != Language.getRegisteredLanguages().firstOrNull { it.id == "SpEL" }
}
}

0 comments on commit f14e25b

Please sign in to comment.