Skip to content

Commit

Permalink
Fixed wrong matching and missing rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
valb3r committed Jun 14, 2020
1 parent e73b872 commit 829b19f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package com.valb3r.bpmn.intellij.plugin.render.elements.shapes

import com.valb3r.bpmn.intellij.plugin.Colors
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.WithParentId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.DiagramElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.BoundsElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.EdgeElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.ShapeElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.diagram.elements.WaypointElement
import com.valb3r.bpmn.intellij.plugin.bpmn.api.events.Event
import com.valb3r.bpmn.intellij.plugin.events.BpmnEdgeObjectAddedEvent
import com.valb3r.bpmn.intellij.plugin.events.BpmnElementRemovedEvent
import com.valb3r.bpmn.intellij.plugin.events.BpmnShapeResizedAndMovedEvent
import com.valb3r.bpmn.intellij.plugin.events.DiagramElementRemovedEvent
import com.valb3r.bpmn.intellij.plugin.newelements.newElementsFactory
import com.valb3r.bpmn.intellij.plugin.render.AreaType
import com.valb3r.bpmn.intellij.plugin.render.AreaWithZindex
import com.valb3r.bpmn.intellij.plugin.render.EdgeElementState
import com.valb3r.bpmn.intellij.plugin.render.ICON_Z_INDEX
import com.valb3r.bpmn.intellij.plugin.render.elements.ACTIONS_ICO_SIZE
import com.valb3r.bpmn.intellij.plugin.render.elements.BaseDiagramRenderElement
import com.valb3r.bpmn.intellij.plugin.render.elements.EPSILON
import com.valb3r.bpmn.intellij.plugin.render.elements.RenderState
import com.valb3r.bpmn.intellij.plugin.render.elements.anchors.ShapeResizeAnchorBottom
import com.valb3r.bpmn.intellij.plugin.render.elements.anchors.ShapeResizeAnchorTop
import com.valb3r.bpmn.intellij.plugin.render.elements.viewtransform.ResizeViewTransform
import com.valb3r.bpmn.intellij.plugin.xmlnav.xmlNavigator
import java.awt.geom.Point2D
import kotlin.math.abs

