Skip to content

Commit

Permalink
FBP-73. Show warnings abount unsupported features
Browse files Browse the repository at this point in the history
  • Loading branch information
valb3r committed Jul 22, 2023
1 parent 77065fb commit a39d8d5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.valb3r.bpmn.intellij.plugin.core

import com.intellij.lang.Language
import com.intellij.notification.NotificationType
import com.intellij.openapi.application.invokeAndWaitIfNeeded
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Document
Expand Down Expand Up @@ -39,7 +41,9 @@ import com.valb3r.bpmn.intellij.plugin.core.render.currentCanvas
import com.valb3r.bpmn.intellij.plugin.core.render.currentIconProvider
import com.valb3r.bpmn.intellij.plugin.core.render.uieventbus.ViewRectangleChangeEvent
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 java.awt.event.*
import java.awt.geom.Point2D
import java.awt.geom.Rectangle2D
Expand Down Expand Up @@ -102,6 +106,7 @@ open class BpmnPluginToolWindow(
fun getContent() = this.mainToolWindowForm

fun openFileAndRender(bpmnFile: PsiFile, context: BpmnActionContext) {
checkIfJavaAndSpelIsPresentAndNotifyOnceIfNot()
onBeforeFileOpen(bpmnFile)
val bpmnParser = currentParser(project)
if (this.canvasBuilder.assertFileContentAndShowErrorOrWarning(bpmnParser, bpmnFile.virtualFile, onBadContentErrorCallback, onBadContentWarningCallback)) return
Expand Down Expand Up @@ -143,6 +148,35 @@ open class BpmnPluginToolWindow(
showTryPolyBpmnAdvertisementNotification(project)
}

private fun checkIfJavaAndSpelIsPresentAndNotifyOnceIfNot() {
if (true == currentSettingsState().pluginState.noJavaOrSpelSupportShown) {
return
}

try {
JavaCodeFragmentFactory.getInstance(project)
} catch (ex: NoClassDefFoundError) {
genericShowNotificationBalloon(
project,
"BPMN plugin issues",
"BPMN: No Java language support found, language injection and code navigation support is OFF",
NotificationType.WARNING
)
currentSettingsState().pluginState.noJavaOrSpelSupportShown = true
return
}

if (null == Language.getRegisteredLanguages().firstOrNull { it.id == "SpEL" }) {
genericShowNotificationBalloon(
project,
"BPMN plugin issues",
"BPMN: No SpEL language support found, language injection and code navigation support is LIMITED",
NotificationType.WARNING
)
currentSettingsState().pluginState.noJavaOrSpelSupportShown = true
}
}

private fun createMultiLineTextField(value: String): TextValueAccessor {
val textField = JExpandableArea(value)

Expand Down Expand Up @@ -185,7 +219,13 @@ open class BpmnPluginToolWindow(
}

private fun createEditor(project: Project, bpmnFile: PsiFile, text: String): TextValueAccessor {
val factory = JavaCodeFragmentFactory.getInstance(project)
val factory = try {
JavaCodeFragmentFactory.getInstance(project)
} catch (ex: NoClassDefFoundError) {
// Non-Java IJ IDE
return nonJavaEditorTextField(text)
}

val fragment: JavaCodeFragment = factory.createExpressionCodeFragment(text, bpmnFile, psiTypeChar(), true)
fragment.visibilityChecker = JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE
val document = PsiDocumentManager.getInstance(project).getDocument(fragment)!!
Expand Down Expand Up @@ -228,7 +268,13 @@ open class BpmnPluginToolWindow(

// JavaCodeFragmentFactory - important
private fun createEditorForClass(project: Project, bpmnFile: PsiFile, text: String?): TextValueAccessor {
val document = JavaReferenceEditorUtil.createDocument(text, project, true)!!
val document = try {
JavaReferenceEditorUtil.createDocument(text, project, true)!!
} catch (ex: NoClassDefFoundError) {
// Non-Java IJ IDE
return nonJavaEditorTextField(text)
}

val textField: EditorTextField = JavaClassEditorTextField(document, project)
textField.setOneLineMode(true)

Expand All @@ -240,6 +286,10 @@ open class BpmnPluginToolWindow(
}
}

private fun nonJavaEditorTextField(text: String?): TextValueAccessor {
return createTextField(text?.trim('"') ?: "")
}

private fun setupUiBeforeRun() {
this.canvasPanel.remove(this.canvasNoDiagramText)
this.canvasPanel.isEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ abstract class BaseBpmnPluginSettingsState: PersistentStateComponent<BaseBpmnPlu
var enableFps = false
var disableXsdSchema = false

// Internal state
var noJavaOrSpelSupportShown: Boolean? = false

fun stateEquals(other: PluginStateData): Boolean {
if (zoomMin != other.zoomMin) return false
if (zoomMax != other.zoomMax) return false
Expand All @@ -66,6 +69,7 @@ abstract class BaseBpmnPluginSettingsState: PersistentStateComponent<BaseBpmnPlu
if (openExtensions != other.openExtensions) return false
if (enableFps != other.enableFps) return false
if (disableXsdSchema != other.disableXsdSchema) return false
if (noJavaOrSpelSupportShown != other.noJavaOrSpelSupportShown) return false

return true
}
Expand All @@ -85,6 +89,7 @@ abstract class BaseBpmnPluginSettingsState: PersistentStateComponent<BaseBpmnPlu
data.openExtensions = openExtensions
data.enableFps = enableFps
data.disableXsdSchema = disableXsdSchema
data.noJavaOrSpelSupportShown = noJavaOrSpelSupportShown
return data
}
}
Expand Down

0 comments on commit a39d8d5

Please sign in to comment.