use of org.eclipse.elk.graph.properties.Property in project lingua-franca by lf-lang.
the class ReactionPortAdjustment method modify.
@Override
public boolean modify(IStyleModifier.StyleModificationContext context) {
try {
KGraphElement node = context.getGraphElement();
if (node instanceof KNode) {
KNode knode = (KNode) node;
// Find root node
KNode parent = knode;
while (parent.eContainer() != null) {
parent = (KNode) parent.eContainer();
}
// Get viewer (this is a bit brittle because it fetches the viewer from some internal property)
Map.Entry<IProperty<?>, Object> first = IterableExtensions.findFirst(parent.getAllProperties().entrySet(), it -> {
return it.getKey().getId().equals("de.cau.cs.kieler.klighd.viewer") || it.getKey().getId().equals("klighd.layout.viewer");
});
Object viewer = first != null ? first.getValue() : null;
ILayoutRecorder recorder = null;
if (viewer instanceof IViewer) {
recorder = ((IViewer) viewer).getViewContext().getLayoutRecorder();
}
if (!knode.getPorts().isEmpty()) {
if (IterableExtensions.head(knode.getPorts()).getYpos() != 0 && !knode.getProperty(ReactionPortAdjustment.PROCESSED)) {
// important for incremental update animation
if (recorder != null) {
recorder.startRecording();
}
List<KPort> in = IterableExtensions.toList(IterableExtensions.sortBy(IterableExtensions.filter(knode.getPorts(), it -> {
return it.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST && !it.hasProperty(CoreOptions.PORT_BORDER_OFFSET);
}), it -> {
return it.getYpos();
}));
List<KPort> out = IterableExtensions.toList(IterableExtensions.sortBy(IterableExtensions.filter(knode.getPorts(), it -> {
return it.getProperty(CoreOptions.PORT_SIDE) == PortSide.EAST && !it.hasProperty(CoreOptions.PORT_BORDER_OFFSET);
}), it -> {
return it.getYpos();
}));
// Adjust
adjustPositions(IterableExtensions.indexed(in), in.size(), true);
adjustPositions(IterableExtensions.indexed(out), out.size(), false);
knode.setProperty(ReactionPortAdjustment.PROCESSED, true);
if (recorder != null) {
recorder.stopRecording(0);
}
} else if (IterableExtensions.head(knode.getPorts()).getYpos() == 0) {
knode.setProperty(PROCESSED, false);
}
}
}
} catch (Exception e) {
e.printStackTrace();
// do not disturb rendering process
}
return false;
}
Aggregations