-
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.
Merge pull request #356 from valb3r/feature/FBP-289-unique-id-validation
Feature/fbp 289 unique id validation
- Loading branch information
Showing
7 changed files
with
164 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
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
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
bpmn-intellij-plugin-core/src/test/kotlin/com/valb3r/bpmn/intellij/plugin/ValidationTest.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 | ||
|
||
import com.nhaarman.mockitokotlin2.any | ||
import com.nhaarman.mockitokotlin2.never | ||
import com.nhaarman.mockitokotlin2.verify | ||
import com.nhaarman.mockitokotlin2.whenever | ||
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyType | ||
import com.valb3r.bpmn.intellij.plugin.core.newelements.registerNewElementsFactory | ||
import com.valb3r.bpmn.intellij.plugin.core.properties.propertiesVisualizer | ||
import com.valb3r.bpmn.intellij.plugin.core.tests.BaseUiTest | ||
import com.valb3r.bpmn.intellij.plugin.flowable.parser.FlowableObjectFactory | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import javax.swing.JTextField | ||
|
||
internal class ValidationTest: BaseUiTest() { | ||
|
||
@BeforeEach | ||
fun prepare() { | ||
registerNewElementsFactory(project, FlowableObjectFactory()) | ||
prepareTwoServiceTaskView() | ||
} | ||
|
||
@Test | ||
fun `Invalid ID (duplicate) not propagated`() { | ||
clickOnId(serviceTaskEndDiagramId) | ||
val idField = textFieldsConstructed[Pair(serviceTaskEndBpmnId, PropertyType.ID)]!! | ||
whenever(idField.text).thenReturn(serviceTaskStartBpmnId.id) | ||
(idField.component as JTextField).text = serviceTaskStartBpmnId.id | ||
|
||
propertiesVisualizer(project).clear() | ||
|
||
verify(fileCommitter, never()).executeCommitAndGetHash(any(), any(), any(), any()) | ||
} | ||
|
||
@Test | ||
fun `Valid ID (not duplicate) propagated`() { | ||
clickOnId(serviceTaskEndDiagramId) | ||
val idField = textFieldsConstructed[Pair(serviceTaskEndBpmnId, PropertyType.ID)]!! | ||
whenever(idField.text).thenReturn(serviceTaskStartBpmnId.id + '1') | ||
(idField.component as JTextField).text = serviceTaskStartBpmnId.id + '1' | ||
|
||
propertiesVisualizer(project).clear() | ||
|
||
verify(fileCommitter).executeCommitAndGetHash(any(), any(), any(), any()) | ||
} | ||
} |