-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1139] Hard code a pseudo "semantic browser" in the default rules for…
… testing Bug: #1139 Signed-off-by: Pierre-Charles David <[email protected]>
- Loading branch information
Showing
2 changed files
with
212 additions
and
0 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
194 changes: 194 additions & 0 deletions
194
...se/sirius/components/emf/compatibility/properties/SemanticBrowserDescriptionProvider.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,194 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 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.emf.compatibility.properties; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.EStructuralFeature.Setting; | ||
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; | ||
import org.eclipse.sirius.components.compatibility.forms.WidgetIdProvider; | ||
import org.eclipse.sirius.components.core.api.IObjectService; | ||
import org.eclipse.sirius.components.emf.compatibility.properties.api.IPropertiesValidationProvider; | ||
import org.eclipse.sirius.components.forms.TreeNode; | ||
import org.eclipse.sirius.components.forms.description.TreeDescription; | ||
import org.eclipse.sirius.components.representations.VariableManager; | ||
|
||
/** | ||
* Provides a tree widget description with incoming, current and outgoing trees. | ||
* | ||
* @author pcdavid | ||
*/ | ||
public class SemanticBrowserDescriptionProvider { | ||
public static final String CANDIDATE_VARIABLE = "candidate"; //$NON-NLS-1$ | ||
|
||
private static final String SEMANTIC_BROWSER = "semantic_browser"; //$NON-NLS-1$ | ||
|
||
private static final String CATEGORY_INCOMING = "Incoming"; //$NON-NLS-1$ | ||
|
||
private static final String CATEGORY_CURRENT = "Current"; //$NON-NLS-1$ | ||
|
||
private static final String CATEGORY_OUTGOING = "Outgoing"; //$NON-NLS-1$ | ||
|
||
private final IObjectService objectService; | ||
|
||
private final IPropertiesValidationProvider propertiesValidationProvider; | ||
|
||
public SemanticBrowserDescriptionProvider(IObjectService objectService, IPropertiesValidationProvider propertiesValidationProvider) { | ||
this.objectService = objectService; | ||
this.propertiesValidationProvider = propertiesValidationProvider; | ||
} | ||
|
||
private String getNodeId(VariableManager variableManager) { | ||
String result = ""; //$NON-NLS-1$ | ||
Optional<Object> optionalCandidate = variableManager.get(CANDIDATE_VARIABLE, Object.class); | ||
if (optionalCandidate.isPresent()) { | ||
Object candidate = optionalCandidate.get(); | ||
result = this.objectService.getId(candidate); | ||
} | ||
return result; | ||
} | ||
|
||
private String getNodeLabel(VariableManager variableManager) { | ||
String result = ""; //$NON-NLS-1$ | ||
Optional<Object> optionalCandidate = variableManager.get(CANDIDATE_VARIABLE, Object.class); | ||
if (optionalCandidate.isPresent()) { | ||
Object candidate = optionalCandidate.get(); | ||
result = this.objectService.getLabel(candidate); | ||
} | ||
return result; | ||
} | ||
|
||
private String getNodeImageURL(VariableManager variableManager) { | ||
String result = ""; //$NON-NLS-1$ | ||
Optional<Object> optionalCandidate = variableManager.get(CANDIDATE_VARIABLE, Object.class); | ||
if (optionalCandidate.isPresent()) { | ||
Object candidate = optionalCandidate.get(); | ||
result = this.objectService.getImagePath(candidate); | ||
} | ||
return result; | ||
} | ||
|
||
private String getNodeKind(VariableManager variableManager) { | ||
String result = ""; //$NON-NLS-1$ | ||
Optional<Object> optionalCandidate = variableManager.get(CANDIDATE_VARIABLE, Object.class); | ||
if (optionalCandidate.isPresent()) { | ||
Object candidate = optionalCandidate.get(); | ||
result = this.objectService.getKind(candidate); | ||
} | ||
return result; | ||
} | ||
|
||
private List<?> getContents(VariableManager variableManager) { | ||
List<?> result = List.of(); | ||
Optional<EObject> optionalCandidate = variableManager.get(CANDIDATE_VARIABLE, EObject.class); | ||
if (optionalCandidate.isPresent()) { | ||
EObject candidate = optionalCandidate.get(); | ||
result = candidate.eContents(); | ||
} | ||
return result; | ||
} | ||
|
||
private List<?> getOutgoing(VariableManager variableManager) { | ||
List<?> result = List.of(); | ||
Optional<EObject> optionalSelf = variableManager.get(VariableManager.SELF, EObject.class); | ||
Optional<EObject> optionalCandidate = variableManager.get(CANDIDATE_VARIABLE, EObject.class); | ||
if (optionalCandidate.isPresent() && optionalCandidate.equals(optionalSelf)) { | ||
EObject candidate = optionalCandidate.get(); | ||
result = candidate.eCrossReferences(); | ||
} | ||
return result; | ||
} | ||
|
||
private List<?> getIncoming(VariableManager variableManager) { | ||
List<?> result = List.of(); | ||
Optional<EObject> optionalSelf = variableManager.get(VariableManager.SELF, EObject.class); | ||
Optional<EObject> optionalCandidate = variableManager.get(CANDIDATE_VARIABLE, EObject.class); | ||
if (optionalCandidate.isPresent() && optionalCandidate.equals(optionalSelf)) { | ||
EObject candidate = optionalCandidate.get(); | ||
ECrossReferenceAdapter xref = ECrossReferenceAdapter.getCrossReferenceAdapter(candidate); | ||
if (xref != null) { | ||
result = xref.getInverseReferences(candidate).stream().map(Setting::getEObject).collect(Collectors.toList()); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public TreeDescription getCurrentTreeDescription() { | ||
// @formatter:off | ||
return TreeDescription.newTreeDescription(SEMANTIC_BROWSER + CATEGORY_CURRENT).idProvider(new WidgetIdProvider()) | ||
.diagnosticsProvider(this.propertiesValidationProvider.getDiagnosticsProvider()) | ||
.kindProvider(this.propertiesValidationProvider.getKindProvider()) | ||
.messageProvider(this.propertiesValidationProvider.getMessageProvider()) | ||
.labelProvider(variableManager -> CATEGORY_CURRENT) | ||
.nodeIdProvider(this::getNodeId) | ||
.nodeLabelProvider(this::getNodeLabel) | ||
.nodeImageURLProvider(this::getNodeImageURL) | ||
.nodeKindProvider(this::getNodeKind) | ||
.nodeSelectableProvider(variableManager -> true) | ||
.childrenProvider(this::getContents) | ||
.expandedNodeIdsProvider(this::getAllNodeIds) | ||
.build(); | ||
// @formatter:on | ||
} | ||
|
||
private List<String> getAllNodeIds(VariableManager variableManager) { | ||
List<String> result = new ArrayList<>(); | ||
for (var element : variableManager.get("nodes", List.class).orElse(List.of())) { //$NON-NLS-1$ | ||
if (element instanceof TreeNode) { | ||
TreeNode node = (TreeNode) element; | ||
result.add(node.getId()); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public TreeDescription getOutgoingTreeDescription() { | ||
// @formatter:off | ||
return TreeDescription.newTreeDescription(SEMANTIC_BROWSER + CATEGORY_OUTGOING).idProvider(new WidgetIdProvider()) | ||
.diagnosticsProvider(this.propertiesValidationProvider.getDiagnosticsProvider()) | ||
.kindProvider(this.propertiesValidationProvider.getKindProvider()) | ||
.messageProvider(this.propertiesValidationProvider.getMessageProvider()) | ||
.labelProvider(variableManager -> CATEGORY_OUTGOING) | ||
.nodeIdProvider(this::getNodeId) | ||
.nodeLabelProvider(this::getNodeLabel) | ||
.nodeImageURLProvider(this::getNodeImageURL) | ||
.nodeKindProvider(this::getNodeKind) | ||
.nodeSelectableProvider(variableManager -> true) | ||
.childrenProvider(this::getOutgoing) | ||
.expandedNodeIdsProvider(this::getAllNodeIds) | ||
.build(); | ||
// @formatter:on | ||
} | ||
|
||
public TreeDescription getIncomingTreeDescription() { | ||
// @formatter:off | ||
return TreeDescription.newTreeDescription(SEMANTIC_BROWSER + CATEGORY_INCOMING).idProvider(new WidgetIdProvider()) | ||
.diagnosticsProvider(this.propertiesValidationProvider.getDiagnosticsProvider()) | ||
.kindProvider(this.propertiesValidationProvider.getKindProvider()) | ||
.messageProvider(this.propertiesValidationProvider.getMessageProvider()) | ||
.labelProvider(variableManager -> CATEGORY_INCOMING) | ||
.nodeIdProvider(this::getNodeId) | ||
.nodeLabelProvider(this::getNodeLabel) | ||
.nodeImageURLProvider(this::getNodeImageURL) | ||
.nodeKindProvider(this::getNodeKind) | ||
.nodeSelectableProvider(variableManager -> true) | ||
.childrenProvider(this::getIncoming) | ||
.expandedNodeIdsProvider(this::getAllNodeIds) | ||
.build(); | ||
// @formatter:on | ||
} | ||
} |