forked from eclipse-sirius/sirius-web
-
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.
Bug : eclipse-sirius#1860 Signed-off-by: Michaël Charfadi <[email protected]>
- Loading branch information
Showing
9 changed files
with
172 additions
and
28 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
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
65 changes: 65 additions & 0 deletions
65
...-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/IIdDiagramProvider.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,65 @@ | ||
/******************************************************************************* | ||
* 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.view.emf.diagram; | ||
|
||
|
||
import org.eclipse.sirius.components.view.DiagramDescription; | ||
import org.eclipse.sirius.components.view.DiagramElementDescription; | ||
|
||
/** | ||
* Interface to provide ids for DiagramDescription & DiagramElementDescription. | ||
* | ||
* @author mcharfadi | ||
*/ | ||
public interface IIdDiagramProvider { | ||
|
||
String SIRIUS_PROTOCOL = "siriusComponents://"; | ||
|
||
String SOURCE_KIND_VIEW = "?sourceKind=view"; | ||
|
||
String DIAGRAM_PATH_VIEW = SIRIUS_PROTOCOL + "diagramDescription" + SOURCE_KIND_VIEW; | ||
|
||
String EDGE_PATH_VIEW = SIRIUS_PROTOCOL + "edgeDescription" + SOURCE_KIND_VIEW; | ||
|
||
String NODE_PATH_VIEW = SIRIUS_PROTOCOL + "nodeDescription" + SOURCE_KIND_VIEW; | ||
|
||
String SOURCE_ID = "sourceId="; | ||
|
||
String SOURCE_ELEMENT_ID = "sourceElementId="; | ||
|
||
String AMPERSAND = "&"; | ||
|
||
String getIdDiagramDescription(DiagramDescription diagramDescription); | ||
|
||
String getIdElementDescription(DiagramElementDescription diagramElementDescription); | ||
|
||
/** | ||
* Implementation which does nothing, used for mocks in unit tests. | ||
* | ||
* @author mcharfadi | ||
*/ | ||
class NoOp implements IIdDiagramProvider { | ||
|
||
@Override | ||
public String getIdDiagramDescription(DiagramDescription diagramDescription) { | ||
return ""; | ||
} | ||
|
||
@Override | ||
public String getIdElementDescription(DiagramElementDescription diagramElementDescription) { | ||
return ""; | ||
} | ||
|
||
} | ||
} | ||
|
62 changes: 62 additions & 0 deletions
62
...w-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/IdDiagramProvider.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,62 @@ | ||
/******************************************************************************* | ||
* 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.view.emf.diagram; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.sirius.components.core.api.IObjectService; | ||
import org.eclipse.sirius.components.view.DiagramDescription; | ||
import org.eclipse.sirius.components.view.DiagramElementDescription; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* descriptionID for DiagramDescription & DiagramElementDescription. | ||
* | ||
* @author mcharfadi | ||
*/ | ||
@Service | ||
public class IdDiagramProvider implements IIdDiagramProvider { | ||
private IObjectService objectService; | ||
|
||
public IdDiagramProvider(IObjectService objectService) { | ||
this.objectService = Objects.requireNonNull(objectService); | ||
} | ||
|
||
@Override | ||
public String getIdDiagramDescription(DiagramDescription diagramDescription) { | ||
String sourceId = this.getSourceIdFromElementDescription(diagramDescription); | ||
String sourceElementId = this.objectService.getId(diagramDescription); | ||
// System.out.println("sourceElementId"); | ||
// System.out.println(diagramDescription.getName()); | ||
// System.out.println(this.objectService.getId(diagramDescription)); | ||
return DIAGRAM_PATH_VIEW + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId; | ||
} | ||
|
||
@Override | ||
public String getIdElementDescription(DiagramElementDescription diagramElementDescription) { | ||
String sourceId = this.getSourceIdFromElementDescription(diagramElementDescription); | ||
String sourceElementId = this.objectService.getId(diagramElementDescription); | ||
if (diagramElementDescription instanceof org.eclipse.sirius.components.view.NodeDescription) { | ||
return NODE_PATH_VIEW + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId; | ||
} | ||
else { | ||
return EDGE_PATH_VIEW + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId; | ||
} | ||
} | ||
|
||
private String getSourceIdFromElementDescription(EObject elementDescription) { | ||
return elementDescription.eResource().getURI().toString().split("///")[1]; | ||
} | ||
|
||
} |
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.