WIP: short labels outside nodes
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package org.springframework.ide.vscode.commons.sprotty.scan;
|
||||
|
||||
import org.eclipse.elk.graph.ElkEdge;
|
||||
import org.eclipse.elk.graph.ElkGraphElement;
|
||||
import org.eclipse.elk.graph.ElkLabel;
|
||||
import org.eclipse.elk.graph.ElkNode;
|
||||
import org.eclipse.elk.graph.ElkPort;
|
||||
import org.eclipse.sprotty.BoundsAware;
|
||||
import org.eclipse.sprotty.Layouting;
|
||||
import org.eclipse.sprotty.SEdge;
|
||||
import org.eclipse.sprotty.SLabel;
|
||||
import org.eclipse.sprotty.SModelElement;
|
||||
import org.eclipse.sprotty.SNode;
|
||||
import org.eclipse.sprotty.SPort;
|
||||
import org.eclipse.sprotty.SShapeElement;
|
||||
import org.eclipse.sprotty.layout.ElkLayoutEngine;
|
||||
|
||||
public class CustomElkLayoutEngine extends ElkLayoutEngine {
|
||||
|
||||
/**
|
||||
* Transform the children of a sprotty model element to their ELK graph counterparts.
|
||||
*/
|
||||
protected int processChildren(SModelElement sParent, ElkGraphElement elkParent, LayoutContext context) {
|
||||
int childrenCount = 0;
|
||||
if (sParent.getChildren() != null) {
|
||||
for (SModelElement schild : sParent.getChildren()) {
|
||||
context.parentMap.put(schild, sParent);
|
||||
ElkGraphElement elkChild = null;
|
||||
if (shouldInclude(schild, sParent, elkParent, context)) {
|
||||
if (schild instanceof SNode) {
|
||||
SNode snode = (SNode) schild;
|
||||
ElkNode elkNode = createNode(snode);
|
||||
if (elkParent instanceof ElkNode) {
|
||||
elkNode.setParent((ElkNode) elkParent);
|
||||
childrenCount++;
|
||||
}
|
||||
context.shapeMap.put(snode, elkNode);
|
||||
elkChild = elkNode;
|
||||
} else if (schild instanceof SPort) {
|
||||
SPort sport = (SPort) schild;
|
||||
ElkPort elkPort = createPort(sport);
|
||||
if (elkParent instanceof ElkNode) {
|
||||
elkPort.setParent((ElkNode) elkParent);
|
||||
childrenCount++;
|
||||
}
|
||||
context.shapeMap.put(sport, elkPort);
|
||||
elkChild = elkPort;
|
||||
} else if (schild instanceof SEdge) {
|
||||
SEdge sedge = (SEdge) schild;
|
||||
ElkEdge elkEdge = createEdge(sedge);
|
||||
// The most suitable container for the edge is determined later
|
||||
childrenCount++;
|
||||
context.edgeMap.put(sedge, elkEdge);
|
||||
elkChild = elkEdge;
|
||||
} else if (schild instanceof SLabel) {
|
||||
SLabel slabel = (SLabel) schild;
|
||||
ElkLabel elkLabel = createLabel(slabel);
|
||||
elkLabel.setParent(elkParent);
|
||||
childrenCount++;
|
||||
context.shapeMap.put(slabel, elkLabel);
|
||||
elkChild = elkLabel;
|
||||
} else if (schild instanceof SShapeElement) {
|
||||
System.out.println("wat?");
|
||||
}
|
||||
}
|
||||
int grandChildrenCount = processChildren(schild, elkChild != null ? elkChild : elkParent, context);
|
||||
childrenCount += grandChildrenCount;
|
||||
if (grandChildrenCount > 0 && sParent instanceof Layouting && schild instanceof BoundsAware) {
|
||||
handleClientLayout((BoundsAware) schild, (Layouting) sParent, elkParent, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return childrenCount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class DiagramServerConfiguration {
|
||||
@Bean
|
||||
public ILayoutEngine layoutEngine(Optional<SprottyLayoutConfigurator> configurator) {
|
||||
ElkLayoutEngine.initialize(new LayeredMetaDataProvider());
|
||||
final ElkLayoutEngine engine = new ElkLayoutEngine();
|
||||
final ElkLayoutEngine engine = new CustomElkLayoutEngine();
|
||||
return (root, action) -> {
|
||||
engine.layout((SGraph)root, configurator.orElse(null), action);
|
||||
};
|
||||
|
||||
4549
headless-services/sprotty-si-view/client/package-lock.json
generated
Normal file
4549
headless-services/sprotty-si-view/client/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"contentDescriptor": {
|
||||
"providerVersion": "5.1.7.RELEASE",
|
||||
"providerFormatVersion": 1.0,
|
||||
"provider": "spring-integration"
|
||||
},
|
||||
"nodes": [
|
||||
{
|
||||
"nodeId": 11,
|
||||
"name": "cafe.placeOrder(com.coffee.barista.model.Order)",
|
||||
"stats": null,
|
||||
"componentType": "gateway",
|
||||
"properties": {},
|
||||
"output": "orders",
|
||||
"errors": null
|
||||
},
|
||||
{
|
||||
"nodeId": 12,
|
||||
"name": "org.springframework.integration.config.ConsumerEndpointFactoryBean#0",
|
||||
"stats": {
|
||||
"countsEnabled": true,
|
||||
"statsEnabled": true,
|
||||
"loggingEnabled": true,
|
||||
"handleCount": 1560,
|
||||
"meanDuration": 1003.518562869151,
|
||||
"minDuration": 1000.233368,
|
||||
"maxDuration": 1112.060177,
|
||||
"standardDeviationDuration": 1.3030029550200601,
|
||||
"errorCount": 0,
|
||||
"activeCount": 1,
|
||||
"duration": {
|
||||
"count": 1559,
|
||||
"min": 1000.233368,
|
||||
"max": 1112.060177,
|
||||
"mean": 1003.518562869151,
|
||||
"standardDeviation": 1.3030029550200601,
|
||||
"countLong": 1559
|
||||
}
|
||||
}
|
||||
}],
|
||||
"links": [
|
||||
]
|
||||
}
|
||||
@@ -51,7 +51,7 @@ import {
|
||||
HtmlRoot,
|
||||
PreRenderedView,
|
||||
PreRenderedElement,
|
||||
labelEditModule, edgeEditModule, RectangularPort, LayoutRegistry, VBoxLayouter, HBoxLayouter
|
||||
labelEditModule, edgeEditModule, RectangularPort, LayoutRegistry, VBoxLayouter, HBoxLayouter, boundsFeature
|
||||
} from "sprotty";
|
||||
import {
|
||||
IntegrationNodeView,
|
||||
@@ -92,7 +92,7 @@ export default (transport: TransportMedium, clientId: string) => {
|
||||
const context = { bind, unbind, isBound, rebind };
|
||||
configureModelElement(context, 'graph', SGraph, ExampleGraphView);
|
||||
configureModelElement(context, 'node:circle', CircularNode, CircleNodeView);
|
||||
configureModelElement(context, 'node:integration_node', RectangularNode, IntegrationNodeView);
|
||||
configureModelElement(context, 'node:integration', RectangularNode, IntegrationNodeView, {disable: [boundsFeature]});
|
||||
configureModelElement(context, 'node:channel', RectangularNode, ChannelNodeView);
|
||||
configureModelElement(context, 'node:label', SLabel, SLabelView);
|
||||
configureModelElement(context, 'compartment', SCompartment, SCompartmentView);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.springframework.ide.si.view;
|
||||
|
||||
import org.eclipse.sprotty.SNode;
|
||||
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
|
||||
|
||||
public class IconElement extends SNode {
|
||||
|
||||
private String code;
|
||||
|
||||
public IconElement() {
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(final String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.addAllFields()
|
||||
.skipNulls()
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.elk.alg.layered.options.LayeredOptions;
|
||||
import org.eclipse.sprotty.Dimension;
|
||||
import org.eclipse.sprotty.EdgePlacement;
|
||||
import org.eclipse.sprotty.EdgePlacement.Side;
|
||||
@@ -166,23 +167,24 @@ public class SIDiagramGenerator implements DiagramGenerator {
|
||||
options.setVAlign("center");
|
||||
}
|
||||
|
||||
private static SNode createIntegrationNode(SpringIntegrationNodeJson json) {
|
||||
SNode node = createNode(json, "integration_node");
|
||||
String id = getId(json);
|
||||
LayoutOptions layoutOptions = new LayoutOptions();
|
||||
layoutOptions.setMinWidth(MIN_WIDTH);
|
||||
layoutOptions.setPaddingBottom(INTEGRATION_NODE_VERTICAL_PADDING);
|
||||
layoutOptions.setPaddingTop(20.0);
|
||||
node.setLayoutOptions(layoutOptions);
|
||||
private static SIntegrationNode createIntegrationNode(SpringIntegrationNodeJson json) {
|
||||
SIntegrationNode node = new SIntegrationNode(json);
|
||||
node.setSize(new Dimension(100, 100));
|
||||
String id = node.getId();
|
||||
// LayoutOptions layoutOptions = new LayoutOptions();
|
||||
// layoutOptions.setMinWidth(MIN_WIDTH);
|
||||
// layoutOptions.setPaddingBottom(INTEGRATION_NODE_VERTICAL_PADDING);
|
||||
// layoutOptions.setPaddingTop(20.0);
|
||||
// node.setLayoutOptions(layoutOptions);
|
||||
|
||||
if (json.getOutput() != null) {
|
||||
SPort outputPort = new SPort();
|
||||
outputPort.setType("output-port");
|
||||
outputPort.setId("output-port-" + id);
|
||||
outputPort.setSize(new Dimension(10,10));
|
||||
outputPort.setSize(new Dimension(10,10));
|
||||
node.getChildren().add(outputPort);
|
||||
}
|
||||
|
||||
|
||||
if (json.getInput() != null) {
|
||||
SPort inputPort = new SPort();
|
||||
inputPort.setType("input-port");
|
||||
@@ -202,6 +204,30 @@ public class SIDiagramGenerator implements DiagramGenerator {
|
||||
return node;
|
||||
}
|
||||
|
||||
private static String getSvgIcon(String componentType) {
|
||||
String color;
|
||||
switch (componentType) {
|
||||
case "gateway":
|
||||
color = "rgb(0,200,0)";
|
||||
break;
|
||||
case "bridge":
|
||||
color = "rgb(0,200,200)";
|
||||
break;
|
||||
default:
|
||||
color = "rgb(200,200,200)";
|
||||
break;
|
||||
}
|
||||
return
|
||||
"<g>" +
|
||||
"<rect class=\"svg-icon\" "+
|
||||
//"x=\"0\" y=\"0\" "+
|
||||
"width=\"100\" height=\"100\" " +
|
||||
"rx=\"5\" ry=\"5\" " +
|
||||
"style=\"fill:"+color+";stroke-width:1;stroke:rgb(0,0,0)\" "+
|
||||
"></rect>" +
|
||||
"</g>";
|
||||
}
|
||||
|
||||
private static String getId(SpringIntegrationNodeJson json) {
|
||||
return json.getNodeId() + "";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.springframework.ide.si.view;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.sprotty.SLabel;
|
||||
import org.eclipse.sprotty.SNode;
|
||||
import org.springframework.ide.si.view.json.SpringIntegrationNodeJson;
|
||||
|
||||
public class SIntegrationNode extends SNode {
|
||||
|
||||
private String componentType;
|
||||
|
||||
{
|
||||
setType("node:integration");
|
||||
setChildren(new ArrayList<>());
|
||||
}
|
||||
|
||||
public SIntegrationNode(SpringIntegrationNodeJson json) {
|
||||
this.setComponentType(json.getComponentType());
|
||||
this.getChildren().add(new SLabel(l -> {
|
||||
l.setType("node:label");
|
||||
l.setText(json.getName());
|
||||
}));
|
||||
this.setId(""+json.getNodeId());
|
||||
}
|
||||
|
||||
public String getComponentType() {
|
||||
return componentType;
|
||||
}
|
||||
|
||||
public void setComponentType(String componentType) {
|
||||
this.componentType = componentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLayout(String layout) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLayout() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package org.springframework.ide.si.view;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.eclipse.elk.alg.layered.options.FixedAlignment;
|
||||
import org.eclipse.elk.alg.layered.options.LayeredOptions;
|
||||
import org.eclipse.elk.core.math.ElkPadding;
|
||||
import org.eclipse.elk.core.options.EdgeRouting;
|
||||
import org.eclipse.elk.core.options.NodeLabelPlacement;
|
||||
import org.eclipse.elk.core.options.PortConstraints;
|
||||
import org.eclipse.elk.core.options.PortSide;
|
||||
import org.eclipse.elk.graph.properties.IPropertyHolder;
|
||||
@@ -42,9 +46,15 @@ public class SprottySiViewApplication {
|
||||
holder = configurator.configureByType("node:channel");
|
||||
holder.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE);
|
||||
|
||||
holder = configurator.configureByType("node:integration_node");
|
||||
holder = configurator.configureByType("node:integration");
|
||||
holder.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_SIDE);
|
||||
|
||||
holder.setProperty(LayeredOptions.NODE_LABELS_PLACEMENT, EnumSet.of(NodeLabelPlacement.OUTSIDE, NodeLabelPlacement.V_BOTTOM));
|
||||
holder.setProperty(LayeredOptions.NODE_LABELS_PADDING, new ElkPadding(5.0));
|
||||
|
||||
holder = configurator.configureByType("node:label");
|
||||
holder.setProperty(LayeredOptions.NODE_LABELS_PLACEMENT, EnumSet.of(NodeLabelPlacement.OUTSIDE, NodeLabelPlacement.V_BOTTOM));
|
||||
holder.setProperty(LayeredOptions.NODE_LABELS_PADDING, new ElkPadding(5.0));
|
||||
|
||||
return configurator;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user