use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class AlignLeftHandler method execute.
// This handler allows for alignment of selected diagram elements that are not docked left or right.
// Any selected element must not an ancestor of another selected element.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
final List<AlignmentElement> alignmentElements = selectedDiagramElements.stream().map(alignmentHelper::createAlignmentElement).collect(Collectors.toList());
diagram.modify("Align Left", m -> {
final AlignmentElement primaryAlignmentElement = Objects.requireNonNull(AlignmentHelper.getPrimaryAlignmentElement(alignmentElements), "primary element must not be null");
for (final AlignmentElement alignmentElement : alignmentElements) {
alignmentHelper.alignElement(m, alignmentElement, primaryAlignmentElement.getAbsoluteLocation(), 0);
}
});
return null;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class AlignRightHandler method execute.
// This handler allows for alignment of selected diagram elements that are not docked left or right.
// Any selected element must not an ancestor of another selected element.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
final List<AlignmentElement> alignmentElements = selectedDiagramElements.stream().map(alignmentHelper::createAlignmentElement).collect(Collectors.toList());
diagram.modify("Align Right", m -> {
final AlignmentElement primaryAlignmentElement = AlignmentHelper.getPrimaryAlignmentElement(alignmentElements);
// Location that elements will be aligned at
final double alignLocation = primaryAlignmentElement.getAbsoluteLocation() + primaryAlignmentElement.getDiagramElement().getWidth();
for (final AlignmentElement alignmentElement : alignmentElements) {
alignmentHelper.alignElement(m, alignmentElement, alignLocation, alignmentElement.getDiagramElement().getWidth());
}
});
return null;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class AlignTopHandler method execute.
// This handler allows for alignment of selected diagram elements that are not docked top or bottom.
// Any selected element must not an ancestor of another selected element.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
final List<AlignmentElement> alignmentElements = selectedDiagramElements.stream().map(alignmentHelper::createAlignmentElement).collect(Collectors.toList());
diagram.modify("Align Top", m -> {
final AlignmentElement primaryAlignmentElement = AlignmentHelper.getPrimaryAlignmentElement(alignmentElements);
for (final AlignmentElement alignmentElement : alignmentElements) {
alignmentHelper.alignElement(m, alignmentElement, primaryAlignmentElement.getAbsoluteLocation(), 0);
}
});
return null;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class DiagramElementLayoutUtil method applyProperties.
/**
* Sets the ELK properties of elements in the specified layout mapping based on the layout options.
* @param layoutMapping
*/
private static void applyProperties(final DiagramNode rootDiagramNode, final LayoutMapping layoutMapping) {
// Set the minimum node size based on the ports and their assigned sides.
final IGraphElementVisitor minNodeSizeVisitor = element -> {
if (element instanceof ElkNode) {
final ElkNode n = (ElkNode) element;
final double maxLabelWidth = n.getLabels().stream().mapToDouble(l -> l.getWidth()).max().orElse(0.0);
final double labelHeightSum = n.getLabels().stream().mapToDouble(l -> l.getHeight()).sum();
// Determine max width for ports on the left and right sides
final double maxLeftPortWidth = n.getPorts().stream().filter(p -> p.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST).mapToDouble(p -> p.getWidth()).max().orElse(0.0);
final double maxRightPortWidth = n.getPorts().stream().filter(p -> p.getProperty(CoreOptions.PORT_SIDE) == PortSide.EAST).mapToDouble(p -> p.getWidth()).max().orElse(0.0);
final DiagramNode dn = (DiagramNode) layoutMapping.getGraphMap().get(n);
double minWidth = 0;
if (n.getProperty(CoreOptions.NODE_LABELS_PLACEMENT).contains(NodeLabelPlacement.H_CENTER)) {
// Ensure the minimum width is such that the label can be centered without overlapping with ports.
// This happens because ports are inside the node due to the PORT_BORDER_OFFSET and ELK centers the labels in the remaining space.
final double widthForPorts = 2 * Math.max(maxLeftPortWidth, maxRightPortWidth);
minWidth = Math.max(40, maxLabelWidth + widthForPorts + PORT_WIDTH_PADDING);
} else {
final double widthForPorts = maxLeftPortWidth + maxRightPortWidth + PORT_WIDTH_PADDING;
minWidth = Math.max(40, Math.max(maxLabelWidth, widthForPorts));
}
double minHeight = Math.max(35, labelHeightSum);
if (dn instanceof DiagramElement) {
final DiagramElement de = ((DiagramElement) dn);
// Special min height handling for initial modes
final Graphic graphic = de.getGraphic();
if (graphic instanceof AgeShape && !((AgeShape) graphic).isResizeable() && de.hasSize()) {
final Dimension dim = de.getSize();
minHeight = dim.height;
minWidth = dim.width;
// Adjust size constraints for fixed sized shapes which do not have contents.
if (n.getChildren().size() == 0 || n.getLabels().size() == 0 && n.getPorts().size() == 0) {
final EnumSet<SizeConstraint> nodeSizeConstraints = EnumSet.of(SizeConstraint.MINIMUM_SIZE);
n.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, nodeSizeConstraints);
}
}
if (graphic instanceof ModeGraphic && ((ModeGraphic) graphic).isInitialMode) {
minHeight += ModeGraphic.INITIAL_MODE_AREA_HEIGHT;
}
// Special min size handling for elements shown as image
final Style style = de.getStyle();
if (style != null && Boolean.TRUE.equals(style.getShowAsImage())) {
final Dimension dim = ((DiagramElement) dn).getSize();
minHeight = dim.height;
minWidth = dim.width;
}
}
// Increase min width and min height for top level nodes.
if (dn != null && dn.getParent() instanceof AgeDiagram) {
minWidth = Math.max(minWidth, 200);
minHeight = Math.max(minHeight, 100);
}
n.setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(minWidth, minHeight));
}
};
ElkUtil.applyVisitors(layoutMapping.getLayoutGraph(), minNodeSizeVisitor);
// If the top level element has a size set, don't shrink it.
if (rootDiagramNode instanceof DiagramElement) {
final DiagramElement rootDiagramElement = (DiagramElement) rootDiagramNode;
final ElkGraphElement rootGraphElement = layoutMapping.getGraphMap().inverse().get(rootDiagramNode);
if (rootGraphElement != null && rootDiagramElement.hasSize() && DiagramElementPredicates.isResizeable(rootDiagramElement)) {
final KVector minSize = rootGraphElement.getProperty(CoreOptions.NODE_SIZE_MINIMUM);
final double newMinWidth = Math.max(rootDiagramElement.getWidth(), minSize == null ? 0.0 : minSize.x);
final double newMinHeight = Math.max(rootDiagramElement.getHeight(), minSize == null ? 0.0 : minSize.y);
rootGraphElement.setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(newMinWidth, newMinHeight));
}
}
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class UiTestUtil method getDiagramElement.
/**
* Returns an optional describing the diagram element contained in the editor for the specified diagram.
* Does not open or activate the editor for the specified diagram.
*/
public static Optional<DiagramElement> getDiagramElement(final DiagramReference diagram, final DiagramElementReference element) {
final AgeEditor editor = getDiagramEditor(diagram);
final AgeDiagram ageDiagram = editor.getDiagram();
ImmutableList<RelativeBusinessObjectReference> refs = element.pathToElement;
DiagramElement de = ageDiagram.getChildByRelativeReference(refs.get(0));
for (int i = 1; i < refs.size() && de != null; i++) {
de = de.getChildByRelativeReference(refs.get(i));
}
return Optional.ofNullable(de);
}
Aggregations