forked from eclipse-syson/syson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[802] Handle imported package elements in diagrams
Bug: eclipse-syson#802 Signed-off-by: Jerome Gout <[email protected]>
- Loading branch information
1 parent
c9bbe6a
commit bba895d
Showing
51 changed files
with
2,604 additions
and
74 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
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
117 changes: 117 additions & 0 deletions
117
...tion/src/main/java/org/eclipse/syson/application/nodes/SysMLImportedPackageNodeStyle.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,117 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.syson.application.nodes; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.components.annotations.Immutable; | ||
import org.eclipse.sirius.components.diagrams.INodeStyle; | ||
import org.eclipse.sirius.components.diagrams.LineStyle; | ||
|
||
/** | ||
* The SysML imported package node style. This code has been fully inspired from {@link SysMLPackageNodeStyle}. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Immutable | ||
public final class SysMLImportedPackageNodeStyle implements INodeStyle { | ||
|
||
private String background; | ||
|
||
private String borderColor; | ||
|
||
private int borderSize; | ||
|
||
private LineStyle borderStyle; | ||
|
||
private SysMLImportedPackageNodeStyle() { | ||
// Prevent instantiation | ||
} | ||
|
||
public static Builder newSysMLImportedPackageNodeStyle() { | ||
return new Builder(); | ||
} | ||
|
||
public String getBackground() { | ||
return this.background; | ||
} | ||
|
||
public String getBorderColor() { | ||
return this.borderColor; | ||
} | ||
|
||
public int getBorderSize() { | ||
return this.borderSize; | ||
} | ||
|
||
public LineStyle getBorderStyle() { | ||
return this.borderStyle; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{'color: {1}, border: '{' background: {2}, size: {3}, style: {4} '}''}'"; | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.background, this.borderColor, this.borderSize, this.borderStyle); | ||
} | ||
|
||
/** | ||
* The builder used to create the imported package node style. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@SuppressWarnings("checkstyle:HiddenField") | ||
public static final class Builder { | ||
|
||
private String background; | ||
|
||
private String borderColor; | ||
|
||
private int borderSize; | ||
|
||
private LineStyle borderStyle; | ||
|
||
private Builder() { | ||
// Prevent instantiation | ||
} | ||
|
||
public Builder background(String background) { | ||
this.background = Objects.requireNonNull(background); | ||
return this; | ||
} | ||
|
||
public Builder borderColor(String borderColor) { | ||
this.borderColor = Objects.requireNonNull(borderColor); | ||
return this; | ||
} | ||
|
||
public Builder borderSize(int borderSize) { | ||
this.borderSize = borderSize; | ||
return this; | ||
} | ||
|
||
public Builder borderStyle(LineStyle borderStyle) { | ||
this.borderStyle = Objects.requireNonNull(borderStyle); | ||
return this; | ||
} | ||
|
||
public SysMLImportedPackageNodeStyle build() { | ||
SysMLImportedPackageNodeStyle nodeStyleDescription = new SysMLImportedPackageNodeStyle(); | ||
nodeStyleDescription.background = Objects.requireNonNull(this.background); | ||
nodeStyleDescription.borderColor = Objects.requireNonNull(this.borderColor); | ||
nodeStyleDescription.borderSize = this.borderSize; | ||
nodeStyleDescription.borderStyle = Objects.requireNonNull(this.borderStyle); | ||
return nodeStyleDescription; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
.../main/java/org/eclipse/syson/application/nodes/SysMLImportedPackageNodeStyleProvider.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,66 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 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.syson.application.nodes; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.sirius.components.diagrams.INodeStyle; | ||
import org.eclipse.sirius.components.diagrams.LineStyle; | ||
import org.eclipse.sirius.components.view.FixedColor; | ||
import org.eclipse.sirius.components.view.diagram.NodeStyleDescription; | ||
import org.eclipse.sirius.components.view.emf.diagram.INodeStyleProvider; | ||
import org.eclipse.syson.sysmlcustomnodes.SysMLImportedPackageNodeStyleDescription; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* This class provides style information for the imported package custom node. | ||
* This code has been fully inspired from {@link SysMLPackageNodeStyleProvider}. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Service | ||
public class SysMLImportedPackageNodeStyleProvider implements INodeStyleProvider { | ||
|
||
public static final String NODE_SYSML_IMPORTED_PACKAGE = "customnode:sysmlimportedpackage"; | ||
|
||
@Override | ||
public Optional<String> getNodeType(NodeStyleDescription nodeStyle) { | ||
if (nodeStyle instanceof SysMLImportedPackageNodeStyleDescription) { | ||
return Optional.of(NODE_SYSML_IMPORTED_PACKAGE); | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<INodeStyle> createNodeStyle(NodeStyleDescription nodeStyle, Optional<String> optionalEditingContextId) { | ||
Optional<INodeStyle> iNodeStyle = Optional.empty(); | ||
Optional<String> nodeType = this.getNodeType(nodeStyle); | ||
if (nodeType.isPresent()) { | ||
return Optional.of(SysMLImportedPackageNodeStyle.newSysMLImportedPackageNodeStyle() | ||
.background(Optional.ofNullable(((SysMLImportedPackageNodeStyleDescription) nodeStyle).getBackground()) | ||
.filter(FixedColor.class::isInstance) | ||
.map(FixedColor.class::cast) | ||
.map(FixedColor::getValue) | ||
.orElse("transparent")) | ||
.borderColor(Optional.ofNullable(nodeStyle.getBorderColor()) | ||
.filter(FixedColor.class::isInstance) | ||
.map(FixedColor.class::cast) | ||
.map(FixedColor::getValue) | ||
.orElse("black")) | ||
.borderSize(nodeStyle.getBorderSize()) | ||
.borderStyle(LineStyle.valueOf(nodeStyle.getBorderLineStyle().getLiteral())).build()); | ||
} | ||
|
||
return iNodeStyle; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.