-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FBP-289. Implement ID uniqueness check
- Loading branch information
Showing
4 changed files
with
112 additions
and
21 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
47 changes: 47 additions & 0 deletions
47
.../src/main/kotlin/com/valb3r/bpmn/intellij/plugin/core/properties/PropertyInputVerifier.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,47 @@ | ||
package com.valb3r.bpmn.intellij.plugin.core.properties | ||
|
||
import com.intellij.ui.JBColor | ||
import java.awt.Color | ||
import javax.swing.* | ||
|
||
class PropertyInputVerifier( | ||
private val initialValue: Any?, | ||
private val message: String, | ||
private val verifier: (JComponent, Any?) -> Boolean | ||
): InputVerifier() { | ||
|
||
private var background: Color? = null | ||
private var activePopup: Popup? = null | ||
|
||
override fun verify(input: JComponent): Boolean { | ||
return verifier(input, initialValue) | ||
} | ||
|
||
fun onStopEditing(input: JComponent): Boolean { | ||
if (verifier(input, initialValue)) { | ||
hidePopupIfOpen() | ||
input.background = this.background | ||
return true | ||
} | ||
|
||
input.background = JBColor.PINK | ||
val popup = PopupFactory.getSharedInstance().getPopup( | ||
input, | ||
JLabel(message), | ||
input.locationOnScreen.x, | ||
input.locationOnScreen.y + input.height | ||
) | ||
hidePopupIfOpen() | ||
popup.show() | ||
this.activePopup = popup | ||
|
||
val timer = Timer(5_000) { popup.hide() } | ||
timer.isRepeats = false | ||
timer.start() | ||
return false | ||
} | ||
|
||
fun hidePopupIfOpen() { | ||
activePopup?.hide() | ||
} | ||
} |
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