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
3 changed files
with
116 additions
and
14 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
88 changes: 88 additions & 0 deletions
88
...nts-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/diagram/IdProvider.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,88 @@ | ||
/******************************************************************************* | ||
* 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 java.util.function.Function; | ||
|
||
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; | ||
|
||
/** | ||
* Set a detailed descriptionID. | ||
* | ||
* @author mcharfadi | ||
*/ | ||
@Service | ||
public class IdProvider { | ||
|
||
private static final String SIRIUS_PROTOCOL = "siriusComponents://"; | ||
|
||
private static final String SOURCE_KIND_VIEW = "?sourceKind=view"; | ||
|
||
private static final String DIAGRAM_PATH_VIEW = SIRIUS_PROTOCOL + "diagramDescription" + SOURCE_KIND_VIEW; | ||
|
||
private static final String EDGE_PATH_VIEW = SIRIUS_PROTOCOL + "edgeDescription" + SOURCE_KIND_VIEW; | ||
|
||
private static final String NODE_PATH_VIEW = SIRIUS_PROTOCOL + "nodeDescription" + SOURCE_KIND_VIEW; | ||
|
||
private static final String SOURCE_ID = "sourceId="; | ||
|
||
private static final String SOURCE_ELEMENT_ID = "sourceElementId="; | ||
|
||
private static final String AMPERSAND = "&"; | ||
|
||
private IObjectService objectService; | ||
|
||
public IdProvider(IObjectService objectService) { | ||
this.objectService = Objects.requireNonNull(objectService); | ||
} | ||
|
||
public String getId(DiagramDescription viewDiagramDescription) { | ||
String sourceId = this.getSourceIdFromElementDescription(viewDiagramDescription); | ||
String sourceElementId = this.objectService.getId(viewDiagramDescription); | ||
return this.getPath(viewDiagramDescription) + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId; | ||
} | ||
|
||
public String getIdElementDescription(DiagramElementDescription diagramElementDescription) { | ||
String sourceId = this.getSourceIdFromElementDescription(diagramElementDescription); | ||
String sourceElementId = this.objectService.getId(diagramElementDescription); | ||
return this.getPath(diagramElementDescription) + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId; | ||
} | ||
|
||
public Function<DiagramElementDescription, String> getIdElementDescription = (diagramElementDescription) -> { | ||
String sourceId = this.getSourceIdFromElementDescription(diagramElementDescription); | ||
String sourceElementId = this.objectService.getId(diagramElementDescription); | ||
return this.getPath(diagramElementDescription) + AMPERSAND + SOURCE_ID + sourceId + AMPERSAND + SOURCE_ELEMENT_ID + sourceElementId; | ||
}; | ||
|
||
private String getPath(EObject elementDescription) { | ||
if (elementDescription instanceof DiagramDescription) { | ||
return DIAGRAM_PATH_VIEW; | ||
} | ||
if (elementDescription instanceof org.eclipse.sirius.components.view.NodeDescription) { | ||
return NODE_PATH_VIEW; | ||
} | ||
if (elementDescription instanceof org.eclipse.sirius.components.view.EdgeDescription) { | ||
return EDGE_PATH_VIEW; | ||
} | ||
return SIRIUS_PROTOCOL; | ||
} | ||
|
||
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