Skip to content

Commit

Permalink
[285][287] Refactor changes to squash with previous commit
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#285
Bug: eclipse-sirius#287
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
  • Loading branch information
florianbarbin committed Mar 1, 2021
1 parent 026ca2d commit e323079
Show file tree
Hide file tree
Showing 34 changed files with 502 additions and 381 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*******************************************************************************/
package org.eclipse.sirius.web.diagrams.layout.api;

import java.util.Optional;

import org.eclipse.sirius.web.diagrams.Diagram;
import org.eclipse.sirius.web.diagrams.MoveEvent;
import org.eclipse.sirius.web.diagrams.Position;
Expand All @@ -38,5 +36,5 @@ public interface ILayoutService {
* for instance.
* @return the new layouted diagram.
*/
Diagram incrementalLayout(Diagram diagram, Optional<MoveEvent> moveEvent, Position startingPosition);
Diagram incrementalLayout(Diagram diagram, MoveEvent moveEvent, Position startingPosition);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 Obeo and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -24,12 +24,12 @@
*
* @author sbegaudeau
*/
public class ConvertedDiagram {
public class ELKConvertedDiagram {
private final ElkNode elkDiagram;

private final Map<String, ElkGraphElement> id2ElkGraphElements;

public ConvertedDiagram(ElkNode elkDiagram, Map<String, ElkGraphElement> id2ElkGraphElements) {
public ELKConvertedDiagram(ElkNode elkDiagram, Map<String, ElkGraphElement> id2ElkGraphElements) {
this.elkDiagram = Objects.requireNonNull(elkDiagram);
this.id2ElkGraphElements = Objects.requireNonNull(id2ElkGraphElements);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* @author sbegaudeau
*/
@Service
public class DiagramConverter {
public class ELKDiagramConverter {

public static final IProperty<String> PROPERTY_TYPE = new Property<>("org.eclipse.sirius.web.layout.type"); //$NON-NLS-1$

Expand All @@ -68,23 +68,23 @@ public class DiagramConverter {

private final ImageNodeStyleSizeProvider imageNodeStyleSizeProvider;

private final Logger logger = LoggerFactory.getLogger(DiagramConverter.class);
private final Logger logger = LoggerFactory.getLogger(ELKDiagramConverter.class);

public DiagramConverter(TextBoundsService textBoundsService) {
public ELKDiagramConverter(TextBoundsService textBoundsService) {
this.textBoundsService = Objects.requireNonNull(textBoundsService);
this.imageSizeProvider = new ImageSizeProvider();
this.imageNodeStyleSizeProvider = new ImageNodeStyleSizeProvider(this.imageSizeProvider);
}

public ConvertedDiagram convert(Diagram diagram) {
public ELKConvertedDiagram convert(Diagram diagram) {
ElkNode elkDiagram = this.convertDiagram(diagram);

Map<String, ElkGraphElement> id2ElkGraphElements = new HashMap<>();
Map<String, ElkConnectableShape> connectableShapeIndex = new LinkedHashMap<>();
diagram.getNodes().stream().forEach(node -> this.convertNode(node, elkDiagram, connectableShapeIndex, id2ElkGraphElements));
diagram.getEdges().stream().forEach(edge -> this.convertEdge(edge, elkDiagram, connectableShapeIndex, id2ElkGraphElements));

return new ConvertedDiagram(elkDiagram, id2ElkGraphElements);
return new ELKConvertedDiagram(elkDiagram, id2ElkGraphElements);
}

private ElkNode convertDiagram(Diagram diagram) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* @author hmarchadour
*/
@Service
public class LayoutedDiagramProvider {
public class ELKLayoutedDiagramProvider {

public Diagram getLayoutedDiagram(Diagram diagram, ElkNode elkDiagram, Map<String, ElkGraphElement> id2ElkGraphElements) {
Size size = Size.of(elkDiagram.getWidth(), elkDiagram.getHeight());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public LayoutConfiguratorRegistry(List<IDiagramLayoutConfiguratorProvider> custo
public LayoutConfigurator getDefaultLayoutConfigurator() {
// @formatter:off
SiriusWebLayoutConfigurator configurator = new SiriusWebLayoutConfigurator();
configurator.configureByType(DiagramConverter.DEFAULT_DIAGRAM_TYPE)
configurator.configureByType(ELKDiagramConverter.DEFAULT_DIAGRAM_TYPE)
.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID)
.setProperty(CoreOptions.HIERARCHY_HANDLING, HierarchyHandling.INCLUDE_CHILDREN)
.setProperty(LayeredOptions.LAYERING_STRATEGY, LayeringStrategy.NETWORK_SIMPLEX)
Expand All @@ -88,7 +88,7 @@ public LayoutConfigurator getDefaultLayoutConfigurator() {
.setProperty(CoreOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.outsideTopCenter());

// This image type does not match any diagram item. We add it to define the image size as constraint for the node image parent.
configurator.configureByType(DiagramConverter.DEFAULT_IMAGE_TYPE)
configurator.configureByType(ELKDiagramConverter.DEFAULT_IMAGE_TYPE)
.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.fixed());
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 Obeo and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -14,7 +14,6 @@

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.elk.alg.layered.options.LayeredOptions;
import org.eclipse.elk.core.IGraphLayoutEngine;
Expand All @@ -30,7 +29,10 @@
import org.eclipse.sirius.web.diagrams.Position;
import org.eclipse.sirius.web.diagrams.description.DiagramDescription;
import org.eclipse.sirius.web.diagrams.layout.api.ILayoutService;
import org.eclipse.sirius.web.diagrams.layout.incremental.IncrementalLayoutConvertedDiagram;
import org.eclipse.sirius.web.diagrams.layout.incremental.IncrementalLayoutDiagramConverter;
import org.eclipse.sirius.web.diagrams.layout.incremental.IncrementalLayoutEngine;
import org.eclipse.sirius.web.diagrams.layout.incremental.IncrementalLayoutedDiagramProvider;
import org.eclipse.sirius.web.diagrams.layout.incremental.data.DiagramLayoutData;
import org.eclipse.sirius.web.diagrams.layout.incremental.data.ILayoutData;
import org.eclipse.sirius.web.services.api.representations.IRepresentationDescriptionService;
Expand All @@ -44,25 +46,32 @@
@Service
public class LayoutService implements ILayoutService {

private final DiagramConverter diagramConverter;
private final ELKDiagramConverter elkDiagramConverter;

private final LayoutConfiguratorRegistry layoutConfiguratorRegistry;

private final LayoutedDiagramProvider layoutedDiagramProvider;
private final ELKLayoutedDiagramProvider elkLayoutedDiagramProvider;

private final IncrementalLayoutedDiagramProvider incrementalLayoutedDiagramProvider;

private final IRepresentationDescriptionService representationDescriptionService;

public LayoutService(DiagramConverter diagramConverter, LayoutConfiguratorRegistry layoutConfiguratorRegistry, LayoutedDiagramProvider layoutedDiagramProvider,
private final IncrementalLayoutDiagramConverter incrementalLayoutDiagramConverter;

public LayoutService(ELKDiagramConverter elkDiagramConverter, IncrementalLayoutDiagramConverter incrementalLayoutDiagramConverter, LayoutConfiguratorRegistry layoutConfiguratorRegistry,
ELKLayoutedDiagramProvider layoutedDiagramProvider, IncrementalLayoutedDiagramProvider incrementalLayoutedDiagramProvider,
IRepresentationDescriptionService representationDescriptionService) {
this.diagramConverter = Objects.requireNonNull(diagramConverter);
this.elkDiagramConverter = Objects.requireNonNull(elkDiagramConverter);
this.incrementalLayoutDiagramConverter = Objects.requireNonNull(incrementalLayoutDiagramConverter);
this.layoutConfiguratorRegistry = Objects.requireNonNull(layoutConfiguratorRegistry);
this.layoutedDiagramProvider = Objects.requireNonNull(layoutedDiagramProvider);
this.elkLayoutedDiagramProvider = Objects.requireNonNull(layoutedDiagramProvider);
this.incrementalLayoutedDiagramProvider = Objects.requireNonNull(incrementalLayoutedDiagramProvider);
this.representationDescriptionService = Objects.requireNonNull(representationDescriptionService);
}

@Override
public Diagram layout(Diagram diagram) {
ConvertedDiagram convertedDiagram = this.diagramConverter.convert(diagram);
ELKConvertedDiagram convertedDiagram = this.elkDiagramConverter.convert(diagram);

ElkNode elkDiagram = convertedDiagram.getElkDiagram();
var representationDescription = this.representationDescriptionService.findRepresentationDescriptionById(diagram.getDescriptionId());
Expand All @@ -80,18 +89,18 @@ public Diagram layout(Diagram diagram) {
engine.layout(elkDiagram, new BasicProgressMonitor());

Map<String, ElkGraphElement> id2ElkGraphElements = convertedDiagram.getId2ElkGraphElements();
Diagram layoutedDiagram = this.layoutedDiagramProvider.getLayoutedDiagram(diagram, elkDiagram, id2ElkGraphElements);
Diagram layoutedDiagram = this.elkLayoutedDiagramProvider.getLayoutedDiagram(diagram, elkDiagram, id2ElkGraphElements);

return layoutedDiagram;
}

@Override
public Diagram incrementalLayout(Diagram newDiagram, Optional<MoveEvent> optionalMoveEvent, Position startingPosition) {
org.eclipse.sirius.web.diagrams.layout.incremental.ConvertedDiagram convertedDiagram = new org.eclipse.sirius.web.diagrams.layout.incremental.DiagramConverter().convert(newDiagram);
public Diagram incrementalLayout(Diagram newDiagram, MoveEvent moveEvent, Position startingPosition) {
IncrementalLayoutConvertedDiagram convertedDiagram = this.incrementalLayoutDiagramConverter.convert(newDiagram);
DiagramLayoutData diagramLayoutData = convertedDiagram.getDiagramLayoutData();
new IncrementalLayoutEngine(optionalMoveEvent, startingPosition).layout(diagramLayoutData);
new IncrementalLayoutEngine(moveEvent, startingPosition).layout(diagramLayoutData);
Map<String, ILayoutData> id2LayoutData = convertedDiagram.getId2LayoutData();
return new org.eclipse.sirius.web.diagrams.layout.incremental.LayoutedDiagramProvider().getLayoutedDiagram(newDiagram, diagramLayoutData, id2LayoutData);
return this.incrementalLayoutedDiagramProvider.getLayoutedDiagram(newDiagram, diagramLayoutData, id2LayoutData);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public IPropertyHolder configureByType(String type) {
public void visit(final ElkGraphElement element) {
super.visit(element);

IPropertyHolder typeProperties = this.getPropertiesByType(element.getProperty(DiagramConverter.PROPERTY_TYPE));
IPropertyHolder typeProperties = this.getPropertiesByType(element.getProperty(ELKDiagramConverter.PROPERTY_TYPE));
this.applyProperties(element, typeProperties);

IPropertyHolder idProperties = this.getPropertiesById(element.getIdentifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
*
* @author wpiers
*/
public class ConvertedDiagram {
public class IncrementalLayoutConvertedDiagram {

private final DiagramLayoutData diagramLayoutData;

private final Map<String, ILayoutData> id2LayoutData;

public ConvertedDiagram(DiagramLayoutData diagramLayoutData, Map<String, ILayoutData> id2LayoutData) {
public IncrementalLayoutConvertedDiagram(DiagramLayoutData diagramLayoutData, Map<String, ILayoutData> id2LayoutData) {
this.diagramLayoutData = Objects.requireNonNull(diagramLayoutData);
this.id2LayoutData = Objects.requireNonNull(id2LayoutData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Thales.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -29,15 +29,17 @@
import org.eclipse.sirius.web.diagrams.layout.incremental.data.ILayoutData;
import org.eclipse.sirius.web.diagrams.layout.incremental.data.LabelLayoutData;
import org.eclipse.sirius.web.diagrams.layout.incremental.data.NodeLayoutData;
import org.springframework.stereotype.Service;

/**
* Used to convert the diagram into layout data. During the transformation.
*
* @author wpiers
*/
public class DiagramConverter {
@Service
public class IncrementalLayoutDiagramConverter {

public ConvertedDiagram convert(Diagram diagram) {
public IncrementalLayoutConvertedDiagram convert(Diagram diagram) {
Map<String, ILayoutData> id2LayoutData = new HashMap<>();

DiagramLayoutData layoutData = new DiagramLayoutData();
Expand All @@ -60,7 +62,7 @@ public ConvertedDiagram convert(Diagram diagram) {
}
layoutData.setEdges(edges);

return new ConvertedDiagram(layoutData, id2LayoutData);
return new IncrementalLayoutConvertedDiagram(layoutData, id2LayoutData);
}

private NodeLayoutData convertNode(Node node, IContainerLayoutData parent, Map<String, ILayoutData> id2LayoutData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*******************************************************************************/
package org.eclipse.sirius.web.diagrams.layout.incremental;

import java.util.Optional;

import org.eclipse.sirius.web.diagrams.MoveEvent;
import org.eclipse.sirius.web.diagrams.Position;
import org.eclipse.sirius.web.diagrams.layout.incremental.data.DiagramLayoutData;
Expand Down Expand Up @@ -44,7 +42,7 @@ public class IncrementalLayoutEngine {
*/
public static final double NODES_GAP = 30;

private Optional<MoveEvent> optionalMoveEvent;
private MoveEvent moveEvent;

private NodeLabelPositionProvider nodeLabelPositionProvider;

Expand All @@ -56,8 +54,8 @@ public class IncrementalLayoutEngine {

private NodePositionProvider nodePositionProvider;

public IncrementalLayoutEngine(Optional<MoveEvent> optionalMoveEvent, Position startingPosition) {
this.optionalMoveEvent = optionalMoveEvent;
public IncrementalLayoutEngine(MoveEvent moveEvent, Position startingPosition) {
this.moveEvent = moveEvent;
this.edgeRoutingPointsProvider = new EdgeRoutingPointsProvider();
this.nodeLabelPositionProvider = new NodeLabelPositionProvider();
this.edgeLabelPositionProvider = new EdgeLabelPositionProvider();
Expand Down Expand Up @@ -101,8 +99,8 @@ private void layoutNode(NodeLayoutData node) {
}

// recompute the node position
if (this.optionalMoveEvent.isPresent() && this.optionalMoveEvent.get().getNodeId().toString().equals(node.getId())) {
Position newPosition = this.optionalMoveEvent.get().getNewPosition();
if (this.moveEvent != null && this.moveEvent.getNodeId().toString().equals(node.getId())) {
Position newPosition = this.moveEvent.getNewPosition();
node.setPosition(newPosition);
node.setChanged(true);
node.setPinned(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Thales.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -26,14 +26,16 @@
import org.eclipse.sirius.web.diagrams.layout.incremental.data.ILayoutData;
import org.eclipse.sirius.web.diagrams.layout.incremental.data.LabelLayoutData;
import org.eclipse.sirius.web.diagrams.layout.incremental.data.NodeLayoutData;
import org.springframework.stereotype.Service;

/**
* This class is used to include layout data in an existing diagram by producing a brand new immutable diagram with the
* proper layout information.
*
* @author wpiers
*/
public class LayoutedDiagramProvider {
@Service
public class IncrementalLayoutedDiagramProvider {

public Diagram getLayoutedDiagram(Diagram diagram, DiagramLayoutData diagramLayoutData, Map<String, ILayoutData> id2LayoutData) {
List<Node> nodes = this.getLayoutedNodes(diagram.getNodes(), id2LayoutData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Thales.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Thales.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Thales.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Thales.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Position getAbsolutePosition() {
NodeLayoutData parentLayoutData = (NodeLayoutData) parentContainerLayoutData;
double absoluteX = this.getPosition().getX() + parentLayoutData.getAbsolutePosition().getX();
double absoluteY = this.getPosition().getY() + parentLayoutData.getAbsolutePosition().getY();
return Position.newPosition().x(absoluteX).y(absoluteY).build();
return Position.at(absoluteX, absoluteY);
}
return this.getPosition();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Thales.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -35,7 +35,7 @@ public Position getCenterPosition(EdgeLayoutData edge, LabelLayoutData label) {
Position targetAnchor = routingPoints.get(routingPoints.size() - 1);
double x = ((sourceAnchor.getX() + targetAnchor.getX()) / 2) - (label.getTextBounds().getSize().getWidth() / 2);
double y = (sourceAnchor.getY() + targetAnchor.getY()) / 2;
return Position.newPosition().x(x).y(y).build();
return Position.at(x, y);
}
return position;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Thales.
* Copyright (c) 2021 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down
Loading

0 comments on commit e323079

Please sign in to comment.