use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class MigrationDiagramMarshallerTest method assertNodeEquals.
private void assertNodeEquals(Diagram<Graph, Metadata> oldDiagram, Diagram<Graph, Metadata> newDiagram, String fileName) {
Map<String, Node<View, ?>> oldNodes = asNodeMap(oldDiagram.getGraph().nodes());
Map<String, Node<View, ?>> newNodes = asNodeMap(newDiagram.getGraph().nodes());
assertEquals(fileName + ": Number of nodes should match", oldNodes.size(), newNodes.size());
for (Node<View, ?> o : oldNodes.values()) {
Node<View, ?> n = newNodes.get(o.getUUID());
View oldContent = o.getContent();
View newContent = n.getContent();
Bounds oldBounds = oldContent.getBounds();
Bounds newBounds = newContent.getBounds();
assertEquals(fileName + ": Bounds should match for " + o.getUUID(), oldBounds, newBounds);
Object oldDefinition = oldContent.getDefinition();
Object newDefinition = newContent.getDefinition();
assertEquals(fileName + ": Definitions should match for " + o.getUUID(), oldDefinition, newDefinition);
}
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerBase method assertNodeEquals.
private void assertNodeEquals(Diagram<Graph, Metadata> oldDiagram, Diagram<Graph, Metadata> newDiagram, String fileName) {
Map<String, Node<View, ?>> oldNodes = asNodeMap(oldDiagram.getGraph().nodes());
Map<String, Node<View, ?>> newNodes = asNodeMap(newDiagram.getGraph().nodes());
assertEquals(fileName + ": Number of nodes should match", oldNodes.size(), newNodes.size());
for (Node<View, ?> o : oldNodes.values()) {
Node<View, ?> n = newNodes.get(o.getUUID());
View oldContent = o.getContent();
View newContent = n.getContent();
Bounds oldBounds = oldContent.getBounds();
Bounds newBounds = newContent.getBounds();
assertEquals(fileName + ": Bounds should match for " + o.getUUID(), oldBounds, newBounds);
Object oldDefinition = oldContent.getDefinition();
Object newDefinition = newContent.getDefinition();
assertEquals(fileName + ": Definitions should match for " + o.getUUID(), oldDefinition, newDefinition);
}
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerTest method testUnmarshallNotBoundaryEvents.
@Test
@SuppressWarnings("unchecked")
public void testUnmarshallNotBoundaryEvents() throws Exception {
Diagram<Graph, Metadata> diagram = unmarshall(BPMN_NOT_BOUNDARY_EVENTS);
assertEquals("Not Boundary Event", diagram.getMetadata().getTitle());
assertDiagram(diagram, 6);
// Assert than the intermediate event is connected using a view connector,
// so not boundary to the task ( not docked ).
Node event = diagram.getGraph().getNode("_CB178D55-8DC2-4CAA-8C42-4F5028D4A1F6");
List<Edge> inEdges = event.getInEdges();
boolean foundViewConnector = false;
for (Edge e : inEdges) {
if (e.getContent() instanceof ViewConnector) {
foundViewConnector = true;
}
}
assertTrue(foundViewConnector);
// Assert absolute position as the node is not docked.
Bounds bounds = ((View) event.getContent()).getBounds();
Bounds.Bound ul = bounds.getUpperLeft();
Bounds.Bound lr = bounds.getLowerRight();
assertEquals(305, ul.getX(), 0);
assertEquals(300, ul.getY(), 0);
assertEquals(335, lr.getX(), 0);
assertEquals(330, lr.getY(), 0);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class ElementParser method initialize.
@Override
@SuppressWarnings("unchecked")
public void initialize(final Context context) {
this.context = context;
Object definition = element.getContent().getDefinition();
// Resource id field.
super.addParser(new StringFieldParser("resourceId", element.getUUID()));
// Properties array.
Object def = element.getContent().getDefinition();
Set<?> properties = context.getDefinitionManager().adapters().forDefinition().getProperties(def);
ObjectParser propertiesParser = new ObjectParser("properties");
super.addParser(propertiesParser);
if (null != properties && !properties.isEmpty()) {
for (Object property : properties) {
PropertyAdapter propertyAdapter = context.getDefinitionManager().adapters().registry().getPropertyAdapter(property.getClass());
PropertyType propertyType = propertyAdapter.getType(property);
String oryxPropId = context.getOryxManager().getMappingsManager().getOryxPropertyId(def.getClass(), property.getClass());
Object value = propertyAdapter.getValue(property);
String valueStr = value != null ? context.getOryxManager().getPropertyManager().serialize(property, propertyType, value) : "";
propertiesParser.addParser(new StringFieldParser(oryxPropId, valueStr));
}
}
// Custom extended prpoerties, if any.
parseExtendedProperties(propertiesParser);
// Stencil id field.
String defId = context.getOryxManager().getMappingsManager().getOryxDefinitionId(definition);
super.addParser(new ObjectParser("stencil").addParser(new StringFieldParser("id", defId)));
// Bounds.
Bounds.Bound ul = element.getContent().getBounds().getUpperLeft();
Bounds.Bound lr = element.getContent().getBounds().getLowerRight();
parseBounds(ul, lr);
}
use of org.kie.workbench.common.stunner.core.graph.content.Bounds in project kie-wb-common by kiegroup.
the class GraphBuilder method translate.
/**
* Move node into a new coordinate system with origin in newOrigin.
* <p>
* E.g., assume origin is currently (0,0), and consider node at (10,11).
* If we move node into a new coordinate system where the origin is in (3, 4)
* then the new coordinates for node are: (10-3, 11-4) = (7,7)
*/
private void translate(Node<? extends View, ?> node, Bounds.Bound newOrigin) {
logger.debug("Translating {} into constraints {}", node.getContent().getBounds(), newOrigin);
Bounds childBounds = node.getContent().getBounds();
double constrainedX = childBounds.getUpperLeft().getX() - newOrigin.getX();
double constrainedY = childBounds.getUpperLeft().getY() - newOrigin.getY();
Point2D coords = Point2D.create(constrainedX, constrainedY);
updatePosition(node, coords);
}
Aggregations