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 Feb 26, 2021
1 parent 9427bd4 commit 5813dcf
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 64 deletions.
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 Down Expand Up @@ -30,7 +30,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 +47,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 +90,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);
IncrementalLayoutConvertedDiagram convertedDiagram = this.incrementalLayoutDiagramConverter.convert(newDiagram);
DiagramLayoutData diagramLayoutData = convertedDiagram.getDiagramLayoutData();
new IncrementalLayoutEngine(optionalMoveEvent, 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
@@ -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
@@ -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 Expand Up @@ -66,21 +66,27 @@ private void updateBottomRight(IContainerLayoutData container) {
maxHeight = Math.max(maxHeight, child.getPosition().getY() + child.getSize().getHeight());
}
if (maxWidth > width || maxHeight > height) {
container.setSize(Size.newSize().width(maxWidth).height(maxHeight).build());
container.setSize(Size.of(maxWidth, maxHeight));
if (container instanceof IConnectable) {
((IConnectable) container).setChanged(true);
}
}
}

private void shift(IContainerLayoutData container, double shiftX, double shiftY) {
container.setPosition(Position.newPosition().x(container.getPosition().getX() - shiftX).y(container.getPosition().getY() - shiftY).build());
container.setSize(Size.newSize().width(container.getSize().getWidth() + shiftX).height(container.getSize().getHeight() + shiftY).build());
double x = container.getPosition().getX() - shiftX;
double y = container.getPosition().getY() - shiftY;
double width = container.getSize().getWidth() + shiftX;
double height = container.getSize().getHeight() + shiftY;
container.setPosition(Position.at(x, y));
container.setSize(Size.of(width, height));
if (container instanceof IConnectable) {
((IConnectable) container).setChanged(true);
}
for (NodeLayoutData child : container.getChildrenNodes()) {
child.setPosition(Position.newPosition().x(child.getPosition().getX() + shiftX).y(child.getPosition().getY() + shiftY).build());
double childX = child.getPosition().getX() + shiftX;
double childY = child.getPosition().getY() + shiftY;
child.setPosition(Position.at(childX, childY));
}
}

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 5813dcf

Please sign in to comment.