Expand All @@ -28,6 +43,65 @@ abstract class ResizeableShapeRenderElement(

override val children: MutableList<BaseDiagramRenderElement> = mutableListOf(anchors.first, anchors.second)

override fun drawActions(x: Float, y: Float): Map<DiagramElementId, AreaWithZindex> {
val spaceCoeff = 1.5f
val actionCount = 3
val start = state.ctx.canvas.camera.fromCameraView(Point2D.Float(0.0f, 0.0f))
val end = state.ctx.canvas.camera.fromCameraView(Point2D.Float(0.0f, ACTIONS_ICO_SIZE * spaceCoeff))
val ySpacing = end.y - start.y

val rect = currentRect(state.ctx.canvas.camera)
val left = state.ctx.canvas.camera.toCameraView(Point2D.Float(rect.x, rect.y))
val right = state.ctx.canvas.camera.toCameraView(Point2D.Float(rect.x + rect.width, rect.y + rect.height))

if (ACTIONS_ICO_SIZE * actionCount >= (right.y - left.y)) {
return mutableMapOf()
}

var currY = y
val delId = DiagramElementId("DEL:$elementId")
val deleteIconArea = state.ctx.canvas.drawIcon(BoundsElement(x, currY, ACTIONS_ICO_SIZE, ACTIONS_ICO_SIZE), state.icons.recycleBin)
state.ctx.interactionContext.clickCallbacks[delId] = { dest ->
dest.addElementRemovedEvent(listOf(DiagramElementRemovedEvent(elementId)), listOf(BpmnElementRemovedEvent(shape.bpmnElement)))
}

currY += ySpacing
val newLinkId = DiagramElementId("NEWLINK:$elementId")
val newLinkArea = state.ctx.canvas.drawIcon(BoundsElement(x, currY, ACTIONS_ICO_SIZE, ACTIONS_ICO_SIZE), state.icons.sequence)
state.ctx.interactionContext.clickCallbacks[newLinkId] = { dest ->
state.currentState.elementByBpmnId[shape.bpmnElement]?.let { it: WithParentId ->
val newSequenceBpmn = newElementsFactory().newOutgoingSequence(it.element)
val bounds = currentRect(state.ctx.canvas.camera)
val width = bounds.width
val height = bounds.height

val newSequenceDiagram = newElementsFactory().newDiagramObject(EdgeElement::class, newSequenceBpmn)
.copy(waypoint = listOf(
WaypointElement(bounds.x + width, bounds.y + height / 2.0f),
WaypointElement(bounds.x + width + WAYPOINT_LEN, bounds.y + height / 2.0f)
))
dest.addObjectEvent(
BpmnEdgeObjectAddedEvent(
WithParentId(parents.first().bpmnElementId, newSequenceBpmn),
EdgeElementState(newSequenceDiagram),
newElementsFactory().propertiesOf(newSequenceBpmn)
)
)
}
}

currY += spaceCoeff * ySpacing
val toXmlId = DiagramElementId("TOXML:$elementId")
val toXmlArea = state.ctx.canvas.drawText(Point2D.Float(x, currY), "<XML/>", Colors.INNER_TEXT_COLOR.color)
state.ctx.interactionContext.clickCallbacks[toXmlId] = { dest -> xmlNavigator().jumpTo(bpmnElementId)}

return mutableMapOf(
delId to AreaWithZindex(deleteIconArea, AreaType.POINT, mutableSetOf(), mutableSetOf(), ICON_Z_INDEX, elementId),
newLinkId to AreaWithZindex(newLinkArea, AreaType.POINT, mutableSetOf(), mutableSetOf(), ICON_Z_INDEX, elementId),
toXmlId to AreaWithZindex(toXmlArea, AreaType.POINT, mutableSetOf(), mutableSetOf(), ICON_Z_INDEX, elementId)
)
}

override fun afterStateChangesAppliedNoChildren() {
// Detect only resize, not drag as drag is handled by higher-level elements and it may happen that two anchors
// were dragged simultaneously
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.valb3r.bpmn.intellij.plugin.render.elements.shapes

import com.valb3r.bpmn.intellij.plugin.Colors
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.BpmnElementId
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.BpmnSequenceFlow
import com.valb3r.bpmn.intellij.plugin.bpmn.api.bpmn.elements.WithParentId
Expand All @@ -21,12 +20,11 @@ import com.valb3r.bpmn.intellij.plugin.render.elements.RenderState
import com.valb3r.bpmn.intellij.plugin.render.elements.internal.CascadeTranslationOrChangesToWaypoint
import com.valb3r.bpmn.intellij.plugin.render.elements.viewtransform.NullViewTransform
import com.valb3r.bpmn.intellij.plugin.state.CurrentState
import com.valb3r.bpmn.intellij.plugin.xmlnav.xmlNavigator
import java.awt.geom.Point2D
import java.awt.geom.Rectangle2D
import java.util.*

private const val WAYPOINT_LEN = 40.0f
const val WAYPOINT_LEN = 40.0f

abstract class ShapeRenderElement(
override val elementId: DiagramElementId,
Expand All @@ -50,20 +48,11 @@ abstract class ShapeRenderElement(
}

override fun drawActions(x: Float, y: Float): Map<DiagramElementId, AreaWithZindex> {
val spaceCoeff = 1.5f
val actionCount = 3
val spaceCoeff = 1.3f
val start = state.ctx.canvas.camera.fromCameraView(Point2D.Float(0.0f, 0.0f))
val end = state.ctx.canvas.camera.fromCameraView(Point2D.Float(0.0f, ACTIONS_ICO_SIZE * spaceCoeff))
val ySpacing = end.y - start.y

val rect = currentRect(state.ctx.canvas.camera)
val left = state.ctx.canvas.camera.toCameraView(Point2D.Float(rect.x, rect.y))
val right = state.ctx.canvas.camera.toCameraView(Point2D.Float(rect.x + rect.width, rect.y + rect.height))

if (ACTIONS_ICO_SIZE * actionCount >= (right.y - left.y)) {
return mutableMapOf()
}

var currY = y
val delId = DiagramElementId("DEL:$elementId")
val deleteIconArea = state.ctx.canvas.drawIcon(BoundsElement(x, currY, ACTIONS_ICO_SIZE, ACTIONS_ICO_SIZE), state.icons.recycleBin)
Expand Down Expand Up @@ -96,15 +85,9 @@ abstract class ShapeRenderElement(
}
}

currY += spaceCoeff * ySpacing
val toXmlId = DiagramElementId("TOXML:$elementId")
val toXmlArea = state.ctx.canvas.drawText(Point2D.Float(x, currY), "<XML/>", Colors.INNER_TEXT_COLOR.color)
state.ctx.interactionContext.clickCallbacks[toXmlId] = { dest -> xmlNavigator().jumpTo(bpmnElementId)}

return mutableMapOf(
delId to AreaWithZindex(deleteIconArea, AreaType.POINT, mutableSetOf(), mutableSetOf(), ICON_Z_INDEX, elementId),
newLinkId to AreaWithZindex(newLinkArea, AreaType.POINT, mutableSetOf(), mutableSetOf(), ICON_Z_INDEX, elementId),
toXmlId to AreaWithZindex(toXmlArea, AreaType.POINT, mutableSetOf(), mutableSetOf(), ICON_Z_INDEX, elementId)
newLinkId to AreaWithZindex(newLinkArea, AreaType.POINT, mutableSetOf(), mutableSetOf(), ICON_Z_INDEX, elementId)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class DefaultXmlNavigator(private val project: Project): XmlNavigator {
}

private fun findOffset(id: BpmnElementId, file: VirtualFile): Int {
val pos = String(file.contentsToByteArray(), StandardCharsets.UTF_8).indexOf(id.id)
return if (pos < 0) 0 else pos
val regex = "id\\s*=\\s*\"${id.id}".toRegex()
val pos = regex.find(String(file.contentsToByteArray(), StandardCharsets.UTF_8)) ?: return 0
val firstMatch = pos.groups.firstOrNull() ?: return 0
return firstMatch.range.first
}
}
4 changes: 2 additions & 2 deletions bpmn-intellij-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Flowable BPMN visualizer</name>

<!-- Plugin version -->
<version>0.3.0</version>
<version>0.3.1</version>

<!-- Unique identifier of the plugin. Cannot be changed between the plugin versions.
If not specified, assumed to be equal to <name>. -->
Expand All @@ -28,7 +28,7 @@
<!-- Description of changes in the latest version of the plugin. Displayed in the "Plugins" settings dialog and
in the plugin repository Web interface. -->
<change-notes><![CDATA[
<p>0.3.0:</p>
<p>0.3.1:</p>
<ul>
<li>
First GA release of the plugin
Expand Down

0 comments on commit 829b19f

Please sign in to comment.