Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new API is only used for diagrams whose name ends with `__EXPERIMENTAL` for now, and the provided implementation does nothing for the moment. Bug: #1527 Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
- Loading branch information
Showing
4 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...src/main/java/org/eclipse/sirius/components/diagrams/layout/api/IDiagramLayoutEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.diagrams.layout.api; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.diagrams.Diagram; | ||
import org.eclipse.sirius.components.diagrams.events.IDiagramEvent; | ||
import org.eclipse.sirius.components.diagrams.layoutdata.DiagramLayoutData; | ||
|
||
/** | ||
* Used to layout diagrams. | ||
* | ||
* @author pcdavid | ||
*/ | ||
public interface IDiagramLayoutEngine { | ||
/** | ||
* Computes the new layout to be used for a diagram and its content. | ||
* | ||
* @param editingContext | ||
* the editing context. | ||
* @param diagram | ||
* the diagram's structure (nodes, edges, etc.). | ||
* @param previousLayoutData | ||
* the layout data from the previous version of the diagram. This may be empty for the initial layout or | ||
* for a "full" layout. | ||
* @param optionalEvent | ||
* if the (incremental) layout was triggered by a user operation (e.g. the invocation of a tool at a | ||
* specific position) the corresponding event with the information relevant for the layout will be | ||
* available here. | ||
* @return the layout information to be used for the new version of the diagram. | ||
*/ | ||
DiagramLayoutData layout(IEditingContext editingContext, Diagram diagram, DiagramLayoutData previousLayoutData, Optional<IDiagramEvent> optionalDiagramEvent); | ||
|
||
/** | ||
* Implementation which does nothing, used for mocks in unit tests. | ||
* | ||
* @author pcdavid | ||
*/ | ||
class NoOp implements IDiagramLayoutEngine { | ||
|
||
@Override | ||
public DiagramLayoutData layout(IEditingContext editingContext, Diagram diagram, DiagramLayoutData previousLayoutData, Optional<IDiagramEvent> optionalDiagramEvent) { | ||
return Optional.ofNullable(previousLayoutData).orElse(new DiagramLayoutData(Map.of(), Map.of(), Map.of())); | ||
} | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../java/org/eclipse/sirius/components/diagrams/layout/experimental/DiagramLayoutEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Obeo. | ||
* 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.diagrams.layout.experimental; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.components.diagrams.Diagram; | ||
import org.eclipse.sirius.components.diagrams.events.IDiagramEvent; | ||
import org.eclipse.sirius.components.diagrams.layout.api.IDiagramLayoutEngine; | ||
import org.eclipse.sirius.components.diagrams.layoutdata.DiagramLayoutData; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* The default {@link IDiagramLayoutEngine}. Empty/no-op for now. | ||
* | ||
* @author pcdavid | ||
*/ | ||
@Service | ||
public class DiagramLayoutEngine implements IDiagramLayoutEngine { | ||
@Override | ||
public DiagramLayoutData layout(IEditingContext editingContext, Diagram diagram, DiagramLayoutData previousLayoutData, Optional<IDiagramEvent> optionalDiagramEvent) { | ||
return new DiagramLayoutData(Map.of(), Map.of(), Map.of()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters