Skip to content

Commit

Permalink
Merge pull request #18 from valb3r/feature/FBP-5-support-for-add-remo…
Browse files Browse the repository at this point in the history
…ve-bpmn-elem

Feature/fbp 5 support for add remove bpmn elem
  • Loading branch information
valb3r authored May 13, 2020
2 parents 4c4d034 + c498b09 commit da028a8
Show file tree
Hide file tree
Showing 36 changed files with 894 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.intellij.ui.EditorTextField
import com.intellij.ui.JavaReferenceEditorUtil
import com.intellij.ui.components.JBScrollPane
import com.valb3r.bpmn.intellij.plugin.render.Canvas
import com.valb3r.bpmn.intellij.plugin.render.CanvasBuilder
import com.valb3r.bpmn.intellij.plugin.ui.components.MultiEditJTable
import javax.swing.JPanel
import javax.swing.JSplitPane
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package com.valb3r.bpmn.intellij.plugin.render
package com.valb3r.bpmn.intellij.plugin

import com.intellij.psi.PsiFile
import com.intellij.ui.EditorTextField
import com.valb3r.bpmn.intellij.plugin.events.updateEventsRegistry
import com.valb3r.bpmn.intellij.plugin.flowable.parser.FlowableObjectFactory
import com.valb3r.bpmn.intellij.plugin.flowable.parser.FlowableParser
import com.valb3r.bpmn.intellij.plugin.newelements.NewElementsProvider
import com.valb3r.bpmn.intellij.plugin.newelements.newElementsFactory
import com.valb3r.bpmn.intellij.plugin.render.BpmnProcessRenderer
import com.valb3r.bpmn.intellij.plugin.render.Canvas
import javax.swing.JTable

class CanvasBuilder {

private val updateEvents = updateEventsRegistry()
private var newObjectsFactory: NewElementsProvider? = null

fun build(properties: JTable, editorFactory: (value: String) -> EditorTextField, canvas: Canvas, bpmnFile: PsiFile) {
updateEvents.reset()
bpmnFile.virtualFile.inputStream.use {
val process = FlowableParser().parse(it)
canvas.reset(properties, editorFactory, process.toView(), BpmnProcessRenderer())
newObjectsFactory = newElementsFactory(FlowableObjectFactory())
canvas.reset(properties, editorFactory, process.toView(newObjectsFactory!!), BpmnProcessRenderer())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class Colors(val color: JBColor) {
WAYPOINT_COLOR(JBColor(Color(0xFF0000), Color(0xFF0000))),
MID_WAYPOINT_COLOR(JBColor(Color(0x0088FF), Color(0x0088FF))),
BACKGROUND_COLOR(JBColor(Color(0xFDFEFF), Color(0x292B2D))),
ACTIONS_BORDER_COLOR(JBColor(Color(0x626466), Color(0x949698))),
UN_HIGHLIGHTED_COLOR(JBColor(Color(0xC6C8CA), Color(0x585A5C))),
NEUTRAL_COLOR(JBColor(Color(0x626466), Color(0x949698))),
HIGHLIGHTED_COLOR(JBColor(Color(0x4285F4), Color(0x589DEF))),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package com.valb3r.bpmn.intellij.plugin

import com.valb3r.bpmn.intellij.plugin.render.Canvas
import com.valb3r.bpmn.intellij.plugin.ui.components.popupmenu.popupMenuProvider
import java.awt.event.*
import java.awt.geom.Point2D
import javax.swing.SwingUtilities

class MouseEventHandler(private val canvas: Canvas): MouseListener, MouseMotionListener, MouseWheelListener {

val popupMenuProvider = popupMenuProvider()

var prevMousePosition: Point2D.Float? = null

override fun mouseClicked(event: MouseEvent) {
val point2D = Point2D.Float(event.x.toFloat(), event.y.toFloat())

if (SwingUtilities.isRightMouseButton(event)) {
popupMenuProvider.popupMenu(canvas.fromCameraView(point2D)).show(event.component, event.x, event.y)
return
}

this.canvas.click(point2D)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.valb3r.bpmn.intellij.plugin.events

import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.WithBpmnId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.DiagramElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.ShapeElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.Property
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyType
import com.valb3r.bpmn.intellij.plugin.render.EdgeElementState
import com.valb3r.bpmn.intellij.plugin.render.WaypointElementState

interface Event

interface EventOrder<T: Event> {
val order: Long
val event: T
}

interface LocationUpdateWithId: Event {
val diagramElementId: DiagramElementId
val dx: Float
Expand All @@ -18,6 +27,26 @@ interface NewWaypoints: Event {
val waypoints: List<WaypointElementState>
}

interface DiagramElementRemoved: Event {
val elementId: DiagramElementId
}

interface BpmnElementRemoved: Event {
val elementId: BpmnElementId
}

interface BpmnShapeObjectAdded: Event {
val bpmnObject: WithBpmnId
val shape: ShapeElement
val props: Map<PropertyType, Property>
}

interface BpmnEdgeObjectAdded: Event {
val bpmnObject: WithBpmnId
val edge: EdgeElementState
val props: Map<PropertyType, Property>
}

interface PropertyUpdateWithId: Event {
val bpmnElementId: BpmnElementId
val property: PropertyType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.valb3r.bpmn.intellij.plugin.events

import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.WithBpmnId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.DiagramElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.ShapeElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.Property
import com.valb3r.bpmn.intellij.plugin.bpmn.api.info.PropertyType
import com.valb3r.bpmn.intellij.plugin.render.EdgeElementState
import com.valb3r.bpmn.intellij.plugin.render.WaypointElementState

data class StringValueUpdatedEvent(override val bpmnElementId: BpmnElementId, override val property: PropertyType, val newValue: String): PropertyUpdateWithId
Expand All @@ -13,4 +17,12 @@ data class DraggedToEvent(override val diagramElementId: DiagramElementId, overr

data class NewWaypointsEvent(override val edgeElementId: DiagramElementId, override val waypoints: List<WaypointElementState>): NewWaypoints

data class DiagramElementRemovedEvent(override val elementId: DiagramElementId): DiagramElementRemoved

data class BpmnElementRemovedEvent(override val elementId: BpmnElementId): BpmnElementRemoved

data class BpmnShapeObjectAddedEvent(override val bpmnObject: WithBpmnId, override val shape: ShapeElement, override val props: Map<PropertyType, Property>): BpmnShapeObjectAdded

data class BpmnEdgeObjectAddedEvent(override val bpmnObject: WithBpmnId, override val edge: EdgeElementState, override val props: Map<PropertyType, Property>): BpmnEdgeObjectAdded

data class CommittedToFile(val eventCount: Int): Event
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.DiagramElementId
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.atomic.AtomicReference

private val updateEvents = AtomicReference<ProcessModelUpdateEvents>()
Expand All @@ -19,52 +20,126 @@ fun updateEventsRegistry(): ProcessModelUpdateEvents {
}

// Global singleton
class ProcessModelUpdateEvents(private val updates: MutableList<Event>) {
class ProcessModelUpdateEvents(private val updates: MutableList<Order<out Event>>) {

private val order: AtomicLong = AtomicLong()
private val fileCommitListeners: MutableList<Any> = ArrayList()
private val parentCreatesByStaticId: MutableMap<DiagramElementId, MutableList<Event>> = ConcurrentHashMap()
private val locationUpdatesByStaticId: MutableMap<DiagramElementId, MutableList<Event>> = ConcurrentHashMap()
private val propertyUpdatesByStaticId: MutableMap<BpmnElementId, MutableList<Event>> = ConcurrentHashMap()
private val parentCreatesByStaticId: MutableMap<DiagramElementId, MutableList<Order<out Event>>> = ConcurrentHashMap()
private val locationUpdatesByStaticId: MutableMap<DiagramElementId, MutableList<Order<out Event>>> = ConcurrentHashMap()
private val propertyUpdatesByStaticId: MutableMap<BpmnElementId, MutableList<Order<out Event>>> = ConcurrentHashMap()
private val newShapeElements: MutableList<Order<BpmnShapeObjectAddedEvent>> = CopyOnWriteArrayList()
private val newDiagramElements: MutableList<Order<BpmnEdgeObjectAddedEvent>> = CopyOnWriteArrayList()
private val deletionsByStaticId: MutableMap<DiagramElementId, MutableList<Order<out Event>>> = ConcurrentHashMap()
private val deletionsByStaticBpmnId: MutableMap<BpmnElementId, MutableList<Order<out Event>>> = ConcurrentHashMap()

@Synchronized
fun reset() {
order.set(0)
fileCommitListeners.clear()
parentCreatesByStaticId.clear()
locationUpdatesByStaticId.clear()
propertyUpdatesByStaticId.clear()
parentCreatesByStaticId.clear()
newShapeElements.clear()
newDiagramElements.clear()
deletionsByStaticId.clear()
deletionsByStaticBpmnId.clear()
}

fun commitToFile() {
}

fun addPropertyUpdateEvent(event: PropertyUpdateWithId) {
updates.add(event)
propertyUpdatesByStaticId.computeIfAbsent(event.bpmnElementId) { CopyOnWriteArrayList() } += event
val toStore = Order(order.getAndIncrement(), event)
updates.add(toStore)
propertyUpdatesByStaticId.computeIfAbsent(event.bpmnElementId) { CopyOnWriteArrayList() } += toStore
}

fun addLocationUpdateEvent(event: LocationUpdateWithId) {
updates.add(event)
locationUpdatesByStaticId.computeIfAbsent(event.diagramElementId) { CopyOnWriteArrayList() } += event
val toStore = Order(order.getAndIncrement(), event)
updates.add(toStore)
locationUpdatesByStaticId.computeIfAbsent(event.diagramElementId) { CopyOnWriteArrayList() } += toStore
}

fun addWaypointStructureUpdate(event: NewWaypointsEvent) {
updates.add(event)
parentCreatesByStaticId.computeIfAbsent(event.edgeElementId) { CopyOnWriteArrayList() } += event
val toStore = Order(order.getAndIncrement(), event)
updates.add(toStore)
parentCreatesByStaticId.computeIfAbsent(event.edgeElementId) { CopyOnWriteArrayList() } += toStore
}

fun addElementRemovedEvent(event: DiagramElementRemovedEvent) {
val toStore = Order(order.getAndIncrement(), event)
updates.add(toStore)
deletionsByStaticId.computeIfAbsent(event.elementId) { CopyOnWriteArrayList() } += toStore
}

fun addElementRemovedEvent(event: BpmnElementRemovedEvent) {
val toStore = Order(order.getAndIncrement(), event)
updates.add(toStore)
deletionsByStaticBpmnId.computeIfAbsent(event.elementId) { CopyOnWriteArrayList() } += toStore
}

fun currentPropertyUpdateEventList(elementId: BpmnElementId): List<PropertyUpdateWithId> {
fun addObjectEvent(event: BpmnShapeObjectAddedEvent) {
val toStore = Order(order.getAndIncrement(), event)
updates.add(toStore)
newShapeElements.add(toStore)
}

fun addObjectEvent(event: BpmnEdgeObjectAddedEvent) {
val toStore = Order(order.getAndIncrement(), event)
updates.add(toStore)
newDiagramElements.add(toStore)
}

fun currentPropertyUpdateEventList(elementId: BpmnElementId): List<EventOrder<PropertyUpdateWithId>> {
val latestRemoval = lastDeletion(elementId)
return propertyUpdatesByStaticId
.getOrDefault(elementId, emptyList<PropertyUpdateWithId>())
.filterIsInstance<PropertyUpdateWithId>()
.getOrDefault(elementId, emptyList<Order<PropertyUpdateWithId>>())
.filterIsInstance<Order<PropertyUpdateWithId>>()
.filter { it.order > latestRemoval.order}
}

fun currentLocationUpdateEventList(elementId: DiagramElementId): List<LocationUpdateWithId> {
fun currentLocationUpdateEventList(elementId: DiagramElementId): List<EventOrder<LocationUpdateWithId>> {
val latestRemoval = lastDeletion(elementId)
return locationUpdatesByStaticId
.getOrDefault(elementId, emptyList<LocationUpdateWithId>())
.filterIsInstance<LocationUpdateWithId>()
.getOrDefault(elementId, emptyList<Order<LocationUpdateWithId>>())
.filterIsInstance<Order<LocationUpdateWithId>>()
.filter { it.order > latestRemoval.order}
}

fun newWaypointStructure(parentElementId: DiagramElementId): List<NewWaypointsEvent> {
fun newWaypointStructure(parentElementId: DiagramElementId): List<EventOrder<NewWaypointsEvent>> {
val latestRemoval = lastDeletion(parentElementId)
return parentCreatesByStaticId
.getOrDefault(parentElementId, emptyList<NewWaypointsEvent>())
.filterIsInstance<NewWaypointsEvent>()
.getOrDefault(parentElementId, emptyList<Order<NewWaypointsEvent>>())
.filterIsInstance<Order<NewWaypointsEvent>>()
.filter { it.order > latestRemoval.order}
}

fun newShapeElements(): List<EventOrder<BpmnShapeObjectAddedEvent>> {
return newShapeElements
.filter { it.order > lastDeletion(it.event.bpmnObject.id).order}
}

fun newEdgeElements(): List<EventOrder<BpmnEdgeObjectAddedEvent>> {
return newDiagramElements
.filter { it.order > lastDeletion(it.event.bpmnObject.id).order}
}

fun isDeleted(elementId: DiagramElementId): Boolean {
return lastDeletion(elementId).event !is NullEvent
}

fun isDeleted(elementId: BpmnElementId): Boolean {
return lastDeletion(elementId).event !is NullEvent
}

private fun lastDeletion(elementId: DiagramElementId): Order<out Event> {
return deletionsByStaticId[elementId]?.maxBy { it.order } ?: Order(-1, NullEvent(elementId.id))
}

private fun lastDeletion(elementId: BpmnElementId): Order<out Event> {
return deletionsByStaticBpmnId[elementId]?.maxBy { it.order } ?: Order(-1, NullEvent(elementId.id))
}

data class Order<T: Event>(override val order: Long, override val event: T): EventOrder<T>
data class NullEvent(val forId: String): Event
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.valb3r.bpmn.intellij.plugin.newelements

import com.valb3r.bpmn.intellij.plugin.bpmn.api.BpmnObjectFactory
import java.util.concurrent.atomic.AtomicReference

private val newElements = AtomicReference<NewElementsProvider>()

fun newElementsFactory(factory: BpmnObjectFactory): NewElementsProvider {
return newElements.updateAndGet {
if (null == it) {
return@updateAndGet NewElementsProvider(factory)
}

return@updateAndGet it
}
}

fun newElementsFactory(): NewElementsProvider {
return newElements.get()!!
}


class NewElementsProvider(private val factory: BpmnObjectFactory): BpmnObjectFactory by factory
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ class PropertiesVisualizer(val table: JTable, val editorFactory: (value: String)

private fun lastStringValueFromRegistry(bpmnElementId: BpmnElementId, type: PropertyType): String? {
return (updateRegistry.currentPropertyUpdateEventList(bpmnElementId)
.map { it.event }
.filter { it.property.id == type.id }
.lastOrNull { it is StringValueUpdatedEvent } as StringValueUpdatedEvent?)
?.newValue
}

private fun lastBooleanValueFromRegistry(bpmnElementId: BpmnElementId, type: PropertyType): Boolean? {
return (updateRegistry.currentPropertyUpdateEventList(bpmnElementId)
.map { it.event }
.filter { it.property.id == type.id }
.lastOrNull { it is BooleanValueUpdatedEvent } as BooleanValueUpdatedEvent?)
?.newValue
Expand Down
Loading

0 comments on commit da028a8

Please sign in to comment.